Bug fixL After removing marker cluster by map.clear() newly added marker cluster not bind markers click callback fn
MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="2.0.0-beta3-20170904-1341" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
+<plugin id="cordova-plugin-googlemaps" version="2.0.0-beta3-20170904-2006" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>cordova-plugin-googlemaps</name>
<js-module name="BaseClass" src="www/BaseClass.js">
<runs />

MODIFY
src/android/plugin/google/maps/PluginMarkerCluster.java
src/android/plugin/google/maps/PluginMarkerCluster.java
@@ -149,7 +149,7 @@ public class PluginMarkerCluster extends PluginMarker {
public void remove(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
String clusterId = args.getString(0);
- Log.d(TAG, "-->remove = " + clusterId);
+ //Log.d(TAG, "-->remove = " + clusterId);
synchronized (debugFlags) {
debugFlags.remove(clusterId);
waitCntManager.remove(clusterId);
@@ -157,7 +157,7 @@ public class PluginMarkerCluster extends PluginMarker {
synchronized (pluginMarkers) {
for(String key: pluginMarkers.keySet()) {
if (key.startsWith(clusterId)) {
- Log.d(TAG, "-->delete = " + key);
+ //Log.d(TAG, "-->delete = " + key);
pluginMarkers.put(key, STATUS.CREATED);
deleteMarkers.add(key);
}
@@ -246,7 +246,7 @@ public class PluginMarkerCluster extends PluginMarker {
final boolean isDebug = debugFlags.get(clusterId);
final JSONObject params = args.getJSONObject(1);
- String clusterId_markerId;
+ String markerId, clusterId_markerId;
JSONArray new_or_update = null;
if (params.has("new_or_update")) {
new_or_update = params.getJSONArray("new_or_update");
@@ -265,7 +265,8 @@ public class PluginMarkerCluster extends PluginMarker {
for (int i = 0; i < new_or_updateCnt; i++) {
clusterData = new_or_update.getJSONObject(i);
positionJSON = clusterData.getJSONObject("position");
- clusterId_markerId = clusterData.getString("id");
+ markerId = clusterData.getString("id");
+ clusterId_markerId = clusterId + "-" + markerId;
// Save the marker properties
pluginMap.objects.put("marker_property_" + clusterId_markerId, clusterData);
@@ -300,7 +301,7 @@ public class PluginMarkerCluster extends PluginMarker {
if (icon.has("label")) {
JSONObject label = icon.getJSONObject("label");
if (isDebug) {
- label.put("text", clusterId_markerId.replace(clusterId, ""));
+ label.put("text", markerId);
} else {
label.put("text", clusterData.getInt("count") + "");
}
@@ -311,7 +312,7 @@ public class PluginMarkerCluster extends PluginMarker {
} else {
Bundle label = new Bundle();
if (isDebug) {
- label.putString("text", clusterId_markerId.replace(clusterId, ""));
+ label.putString("text", markerId);
} else {
label.putInt("fontSize", 15);
label.putBoolean("bold", true);

MODIFY
src/ios/GoogleMaps/PluginMarkerCluster.m
src/ios/GoogleMaps/PluginMarkerCluster.m
@@ -167,7 +167,7 @@ const int GEOCELL_GRID_SIZE = 4;
BOOL isDebug = [[self.debugFlags objectForKey:clusterId] boolValue];
__block NSDictionary *params = [command.arguments objectAtIndex:1];
- NSString *clusterId_markerId;
+ NSString *clusterId_markerId, *markerId;
NSMutableArray *new_or_update = nil;
if ([params objectForKey:@"new_or_update"]) {
@@ -186,7 +186,8 @@ const int GEOCELL_GRID_SIZE = 4;
NSMutableDictionary *properties;
for (int i = 0; i < new_or_updateCnt; i++) {
clusterData = [new_or_update objectAtIndex:i];
- clusterId_markerId = [clusterData objectForKey:@"id"];
+ markerId = [clusterData objectForKey:@"id"];
+ clusterId_markerId = [NSString stringWithFormat:@"%@-%@", clusterId, markerId];
// Save the marker properties
[self.mapCtrl.objects setObject:clusterData forKey:[NSString stringWithFormat:@"marker_property_%@", clusterId_markerId]];

MODIFY
www/Map.js
www/Map.js
@@ -992,7 +992,7 @@ Map.prototype.addMarkerCluster = function(markerClusterOptions, callback) {
markerOptions = common.markerOptionsFilter(markerOptions);
var markerId = markerOptions.id || "marker_" + idx;
- markerId = result.id + "-" + markerId;
+ //markerId = result.id + "-" + markerId;
markerOptions.id = markerId;
markerOptions._cluster = {
isRemoved: false,

MODIFY
www/MarkerCluster.js
www/MarkerCluster.js
@@ -148,7 +148,7 @@ var MarkerCluster = function(map, markerClusterId, markerClusterOptions, _exec)
markerOptions = common.markerOptionsFilter(markerOptions);
var geocell = geomodel.getGeocell(markerOptions.position.lat, markerOptions.position.lng, self.MAX_RESOLUTION + 1);
- var markerId = markerClusterId + "-" + (markerOptions.id || "marker_" + idxCount);
+ var markerId = (markerOptions.id || "marker_" + idxCount);
markerOptions.id = markerId;
markerOptions._cluster = {
isRemoved: false,
@@ -322,6 +322,10 @@ MarkerCluster.prototype.remove = function() {
}
exec(null, self.errorHandler, self.getPluginName(), 'remove', [self.getId()], {sync: true});
+ var keys = Object.keys(self._markerMap);
+ keys.forEach(function(markerId) {
+ delete self._markerMap[markerId]._cluster;
+ });
if (self.boundsDraw && self.get("polygon")) {
self.get("polygon").remove();
}
@@ -374,9 +378,9 @@ MarkerCluster.prototype.getMarkerById = function(markerId) {
if (self._isRemove) {
return null;
}
- if (markerId.indexOf(self.id + "-") === -1) {
- markerId = self.id + "-" + markerId;
- }
+ //if (markerId.indexOf(self.id + "-") === -1) {
+ // markerId = self.id + "-" + markerId;
+ //}
var markerOpts = self._markerMap[markerId];
if (!markerOpts) {
return null;

Bug fixL After removing marker cluster by map.clear() newly added marker cluster not bind markers click callback fn  #1701