Add: implement Android version
Add: remove() method
MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="cluster-20170729-0150" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
+<plugin id="cordova-plugin-googlemaps" version="cluster-20170730-0041" 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/MyPlugin.java
src/android/plugin/google/maps/MyPlugin.java
@@ -149,7 +149,7 @@ public class MyPlugin extends CordovaPlugin implements MyPluginInterface {
}
protected synchronized Marker getMarker(String id) {
if (!this.objects.containsKey(id)) {
- Log.e(TAG, "---> can not find the maker : " + id);
+ //Log.e(TAG, "---> can not find the maker : " + id);
return null;
}
return (Marker)this.objects.get(id);

MODIFY
src/android/plugin/google/maps/PluginMap.java
src/android/plugin/google/maps/PluginMap.java
@@ -1975,34 +1975,57 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
});
}
+ /**
+ * update the active marker (for internal use)
+ * @param args
+ * @param callbackContext
+ * @throws JSONException
+ */
+ public void setActiveMarkerId(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
+ final String id = args.getString(0);
+
+ cordova.getActivity().runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Marker marker = (Marker) objects.get(id);
+ if (marker != null) {
+ activeMarker = marker;
+ }
+ sendNoResult(callbackContext);
+ }
+ });
+ }
+
@Override
public boolean onMarkerClick(Marker marker) {
//Log.d(TAG, "---> onMarkerClick / marker.tag = " + marker.getTag());
JSONObject properties = null;
- String markerTag = (String) marker.getTag();
- if (markerTag == null) {
- return true;
+ String clusterId_markerId = marker.getTag() + "";
+ if (clusterId_markerId.contains("markercluster_")) {
+ if (clusterId_markerId.contains("-marker_")) {
+ activeMarker = marker;
+ } else {
+ if (activeMarker != null) {
+ this.onClusterEvent("info_close", activeMarker);
+ }
+ }
+ this.onClusterEvent("cluster_click", marker);
+ } else {
+ this.onMarkerEvent("marker_click", marker);
+ activeMarker = marker;
}
- String tmp[] = markerTag.split("_");
- String pluginName = tmp[0];
- tmp = markerTag.split("-");
- String markerId = tmp[tmp.length - 1];
- PluginEntry pluginEntry = plugins.get(mapId + "-" + pluginName);
- //Log.d(TAG, "---> onMarkerClick / pluginEntry = " + pluginEntry);
+ String tmp[] = clusterId_markerId.split("_");
+ String className = tmp[0];
+
+ PluginEntry pluginEntry = plugins.get(mapId + "-" + className);
if (pluginEntry == null) {
return true;
}
MyPlugin myPlugin = (MyPlugin)pluginEntry.plugin;
- if ("marker".equals(pluginName)) {
- this.onMarkerEvent("marker_click", marker);
- }
- if ("markercluster".equals(pluginName)) {
- this.onClusterEvent("cluster_click", marker);
- }
- String propertyId = "marker_property_" + marker.getTag();
+ String propertyId = "marker_property_" + clusterId_markerId;
//Log.d(TAG, "---> onMarkerClick / propertyId = " + propertyId);
if (myPlugin.objects.containsKey(propertyId)) {
properties = (JSONObject) myPlugin.objects.get(propertyId);
@@ -2068,8 +2091,12 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
@Override
public void onInfoWindowClose(Marker marker) {
+ boolean useHtmlInfoWnd = marker.getTitle() == null &&
+ marker.getSnippet() == null;
+ if (useHtmlInfoWnd) {
this.onMarkerEvent("info_close", marker);
- activeMarker = null;
+ }
+ //activeMarker = null; // <-- This causes HTMLinfoWindow is not able to close when you tap on the map.
}
@Override
@@ -2110,15 +2137,18 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
LatLng latLng = marker.getPosition();
String markerTag = (String) marker.getTag();
- String tmp[] = markerTag.split("_");
- tmp = markerTag.split("-");
- String markerId = tmp[tmp.length - 1];
+ String tmp[] = markerTag.split("-");
String clusterId = tmp[0];
+ String markerId = tmp[1];
String js = String.format(Locale.ENGLISH, "javascript:cordova.fireDocumentEvent('%s', {evtName: '%s', callback:'_onClusterEvent', args:['%s', '%s', new plugin.google.maps.LatLng(%f, %f)]})",
mapId, eventName, clusterId, markerId, latLng.latitude, latLng.longitude);
jsCallback(js);
}
public void syncInfoWndPosition() {
+ if (activeMarker == null) {
+ Log.d(TAG, "--->no active marker");
+ return;
+ }
LatLng latLng = activeMarker.getPosition();
Point point = projection.toScreenLocation(latLng);
@@ -2541,9 +2571,15 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
@Override
public void run() {
+ //Log.d(TAG, "---> onMapClick : " + activeMarker);
if (activeMarker != null) {
+ //Log.d(TAG, "---> activeMarker.getTag() : " + activeMarker.getTag());
+ if ((activeMarker.getTag() + "").contains("markercluster")) {
+ onClusterEvent("info_close", activeMarker);
+ } else {
onInfoWindowClose(activeMarker);
-
+ }
+ activeMarker = null;
}
String key;
Map.Entry<String, Object> entry;

MODIFY
src/android/plugin/google/maps/PluginMarker.java
src/android/plugin/google/maps/PluginMarker.java
@@ -52,7 +52,12 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
protected ArrayList<AsyncTask> iconLoadingTasks = new ArrayList<AsyncTask>();
protected ArrayList<Bitmap> icons = new ArrayList<Bitmap>();
protected HashMap<String, Integer> iconCacheKeys = new HashMap<String, Integer>();
- private static Paint paint = new Paint();
+ private static final Paint paint = new Paint();
+
+ protected interface ICreateMarkerCallback {
+ void onSuccess(Marker marker);
+ void onError(String message);
+ }
@Override
public void initialize(CordovaInterface cordova, final CordovaWebView webView) {
@@ -173,10 +178,28 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
public void create(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
// Create an instance of Marker class
- final MarkerOptions markerOptions = new MarkerOptions();
- final JSONObject properties = new JSONObject();
- final JSONObject opts = args.getJSONObject(1);
+ JSONObject opts = args.getJSONObject(1);
+ final String markerId = "marker_" + callbackContext.hashCode();
+ final JSONObject result = new JSONObject();
+ result.put("id", markerId);
+
+ _create(markerId, opts, new ICreateMarkerCallback() {
+ @Override
+ public void onSuccess(Marker marker) {
+ callbackContext.success(result);
+ }
+
+ @Override
+ public void onError(String message) {
+ callbackContext.error(message);
+ }
+ });
+ }
+
+ protected void _create(final String markerId, final JSONObject opts, final ICreateMarkerCallback callback) throws JSONException {
+ final JSONObject properties = new JSONObject();
+ final MarkerOptions markerOptions = new MarkerOptions();
if (opts.has("position")) {
JSONObject position = opts.getJSONObject("position");
markerOptions.position(new LatLng(position.getDouble("lat"), position.getDouble("lng")));
@@ -235,7 +258,6 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
@Override
public void run() {
final Marker marker = map.addMarker(markerOptions);
- final String markerId = "marker_" + marker.getId();
marker.setTag(markerId);
marker.hideInfoWindow();
@@ -247,7 +269,7 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
// Store the marker
self.objects.put(markerId, marker);
- self.objects.put("marker_property_" + marker.getTag(), properties);
+ self.objects.put("marker_property_" + markerId, properties);
// Prepare the result
final JSONObject result = new JSONObject();
@@ -356,16 +378,16 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
@Override
public void onPostExecute(Object object) {
Marker marker = (Marker) object;
- callbackContext.success(result);
+ callback.onSuccess(marker);
}
@Override
public void onError(String errorMsg) {
- callbackContext.error(errorMsg);
+ callback.onError(errorMsg);
}
});
} else {
- callbackContext.success(result);
+ callback.onSuccess(marker);
}
}
});
@@ -373,7 +395,7 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
@Override
public void onError(String errorMsg) {
- callbackContext.error(errorMsg);
+ callback.onError(errorMsg);
}
});
@@ -391,31 +413,29 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
@Override
public void onPostExecute(Object object) {
- callbackContext.success(result);
+ callback.onSuccess(marker);
}
@Override
public void onError(String errorMsg) {
- callbackContext.error(errorMsg);
+ callback.onError(errorMsg);
}
});
} else {
// Return the result if does not specify the icon property.
- callbackContext.success(result);
+ callback.onSuccess(marker);
}
}
} catch (Exception e) {
e.printStackTrace();
- callbackContext.error("" + e.getMessage());
+ callback.onError("" + e.getMessage());
}
}
});
}
});
-
-
}
private void setDropAnimation_(final Marker marker, final PluginAsyncInterface callback) {
@@ -524,22 +544,6 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
}
}
-
- public void setActiveMarkerId(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
- final String id = args.getString(0);
-
- cordova.getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- Marker marker = (Marker) objects.get(id);
- if (marker == null) {
- return;
- }
- pluginMap.activeMarker = marker;
- }
- });
- }
-
/**
*
* http://android-er.blogspot.com/2013/01/implement-bouncing-marker-for-google.html
@@ -967,7 +971,7 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
options.height = height;
options.noCaching = noCaching;
- AsyncLoadImage task = new AsyncLoadImage(cordova, webView, options, new AsyncLoadImageInterface() {
+ final AsyncLoadImage task = new AsyncLoadImage(cordova, webView, options, new AsyncLoadImageInterface() {
@Override
public void onPostExecute(AsyncLoadImage.AsyncLoadImageResult result) {
if (result == null || result.image == null) {
@@ -1041,7 +1045,12 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
callback.onPostExecute(marker);
}
});
+ cordova.getActivity().runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
task.execute();
+ }
+ });
iconLoadingTasks.add(task);
}

MODIFY
src/android/plugin/google/maps/PluginMarkerCluster.java
src/android/plugin/google/maps/PluginMarkerCluster.java
@@ -49,15 +49,12 @@ public class PluginMarkerCluster extends PluginMarker {
public void onDestroy() {
super.onDestroy();
stopFlag = true;
- this.clear();
-
- }
-
- @Override
- protected void clear() {
}
+ //---------------------
+ // Delete thread
+ //---------------------
private Thread deleteThread = new Thread(new Runnable() {
@Override
public void run() {
@@ -159,7 +156,6 @@ public class PluginMarkerCluster extends PluginMarker {
synchronized (semaphore) {
JSONObject params = args.getJSONObject(1);
String clusterId_markerId;
- String markerId;
JSONArray deleteClusters = null;
if (params.has("delete")) {
deleteClusters = params.getJSONArray("delete");
@@ -175,8 +171,8 @@ public class PluginMarkerCluster extends PluginMarker {
//-------------------------------------
int deleteCnt = deleteClusters.length();
for (int i = 0; i < deleteCnt; i++) {
- markerId = deleteClusters.getString(i);
- deleteMarkers.add(clusterId + "-" + markerId);
+ clusterId_markerId = deleteClusters.getString(i);
+ deleteMarkers.add(clusterId_markerId);
}
}
@@ -188,28 +184,30 @@ public class PluginMarkerCluster extends PluginMarker {
new_or_updateCnt = new_or_update.length();
}
JSONObject clusterData, positionJSON;
- Bundle properites;
+ Bundle properties;
for (int i = 0; i < new_or_updateCnt; i++) {
clusterData = new_or_update.getJSONObject(i);
positionJSON = clusterData.getJSONObject("position");
- markerId = clusterData.getString("id");
- clusterId_markerId = clusterId + "-" + markerId;
+ clusterId_markerId = clusterData.getString("id");
+
// Save the marker properties
self.objects.put("marker_property_" + clusterId_markerId, clusterData);
// Set the WORKING status flag
+ synchronized (pluginMarkers) {
pluginMarkers.put(clusterId_markerId, STATUS.WORKING);
+ }
updateClusterIDs.add(clusterId_markerId);
// Prepare the marker properties for addMarker()
- properites = new Bundle();
- properites.putDouble("lat", positionJSON.getDouble("lat"));
- properites.putDouble("lng", positionJSON.getDouble("lng"));
+ properties = new Bundle();
+ properties.putDouble("lat", positionJSON.getDouble("lat"));
+ properties.putDouble("lng", positionJSON.getDouble("lng"));
if (clusterData.has("title")) {
- properites.putString("title", clusterData.getString("title"));
+ properties.putString("title", clusterData.getString("title"));
}
- properites.putString("id", clusterId_markerId);
+ properties.putString("id", clusterId_markerId);
if (clusterData.has("icon")) {
Object iconObj = clusterData.get("icon");
@@ -217,7 +215,7 @@ public class PluginMarkerCluster extends PluginMarker {
if (iconObj instanceof String) {
Bundle iconProperties = new Bundle();
iconProperties.putString("url", (String) iconObj);
- properites.putBundle("icon", iconProperties);
+ properties.putBundle("icon", iconProperties);
} else if (iconObj instanceof JSONObject) {
JSONObject icon = clusterData.getJSONObject("icon");
@@ -225,7 +223,7 @@ public class PluginMarkerCluster extends PluginMarker {
if (icon.has("label")) {
JSONObject label = icon.getJSONObject("label");
if (isDebug) {
- label.put("text", markerId);
+ label.put("text", clusterId_markerId.replace(clusterId, ""));
} else {
label.put("text", clusterData.getInt("count") + "");
}
@@ -236,7 +234,7 @@ public class PluginMarkerCluster extends PluginMarker {
} else {
Bundle label = new Bundle();
if (isDebug) {
- label.putString("text", markerId);
+ label.putString("text", clusterId_markerId.replace(clusterId, ""));
} else {
label.putInt("fontSize", 15);
label.putBoolean("bold", true);
@@ -246,45 +244,21 @@ public class PluginMarkerCluster extends PluginMarker {
}
if (icon.has("anchor")) {
double[] anchor = new double[2];
- if (icon.get("anchor") instanceof String) {
- JSONArray points = null;
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
- points = new JSONArray(icon.getString("anchor"));
- anchor[0] = points.getDouble(0);
- anchor[1] = points.getDouble(1);
- }
- } else if (icon.get("anchor") instanceof JSONObject) {
- anchor[0] = icon.getJSONObject("anchor").getDouble("x");
- anchor[1] = icon.getJSONObject("anchor").getDouble("y");
- } else if (icon.get("anchor") instanceof JSONArray) {
anchor[0] = icon.getJSONArray("anchor").getDouble(0);
anchor[1] = icon.getJSONArray("anchor").getDouble(1);
- }
iconProperties.putDoubleArray("anchor", anchor);
}
if (icon.has("infoWindowAnchor")) {
double[] anchor = new double[2];
- if (icon.get("infoWindowAnchor") instanceof String) {
- JSONArray points = null;
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
- points = new JSONArray(icon.getString("infoWindowAnchor"));
- anchor[0] = points.getDouble(0);
- anchor[1] = points.getDouble(1);
- }
- } else if (icon.get("infoWindowAnchor") instanceof JSONObject) {
- anchor[0] = icon.getJSONObject("infoWindowAnchor").getDouble("x");
- anchor[1] = icon.getJSONObject("infoWindowAnchor").getDouble("y");
- } else if (icon.get("infoWindowAnchor") instanceof JSONArray) {
anchor[0] = icon.getJSONArray("infoWindowAnchor").getDouble(0);
anchor[1] = icon.getJSONArray("infoWindowAnchor").getDouble(1);
- }
iconProperties.putDoubleArray("infoWindowAnchor", anchor);
}
- properites.putBundle("icon", iconProperties);
+ properties.putBundle("icon", iconProperties);
}
}
- changeProperties.put(clusterId_markerId, properites);
+ changeProperties.put(clusterId_markerId, properties);
}
//Log.d(TAG, "---> deleteCnt : " + deleteCnt + ", newCnt : " + newCnt + ", updateCnt : " + updateCnt + ", reuseCnt : " + reuseCnt);
@@ -297,7 +271,7 @@ public class PluginMarkerCluster extends PluginMarker {
@Override
public void run() {
Iterator<String> iterator;
- String markerId;
+ String clusterId_markerId;
Bundle markerProperties;
Marker marker;
Boolean isNew;
@@ -308,14 +282,62 @@ public class PluginMarkerCluster extends PluginMarker {
waitCntManager.put(clusterId, updateClusterIDs.size());
iterator = updateClusterIDs.iterator();
while (iterator.hasNext()) {
- markerId = iterator.next();
+ clusterId_markerId = iterator.next();
synchronized (pluginMarkers) {
- pluginMarkers.put(markerId, STATUS.WORKING);
+ pluginMarkers.put(clusterId_markerId, STATUS.WORKING);
}
- isNew = !objects.containsKey(markerId);
+ isNew = !objects.containsKey(clusterId_markerId);
// Get the marker properties
- markerProperties = changeProperties.get(markerId);
+ markerProperties = changeProperties.get(clusterId_markerId);
+ if (clusterId_markerId.contains("-marker_")) {
+ if (isNew) {
+ final String fMarkerId = clusterId_markerId;
+ JSONObject properties = (JSONObject) objects.get("marker_property_" + clusterId_markerId);
+ try {
+ _create(clusterId_markerId, properties, new ICreateMarkerCallback() {
+ @Override
+ public void onSuccess(Marker marker) {
+
+ synchronized (pluginMarkers) {
+ pluginMarkers.put(fMarkerId, STATUS.CREATED);
+ }
+ decreaseWaitCnt(clusterId);
+ }
+
+ @Override
+ public void onError(String message) {
+ synchronized (pluginMarkers) {
+ pluginMarkers.put(fMarkerId, STATUS.DELETED);
+ }
+ Log.e(TAG, message);
+ decreaseWaitCnt(clusterId);
+ synchronized (deleteMarkers) {
+ deleteMarkers.add(fMarkerId);
+ }
+ }
+ });
+ } catch (JSONException e) {
+ e.printStackTrace();
+ decreaseWaitCnt(clusterId);
+ }
+ } else {
+ marker = getMarker(clusterId_markerId);
+ //----------------------------------------
+ // Set the title and snippet properties
+ //----------------------------------------
+ if (markerProperties.containsKey("title")) {
+ marker.setTitle(markerProperties.getString("title"));
+ }
+ if (markerProperties.containsKey("snippet")) {
+ marker.setSnippet(markerProperties.getString("snippet"));
+ }
+ }
+ continue;
+ }
+ //--------------------------
+ // cluster icon
+ //--------------------------
if (isNew) {
// If the requested id is new location, create a marker
marker = map.addMarker(new MarkerOptions()
@@ -325,10 +347,10 @@ public class PluginMarkerCluster extends PluginMarker {
// Store the marker instance with markerId
synchronized (self.objects) {
- self.objects.put(markerId, marker);
+ self.objects.put(clusterId_markerId, marker);
}
} else {
- marker = getMarker(markerId);
+ marker = getMarker(clusterId_markerId);
}
//----------------------------------------
// Set the title and snippet properties
@@ -350,14 +372,18 @@ public class PluginMarkerCluster extends PluginMarker {
*/
if (markerProperties.containsKey("icon")) {
Bundle icon = markerProperties.getBundle("icon");
+ final String fMarkerId = clusterId_markerId;
//Log.d(TAG, "---> targetMarkerId = " + targetMarkerId + ", marker = " + marker);
- setIconToClusterMarker(markerId, marker, icon, new PluginAsyncInterface() {
+ setIconToClusterMarker(clusterId_markerId, marker, icon, new PluginAsyncInterface() {
@Override
public void onPostExecute(Object object) {
//--------------------------------------
// Marker was updated
//--------------------------------------
decreaseWaitCnt(clusterId);
+ synchronized (pluginMarkers) {
+ pluginMarkers.put(fMarkerId, STATUS.CREATED);
+ }
}
@Override
@@ -367,6 +393,12 @@ public class PluginMarkerCluster extends PluginMarker {
//--------------------------------------
Log.e(TAG, errorMsg);
decreaseWaitCnt(clusterId);
+ synchronized (deleteMarkers) {
+ deleteMarkers.add(fMarkerId);
+ }
+ synchronized (pluginMarkers) {
+ pluginMarkers.put(fMarkerId, STATUS.DELETED);
+ }
}
});
} else {
@@ -375,7 +407,7 @@ public class PluginMarkerCluster extends PluginMarker {
//--------------------
synchronized (pluginMarkers) {
//Log.d(TAG, "create : " + markerId + " = CREATED");
- pluginMarkers.put(markerId, STATUS.CREATED);
+ pluginMarkers.put(clusterId_markerId, STATUS.CREATED);
}
decreaseWaitCnt(clusterId);
}

MODIFY
src/ios/GoogleMaps/GoogleMapsViewController.m
src/ios/GoogleMaps/GoogleMapsViewController.m
if ([clusterId_markerId containsString:@"markercluster_"]) {
if ([clusterId_markerId containsString:@"-marker_"]) {
- NSLog(@"--->activeMarker = %@", marker.userData);
+ //NSLog(@"--->activeMarker = %@", marker.userData);
self.map.selectedMarker = marker;
self.activeMarker = marker;
+ } else {
+ if (self.activeMarker != nil) {
+ [self triggerClusterEvent:@"info_close" marker:self.activeMarker];
+ }
}
[self triggerClusterEvent:@"cluster_click" marker:marker];
} else {
[self triggerMarkerEvent:@"marker_click" marker:marker];
- NSLog(@"--->activeMarker = %@", marker.userData);
+ //NSLog(@"--->activeMarker = %@", marker.userData);
self.map.selectedMarker = marker;
self.activeMarker = marker;
}
CDVPlugin<MyPlgunProtocol> *plugin = [self.plugins objectForKey:pluginId];
// Get the marker properties
- NSString *markerPropertyId = [NSString stringWithFormat:@"marker_property_%@", marker.userData];
+ NSString *markerPropertyId = [NSString stringWithFormat:@"marker_property_%@", clusterId_markerId];
NSDictionary *properties = [plugin.objects objectForKey:markerPropertyId];
BOOL disableAutoPan = false;

MODIFY
src/ios/GoogleMaps/PluginMarkerCluster.m
src/ios/GoogleMaps/PluginMarkerCluster.m
@@ -231,7 +231,7 @@ const int GEOCELL_GRID_SIZE = 4;
//---------------------------
[[NSOperationQueue mainQueue] addOperationWithBlock: ^{
self.mapCtrl.map.selectedMarker = nil;
- NSString *markerId;
+ NSString *clusterId_markerId;
NSMutableDictionary *markerProperties;
GMSMarker *marker;
CLLocationCoordinate2D position;
@@ -244,38 +244,43 @@ const int GEOCELL_GRID_SIZE = 4;
//---------------------
[self.waitCntManager setObject:[NSNumber numberWithInteger:[updateClusterIDs count]] forKey:clusterId];
for (int i = 0; i < [updateClusterIDs count]; i++) {
- markerId = [updateClusterIDs objectAtIndex:i];
+ clusterId_markerId = [updateClusterIDs objectAtIndex:i];
@synchronized(self.pluginMarkers) {
- [self.pluginMarkers setObject:@"WORKING" forKey:markerId];
+ [self.pluginMarkers setObject:@"WORKING" forKey:clusterId_markerId];
}
// Get the marker properties
- markerProperties = [changeProperties objectForKey:markerId];
+ markerProperties = [changeProperties objectForKey:clusterId_markerId];
- isNew = [self.objects objectForKey:markerId] == nil;
+ isNew = [self.objects objectForKey:clusterId_markerId] == nil;
//--------------------------
// regular marker
//--------------------------
- if ([markerId containsString:@"-marker_"]) {
+ if ([clusterId_markerId containsString:@"-marker_"]) {
if (isNew) {
- [super _create:markerId markerOptions:markerProperties callbackBlock:^(BOOL successed, id resultObj) {
+ [super _create:clusterId_markerId markerOptions:markerProperties callbackBlock:^(BOOL successed, id resultObj) {
@synchronized (self.pluginMarkers) {
if (successed) {
//((GMSMarker *)resultObj).map = self.mapCtrl.map;
- [self.pluginMarkers setObject:@"CREATED" forKey:markerId];
+ [self.pluginMarkers setObject:@"CREATED" forKey:clusterId_markerId];
} else {
//--------------------------------------
// Could not read icon for some reason
//--------------------------------------
- [self.pluginMarkers setObject:@"DELETED" forKey:markerId];
+ [self.pluginMarkers setObject:@"DELETED" forKey:clusterId_markerId];
NSLog(@"(error) %@", resultObj);
+ @synchronized (self.deleteMarkers) {
+ [self.deleteMarkers addObject:clusterId_markerId];
+ }
}
}
[self decreaseWaitWithClusterId:clusterId];
}];
} else {
+
+ marker = [self.objects objectForKey:clusterId_markerId];
//----------------------------------------
// Set the title and snippet properties
//----------------------------------------
@@ -300,15 +305,15 @@ const int GEOCELL_GRID_SIZE = 4;
longitude = [[positionJSON objectForKey:@"lng"] doubleValue];
position = CLLocationCoordinate2DMake(latitude, longitude);
marker = [GMSMarker markerWithPosition:position];
- marker.userData = markerId;
+ marker.userData = clusterId_markerId;
// Store the marker instance with markerId
@synchronized (self.objects) {
- [self.objects setObject:marker forKey:markerId];
+ [self.objects setObject:marker forKey:clusterId_markerId];
}
} else {
@synchronized (self.objects) {
- marker = [self.objects objectForKey:markerId];
+ marker = [self.objects objectForKey:clusterId_markerId];
}
}
@@ -326,24 +331,33 @@ const int GEOCELL_GRID_SIZE = 4;
if ([markerProperties objectForKey:@"icon"]) {
PluginMarkerCluster *self_ = self;
NSDictionary *icon = [markerProperties objectForKey:@"icon"];
- [self setIconToClusterMarker:markerId marker:marker iconProperty:icon callbackBlock:^(BOOL successed, id resultObj) {
+ [self setIconToClusterMarker:clusterId_markerId marker:marker iconProperty:icon callbackBlock:^(BOOL successed, id resultObj) {
if (successed == NO) {
//--------------------------------------
// Could not read icon for some reason
//--------------------------------------
NSLog(@"(error) %@", resultObj);
+ @synchronized (self_.deleteMarkers) {
+ [self_.deleteMarkers addObject:clusterId_markerId];
+ }
+ @synchronized (self_.pluginMarkers) {
+ [self_.pluginMarkers setObject:@"DELETED" forKey:clusterId_markerId];
+ }
} else {
//--------------------------------------
// Marker was updated
//--------------------------------------
marker.map = self_.mapCtrl.map;
+ @synchronized (self_.pluginMarkers) {
+ [self_.pluginMarkers setObject:@"CREATED" forKey:clusterId_markerId];
+ }
}
[self_ decreaseWaitWithClusterId:clusterId];
}];
} else {
marker.map = self.mapCtrl.map;
@synchronized (self.pluginMarkers) {
- [self.pluginMarkers setObject:@"CREATED" forKey:markerId];
+ [self.pluginMarkers setObject:@"CREATED" forKey:clusterId_markerId];
}
[self decreaseWaitWithClusterId:clusterId];
}

MODIFY
www/Common.js
www/Common.js
@@ -546,6 +546,7 @@ function markerOptionsFilter(markerOptions) {
markerOptions.position.lng = markerOptions.position.lng || 0.0;
markerOptions.draggable = markerOptions.draggable === true;
markerOptions.icon = markerOptions.icon || undefined;
+ markerOptions.zIndex = markerOptions.zIndex || 0;
markerOptions.snippet = typeof(markerOptions.snippet) === "string" ? markerOptions.snippet : undefined;
markerOptions.title = typeof(markerOptions.title) === "string" ? markerOptions.title : undefined;
markerOptions.visible = defaultTrueOption(markerOptions.visible);

MODIFY
www/Map.js
www/Map.js
@@ -237,6 +237,9 @@ Map.prototype.clear = function(callback) {
var id;
for (var i = 0; i < ids.length; i++) {
id = ids[i];
+ if (obj[id].type === "MarkerCluster") {
+ obj[id].remove();
+ }
obj[id].off();
delete obj[id];
}
@@ -975,16 +978,32 @@ Map.prototype.addMarkerCluster = function(markerClusterOptions, callback) {
};
markerMap[markerId] = marker;
- self.MARKERS[marker.getId()] = marker;
- self.OVERLAYS[marker.getId()] = marker;
+ //self.MARKERS[marker.getId()] = marker;
+ //self.OVERLAYS[marker.getId()] = marker;
});
var markerCluster = new MarkerCluster(self, result.id, {
"icons": markerClusterOptions.icons,
"markerMap": markerMap,
- "maxZoomLevel": markerClusterOptions.maxZoomLevel || 15,
+ "maxZoomLevel": Math.max(markerClusterOptions.maxZoomLevel, 18) || 15,
"debug": markerClusterOptions.debug === true
});
+ markerCluster.one("remove", function() {
+ delete self.OVERLAYS[result.id];
+/*
+ result.geocellList.forEach(function(geocell, idx) {
+ var markerOptions = markerClusterOptions.markers[idx];
+ var markerId = result.id + "-" + (markerOptions.id || "marker_" + idx);
+ var marker = self.MARKERS[markerId];
+ if (marker) {
+ marker.off();
+ }
+ //delete self.MARKERS[markerId];
+ delete self.OVERLAYS[markerId];
+ });
+*/
+ markerCluster.off();
+ });
self.OVERLAYS[result.id] = markerCluster;
@@ -1027,7 +1046,7 @@ Map.prototype._onClusterEvent = function(eventName, markerClusterId, clusterId,
var self = this;
var markerCluster = self.OVERLAYS[markerClusterId] || null;
if (markerCluster) {
- if (/marker_/i.test(clusterId)) {
+ if (/^marker_/i.test(clusterId)) {
// regular marker
var marker = markerCluster.getMarkerById(clusterId);
if (eventName === event.INFO_CLOSE ||

MODIFY
www/MarkerCluster.js
www/MarkerCluster.js
@@ -50,6 +50,7 @@ var MarkerCluster = function(map, id, markerClusterOptions) {
writable: false
});
self.taskQueue = [];
+ self._isRemove = false;
//----------------------------------------------------
// If a marker has been removed,
@@ -119,6 +120,12 @@ var MarkerCluster = function(map, id, markerClusterOptions) {
map.on(event.CAMERA_MOVE_END, self._onCameraMoved.bind(self));
self.on("cluster_click", self.onClusterClicked);
+ self.on("nextTask", function(){
+ if (self.taskQueue.length === 0) {
+ return;
+ }
+ sel.redraw();
+ });
self._onCameraMoved(false);
@@ -166,6 +173,45 @@ MarkerCluster.prototype._onCameraMoved = function(force) {
});
};
+MarkerCluster.prototype.remove = function() {
+ var self = this;
+ if (self._isRemove) {
+ return;
+ }
+
+ var resolution = self.get("resolution"),
+ activeMarkerId = self.map.get("active_marker_id"),
+ deleteClusters = [];
+
+ self.trigger("remove");
+ self.taskQueue = [];
+ self._isRemove = true;
+
+ var keys = Object.keys(self._clusters[resolution]);
+ keys.forEach(function(geocell) {
+ var cluster = self._clusters[resolution][geocell];
+ var noClusterMode = cluster.getMode() === cluster.NO_CLUSTER_MODE;
+ if (noClusterMode) {
+ cluster.getMarkers().forEach(function(marker, idx) {
+ if (marker.getId() === activeMarkerId) {
+ marker.trigger(event.INFO_CLOSE);
+ marker.hideInfoWindow();
+ }
+ deleteClusters.push(marker.getId());
+ });
+ }
+ if (!noClusterMode) {
+ deleteClusters.push(self.id + "-" + geocell);
+ }
+ cluster.remove();
+ });
+ exec(null, self.errorHandler, self.getPluginName(), 'redrawClusters', [self.getId(), {
+ "resolution": resolution,
+ "new_or_update": [],
+ "delete": deleteClusters
+ }]);
+
+};
MarkerCluster.prototype.getMarkerById = function(markerId) {
var self = this;
return self._markerMap[markerId];
@@ -193,7 +239,7 @@ MarkerCluster.prototype.redraw = function(clusterDistance, force) {
if (self.debug) {
console.log("self.taskQueue.push = " + self.taskQueue.length);
}
- if (self.taskQueue.length > 1) {
+ if (self._isRemove || self.taskQueue.length > 1) {
return;
}
var taskParams = self.taskQueue.shift();
@@ -205,6 +251,10 @@ MarkerCluster.prototype._redraw = function(clusterDistance, force) {
currentZoomLevel = Math.floor(self.map.getCameraZoom()),
prevResolution = self.get("resolution");
+ if (self._isRemove) {
+ return;
+ }
+
currentZoomLevel = currentZoomLevel < 0 ? 0 : currentZoomLevel;
self.set("zoom", currentZoomLevel);
@@ -247,9 +297,10 @@ MarkerCluster.prototype._redraw = function(clusterDistance, force) {
var keys;
var ignoreGeocells = [];
var allGeocells = [];
+ var activeMarkerId = self.map.get("active_marker_id");
if (prevResolution === -1) {
if (resolution === -1) {
- self.nextTask();
+ self.trigger("nextTask");
return;
}
keys = Object.keys(self._markerMap);
@@ -295,6 +346,10 @@ MarkerCluster.prototype._redraw = function(clusterDistance, force) {
if (self.debug) {
console.log("---> (js)delete:" + marker.getId());
}
+ if (marker.getId() === activeMarkerId) {
+ marker.trigger(event.INFO_CLOSE);
+ marker.hideInfoWindow();
+ }
});
} else {
deleteClusters[self.id + "-" + geocell] = 1;
@@ -332,6 +387,10 @@ MarkerCluster.prototype._redraw = function(clusterDistance, force) {
if (self.debug) {
console.log("---> (js)delete:" + marker.getId());
}
+ if (marker.getId() === activeMarkerId) {
+ marker.trigger(event.INFO_CLOSE);
+ marker.hideInfoWindow();
+ }
deleteClusters[marker.getId()] = 1;
}
});
@@ -356,6 +415,10 @@ MarkerCluster.prototype._redraw = function(clusterDistance, force) {
if (self.debug) {
console.log("---> (js)delete:" + marker.getId());
}
+ if (marker.getId() === activeMarkerId) {
+ marker.trigger(event.INFO_CLOSE);
+ marker.hideInfoWindow();
+ }
deleteClusters[marker.getId()] = 1;
}
});
@@ -545,7 +608,7 @@ MarkerCluster.prototype._redraw = function(clusterDistance, force) {
}
if (expandedRegion.contains(marker.getPosition())) {
var markerOptions = marker.getOptions();
- clusterOpts.isClusterIcon = false;
+ markerOptions.isClusterIcon = false;
if (self.debug) {
console.log("---> (js)add:" + marker.getId());
}
@@ -558,13 +621,14 @@ MarkerCluster.prototype._redraw = function(clusterDistance, force) {
}
var delete_clusters = Object.keys(deleteClusters);
if (new_or_update_clusters.length === 0 && delete_clusters === 0) {
- self.nextTask();
+ self.trigger("nextTask");
+ return;
+ }
+ if (self._isRemove) {
return;
}
-
-
exec(function() {
- self.nextTask();
+ self.trigger("nextTask");
}, self.errorHandler, self.getPluginName(), 'redrawClusters', [self.getId(), {
"resolution": resolution,
"new_or_update": new_or_update_clusters,
@@ -573,10 +637,6 @@ MarkerCluster.prototype._redraw = function(clusterDistance, force) {
};
-MarkerCluster.prototype.nextTask = function() {
- var self = this;
- self.redraw();
-};
MarkerCluster.prototype.getClusterIcon = function(cluster) {
var self = this,

Add: implement Android version
Add: remove() method