Skip to content

Commit

Permalink
[LngLat] toBounds - set default radius value to 0 (#7723)
Browse files Browse the repository at this point in the history
  • Loading branch information
cherniavskii authored and ansis committed Dec 20, 2018
1 parent 1f18b78 commit 2fe94c3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/geo/lng_lat.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ class LngLat {
/**
* Returns a `LngLatBounds` from the coordinates extended by a given `radius`.
*
* @param {number} radius Distance in meters from the coordinates to extend the bounds.
* @param {number} [radius=0] Distance in meters from the coordinates to extend the bounds.
* @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).toArray(); // = [[-73.97501862141328, 40.77351016847229], [-73.97478137858673, 40.77368983152771]]
*/
toBounds(radius: number) {
toBounds(radius?: number = 0) {
const earthCircumferenceInMetersAtEquator = 40075017;
const latAccuracy = 360 * radius / earthCircumferenceInMetersAtEquator,
lngAccuracy = latAccuracy / Math.cos((Math.PI / 180) * this.lat);
Expand Down
1 change: 1 addition & 0 deletions test/unit/geo/lng_lat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ test('LngLat', (t) => {
t.test('#toBounds', (t) => {
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.deepEqual(new LngLat(-73.9749, 40.7736).toBounds().toArray(), [[-73.9749, 40.7736], [-73.9749, 40.7736]]);
t.end();
});

Expand Down

0 comments on commit 2fe94c3

Please sign in to comment.