[Pkg-javascript-commits] [leaflet-markercluster] 10/219: Add ability to use a function for maxClusterRadius
Jonas Smedegaard
dr at jones.dk
Sat May 7 09:39:06 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository leaflet-markercluster.
commit 9381d3ea9200a881a007dcfee94c31ecb977bb51
Author: Ken Schwencke <schwank at gmail.com>
Date: Sat Jan 4 15:26:04 2014 -0800
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.
---
src/MarkerClusterGroup.js | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index 7f8f0fb..2218583 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -1,4 +1,3 @@
-
/*
* L.MarkerClusterGroup extends L.FeatureGroup by clustering the markers contained within
*/
@@ -696,7 +695,17 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
_generateInitialClusters: function () {
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) {
maxZoom = this.options.disableClusteringAtZoom - 1;
@@ -704,12 +713,12 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
this._maxZoom = maxZoom;
this._gridClusters = {};
this._gridUnclustered = {};
-
- //Set up DistanceGrids for each zoom
- for (var zoom = maxZoom; zoom >= 0; zoom--) {
- this._gridClusters[zoom] = new L.DistanceGrid(radius);
- this._gridUnclustered[zoom] = new L.DistanceGrid(radius);
- }
+
+ //Set up DistanceGrids for each zoom
+ for (var zoom = maxZoom; zoom >= 0; zoom--) {
+ this._gridClusters[zoom] = new L.DistanceGrid(radiusFunction(zoom));
+ this._gridUnclustered[zoom] = new L.DistanceGrid(radiusFunction(zoom));
+ }
this._topClusterLevel = new L.MarkerCluster(this, -1);
},
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/leaflet-markercluster.git
More information about the Pkg-javascript-commits
mailing list