[Maps] handle extents that wrap globe (#29033) (#29108)

* [Maps] handle extents that wrap globe

* simplify logic
This commit is contained in:
Nathan Reese 2019-01-22 09:19:53 -07:00 committed by GitHub
parent 49d76ab813
commit 2b1b61765f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View file

@ -224,7 +224,8 @@ function formatEnvelopeAsPolygon({ maxLat, maxLon, minLat, minLon }) {
* Convert map bounds to polygon
*/
export function convertMapExtentToPolygon({ maxLat, maxLon, minLat, minLon }) {
if (maxLon > 180 && minLon < -180) {
const lonDelta = maxLon - minLon;
if (lonDelta >= 360) {
return formatEnvelopeAsPolygon({
maxLat,
maxLon: 180,

View file

@ -299,6 +299,21 @@ describe('convertMapExtentToPolygon', () => {
});
});
it('should clamp longitudes to -180 to 180 when bounds span entire globe (360)', () => {
const bounds = {
maxLat: 10,
maxLon: 170,
minLat: -10,
minLon: -400,
};
expect(convertMapExtentToPolygon(bounds)).toEqual({
"type": "polygon",
"coordinates": [
[[-180, 10], [-180, -10], [180, -10], [180, 10], [-180, 10]]
]
});
});
it('should handle bounds that cross dateline(east to west)', () => {
const bounds = {
maxLat: 10,