From bc8a251a0b6774274a153443838ee98b1789b7c3 Mon Sep 17 00:00:00 2001 From: Kesha Antonov Date: Tue, 2 Feb 2016 01:33:32 +0300 Subject: [PATCH 1/4] add cssClass option --- src/markerclusterer.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/markerclusterer.js b/src/markerclusterer.js index a31e3a9..6d1374e 100755 --- a/src/markerclusterer.js +++ b/src/markerclusterer.js @@ -87,6 +87,11 @@ function MarkerClusterer(map, opt_markers, opt_options) { */ this.styles_ = []; + /** + * @private + */ + this.cssClass_ = null; + /** * @type {boolean} * @private @@ -115,6 +120,8 @@ function MarkerClusterer(map, opt_markers, opt_options) { this.styles_ = options['styles'] || []; + this.cssClass_ = options['cssClass'] || null; + /** * @type {string} * @private @@ -1068,6 +1075,10 @@ ClusterIcon.prototype.onAdd = function() { var pos = this.getPosFromLatLng_(this.center_); this.div_.style.cssText = this.createCss(pos); this.div_.innerHTML = this.sums_.text; + var markerClusterer = this.cluster_.getMarkerClusterer(); + if (markerClusterer.cssClass_) { + this.div_.className = markerClusterer.cssClass_; + } } var panes = this.getPanes(); @@ -1214,6 +1225,7 @@ ClusterIcon.prototype.setCenter = function(center) { */ ClusterIcon.prototype.createCss = function(pos) { var style = []; + var markerClusterer = this.cluster_.getMarkerClusterer(); style.push('background-image:url(' + this.url_ + ');'); var backgroundPosition = this.backgroundPosition_ ? this.backgroundPosition_ : '0 0'; style.push('background-position:' + backgroundPosition + ';'); @@ -1249,6 +1261,7 @@ ClusterIcon.prototype.createCss = function(pos) { style.push('cursor:pointer; top:' + pos.y + 'px; left:' + pos.x + 'px; color:' + txtColor + '; position:absolute; font-size:' + txtSize + 'px; font-family:Arial,sans-serif; font-weight:bold'); + return style.join(''); }; From 12a7305b75befcc5210006fe826ffdb082b10f96 Mon Sep 17 00:00:00 2001 From: Kesha Antonov Date: Tue, 2 Feb 2016 01:34:51 +0300 Subject: [PATCH 2/4] remove unused var --- src/markerclusterer.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/markerclusterer.js b/src/markerclusterer.js index 6d1374e..ae5f93a 100755 --- a/src/markerclusterer.js +++ b/src/markerclusterer.js @@ -1225,7 +1225,6 @@ ClusterIcon.prototype.setCenter = function(center) { */ ClusterIcon.prototype.createCss = function(pos) { var style = []; - var markerClusterer = this.cluster_.getMarkerClusterer(); style.push('background-image:url(' + this.url_ + ');'); var backgroundPosition = this.backgroundPosition_ ? this.backgroundPosition_ : '0 0'; style.push('background-position:' + backgroundPosition + ';'); @@ -1261,7 +1260,6 @@ ClusterIcon.prototype.createCss = function(pos) { style.push('cursor:pointer; top:' + pos.y + 'px; left:' + pos.x + 'px; color:' + txtColor + '; position:absolute; font-size:' + txtSize + 'px; font-family:Arial,sans-serif; font-weight:bold'); - return style.join(''); }; From d30b357e361c9502ef515b0732140cee288c75e7 Mon Sep 17 00:00:00 2001 From: Kesha Antonov Date: Tue, 15 Mar 2016 09:35:18 +0300 Subject: [PATCH 3/4] add maxZoomOnClick option --- src/markerclusterer.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/markerclusterer.js b/src/markerclusterer.js index ae5f93a..ef4c4ed 100755 --- a/src/markerclusterer.js +++ b/src/markerclusterer.js @@ -43,6 +43,8 @@ * cluster. * 'zoomOnClick': (boolean) Whether the default behaviour of clicking on a * cluster is to zoom into it. + * 'maxZoomOnClick': (number) The maximum zoom level that will be applied to + * map on click on cluster. * 'averageCenter': (boolean) Wether the center of each cluster should be * the average of all markers in the cluster. * 'minimumClusterSize': (number) The minimum number of markers to be in a @@ -146,6 +148,16 @@ function MarkerClusterer(map, opt_markers, opt_options) { this.zoomOnClick_ = options['zoomOnClick']; } + /** + * @type {number} + * @private + */ + this.maxZoomOnClick_ = 20; + + if (options['maxZoomOnClick'] != undefined) { + this.maxZoomOnClick_ = options['maxZoomOnClick']; + } + /** * @type {boolean} * @private @@ -1059,6 +1071,9 @@ ClusterIcon.prototype.triggerClusterClick = function(event) { google.maps.event.trigger(markerClusterer, 'clusterclick', this.cluster_, event); if (markerClusterer.isZoomOnClick()) { + google.maps.event.addListenerOnce(this.map_, 'bounds_changed', function(e) { + if (this.getZoom() > markerClusterer.maxZoomOnClick_) this.setZoom(markerClusterer.maxZoomOnClick_); + }); // Zoom into the cluster. this.map_.fitBounds(this.cluster_.getBounds()); } From 723958bb9bf5053fa3ce488d9fa8dd48db577b45 Mon Sep 17 00:00:00 2001 From: Kesha Antonov Date: Thu, 3 Nov 2016 17:32:25 +0300 Subject: [PATCH 4/4] add module exports --- src/markerclusterer.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/markerclusterer.js b/src/markerclusterer.js index ef4c4ed..3a28b2e 100755 --- a/src/markerclusterer.js +++ b/src/markerclusterer.js @@ -1328,3 +1328,5 @@ Cluster.prototype['getMarkers'] = Cluster.prototype.getMarkers; ClusterIcon.prototype['onAdd'] = ClusterIcon.prototype.onAdd; ClusterIcon.prototype['draw'] = ClusterIcon.prototype.draw; ClusterIcon.prototype['onRemove'] = ClusterIcon.prototype.onRemove; + +module.exports = MarkerClusterer;