Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct unspiderfy vector #604

Merged
merged 4 commits into from
Nov 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion spec/suites/removeOutsideVisibleBoundsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ describe('Option removeOutsideVisibleBounds', function () {
var mapZoom = map.getZoom();

for (i = 0; i < markers.length; i++) {
markers[i].setLatLng(latLngs[i]);
try {
expect(markers[i].__parent._zoom).to.be.below(mapZoom);
} catch (e) {
Expand Down
47 changes: 30 additions & 17 deletions src/MarkerCluster.Spiderfier.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,21 +203,23 @@ L.MarkerCluster.include({
if (svg) {
legPath = leg._path;
legLength = legPath.getTotalLength() + 0.1; // Need a small extra length to avoid remaining dot in Firefox.
legPath.style.strokeDasharray = legLength + ' ' + legLength;
legPath.style.strokeDasharray = legLength; // Just 1 length is enough, it will be duplicated.
legPath.style.strokeDashoffset = legLength;
}

// If it is a marker, add it now and we'll animate it out
if (m.setOpacity) {
if (m.setZIndexOffset) {
m.setZIndexOffset(1000000); // Make normal markers appear on top of EVERYTHING
}
if (m.clusterHide) {
m.clusterHide();

fg.addLayer(m);
}

// Vectors just get immediately added
fg.addLayer(m);

if (m._setPos) {
m._setPos(thisLayerPos);
} else {
// Vectors just get immediately added
fg.addLayer(m);
}
}

Expand All @@ -233,7 +235,7 @@ L.MarkerCluster.include({
m._preSpiderfyLatlng = m._latlng;
m.setLatLng(newPos);

if (m.setOpacity) {
if (m.clusterShow) {
m.clusterShow();
}

Expand Down Expand Up @@ -261,7 +263,7 @@ L.MarkerCluster.include({
thisLayerPos = zoomDetails ? map._latLngToNewLayerPoint(this._latlng, zoomDetails.zoom, zoomDetails.center) : map.latLngToLayerPoint(this._latlng),
childMarkers = this.getAllChildMarkers(),
svg = L.Path.SVG,
m, i, leg, legPath, legLength;
m, i, leg, legPath, legLength, nonAnimatable;

group._animationStart();

Expand All @@ -278,11 +280,18 @@ L.MarkerCluster.include({
//Fix up the location to the real one
m.setLatLng(m._preSpiderfyLatlng);
delete m._preSpiderfyLatlng;

//Hack override the location to be our center
if (m.setOpacity) {
nonAnimatable = true;
if (m._setPos) {
m._setPos(thisLayerPos);
nonAnimatable = false;
}
if (m.clusterHide) {
m.clusterHide();
} else {
nonAnimatable = false;
}
if (nonAnimatable) {
fg.removeLayer(m);
}

Expand Down Expand Up @@ -314,9 +323,10 @@ L.MarkerCluster.include({
continue;
}


if (m.setOpacity) {
if (m.clusterShow) {
m.clusterShow();
}
if (m.setZIndexOffset) {
m.setZIndexOffset(0);
}

Expand Down Expand Up @@ -355,7 +365,6 @@ L.MarkerClusterGroup.include({
this._unspiderfy(); //Ensure that markers are back where they should be
},


//On zoom start we add a zoomanim handler so that we are guaranteed to be last (after markers are animated)
//This means we can define the animation they do rather than Markers doing an animation to their actual location
_unspiderfyZoomStart: function () {
Expand All @@ -365,6 +374,7 @@ L.MarkerClusterGroup.include({

this._map.on('zoomanim', this._unspiderfyZoomAnim, this);
},

_unspiderfyZoomAnim: function (zoomDetails) {
//Wait until the first zoomanim after the user has finished touch-zooming before running the animation
if (L.DomUtil.hasClass(this._map._mapPane, 'leaflet-touching')) {
Expand All @@ -375,7 +385,6 @@ L.MarkerClusterGroup.include({
this._unspiderfy(zoomDetails);
},


_unspiderfyWrapper: function () {
/// <summary>_unspiderfy but passes no arguments</summary>
this._unspiderfy();
Expand All @@ -398,9 +407,13 @@ L.MarkerClusterGroup.include({
if (layer._spiderLeg) {
this._featureGroup.removeLayer(layer);

layer.setOpacity(1);
if (layer.clusterShow) {
layer.clusterShow();
}
//Position will be fixed up immediately in _animationUnspiderfy
layer.setZIndexOffset(0);
if (layer.setZIndexOffset) {
layer.setZIndexOffset(0);
}

this._map.removeLayer(layer._spiderLeg);
delete layer._spiderLeg;
Expand Down