Normalize longitude to the range between -180 to +180 degrees (#3872)

* normalize longitude to the range between -180 to +180 degrees

* only normalize longitude if out of valid range
This commit is contained in:
Malte Franken 2019-10-07 18:49:00 +11:00 committed by Bram Kragten
parent efb28d337a
commit 7494a49238

View File

@ -77,7 +77,12 @@ class LocationEditor extends LitElement {
}
private _updateLocation(latlng: LatLng) {
this.location = this._ignoreFitToMap = [latlng.lat, latlng.lng];
let longitude = latlng.lng;
if (Math.abs(longitude) > 180.0) {
// Normalize longitude if map provides values beyond -180 to +180 degrees.
longitude = (((longitude % 360.0) + 540.0) % 360.0) - 180.0;
}
this.location = this._ignoreFitToMap = [latlng.lat, longitude];
fireEvent(this, "change", undefined, { bubbles: false });
}