From 7eaef8530af3c5dac9f23c188f3bdae1cf26a926 Mon Sep 17 00:00:00 2001 From: danzel Date: Wed, 17 Oct 2012 09:49:35 +1300 Subject: [PATCH] Replace _getExpandedVisibleBounds with lat/lng diff implementation as provided by andersarstrand in #74. Should improve behaviour with custom projections --- src/MarkerClusterGroup.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js index ac806653b..cf4434b65 100644 --- a/src/MarkerClusterGroup.js +++ b/src/MarkerClusterGroup.js @@ -589,13 +589,15 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ //Gets the maps visible bounds expanded in each direction by the size of the screen (so the user cannot see an area we do not cover in one pan) _getExpandedVisibleBounds: function () { var map = this._map, - bounds = map.getPixelBounds(), - width = L.Browser.mobile ? 0 : Math.abs(bounds.max.x - bounds.min.x), - height = L.Browser.mobile ? 0 : Math.abs(bounds.max.y - bounds.min.y), - sw = map.unproject(new L.Point(bounds.min.x - width, bounds.min.y - height)), - ne = map.unproject(new L.Point(bounds.max.x + width, bounds.max.y + height)); + bounds = map.getBounds(), + sw = bounds._southWest, + ne = bounds._northEast, + latDiff = L.Browser.mobile ? 0 : Math.abs(sw.lat - ne.lat), + lngDiff = L.Browser.mobile ? 0 : Math.abs(sw.lng - ne.lng); - return new L.LatLngBounds(sw, ne); + return new L.LatLngBounds( + new L.LatLng(sw.lat - latDiff, sw.lng - lngDiff, true), + new L.LatLng(ne.lat + latDiff, ne.lng + lngDiff, true)); }, //Shared animation code