mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-28 00:24:21 +02:00
Working towards fixing adding/removing. Think I'm going to have to bite the bullet and tree this up harder.
This commit is contained in:
+29
-3
@@ -85,7 +85,7 @@ L.MarkerCluster = L.Marker.extend({
|
||||
for (i = markers.length - 1; i >= 0; i--) {
|
||||
if (markers[i] == layer) {
|
||||
markers.splice(i, 1);
|
||||
//TODO? Recalculate bounds
|
||||
this._recalculateBounds();
|
||||
|
||||
this._childCount--;
|
||||
if (this._icon) {
|
||||
@@ -97,9 +97,17 @@ L.MarkerCluster = L.Marker.extend({
|
||||
|
||||
//Otherwise check our childClusters
|
||||
for (i = childClusters.length - 1; i >= 0; i--) {
|
||||
if (childClusters[i]._recursivelyRemoveChildMarker(layer)) {
|
||||
var child = childClusters[i];
|
||||
if (child._recursivelyRemoveChildMarker(layer)) {
|
||||
this._childCount--;
|
||||
//TODO? Recalculate bounds
|
||||
|
||||
//if our child cluster is no longer a cluster, remove it and replace with just the marker
|
||||
if (child._childCount === 1) {
|
||||
markers.push(child._markers[0]);
|
||||
childClusters.splice(i, 1);
|
||||
}
|
||||
|
||||
this._recalculateBounds();
|
||||
|
||||
if (this._icon) {
|
||||
this.setIcon(this._group.options.iconCreateFunction(this._childCount));
|
||||
@@ -231,6 +239,24 @@ L.MarkerCluster = L.Marker.extend({
|
||||
}
|
||||
},
|
||||
|
||||
_recalculateBounds: function () {
|
||||
var markers = this._markers,
|
||||
childClusters = this._childClusters,
|
||||
i;
|
||||
|
||||
this._bounds = new L.LatLngBounds();
|
||||
|
||||
for (i = markers.length - 1; i >= 0; i--) {
|
||||
this._bounds.extend(markers[i].getLatLng());
|
||||
}
|
||||
for (i = childClusters.length - 1; i >= 0; i--) {
|
||||
this._bounds.extend(childClusters[i]._bounds);
|
||||
}
|
||||
|
||||
this.setLatLng(this._bounds.getCenter());
|
||||
},
|
||||
|
||||
|
||||
//Returns true if we are the parent of only one cluster and that cluster is the same as us
|
||||
_isSingleParent: function () {
|
||||
//Don't need to check this._markers as the rest won't work if there are any
|
||||
|
||||
@@ -235,7 +235,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
|
||||
if (c._childCount == 1) {
|
||||
//Remove cluster and add individual marker
|
||||
L.FeatureGroup.prototype.removeLayer.call(this, c);
|
||||
var marker = c.getAllChildMarkers()[0];
|
||||
var marker = c._markers[0];
|
||||
L.FeatureGroup.prototype.addLayer.call(this, marker);
|
||||
current.unclustered.push(marker);
|
||||
current.clusters.splice(i, 1);
|
||||
|
||||
Reference in New Issue
Block a user