From 53eab49a7ecac32218c6d5e6dbba15ca7e80558b Mon Sep 17 00:00:00 2001 From: danzel Date: Fri, 6 Dec 2013 13:34:43 +1300 Subject: [PATCH] Fix incorrectly adding parent clusters when doing a big move that changes zoom levels. Fixes #281 --- spec/suites/zoomAnimationSpec.js | 34 ++++++++++++++++++++++++++++++-- src/MarkerClusterGroup.js | 2 +- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/spec/suites/zoomAnimationSpec.js b/spec/suites/zoomAnimationSpec.js index 7fb8e29e1..dbf60f9bc 100644 --- a/spec/suites/zoomAnimationSpec.js +++ b/spec/suites/zoomAnimationSpec.js @@ -16,7 +16,7 @@ document.body.removeChild(div); }); - it('adds the visible marker to the map', function () { + it('adds the visible marker to the map when zooming in', function () { map.setView(new L.LatLng(-37.36142550190516, 174.254150390625), 7); var markers = new L.MarkerClusterGroup({ @@ -39,7 +39,7 @@ expect(marker._icon).to.not.be(null); }); - it('adds the visible marker to the map', function () { + it('adds the visible marker to the map when jumping around', function () { var markers = new L.MarkerClusterGroup(); var marker1 = new L.Marker([48.858280181884766, 2.2945759296417236]); @@ -62,4 +62,34 @@ expect(marker2._icon).to.not.be(undefined); expect(marker2._icon).to.not.be(null); }); + + it('adds the visible markers to the map, but not parent clusters when jumping around', function () { + + var markers = new L.MarkerClusterGroup(), + marker1 = new L.Marker([59.9520, 30.3307]), + marker2 = new L.Marker([59.9516, 30.3308]), + marker3 = new L.Marker([59.9513, 30.3312]); + + markers.addLayer(marker1); + markers.addLayer(marker2); + markers.addLayer(marker3); + map.addLayer(markers); + + //Show none of them + map.setView([53.0676, 170.6835], 16); + + clock.tick(1000); + + //Zoom so that all the markers will be visible (Same as zoomToShowLayer) + map.setView(marker1.getLatLng(), 18); + + //Run the the animation + clock.tick(1000); + + //Now the markers should all be visible, and there should be no visible clusters + expect(marker1._icon.parentNode).to.be(map._panes.markerPane); + expect(marker2._icon.parentNode).to.be(map._panes.markerPane); + expect(marker3._icon.parentNode).to.be(map._panes.markerPane); + expect(map._panes.markerPane.childNodes.length).to.be(3); + }); }); \ No newline at end of file diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js index 5196ecb9f..cc8efdda0 100644 --- a/src/MarkerClusterGroup.js +++ b/src/MarkerClusterGroup.js @@ -656,7 +656,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ var newBounds = this._getExpandedVisibleBounds(); this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, this._zoom, newBounds); - this._topClusterLevel._recursivelyAddChildrenToMap(null, this._zoom, newBounds); + this._topClusterLevel._recursivelyAddChildrenToMap(null, this._map._zoom, newBounds); this._currentShownBounds = newBounds; return;