From be25cefd9788aa2d2b46e0b2338400e1c75f4cb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4chler?= Date: Fri, 20 May 2016 15:38:26 +0200 Subject: [PATCH] #68 Add option to ignore hidden markers --- CONTRIBUTORS | 1 + src/markerclusterer.js | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index aa5a6d9..1a55d4d 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -14,3 +14,4 @@ Brendan Kenny Moisés Arcos Peter Grassberger Chris Fritz +Markus Mächler diff --git a/src/markerclusterer.js b/src/markerclusterer.js index 554fcec..17e9fef 100755 --- a/src/markerclusterer.js +++ b/src/markerclusterer.js @@ -51,6 +51,8 @@ * 'minimumClusterSize': (number) The minimum number of markers to be in a * cluster before the markers are hidden and a count * is shown. + * 'ignoreHiddenMarkers': (boolean) Whether to ignore markers that are not + * visible or count and cluster them anyway * 'styles': (object) An object that has style properties: * 'url': (string) The image url. * 'height': (number) The image height. @@ -109,6 +111,11 @@ function MarkerClusterer(map, opt_markers, opt_options) { */ this.minClusterSize_ = options['minimumClusterSize'] || 2; + /** + * @type {boolean} + * @private + */ + this.ignoreHiddenMarkers_ = options['ignoreHiddenMarkers'] || false; /** * @type {?number} @@ -785,7 +792,7 @@ MarkerClusterer.prototype.createClusters_ = function() { var bounds = this.getExtendedBounds(mapBounds); for (var i = 0, marker; marker = this.markers_[i]; i++) { - if (!marker.isAdded && this.isMarkerInBounds_(marker, bounds)) { + if (!marker.isAdded && this.isMarkerInBounds_(marker, bounds) && (!this.ignoreHiddenMarkers_ || marker.getVisible())) { this.addToClosestCluster_(marker); } }