Fix incorrectly adding parent clusters when doing a big move that changes zoom levels. Fixes #281

This commit is contained in:
danzel
2013-12-06 13:34:43 +13:00
parent 432cd19403
commit 53eab49a7e
2 changed files with 33 additions and 3 deletions
+32 -2
View File
@@ -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);
});
});
+1 -1
View File
@@ -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;