Skip to content

Commit

Permalink
make LngLat.toBounds return a LngLatBounds object not a LngLatBoundsL…
Browse files Browse the repository at this point in the history
…ike object
  • Loading branch information
andrewharvey committed Dec 13, 2016
1 parent 7d862a4 commit 96d2bfe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions js/geo/lng_lat.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,21 @@ class LngLat {
}

/**
* Returns a `LngLatBoundsLike` from the coordinates extended by a given `radius`.
* Returns a `LngLatBounds` from the coordinates extended by a given `radius`.
*
* @param {number} radius Distance in meters from the coordinates to extend the bounds.
* @returns {LngLatBoundsLike} A new `LngLatBoundsLike` object representing the coordinates extended by the `radius`.
* @returns {LngLatBounds} A new `LngLatBounds` object representing the coordinates extended by the `radius`.
* @example
* var ll = new mapboxgl.LngLat(-73.9749, 40.7736);
* ll.toBounds(100); // = [[-73.97501862141328, 40.77351016847229], [-73.97478137858673, 40.77368983152771]]
* ll.toBounds(100).toArray(); // = [[-73.97501862141328, 40.77351016847229], [-73.97478137858673, 40.77368983152771]]
*/
toBounds(radius) {
const latAccuracy = 360 * radius / 40075017,
lngAccuracy = latAccuracy / Math.cos((Math.PI / 180) * this.lat);

// returning a LngLatBounds object is troublesome due to the circular dependency hence a simple LngLatBoundsLike object is used
return [ [this.lng - lngAccuracy, this.lat - latAccuracy],
[this.lng + lngAccuracy, this.lat + latAccuracy] ];
const LngLatBounds = require('./lng_lat_bounds');
return new LngLatBounds(new LngLat(this.lng - lngAccuracy, this.lat - latAccuracy),
new LngLat(this.lng + lngAccuracy, this.lat + latAccuracy));
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/js/geo/lng_lat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ test('LngLat', (t) => {
});

t.test('#toBounds', (t) => {
t.deepEqual(new LngLat(0, 0).toBounds(10), [[-0.00008983152770714982, -0.00008983152770714982], [0.00008983152770714982, 0.00008983152770714982]]);
t.deepEqual(new LngLat(-73.9749, 40.7736).toBounds(10), [[-73.97501862141328, 40.77351016847229], [-73.97478137858673, 40.77368983152771]]);
t.deepEqual(new LngLat(0, 0).toBounds(10).toArray(), [[-0.00008983152770714982, -0.00008983152770714982], [0.00008983152770714982, 0.00008983152770714982]]);
t.deepEqual(new LngLat(-73.9749, 40.7736).toBounds(10).toArray(), [[-73.97501862141328, 40.77351016847229], [-73.97478137858673, 40.77368983152771]]);
t.end();
});

Expand Down

0 comments on commit 96d2bfe

Please sign in to comment.