mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-28 08:02:41 +02:00
Fix addLayer (was broken since making everything in to a tree)
This commit is contained in:
+29
-5
@@ -81,9 +81,9 @@ L.MarkerCluster = L.Marker.extend({
|
||||
|
||||
//layer: The layer to try add
|
||||
//returns:
|
||||
// true: was able to put this marker in, but don't know its current visible parents position
|
||||
// true: was able to put this marker in, but don't know its current visible parents position (If returned externally, add this marker at its position)
|
||||
// false: wasn't able to put this marker in
|
||||
// a Marker/MarkerCluster: the visible parent of the marker (or the marker itself if it should be visible)
|
||||
// a MarkerCluster: the visible parent of the marker
|
||||
_recursivelyAddLayer: function (layer, zoom) {
|
||||
var result = false;
|
||||
|
||||
@@ -103,11 +103,37 @@ L.MarkerCluster = L.Marker.extend({
|
||||
if (!result && (this._canAcceptPosition(layer.getLatLng(), zoom) || this._zoom)) {
|
||||
|
||||
//Add to ourself instead
|
||||
result = this._group._clusterOne(this._markers, layer, zoom);
|
||||
result = this._group._clusterOne(this._markers, layer, zoom + 1);
|
||||
|
||||
if (result) {
|
||||
result._baseInit();
|
||||
this._childCount--;
|
||||
this._addChild(result);
|
||||
|
||||
//We may be above the zoom that these 2 markers would initially cluster at
|
||||
// so push the new cluster as deep as it can go
|
||||
var wantedZoom = this._group._map.getZoom() - 1,
|
||||
maxZoom = this._group._map.getMaxZoom(),
|
||||
newResult,
|
||||
finalResult = (zoom === wantedZoom) ? result : true;
|
||||
while (zoom < maxZoom) {
|
||||
zoom++;
|
||||
newResult = this._group._clusterOne([result._markers[0]], layer, zoom + 1);
|
||||
|
||||
if (newResult == null) {
|
||||
break;
|
||||
}
|
||||
newResult._baseInit();
|
||||
result._markers = [];
|
||||
result._childClusters.push(newResult);
|
||||
result = newResult;
|
||||
|
||||
if (zoom == wantedZoom) {
|
||||
finalResult = result;
|
||||
}
|
||||
}
|
||||
result = finalResult;
|
||||
|
||||
} else {
|
||||
this._addChild(layer);
|
||||
result = true;
|
||||
@@ -123,8 +149,6 @@ L.MarkerCluster = L.Marker.extend({
|
||||
if (result === true) {
|
||||
if (this._icon) {
|
||||
result = this;
|
||||
} else if ((this._markers.length > 0 && this._markers[0]._icon) || (this._childClusters.length > 1 && this._childClusters[0]._icon)) {
|
||||
result = layer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -257,9 +257,11 @@ L.MarkerClusterGroup.include(!L.DomUtil.TRANSITION ? {
|
||||
this._topClusterLevel._recursivelyAddChildrenToMap(null, newZoomLevel - this._topClusterLevel._zoom + 1, this._getExpandedVisibleBounds());
|
||||
},
|
||||
_animationAddLayer: function (layer, newCluster) {
|
||||
L.FeatureGroup.prototype.addLayer.call(this, layer);
|
||||
if (newCluster !== true && newCluster._childCount === 2) {
|
||||
newCluster._recursivelyRemoveChildrenFromMap(newCluster._bounds, 1);
|
||||
if (newCluster === true) {
|
||||
L.FeatureGroup.prototype.addLayer.call(this, layer);
|
||||
} else if (newCluster._childCount === 2) {
|
||||
newCluster._addToMap();
|
||||
newCluster._recursivelyRemoveChildrenFromMap(newCluster._bounds, this._map.getMaxZoom()); //getMaxZoom will always get all children
|
||||
}
|
||||
}
|
||||
} : {
|
||||
@@ -398,7 +400,7 @@ L.MarkerClusterGroup.include(!L.DomUtil.TRANSITION ? {
|
||||
this._forceLayout();
|
||||
|
||||
me._animationStart();
|
||||
me._animationZoomOutSingle(newCluster, 0, 1);
|
||||
me._animationZoomOutSingle(newCluster, 0, this._map.getMaxZoom());
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user