Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Oct 7, 2019

Conversation

exxamalte
Copy link
Contributor

Fixes #3793
Fixes home-assistant/core#26057

When fully zooming out of the map in the general configuration section, you will see multiple "versions" of the world's surface. When selecting a position outside the central version of the map, the longitude value will be smaller than -180º or greater than +180º which is wrong and won't be accepted by the HA backend's validator.

This change normalizes the longitude value received by the map.

The long form of the normalization would be to keep adding 360 to the value while it is smaller than -180º, or subtract 360 from the value while it is greater than +180º. The proposed code yields the same result in a single line.

@@ -77,7 +77,9 @@ class LocationEditor extends LitElement {
}

private _updateLocation(latlng: LatLng) {
this.location = this._ignoreFitToMap = [latlng.lat, latlng.lng];
// Normalize longitude if map provides values beyond -180 to +180 degrees.
const longitude = (((latlng.lng % 360.0) + 540.0) % 360.0) - 180.0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we only do this is the longitude is beyond -180 to +180?

if (Math.abs(latlng.lng) > 180) {
   ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll add that.

@bramkragten bramkragten merged commit 7494a49 into home-assistant:dev Oct 7, 2019
@exxamalte exxamalte deleted the fix-location-editor branch October 7, 2019 09:47
@github-actions github-actions bot locked and limited conversation to collaborators Jul 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Save location sometimes fails Cannot Save location using map in General Config if scrolling west
4 participants