mirror of
https://github.com/stylersnico/librenms.git
synced 2026-08-03 00:11:49 +02:00
Add ability to use a function for maxClusterRadius
I find it's necessary to use a different radius at different zoom levels. This patch lets you continue to use a single number for all zoom levels, but also lets you use a function to vary the radius for each zoom level.
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* L.MarkerClusterGroup extends L.FeatureGroup by clustering the markers contained within
|
* L.MarkerClusterGroup extends L.FeatureGroup by clustering the markers contained within
|
||||||
*/
|
*/
|
||||||
@@ -696,7 +695,17 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
|
|||||||
|
|
||||||
_generateInitialClusters: function () {
|
_generateInitialClusters: function () {
|
||||||
var maxZoom = this._map.getMaxZoom(),
|
var maxZoom = this._map.getMaxZoom(),
|
||||||
radius = this.options.maxClusterRadius;
|
radius = this.options.maxClusterRadius,
|
||||||
|
radiusFunction = null;
|
||||||
|
|
||||||
|
//If we just set maxClusterRadius to a single number, we need to create
|
||||||
|
//a simple function to return that number. Otherwise, we just have to
|
||||||
|
//use the function we've passed in.
|
||||||
|
if(typeof radius == "number") {
|
||||||
|
radiusFunction = function(){ return radius };
|
||||||
|
} else if(typeof radius == "function") {
|
||||||
|
radiusFunction = radius;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.options.disableClusteringAtZoom) {
|
if (this.options.disableClusteringAtZoom) {
|
||||||
maxZoom = this.options.disableClusteringAtZoom - 1;
|
maxZoom = this.options.disableClusteringAtZoom - 1;
|
||||||
@@ -705,11 +714,11 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
|
|||||||
this._gridClusters = {};
|
this._gridClusters = {};
|
||||||
this._gridUnclustered = {};
|
this._gridUnclustered = {};
|
||||||
|
|
||||||
//Set up DistanceGrids for each zoom
|
//Set up DistanceGrids for each zoom
|
||||||
for (var zoom = maxZoom; zoom >= 0; zoom--) {
|
for (var zoom = maxZoom; zoom >= 0; zoom--) {
|
||||||
this._gridClusters[zoom] = new L.DistanceGrid(radius);
|
this._gridClusters[zoom] = new L.DistanceGrid(radiusFunction(zoom));
|
||||||
this._gridUnclustered[zoom] = new L.DistanceGrid(radius);
|
this._gridUnclustered[zoom] = new L.DistanceGrid(radiusFunction(zoom));
|
||||||
}
|
}
|
||||||
|
|
||||||
this._topClusterLevel = new L.MarkerCluster(this, -1);
|
this._topClusterLevel = new L.MarkerCluster(this, -1);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user