Bug fix: markerCluster / plugin.google.maps.event.MARKER_CLICK is not fired
MODIFY
www/Map.js
www/Map.js
@@ -960,7 +960,7 @@ Map.prototype.addMarkerCluster = function(markerClusterOptions, callback) {
exec(function(result) {
- var markers = new BaseArrayClass();
+ var markerMap = {};
result.geocellList.forEach(function(geocell, idx) {
var markerOptions = markerClusterOptions.markers[idx];
markerOptions = common.markerOptionsFilter(markerOptions);
@@ -970,13 +970,12 @@ Map.prototype.addMarkerCluster = function(markerClusterOptions, callback) {
marker.set("isAdded", false, true);
marker.set("geocell", geocell, true);
marker.set("position", markerOptions.position, true);
- markers.push(marker);
-
+ markerMap[markerId] = marker;
});
var markerCluster = new MarkerCluster(self, result.id, {
"icons": markerClusterOptions.icons,
- "markers": markers,
+ "markerMap": markerMap,
"maxZoomLevel": Math.min(markerClusterOptions.maxZoomLevel || 15, 15)
});
@@ -1021,18 +1020,13 @@ Map.prototype._onClusterEvent = function(eventName, markerClusterId, clusterId,
var self = this;
var markerCluster = self.OVERLAYS[markerClusterId] || null;
if (markerCluster) {
- var cluster = markerCluster.getClusterByClusterId(clusterId);
- if (!cluster) {
- return;
- }
- if (clusterId.indexOf(";") > -1) {
- var idx = clusterId.split(";")[1];
- var marker = cluster.getMarkers()[idx];
- if (marker) {
- eventName = eventName.replace("cluster", "marker");
- markerCluster.trigger(eventName, position, marker);
- }
+ if (/marker_/i.test(clusterId)) {
+ // regular marker
+ var marker = markerCluster.getMarkerById(clusterId);
+ markerCluster.trigger(event.MARKER_CLICK, position, marker);
} else {
+ // clusterred marker
+ var cluster = markerCluster.getClusterByClusterId(clusterId);
markerCluster.trigger(eventName, cluster);
}
}

MODIFY
www/MarkerCluster.js
www/MarkerCluster.js
@@ -18,7 +18,7 @@ var argscheck = require('cordova/argscheck'),
var MarkerCluster = function(map, id, markerClusterOptions) {
BaseClass.call(this);
- var idxCount = markerClusterOptions.markers.getLength() - 1;
+ var idxCount = Object.keys(markerClusterOptions.markerMap) + 1;
var self = this;
Object.defineProperty(self, "maxZoomLevel", {
@@ -29,8 +29,8 @@ var MarkerCluster = function(map, id, markerClusterOptions) {
value: {},
writable: false
});
- Object.defineProperty(self, "_markers", {
- value: markerClusterOptions.markers,
+ Object.defineProperty(self, "_markerMap", {
+ value: markerClusterOptions.markerMap,
writable: false
});
Object.defineProperty(self, "debug", {
@@ -61,7 +61,9 @@ var MarkerCluster = function(map, id, markerClusterOptions) {
markerClusterOptions.markers.removeAt(idx);
}
};
- markerClusterOptions.markers.forEach(function(marker) {
+ var keys = Object.keys(self._markerMap);
+ keys.forEach(function(markerId) {
+ var marker = self._markerMap[markerId];
marker.one(marker.getId() + "_remove", onRemoveMarker);
});
@@ -109,7 +111,7 @@ var MarkerCluster = function(map, id, markerClusterOptions) {
marker.set("isAdded", false, true);
marker.set("geocell", geocell, true);
marker.set("position", markerOptions.position, true);
- self._markers.push(marker);
+ self._markerMap[markerId] = marker;
self.redraw(true);
};
@@ -143,6 +145,10 @@ MarkerCluster.prototype.onClusterClicked = function(cluster) {
duration: 500
});
};
+MarkerCluster.prototype.getMarkerById = function(markerId) {
+ var self = this;
+ return self._markerMap[markerId];
+};
MarkerCluster.prototype.getClusterByClusterId = function(clusterId) {
var self = this,
@@ -204,7 +210,9 @@ MarkerCluster.prototype.redraw = function(force) {
if (resolution === -1) {
return;
}
- self._markers.forEach(function(marker) {
+ keys = Object.keys(self._markerMap);
+ keys.forEach(function(markerId) {
+ var marker = self._markerMap[markerId];
var geocell = marker.get("geocell");
//if (!marker.get("isAdded")) {
// return;
@@ -219,7 +227,9 @@ MarkerCluster.prototype.redraw = function(force) {
}
//deleteClusters[marker.getId()] = 1;
});
- self._markers.forEach(function(marker) {
+ keys = Object.keys(self._markerMap);
+ keys.forEach(function(markerId) {
+ var marker = self._markerMap[markerId];
var geocell = marker.get("geocell");
if (allGeocells.indexOf(geocell) > -1) {
targetMarkers.push(marker);
@@ -248,7 +258,9 @@ MarkerCluster.prototype.redraw = function(force) {
delete self._clusters[resolution][geocell];
}
});
- self._markers.forEach(function(marker) {
+ keys = Object.keys(self._markerMap);
+ keys.forEach(function(markerId) {
+ var marker = self._markerMap[markerId];
var geocell = marker.get("geocell");
if (ignoreGeocells.indexOf(geocell) === -1) {
targetMarkers.push(marker);
@@ -297,7 +309,9 @@ MarkerCluster.prototype.redraw = function(force) {
geocell = geocell.substr(0, resolution + 1);
allGeocells.push(geocell);
});
- self._markers.forEach(function(marker) {
+ keys = Object.keys(self._markerMap);
+ keys.forEach(function(markerId) {
+ var marker = self._markerMap[markerId];
var geocell = marker.get("geocell");
if (allGeocells.indexOf(geocell) > -1) {
targetMarkers.push(marker);
@@ -317,7 +331,9 @@ MarkerCluster.prototype.redraw = function(force) {
delete self._clusters[prevResolution];
}
} else {
- self._markers.forEach(function(marker) {
+ keys = Object.keys(self._markerMap);
+ keys.forEach(function(markerId) {
+ var marker = self._markerMap[markerId];
var geocell = marker.get("geocell");
if (allGeocells.indexOf(geocell) > -1) {
targetMarkers.push(marker);

Bug fix: markerCluster / plugin.google.maps.event.MARKER_CLICK is not fired #5