diff --git a/index.js b/index.js index dc2601b..fef04c8 100644 --- a/index.js +++ b/index.js @@ -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); } function latY(lat) { const sin = Math.sin(lat * Math.PI / 180); diff --git a/test/test.js b/test/test.js index f48cc76..50a2cbf 100644 --- a/test/test.js +++ b/test/test.js @@ -187,3 +187,26 @@ test('makes sure unclustered point coords are not rounded', (t) => { t.end(); }); + +test('returns clusters when points are outside of -180 and 180 longitude range', (t) => { + const index = new Supercluster().load([ + { + type: 'Feature', + properties: null, + geometry: { + type: 'Point', + coordinates: [-190, 0] + } + }, { + type: 'Feature', + properties: null, + geometry: { + type: 'Point', + coordinates: [190, 0] + } + } + ]); + + t.equal(index.getClusters([-180, -90, 180, 90], 1).length, 2); + t.end(); +});