Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ function getClusterProperties(cluster) {

// longitude/latitude to spherical mercator in [0..1] range
function lngX(lng) {
return lng / 360 + 0.5;
return lng / 360 + 0.5 + (lng > 180 || lng < -180 ? -Math.sign(lng) : 0);
Copy link
Member

Choose a reason for hiding this comment

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

A slightly simpler / more reliable way to wrap the value:

Suggested change
return lng / 360 + 0.5 + (lng > 180 || lng < -180 ? -Math.sign(lng) : 0);
return ((lng / 360 + 0.5) % 1 + 1) % 1;

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the tip on the alternative math. I tested it and unfortunately, it breaks the tests.

With the suggested approach, the returned values from lngX are different from the values from the first solution at their ~14-15 decimal digit, which causes the tests to fail. So I kept the original solution for now.

I've also added a test for this change in 99c877f.

Copy link
Author

Choose a reason for hiding this comment

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

@mourner just a quick follow-up on this PR to see if there are any other changes you'd like me to include. :)

}
function latY(lat) {
const sin = Math.sin(lat * Math.PI / 180);
Expand Down