Skip to content
This repository was archived by the owner on Jun 16, 2019. It is now read-only.

Add cssClass option to override any styles in css #43

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/markerclusterer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -87,6 +89,11 @@ function MarkerClusterer(map, opt_markers, opt_options) {
*/
this.styles_ = [];

/**
* @private
*/
this.cssClass_ = null;

/**
* @type {boolean}
* @private
Expand Down Expand Up @@ -115,6 +122,8 @@ function MarkerClusterer(map, opt_markers, opt_options) {

this.styles_ = options['styles'] || [];

this.cssClass_ = options['cssClass'] || null;

/**
* @type {string}
* @private
Expand All @@ -139,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
Expand Down Expand Up @@ -1052,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());
}
Expand All @@ -1068,6 +1090,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();
Expand Down Expand Up @@ -1302,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;