Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enhancement] check bounds before calling fitbounds (#1348)
Signed-off-by: Shan He <heshan0131@gmail.com>
- Loading branch information
1 parent
f046ac1
commit 7f3be27
Showing
4 changed files
with
53 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
function isLat(num) { | ||
return Number.isFinite(num) && num <= 90 && num >= -90; | ||
} | ||
function isLng(num) { | ||
return Number.isFinite(num) && num <= 180 && num >= -180; | ||
} | ||
|
||
/** | ||
* bounds should be [minLng, minLat, maxLng, maxLat] | ||
* @param {*} bounds | ||
*/ | ||
export function validateBounds(bounds) { | ||
// array: [ -180, -85.05112877980659, 180, 85.0511287798066 ] | ||
// validate bounds | ||
if ( | ||
Array.isArray(bounds) && | ||
bounds.length === 4 && | ||
[bounds[0], bounds[2]].every(isLng) && | ||
[bounds[1], bounds[3]].every(isLat) | ||
) { | ||
return bounds; | ||
} | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters