(Android) implement the click mechanism
MODIFY
src/android/plugin/google/maps/MyPlugin.java
src/android/plugin/google/maps/MyPlugin.java
@@ -151,10 +151,12 @@ public class MyPlugin extends CordovaPlugin implements MyPluginInterface {
if (objects == null) {
return null;
}
+ /*
if (!this.objects.containsKey(id)) {
Log.e("MyPlugin", "---> !this.objects.containsKey(id) : " + id);
return null;
}
+ */
return (Marker)this.objects.get(id);
}
protected synchronized Polyline getPolyline(String id) {

MODIFY
src/android/plugin/google/maps/PluginMap.java
src/android/plugin/google/maps/PluginMap.java
@@ -718,19 +718,26 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
return null;
}
- PluginEntry pluginEntry = plugins.get(mapId + "-marker");
+ String markerTag = (String) marker.getTag();
+ String tmp[] = markerTag.split("_");
+ String className = tmp[0];
+ tmp = markerTag.split("-");
+ String markerId = tmp[tmp.length - 1];
+
+ PluginEntry pluginEntry = plugins.get(mapId + "-" + className);
if (pluginEntry == null) {
- Log.d(TAG, "---> marker.title = " + marker.getTitle());
+ Log.d(TAG, "---> getInfoContents / marker.title = " + marker.getTitle());
return null;
}
- PluginMarker pluginMarker = (PluginMarker)pluginEntry.plugin;
+ MyPlugin myPlugin = (MyPlugin)pluginEntry.plugin;
JSONObject properties = null;
JSONObject styles = null;
- String propertyId = "marker_property_" + marker.getId();
+ String propertyId = "marker_property_" + markerTag;
+ Log.d(TAG, "---> getInfoContents / propertyId = " + propertyId);
- if (pluginMarker.objects.containsKey(propertyId)) {
- properties = (JSONObject) pluginMarker.objects.get(propertyId);
+ if (myPlugin.objects.containsKey(propertyId)) {
+ properties = (JSONObject) myPlugin.objects.get(propertyId);
try {
if (properties.has("styles")) {
@@ -836,7 +843,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
if (title != null) {
if (title.contains("data:image/") && title.contains(";base64,")) {
- String[] tmp = title.split(",");
+ tmp = title.split(",");
Bitmap image = PluginUtil.getBitmapFromBase64encodedImage(tmp[1]);
image = PluginUtil.scaleBitmapForDevice(image);
ImageView imageView = new ImageView(this.activity);
@@ -923,17 +930,26 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
activeMarker = marker;
JSONObject properties = null;
- String propertyId = "marker_property_" + marker.getId();
- PluginEntry pluginEntry = plugins.get(mapId + "-marker");
+ String markerTag = (String) marker.getTag();
+ String tmp[] = markerTag.split("_");
+ String className = tmp[0];
+ tmp = markerTag.split("-");
+ String markerId = tmp[tmp.length - 1];
+
+ String propertyId = "marker_property_" + markerTag;
+
+ Log.e(TAG, "---> getInfoWindow / propertyId = " + propertyId);
+ Log.e(TAG, "---> getInfoWindow / marker.title = " + marker.getTitle());
+ PluginEntry pluginEntry = plugins.get(mapId + "-" + className);
if (pluginEntry == null) {
- Log.d(TAG, "---> marker.title = " + marker.getTitle());
+ Log.e(TAG, "---> getInfoWindow / marker.title = " + marker.getTitle());
return null;
}
- PluginMarker pluginMarker = (PluginMarker)pluginEntry.plugin;
+ MyPlugin myPlugin = (MyPlugin)pluginEntry.plugin;
- if (pluginMarker.objects.containsKey(propertyId)) {
- properties = (JSONObject) pluginMarker.objects.get(propertyId);
+ if (myPlugin.objects.containsKey(propertyId)) {
+ properties = (JSONObject) myPlugin.objects.get(propertyId);
try {
if (properties.has("useHtmlInfoWnd") && properties.getBoolean("useHtmlInfoWnd")) {
@@ -1943,22 +1959,31 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
@Override
public boolean onMarkerClick(Marker marker) {
- Log.d(TAG, "---> marker.title = " + marker.getTitle());
+ Log.d(TAG, "---> onMarkerClick / marker.tag = " + marker.getTag());
JSONObject properties = null;
- PluginEntry pluginEntry = plugins.get(mapId + "-" + marker.getTag());
- if (pluginEntry == null) {
+ String markerTag = (String) marker.getTag();
+ if (markerTag == null) {
return true;
}
- MyPlugin myPlugin = (MyPlugin)pluginEntry.plugin;
- if (myPlugin instanceof PluginMarkerCluster) {
- marker.showInfoWindow();
+ String tmp[] = markerTag.split("_");
+ String pluginName = tmp[0];
+ tmp = markerTag.split("-");
+ String markerId = tmp[tmp.length - 1];
+
+ PluginEntry pluginEntry = plugins.get(mapId + "-" + pluginName);
+ if (pluginEntry == null) {
return true;
}
-
- if (myPlugin instanceof PluginMarker) {
+ MyPlugin myPlugin = (MyPlugin)pluginEntry.plugin;
+ if ("marker".equals(pluginName)) {
this.onMarkerEvent("marker_click", marker);
- String propertyId = "marker_property_" + marker.getId();
+ }
+ if ("markercluster".equals(pluginName)) {
+ this.onClusterEvent("cluster_click", marker);
+ }
+ String propertyId = "marker_property_" + marker.getTag();
+ Log.d(TAG, "---> onMarkerClick / propertyId = " + propertyId);
if (myPlugin.objects.containsKey(propertyId)) {
properties = (JSONObject) myPlugin.objects.get(propertyId);
if (properties.has("disableAutoPan")) {
@@ -1977,7 +2002,6 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
}
}
}
- }
marker.showInfoWindow();
return true;
@@ -2048,11 +2072,26 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
public void onMarkerEvent(String eventName, Marker marker) {
LatLng latLng = marker.getPosition();
- String markerId = "marker_" + marker.getId();
+ String markerTag = (String) marker.getTag();
+ String tmp[] = markerTag.split("_");
+ tmp = markerTag.split("-");
+ String markerId = tmp[tmp.length - 1];
String js = String.format(Locale.ENGLISH, "javascript:cordova.fireDocumentEvent('%s', {evtName: '%s', callback:'_onMarkerEvent', args:['%s', new plugin.google.maps.LatLng(%f, %f)]})",
mapId, eventName, markerId, latLng.latitude, latLng.longitude);
jsCallback(js);
}
+ public void onClusterEvent(String eventName, Marker marker) {
+ LatLng latLng = marker.getPosition();
+
+ String markerTag = (String) marker.getTag();
+ String tmp[] = markerTag.split("_");
+ tmp = markerTag.split("-");
+ String markerId = tmp[tmp.length - 1];
+ String clusterId = tmp[0];
+ 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() {
LatLng latLng = activeMarker.getPosition();
Point point = projection.toScreenLocation(latLng);

MODIFY
src/android/plugin/google/maps/PluginMarker.java
src/android/plugin/google/maps/PluginMarker.java
@@ -247,7 +247,8 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
@Override
public void run() {
final Marker marker = map.addMarker(markerOptions);
- marker.setTag("marker");
+ final String id = marker.getId();
+ marker.setTag("marker_" + id);
marker.hideInfoWindow();
cordova.getThreadPool().execute(new Runnable() {
@@ -256,10 +257,9 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
try {
// Store the marker
- String id = "marker_" + marker.getId();
self.objects.put(id, marker);
- self.objects.put("marker_property_" + marker.getId(), properties);
+ self.objects.put("marker_property_" + marker.getTag(), properties);
// Prepare the result
final JSONObject result = new JSONObject();
@@ -684,7 +684,7 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
this.sendNoResult(callbackContext);
return;
}
- String propertyId = "marker_property_" + marker.getId();
+ String propertyId = "marker_property_" + marker.getTag();
JSONObject properties = null;
if (self.objects.containsKey(propertyId)) {
properties = (JSONObject)self.objects.get(propertyId);
@@ -709,7 +709,7 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
this.sendNoResult(callbackContext);
return;
}
- String propertyId = "marker_property_" + marker.getId();
+ String propertyId = "marker_property_" + marker.getTag();
JSONObject properties = null;
if (self.objects.containsKey(propertyId)) {
properties = (JSONObject)self.objects.get(propertyId);
@@ -785,7 +785,7 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
}
*/
- String propertyId = "marker_property_" + id;
+ String propertyId = "marker_property_" + marker.getTag();
objects.remove(propertyId);
cordova.getActivity().runOnUiThread(new Runnable() {
@@ -808,6 +808,7 @@ public class PluginMarker extends MyPlugin implements MyPluginInterface {
synchronized (marker) {
marker.setTag(null);
marker.remove();
+
String iconCacheKey = "marker_icon_" + marker.getId();
if (objects.containsKey(iconCacheKey)) {
String cacheKey = (String) objects.remove(iconCacheKey);

MODIFY
src/android/plugin/google/maps/PluginMarkerCluster.java
src/android/plugin/google/maps/PluginMarkerCluster.java
@@ -107,8 +107,8 @@ public class PluginMarkerCluster extends PluginMarker {
synchronized (dummyObj) {
JSONObject params = args.getJSONObject(1);
- String geocell, clusterId_geocell, deleteGeocell;
-
+ String clusterId_markerId, deleteMarkerId;
+ String markerId;
JSONArray deleteClusters = params.getJSONArray("delete");
JSONArray new_or_update = params.getJSONArray("new_or_update");
@@ -122,8 +122,8 @@ public class PluginMarkerCluster extends PluginMarker {
new_or_updateCnt = new_or_update.length();
}
for (int i = 0; i < deleteCnt; i++) {
- geocell = deleteClusters.getString(i);
- deleteClusterIDs.add(clusterId + "-" + geocell);
+ markerId = deleteClusters.getString(i);
+ deleteClusterIDs.add(clusterId + "-" + markerId);
}
//---------------------------
@@ -134,29 +134,35 @@ public class PluginMarkerCluster extends PluginMarker {
for (int i = 0; i < new_or_updateCnt; i++) {
clusterData = new_or_update.getJSONObject(i);
positionJSON = clusterData.getJSONObject("position");
- geocell = clusterData.getString("geocell");
- clusterId_geocell = clusterId + "-" + geocell;
- if (self.objects.containsKey(clusterId_geocell) || pluginMarkers.containsKey(clusterId_geocell)) {
- updateClusterIDs.put(clusterId_geocell, clusterId_geocell);
+ markerId = clusterData.getString("id");
+ clusterId_markerId = clusterId + "-" + markerId;
+
+ self.objects.put("marker_property_" + clusterId_markerId, clusterData);
+
+ if (self.objects.containsKey(clusterId_markerId) || pluginMarkers.containsKey(clusterId_markerId)) {
+ updateClusterIDs.put(clusterId_markerId, clusterId_markerId);
} else {
if (reuseCnt < deleteCnt) {
//---------------
// Reuse a marker
//---------------
- deleteGeocell = deleteClusterIDs.remove(0);
+ deleteMarkerId = deleteClusterIDs.remove(0);
deleteCnt--;
- updateClusterIDs.put(deleteGeocell, clusterId_geocell);
+ updateClusterIDs.put(deleteMarkerId, clusterId_markerId);
reuseCnt++;
} else {
- pluginMarkers.put(clusterId_geocell, STATUS.WORKING);
- updateClusterIDs.put(clusterId_geocell, null);
+ pluginMarkers.put(clusterId_markerId, STATUS.WORKING);
+ updateClusterIDs.put(clusterId_markerId, null);
}
}
properites = new Bundle();
properites.putDouble("lat", positionJSON.getDouble("lat"));
properites.putDouble("lng", positionJSON.getDouble("lng"));
- properites.putString("title", clusterId_geocell);
+ if (clusterData.has("title")) {
+ properites.putString("title", clusterData.getString("title"));
+ }
+ properites.putString("id", clusterId_markerId);
if (clusterData.has("icon")) {
Object iconObj = clusterData.get("icon");
@@ -223,7 +229,7 @@ public class PluginMarkerCluster extends PluginMarker {
}
}
- changeProperties.put(clusterId_geocell, properites);
+ changeProperties.put(clusterId_markerId, properites);
}
//Log.d(TAG, "---> deleteCnt : " + deleteCnt + ", newCnt : " + newCnt + ", updateCnt : " + updateCnt + ", reuseCnt : " + reuseCnt);
@@ -236,7 +242,7 @@ public class PluginMarkerCluster extends PluginMarker {
@Override
public void run() {
Iterator<String> iterator;
- String oldGeocell, newGeocell, markerGeocell;
+ String oldMarkerId, newMarkerId, targetMarkerId;
Bundle markerProperties;
Marker marker;
Polygon polygon;
@@ -248,22 +254,32 @@ public class PluginMarkerCluster extends PluginMarker {
waitCntManager.put(clusterId, updateClusterIDs.size());
iterator = updateClusterIDs.keySet().iterator();
while (iterator.hasNext()) {
- oldGeocell = iterator.next();
- newGeocell = updateClusterIDs.get(oldGeocell);
- if (newGeocell == null) {
- markerGeocell = oldGeocell;
- markerProperties = changeProperties.get(oldGeocell);
+ oldMarkerId = iterator.next();
+ newMarkerId = updateClusterIDs.get(oldMarkerId);
+ if (newMarkerId == null) {
+ targetMarkerId = oldMarkerId;
+ markerProperties = changeProperties.get(oldMarkerId);
marker = map.addMarker(new MarkerOptions()
- .position(new LatLng(markerProperties.getDouble("lat"), markerProperties.getDouble("lng")))
- .title(oldGeocell));
- marker.setTag("markercluster");
+ .position(new LatLng(markerProperties.getDouble("lat"), markerProperties.getDouble("lng"))));
+ if (markerProperties.containsKey("title")) {
+ marker.setTitle(markerProperties.getString("title"));
+ } else {
+ marker.setTitle(null);
+ }
+ if (markerProperties.containsKey("snippet")) {
+ marker.setSnippet(markerProperties.getString("snippet"));
+ } else {
+ marker.setSnippet(null);
+ }
+ marker.setTag(markerProperties.getString("id"));
synchronized (self.objects) {
- self.objects.put(oldGeocell, marker);
- pluginMarkers.put(oldGeocell, STATUS.WORKING);
+ self.objects.put(oldMarkerId, marker);
+ //self.objects.put("marker_property_" + markerProperties.getString("id"), markerProperties);
+ pluginMarkers.put(oldMarkerId, STATUS.WORKING);
}
if (markerClusterOptions.get(clusterId).debug) {
- bounds = computeBox(oldGeocell);
+ bounds = computeBox(oldMarkerId);
polygon = map.addPolygon(new PolygonOptions()
.add(bounds.northeast)
.add(new LatLng(bounds.northeast.latitude, bounds.southwest.longitude))
@@ -273,39 +289,48 @@ public class PluginMarkerCluster extends PluginMarker {
.strokeColor(Color.BLUE)
.strokeWidth(2 * density));
polygon.setTag("polygon");
- self.objects.put("polygon" + oldGeocell, polygon);
+ self.objects.put("polygon" + oldMarkerId, polygon);
}
} else {
- if (STATUS.DELETED.equals(pluginMarkers.get(oldGeocell))) {
+ if (STATUS.DELETED.equals(pluginMarkers.get(oldMarkerId))) {
continue;
}
marker = null;
polygon = null;
while (marker == null) {
- marker = self.getMarker(oldGeocell);
- polygon = self.getPolygon("polygon" + oldGeocell);
+ marker = self.getMarker(oldMarkerId);
+ polygon = self.getPolygon("polygon" + oldMarkerId);
if (marker == null || marker.getTag() == null) {
if (deleteClusterIDs.size() > 0) {
- oldGeocell = deleteClusterIDs.remove(0);
+ oldMarkerId = deleteClusterIDs.remove(0);
} else {
marker = map.addMarker(new MarkerOptions()
.position(new LatLng(0, 0)));
- marker.setTag("markercluster");
}
}
}
synchronized (marker) {
- markerProperties = changeProperties.get(newGeocell);
- if (STATUS.DELETED.equals(pluginMarkers.get(newGeocell))) {
+ markerProperties = changeProperties.get(newMarkerId);
+ if (STATUS.DELETED.equals(pluginMarkers.get(newMarkerId))) {
continue;
}
marker.setPosition(new LatLng(markerProperties.getDouble("lat"), markerProperties.getDouble("lng")));
- marker.setTitle(newGeocell);
- markerGeocell = newGeocell;
+ if (markerProperties.containsKey("title")) {
+ marker.setTitle(markerProperties.getString("title"));
+ } else {
+ marker.setTitle(null);
+ }
+ if (markerProperties.containsKey("snippet")) {
+ marker.setSnippet(markerProperties.getString("snippet"));
+ } else {
+ marker.setSnippet(null);
+ }
+ marker.setTag(newMarkerId);
+ targetMarkerId = newMarkerId;
if (markerClusterOptions.get(clusterId).debug) {
- bounds = computeBox(newGeocell);
+ bounds = computeBox(newMarkerId);
ArrayList<LatLng> points = new ArrayList<LatLng>();
if (polygon == null) {
@@ -327,33 +352,36 @@ public class PluginMarkerCluster extends PluginMarker {
}
}
- if (oldGeocell.hashCode() != newGeocell.hashCode()) {
+ if (oldMarkerId.hashCode() != newMarkerId.hashCode()) {
//Log.d(TAG, "reuse : " + oldGeocell + " -> " + newGeocell);
synchronized (self.objects) {
- self.objects.put(newGeocell, marker);
+ self.objects.put(newMarkerId, marker);
+ //self.objects.put("marker_property_" + newMarkerId, markerProperties);
if (polygon != null) {
- self.objects.put("polygon" + newGeocell, polygon);
+ self.objects.put("polygon" + newMarkerId, polygon);
}
- pluginMarkers.put(newGeocell, STATUS.CREATED);
- self.objects.remove(oldGeocell);
- self.objects.remove("polygon" + oldGeocell);
- pluginMarkers.remove(oldGeocell);
+ pluginMarkers.put(newMarkerId, STATUS.CREATED);
+ self.objects.remove(oldMarkerId);
+ self.objects.remove("marker_property_" + oldMarkerId);
+ self.objects.remove("polygon" + oldMarkerId);
+ pluginMarkers.remove(oldMarkerId);
}
} else {
//Log.d(TAG, "update : " + newGeocell);
synchronized (self.objects) {
- self.objects.put(newGeocell, marker);
+ self.objects.put(newMarkerId, marker);
if (polygon != null) {
- self.objects.put("polygon" + newGeocell, polygon);
+ self.objects.put("polygon" + newMarkerId, polygon);
}
}
}
}
}
+ if (markerProperties.containsKey("icon")) {
Bundle icon = markerProperties.getBundle("icon");
if (icon != null) {
- setIconToClusterMarker(clusterId, markerGeocell, marker, icon, new PluginAsyncInterface() {
+ setIconToClusterMarker(targetMarkerId, marker, icon, new PluginAsyncInterface() {
@Override
public void onPostExecute(Object object) {
@@ -396,6 +424,20 @@ public class PluginMarkerCluster extends PluginMarker {
dummyObj.notify();
}
+ }
+ waitCntManager.put(clusterId, waitCnt);
+ }
+ }
+ } else {
+ marker.setIcon(null);
+ synchronized (waitCntManager) {
+ int waitCnt = waitCntManager.get(clusterId);
+ waitCnt = waitCnt - 1;
+ if (waitCnt == 0) {
+ synchronized (dummyObj) {
+ dummyObj.notify();
+ }
+
}
waitCntManager.put(clusterId, waitCnt);
}
@@ -409,25 +451,26 @@ public class PluginMarkerCluster extends PluginMarker {
//---------
iterator = deleteClusterIDs.iterator();
while (iterator.hasNext()) {
- oldGeocell = iterator.next();
- //Log.d(TAG, "delete : " + oldGeocell);
- marker = self.getMarker(oldGeocell);
- polygon = self.getPolygon("polygon" + oldGeocell);
+ oldMarkerId = iterator.next();
+ Log.d(TAG, "delete : " + oldMarkerId);
+ marker = self.getMarker(oldMarkerId);
+ polygon = self.getPolygon("polygon" + oldMarkerId);
synchronized (self.objects) {
- objects.remove(oldGeocell);
- objects.remove("polygon" + oldGeocell);
- pluginMarkers.remove(oldGeocell);
+ objects.remove(oldMarkerId);
+ objects.remove("marker_property_" + oldMarkerId);
+ objects.remove("polygon" + oldMarkerId);
+ pluginMarkers.remove(oldMarkerId);
}
synchronized (pluginMarkers) {
- if (!STATUS.WORKING.equals(pluginMarkers.get(oldGeocell))) {
+ if (!STATUS.WORKING.equals(pluginMarkers.get(oldMarkerId))) {
_removeMarker(marker);
if (polygon != null && polygon.getTag() != null) {
polygon.setTag(null);
polygon.remove();
}
- pluginMarkers.remove(oldGeocell);
+ pluginMarkers.remove(oldMarkerId);
} else {
- pluginMarkers.put(oldGeocell, STATUS.DELETED);
+ pluginMarkers.put(oldMarkerId, STATUS.DELETED);
}
}
}
@@ -446,12 +489,12 @@ public class PluginMarkerCluster extends PluginMarker {
}
- private void setIconToClusterMarker(final String clusterId, final String geocell, final Marker marker, final Bundle iconProperty, final PluginAsyncInterface callback) {
+ private void setIconToClusterMarker(final String markerId, final Marker marker, final Bundle iconProperty, final PluginAsyncInterface callback) {
//synchronized (pluginMarkers) {
- if (STATUS.DELETED.equals(pluginMarkers.get(geocell))) {
+ if (STATUS.DELETED.equals(pluginMarkers.get(markerId))) {
PluginMarkerCluster.this._removeMarker(marker);
- pluginMarkers.remove(geocell);
- Polygon polygon = self.getPolygon("polygon" + geocell);
+ pluginMarkers.remove(markerId);
+ Polygon polygon = self.getPolygon("polygon" + markerId);
if (polygon != null && polygon.getTag() != null) {
polygon.setTag(null);
polygon.remove();
@@ -459,17 +502,17 @@ public class PluginMarkerCluster extends PluginMarker {
callback.onError("marker has been removed");
return;
}
- pluginMarkers.put(geocell, STATUS.WORKING);
+ pluginMarkers.put(markerId, STATUS.WORKING);
//}
PluginMarkerCluster.super.setIcon_(marker, iconProperty, new PluginAsyncInterface() {
@Override
public void onPostExecute(Object object) {
Marker marker = (Marker) object;
//synchronized (pluginMarkers) {
- if (STATUS.DELETED.equals(pluginMarkers.get(geocell))) {
+ if (STATUS.DELETED.equals(pluginMarkers.get(markerId))) {
PluginMarkerCluster.this._removeMarker(marker);
- pluginMarkers.remove(geocell);
- Polygon polygon = self.getPolygon("polygon" + geocell);
+ pluginMarkers.remove(markerId);
+ Polygon polygon = self.getPolygon("polygon" + markerId);
if (polygon != null && polygon.getTag() != null) {
polygon.setTag(null);
polygon.remove();
@@ -479,7 +522,7 @@ public class PluginMarkerCluster extends PluginMarker {
}
//}
- pluginMarkers.put(geocell, STATUS.CREATED);
+ pluginMarkers.put(markerId, STATUS.CREATED);
callback.onPostExecute(object);
}
@@ -497,9 +540,9 @@ public class PluginMarkerCluster extends PluginMarker {
e.printStackTrace();
}
synchronized (objects) {
- pluginMarkers.remove(geocell);
- objects.remove(geocell);
- objects.remove("polygon" + geocell);
+ pluginMarkers.remove(markerId);
+ objects.remove(markerId);
+ objects.remove("polygon" + markerId);
}
callback.onPostExecute(errorMsg);
}

MODIFY
www/Cluster.js
www/Cluster.js
@@ -34,7 +34,7 @@ var Cluster = function(geocell, markerRefs) {
writable: false
});
Object.defineProperty(self, "_markerRefs", {
- value: markerRefs,
+ value: common.createMvcArray(markerRefs),
writable: false
});
@@ -46,7 +46,7 @@ Cluster.prototype.NO_CLUSTER_MODE = 1;
Cluster.prototype.CLUSTER_MODE = 2;
Cluster.prototype.getPluginName = function() {
- return this.map.getId() + "-Cluster";
+ return this.map.getId() + "-cluster";
};
Cluster.prototype.getBounds = function() {
return this.bounds;
@@ -55,6 +55,10 @@ Cluster.prototype.getCenter = function() {
return this.bounds.getCenter();
};
+Cluster.prototype.getMarkers = function() {
+ return this._markerRefs.getArray();
+};
+
Cluster.prototype.addMarkers = function(markerRefs) {
var self = this;
markerRefs.forEach(function(markerRef) {

MODIFY
www/Map.js
www/Map.js
@@ -916,8 +916,9 @@ Map.prototype.addCircle = function(circleOptions, callback) {
//-------------
// Marker
//-------------
-Map.prototype.addMarker = function(markerOptions, callback) {
- var self = this;
+function _markerOptionsFilter(markerOptions) {
+ markerOptions = markerOptions || {};
+
markerOptions.animation = markerOptions.animation || undefined;
markerOptions.position = markerOptions.position || {};
markerOptions.position.lat = markerOptions.position.lat || 0.0;
@@ -962,10 +963,14 @@ Map.prototype.addMarker = function(markerOptions, callback) {
common.isHTMLColorString(markerOptions.icon.label.color)) {
markerOptions.icon.label.color = common.HTMLColor2RGBA(markerOptions.icon.label.color);
}
-
+ return markerOptions;
+}
+Map.prototype.addMarker = function(markerOptions, callback) {
+ var self = this;
+ markerOptions = _markerOptionsFilter(markerOptions);
exec(function(result) {
markerOptions.hashCode = result.hashCode;
- var marker = new Marker(self, result.id, markerOptions);
+ var marker = new Marker(self, result.id, markerOptions, "marker");
self.MARKERS[result.id] = marker;
self.OVERLAYS[result.id] = marker;
@@ -992,46 +997,21 @@ Map.prototype.addMarkerCluster = function(markerClusterOptions, callback) {
markerClusterOptions = null;
}
markerClusterOptions = markerClusterOptions || {};
- var markerMap = new BaseClass();
- markerClusterOptions.markers.forEach(function(markerOpts, idx) {
-
- if (typeof markerOpts.icon === "object") {
- if ("anchor" in markerOpts.icon &&
- typeof markerOpts.icon.anchor === "object" &&
- "x" in markerOpts.icon.anchor &&
- "y" in markerOpts.icon.anchor) {
- markerOpts.icon.anchor = [markerOpts.icon.anchor.x, markerOpts.icon.anchor.y];
- }
- if ("infoWindowAnchor" in markerOpts.icon &&
- typeof markerOpts.icon.infoWindowAnchor === "object" &&
- "x" in markerOpts.icon.infoWindowAnchor &&
- "y" in markerOpts.icon.infoWindowAnchor) {
- markerOpts.icon.infoWindowAnchor = [markerOpts.icon.infoWindowAnchor.x, markerOpts.icon.infoWindowAnchor.anchor.y];
- }
- }
-
- var markerRef = new BaseClass();
- markerRef.set("isAdded", false);
- markerRef.set("position", new LatLng(markerOpts.position.lat, markerOpts.position.lng));
- markerRef.set("icon", markerOpts.icon);
- markerRef.set("options", markerOpts);
-
- markerMap.set("marker_" + idx, markerRef);
- });
var positionList = markerClusterOptions.markers.map(function(marker) {
return marker.position;
});
exec(function(result) {
+
var markers = new BaseArrayClass();
result.geocellList.forEach(function(geocell, idx) {
- var markerOpts = markerClusterOptions.markers[idx];
- var markerRef = new BaseClass();
- markerRef.set("geocell", geocell);
- markerRef.set("icon", markerOpts.icon);
- markerRef.set("position", markerOpts.position);
- markerRef.set("options", markerOpts);
- markers.push(markerRef);
+ var markerOptions = markerClusterOptions.markers[idx];
+ markerOptions = _markerOptionsFilter(markerOptions);
+ var marker = new Marker(self, "marker_" + idx, markerOptions, "markercluster");
+ marker.set("isAdded", false);
+ marker.set("geocell", geocell);
+ marker.set("position", markerOptions.position);
+ markers.push(marker);
});
var markerCluster = new MarkerCluster(self, result.id, {
@@ -1073,10 +1053,30 @@ Map.prototype._onMarkerEvent = function(eventName, markerId, position) {
var marker = self.MARKERS[markerId] || null;
if (marker) {
marker.set('position', position);
- marker.trigger(eventName, position);
+ marker.trigger(eventName, position, marker);
}
};
+Map.prototype._onClusterEvent = function(eventName, markerClusterId, clusterId, position) {
+ var self = this;
+ var markerCluster = self.OVERLAYS[markerClusterId] || null;
+ if (markerCluster) {
+ var cluster = markerCluster.getCluster(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);
+ }
+ } else {
+ markerCluster.trigger(eventName, cluster);
+ }
+ }
+};
Map.prototype._onOverlayEvent = function(eventName, hashCode) {
var self = this;

MODIFY
www/Marker.js
www/Marker.js
@@ -9,7 +9,7 @@ var argscheck = require('cordova/argscheck'),
/*****************************************************************************
* Marker Class
*****************************************************************************/
-var Marker = function(map, id, markerOptions) {
+var Marker = function(map, id, markerOptions, className) {
BaseClass.apply(this);
var self = this;
@@ -31,6 +31,14 @@ var Marker = function(map, id, markerOptions) {
writable: false
});
+ className = className.toLowerCase();
+ Object.defineProperty(self, "getPluginName", {
+ writable: false,
+ value: function() {
+ return this.map.getId() + "-" + className;
+ }
+ });
+
if (markerOptions && markerOptions.position) {
self.set('position', markerOptions.position);
}
@@ -117,10 +125,6 @@ var Marker = function(map, id, markerOptions) {
utils.extend(Marker, BaseClass);
-Marker.prototype.getPluginName = function() {
- return this.map.getId() + "-marker";
-};
-
Marker.prototype.remove = function(callback) {
var self = this;
self.trigger(self.id + "_remove");
@@ -131,6 +135,23 @@ Marker.prototype.remove = function(callback) {
}, self.errorHandler, self.getPluginName(), 'remove', [this.getId()]);
};
+Marker.prototype.getOptions = function() {
+ var self = this;
+ return {
+ "position": self.getPosition(),
+ "disableAutoPan": self.get("disableAutoPan"),
+ "opacity": self.get("opacity"),
+ "icon": self.get("icon"),
+ "zIndex": self.get("zIndex"),
+ "anchor": self.get("anchor"),
+ "infoWindowAnchor": self.get("infoWindowAnchor"),
+ "draggable": self.get("draggable"),
+ "title": self.getTitle(),
+ "snippet": self.getSnippet(),
+ "visible": self.get("visible"),
+ "rotation": self.getRotation()
+ };
+};
Marker.prototype.getPosition = function() {
var position = this.get('position');
if (!(position instanceof LatLng)) {

MODIFY
www/MarkerCluster.js
www/MarkerCluster.js
@@ -88,6 +88,19 @@ MarkerCluster.prototype.getHashCode = function() {
return this.hashCode;
};
+MarkerCluster.prototype.getCluster = function(clusterId) {
+ var self = this,
+ resolution = self.get("resolution");
+
+ if (!self._clusters[resolution]) {
+ return null;
+ }
+
+ var tmp = clusterId.split(";");
+ clusterId = tmp[0];
+ var cluster = self._clusters[resolution][clusterId];
+ return cluster;
+};
MarkerCluster.prototype.onCameraMoveEnd = function() {
var self = this;
@@ -162,8 +175,8 @@ MarkerCluster.prototype.redraw = function() {
!visibleRegion.contains(bounds.southwest)) {
if (cluster.getMode() === cluster.NO_CLUSTER_MODE) {
- cluster._markerRefs.forEach(function(mRef, idx) {
- deleteClusters.push(geocell + "-" + idx);
+ cluster.getMarkers().forEach(function(mRef, idx) {
+ deleteClusters.push(geocell + ";" + idx);
});
} else {
deleteClusters.push(geocell);
@@ -178,8 +191,8 @@ MarkerCluster.prototype.redraw = function() {
keys.forEach(function(geocell) {
cluster = self._clusters[prevResolution][geocell];
if (cluster.getMode() === cluster.NO_CLUSTER_MODE) {
- cluster._markerRefs.forEach(function(mRef, idx) {
- deleteClusters.push(geocell + "-" + idx);
+ cluster.getMarkers().forEach(function(mRef, idx) {
+ deleteClusters.push(geocell + ";" + idx);
});
} else {
deleteClusters.push(geocell);
@@ -204,16 +217,16 @@ MarkerCluster.prototype.redraw = function() {
self.set("prevNEcell", neCell);
var prepareClusters = {};
- self._markers.forEach(function(markerRef) {
- if (markerRef.get("isAdded")) {
+ self._markers.forEach(function(marker) {
+ if (marker.get("isAdded")) {
return;
}
- if (!visibleRegion.contains(markerRef.get("position"))) {
+ if (!visibleRegion.contains(marker.get("position"))) {
return;
}
- var geocell = markerRef.get("geocell").substr(0, resolution + 1);
+ var geocell = marker.get("geocell").substr(0, resolution + 1);
prepareClusters[geocell] = prepareClusters[geocell] || [];
- prepareClusters[geocell].push(markerRef);
+ prepareClusters[geocell].push(marker);
});
//------------------------------------------
@@ -231,9 +244,9 @@ MarkerCluster.prototype.redraw = function() {
var hit,
clusterCnt = cluster.getItemLength(),
clusterOpts = {
- "geocell": geocell,
"count": clusterCnt,
- "position": cluster.bounds.getCenter()
+ "position": cluster.bounds.getCenter(),
+ "id": geocell
};
for (var i = 0; i < self.icons.length; i++) {
@@ -258,37 +271,19 @@ MarkerCluster.prototype.redraw = function() {
}
if (hit) {
if (cluster.getMode() === cluster.NO_CLUSTER_MODE) {
- cluster._markerRefs.forEach(function(mRef, idx) {
- deleteClusters.push(geocell + "-" + idx);
+ cluster.getMarkers().forEach(function(marker, idx) {
+ deleteClusters.push(marker.getId());
});
}
cluster.setMode(cluster.CLUSTER_MODE);
- /*
- var nextLevels = {};
- var max = 0, maxGeocell;
- cluster._markerRefs.forEach(function(mRef) {
- var geocell = mRef.get("geocell").substr(0, resolution + 2);
- nextLevels[geocell] = nextLevels[geocell] || 0;
- nextLevels[geocell]++;
- if (nextLevels[geocell] > max) {
- max = nextLevels[geocell];
- maxGeocell = geocell;
- }
- });
- var bounds = geomodel.computeBox(maxGeocell);
- clusterOpts.position = bounds.getCenter();
- */
clusters.push(clusterOpts);
return;
}
- cluster._markerRefs.forEach(function(mRef, idx) {
- var markerOpts = {
- "count": 1,
- "position": mRef.get("position"),
- "icon": mRef.get("icon"),
- "geocell": clusterOpts.geocell + "-" + idx
- };
- clusters.push(markerOpts);
+ cluster.getMarkers().forEach(function(marker, idx) {
+ var markerOptions = marker.getOptions();
+ markerOptions.count = 1;
+ markerOptions.id = geocell + ";" + idx;
+ clusters.push(markerOptions);
});
cluster.setMode(cluster.NO_CLUSTER_MODE);
});

MODIFY
www/event.js
www/event.js
@@ -18,6 +18,7 @@ module.exports = {
INFO_LONG_CLICK: 'info_long_click',
INFO_CLOSE: 'info_close',
INFO_OPEN: 'info_open',
+ CLUSTER_CLICK: 'cluster_click',
MARKER_CLICK: 'marker_click',
MARKER_DRAG: 'marker_drag',
MARKER_DRAG_START: 'marker_drag_start',

(Android) implement the click mechanism