mirror of
https://github.com/stylersnico/librenms.git
synced 2026-08-02 00:32:09 +02:00
Implement generating new clusters as required when zooming down
This commit is contained in:
@@ -351,6 +351,10 @@ L.MarkerCluster = L.Marker.extend({
|
|||||||
//TODO: When zooming down we need to generate new clusters for levels that don't have them yet
|
//TODO: When zooming down we need to generate new clusters for levels that don't have them yet
|
||||||
|
|
||||||
if (depthToStartAt > 0) { //Still going down to required depth, just recurse to child clusters
|
if (depthToStartAt > 0) { //Still going down to required depth, just recurse to child clusters
|
||||||
|
if (!this._haveGeneratedChildClusters) {
|
||||||
|
this._generateChildClusters();
|
||||||
|
}
|
||||||
|
|
||||||
for (i = childClusters.length - 1; i >= 0; i--) {
|
for (i = childClusters.length - 1; i >= 0; i--) {
|
||||||
c = childClusters[i];
|
c = childClusters[i];
|
||||||
if (boundsToApplyTo.intersects(c._bounds)) {
|
if (boundsToApplyTo.intersects(c._bounds)) {
|
||||||
@@ -378,6 +382,33 @@ L.MarkerCluster = L.Marker.extend({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_generateChildClusters: function () {
|
||||||
|
var res = this._group._cluster(this._markers, this._zoomForCluster),
|
||||||
|
unclustered = res.unclustered,
|
||||||
|
clusters = res.clusters,
|
||||||
|
i;
|
||||||
|
|
||||||
|
var oldMarkers = this._markers;
|
||||||
|
var old = this._childCount;
|
||||||
|
|
||||||
|
this._markers = [];
|
||||||
|
this._childCount = 0;
|
||||||
|
|
||||||
|
for (i = unclustered.length - 1; i >= 0; i--) {
|
||||||
|
this._addChild(unclustered[i]);
|
||||||
|
}
|
||||||
|
for (i = clusters.length - 1; i >= 0; i--) {
|
||||||
|
this._addChild(clusters[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._childCount != old) {
|
||||||
|
debugger;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete this._zoomForCluster;
|
||||||
|
this._haveGeneratedChildClusters = true;
|
||||||
|
},
|
||||||
|
|
||||||
_recalculateBounds: function () {
|
_recalculateBounds: function () {
|
||||||
var markers = this._markers,
|
var markers = this._markers,
|
||||||
childClusters = this._childClusters,
|
childClusters = this._childClusters,
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
|
|||||||
//Takes a list of objects that have a 'getLatLng()' function (Marker / MarkerCluster)
|
//Takes a list of objects that have a 'getLatLng()' function (Marker / MarkerCluster)
|
||||||
//Performs clustering on them (using a greedy algorithm) and returns those clusters.
|
//Performs clustering on them (using a greedy algorithm) and returns those clusters.
|
||||||
//toCluster: List of Markers/MarkerClusters to cluster. MarkerClusters MUST be first in the list
|
//toCluster: List of Markers/MarkerClusters to cluster. MarkerClusters MUST be first in the list
|
||||||
//Returns FIXME TODO
|
//Returns { 'clusters': [new clusters], 'unclustered': [unclustered markers] }
|
||||||
_cluster: function (toCluster, zoom) {
|
_cluster: function (toCluster, zoom) {
|
||||||
var clusterRadiusSqrd = this.options.maxClusterRadius * this.options.maxClusterRadius,
|
var clusterRadiusSqrd = this.options.maxClusterRadius * this.options.maxClusterRadius,
|
||||||
clusters = [],
|
clusters = [],
|
||||||
@@ -213,6 +213,9 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
|
|||||||
var newCluster = this._clusterOne(unclustered, point);
|
var newCluster = this._clusterOne(unclustered, point);
|
||||||
if (newCluster) {
|
if (newCluster) {
|
||||||
newCluster._haveGeneratedChildClusters = hasChildClusters;
|
newCluster._haveGeneratedChildClusters = hasChildClusters;
|
||||||
|
if (!hasChildClusters) {
|
||||||
|
newCluster._zoomForCluster = zoom + 1;
|
||||||
|
}
|
||||||
newCluster._projCenter = this._map.project(newCluster.getLatLng(), zoom);
|
newCluster._projCenter = this._map.project(newCluster.getLatLng(), zoom);
|
||||||
clusters.push(newCluster);
|
clusters.push(newCluster);
|
||||||
} else {
|
} else {
|
||||||
@@ -229,6 +232,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
|
|||||||
|
|
||||||
if (c instanceof L.MarkerCluster) {
|
if (c instanceof L.MarkerCluster) {
|
||||||
var nc = new L.MarkerCluster(this, c);
|
var nc = new L.MarkerCluster(this, c);
|
||||||
|
nc._haveGeneratedChildClusters = true;
|
||||||
clusters.push(nc);
|
clusters.push(nc);
|
||||||
unclustered.splice(i, 1);
|
unclustered.splice(i, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user