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

Implement a way to get current marker's Cluster so we can get additio… #109

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
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
37 changes: 37 additions & 0 deletions src/markerclusterer.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ function MarkerClusterer(map, opt_markers, opt_options) {
*/
this.clusters_ = [];

/**
* @type {Object} holding information about every markers cluster
*/
this.markersCluster_ = {};

/**
* @type {Number} Unique markers ID
*/
this.markersUniqueID = 1;

this.sizes = [53, 56, 66, 78, 90];

/**
Expand Down Expand Up @@ -346,6 +356,18 @@ MarkerClusterer.prototype.getMaxZoom = function() {
};


/**
* Gets marker's cluster object based on given marker
*
* @param {google.maps.Marker} marker
*
* @return {Cluster}
*/
MarkerClusterer.prototype.getMarkersCluster = function(marker) {
return this.clusters_[this.markersCluster_[marker.uniqueID]];
};


/**
* The function for calculating the cluster icon image.
*
Expand Down Expand Up @@ -427,6 +449,8 @@ MarkerClusterer.prototype.pushMarkerTo_ = function(marker) {
that.repaint();
});
}
marker.uniqueID = this.markersUniqueID;
this.markersUniqueID++;
this.markers_.push(marker);
};

Expand Down Expand Up @@ -473,6 +497,7 @@ MarkerClusterer.prototype.removeMarker_ = function(marker) {
marker.setMap(null);

this.markers_.splice(index, 1);
delete this.markersCluster_[marker.uniqueID];

return true;
};
Expand Down Expand Up @@ -660,6 +685,8 @@ MarkerClusterer.prototype.clearMarkers = function() {

// Set the markers a empty array.
this.markers_ = [];
this.markersCluster_ = {};
this.markersUniqueID = 1;
};


Expand All @@ -682,6 +709,8 @@ MarkerClusterer.prototype.resetViewport = function(opt_hide) {
}

this.clusters_ = [];
this.markersCluster_ = {};
this.markersUniqueID = 1;
};

/**
Expand Down Expand Up @@ -747,13 +776,15 @@ MarkerClusterer.prototype.addToClosestCluster_ = function(marker) {
var distance = 40000; // Some large number
var clusterToAddTo = null;
var pos = marker.getPosition();
var clusterIndex = null;
for (var i = 0, cluster; cluster = this.clusters_[i]; i++) {
var center = cluster.getCenter();
if (center) {
var d = this.distanceBetweenPoints_(center, marker.getPosition());
if (d < distance) {
distance = d;
clusterToAddTo = cluster;
clusterIndex = i;
}
}
}
Expand All @@ -764,6 +795,11 @@ MarkerClusterer.prototype.addToClosestCluster_ = function(marker) {
var cluster = new Cluster(this);
cluster.addMarker(marker);
this.clusters_.push(cluster);
clusterIndex = this.clusters_.length - 1;
}

if (marker.isAdded) {
this.markersCluster_[marker.uniqueID] = clusterIndex;
}
};

Expand Down Expand Up @@ -1283,6 +1319,7 @@ MarkerClusterer.prototype['getExtendedBounds'] =
MarkerClusterer.prototype['getMap'] = MarkerClusterer.prototype.getMap;
MarkerClusterer.prototype['getMarkers'] = MarkerClusterer.prototype.getMarkers;
MarkerClusterer.prototype['getMaxZoom'] = MarkerClusterer.prototype.getMaxZoom;
MarkerClusterer.prototype['getMarkersCluster'] = MarkerClusterer.prototype.getMarkersCluster;
MarkerClusterer.prototype['getStyles'] = MarkerClusterer.prototype.getStyles;
MarkerClusterer.prototype['getTotalClusters'] =
MarkerClusterer.prototype.getTotalClusters;
Expand Down