Bug fix: Marker INFO_CLICK event not firing when is applied on clicked marker in clusterer.
MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="2.0.0-beta3-20170829-1218" 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-20170830-1054" 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/PluginMap.java
src/android/plugin/google/maps/PluginMap.java
@@ -759,7 +759,11 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
}
}
+ if ((marker.getTag() + "").startsWith("markercluster_")){
+ this.onClusterEvent("info_open", marker);
+ } else {
this.onMarkerEvent("info_open", marker);
+ }
// Linear layout
LinearLayout windowLayer = new LinearLayout(activity);
@@ -966,7 +970,12 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
if (marker.getTitle() == null && marker.getSnippet() == null) {
syncInfoWndPosition();
+
+ if ((marker.getTag() + "").startsWith("markercluster_")){
+ this.onClusterEvent("info_open", marker);
+ } else {
this.onMarkerEvent("info_open", marker);
+ }
int resId = PluginUtil.getAppResource(cordova.getActivity(), "dummy_infowindow", "layout");
return cordova.getActivity().getLayoutInflater().inflate(resId, null);
@@ -1987,9 +1996,10 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
if (clusterId_markerId.contains("markercluster_")) {
if (clusterId_markerId.contains("-marker_")) {
activeMarker = marker;
+ this.onClusterEvent("marker_click", activeMarker);
} else {
if (activeMarker != null) {
- this.onClusterEvent("info_close", activeMarker);
+ this.onMarkerEvent("info_close", activeMarker);
}
}
this.onClusterEvent("cluster_click", marker);
@@ -2037,47 +2047,75 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
public void onInfoWindowClick(Marker marker) {
activeMarker = marker;
syncInfoWndPosition();
+ String markerTag = marker.getTag() + "";
+ if (markerTag.startsWith("markercluster_")){
+ this.onClusterEvent("info_click", marker);
+ } else {
this.onMarkerEvent("info_click", marker);
}
+ }
@Override
public void onMarkerDrag(Marker marker) {
if (marker.equals(activeMarker)) {
syncInfoWndPosition();
}
+ if ((marker.getTag() + "").startsWith("markercluster_")){
+ this.onClusterEvent("marker_drag", marker);
+ } else {
this.onMarkerEvent("marker_drag", marker);
}
+ }
@Override
public void onMarkerDragEnd(Marker marker) {
if (marker.equals(activeMarker)) {
syncInfoWndPosition();
}
+ if ((marker.getTag() + "").startsWith("markercluster_")){
+ this.onClusterEvent("marker_drag_end", marker);
+ } else {
this.onMarkerEvent("marker_drag_end", marker);
}
+ }
@Override
public void onMarkerDragStart(Marker marker) {
if (marker.equals(activeMarker)) {
syncInfoWndPosition();
}
+ if ((marker.getTag() + "").startsWith("markercluster_")){
+ this.onClusterEvent("marker_drag_start", marker);
+ } else {
this.onMarkerEvent("marker_drag_start", marker);
}
+ }
@Override
public void onInfoWindowLongClick(Marker marker) {
activeMarker = marker;
syncInfoWndPosition();
+ if ((marker.getTag() + "").startsWith("markercluster_")){
+ this.onClusterEvent("info_long_click", marker);
+ } else {
this.onMarkerEvent("info_long_click", marker);
}
+ }
@Override
public void onInfoWindowClose(Marker marker) {
boolean useHtmlInfoWnd = marker.getTitle() == null &&
marker.getSnippet() == null;
if (useHtmlInfoWnd) {
+ String markerTag = marker.getTag() + "";
+ if (markerTag.startsWith("markercluster_")){
+ if (markerTag.contains("-marker_")) {
+ this.onClusterEvent("info_close", marker);
+ }
+ } else {
this.onMarkerEvent("info_close", marker);
}
+ }
//activeMarker = null; // <-- This causes HTMLinfoWindow is not able to close when you tap on the map.
}
@@ -2559,8 +2597,11 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
//Log.d(TAG, "---> onMapClick : " + activeMarker);
if (activeMarker != null) {
//Log.d(TAG, "---> activeMarker.getTag() : " + activeMarker.getTag());
- if ((activeMarker.getTag() + "").contains("markercluster")) {
+ String markerTag = activeMarker.getTag() + "";
+ if (markerTag.contains("markercluster")) {
+ if (markerTag.contains("-marker_")) {
onClusterEvent("info_close", activeMarker);
+ }
} else {
onInfoWindowClose(activeMarker);
}

MODIFY
src/ios/GoogleMaps/GoogleMapsViewController.m
src/ios/GoogleMaps/GoogleMapsViewController.m
NSArray *tmp = [clusterId_markerId componentsSeparatedByString:@"_"];
NSString *className = [tmp objectAtIndex:0];
if ([className isEqualToString:@"markercluster"]) {
+ if ([clusterId_markerId containsString:@"-marker_"]) {
[self triggerClusterEvent:@"info_close" marker:self.activeMarker];
+ }
} else {
[self triggerMarkerEvent:@"info_close" marker:self.activeMarker];
}
*/
- (void) mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker
{
+ NSString *markerTag = [NSString stringWithFormat:@"%@", marker.userData];
+ if ([markerTag hasPrefix:@"markercluster_"]) {
+ [self triggerClusterEvent:@"info_click" marker:marker];
+ } else {
[self triggerMarkerEvent:@"info_click" marker:marker];
+ }
[self syncInfoWndPosition];
}
/**
- (void)mapView:(GMSMapView *)mapView didLongPressInfoWindowOfMarker:(GMSMarker *)marker {
[self syncInfoWndPosition];
+ NSString *markerTag = [NSString stringWithFormat:@"%@", marker.userData];
+ if ([markerTag hasPrefix:@"markercluster_"]) {
+ [self triggerClusterEvent:@"info_long_click" marker:marker];
+ } else {
[self triggerMarkerEvent:@"info_long_click" marker:marker];
}
+}
/**
* @callback plugin.google.maps.event.MARKER_DRAG_START
*/
- (void) mapView:(GMSMapView *) mapView didBeginDraggingMarker:(GMSMarker *)marker
{
[self syncInfoWndPosition];
+ NSString *markerTag = [NSString stringWithFormat:@"%@", marker.userData];
+ if ([markerTag hasPrefix:@"markercluster_"]) {
+ [self triggerClusterEvent:@"marker_drag_start" marker:marker];
+ } else {
[self triggerMarkerEvent:@"marker_drag_start" marker:marker];
}
+}
/**
* @callback plugin.google.maps.event.MARKER_DRAG_END
*/
- (void) mapView:(GMSMapView *) mapView didEndDraggingMarker:(GMSMarker *)marker
{
[self syncInfoWndPosition];
+ NSString *markerTag = [NSString stringWithFormat:@"%@", marker.userData];
+ if ([markerTag hasPrefix:@"markercluster_"]) {
+ [self triggerClusterEvent:@"marker_drag_end" marker:marker];
+ } else {
[self triggerMarkerEvent:@"marker_drag_end" marker:marker];
}
+}
/**
* @callback plugin.google.maps.event.MARKER_DRAG
*/
- (void) mapView:(GMSMapView *) mapView didDragMarker:(GMSMarker *)marker
{
[self syncInfoWndPosition];
+ NSString *markerTag = [NSString stringWithFormat:@"%@", marker.userData];
+ if ([markerTag hasPrefix:@"markercluster_"]) {
+ [self triggerClusterEvent:@"marker_drag" marker:marker];
+ } else {
[self triggerMarkerEvent:@"marker_drag" marker:marker];
}
+}
- (void) syncInfoWndPosition {
if (self.activeMarker == nil) {
//NSLog(@"--->activeMarker = %@", marker.userData);
self.map.selectedMarker = marker;
self.activeMarker = marker;
+ NSString *markerTag = [NSString stringWithFormat:@"%@", marker.userData];
+ if ([markerTag hasPrefix:@"markercluster_"]) {
+ [self triggerClusterEvent:@"marker_click" marker:marker];
+ } else {
+ [self triggerMarkerEvent:@"marker_click" marker:marker];
+ }
} else {
if (self.activeMarker != nil) {
+ NSString *markerTag = [NSString stringWithFormat:@"%@", self.activeMarker.userData];
+ if ([markerTag hasPrefix:@"markercluster_"]) {
+ if ([markerTag containsString:@"-marker_"]) {
[self triggerClusterEvent:@"info_close" marker:self.activeMarker];
}
+ } else {
+ [self triggerMarkerEvent:@"info_close" marker:self.activeMarker];
+ }
+ }
}
[self triggerClusterEvent:@"cluster_click" marker:marker];
} else {
marker.snippet == nil;
if (useHtmlInfoWnd) {
+ NSString *markerTag = [NSString stringWithFormat:@"%@", marker.userData];
+ if ([markerTag hasPrefix:@"markercluster_"]) {
+ if ([markerTag containsString:@"-marker_"]) {
+ [self triggerClusterEvent:@"info_close" marker:marker];
+ }
+ } else {
[self triggerMarkerEvent:@"info_close" marker:marker];
}
+ }
//self.map.selectedMarker = nil; // <-- this causes the didCloseInfoWindowOfMarker event again
//self.activeMarker = nil; // <-- This causes HTMLinfoWindow is not able to close when you tap on the map.
if (useHtmlInfoWnd) {
[self syncInfoWndPosition];
+ NSString *markerTag = [NSString stringWithFormat:@"%@", marker.userData];
+ if ([markerTag hasPrefix:@"markercluster_"]) {
+ [self triggerClusterEvent:@"info_open" marker:marker];
+ } else {
[self triggerMarkerEvent:@"info_open" marker:marker];
+ }
return [[UIView alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
}
return NULL;
}
+ NSString *markerTag = [NSString stringWithFormat:@"%@", marker.userData];
+ if ([markerTag hasPrefix:@"markercluster_"]) {
+ [self triggerClusterEvent:@"info_open" marker:marker];
+ } else {
[self triggerMarkerEvent:@"info_open" marker:marker];
+ }
// Load styles
NSDictionary *styles = nil;

MODIFY
www/Map.js
www/Map.js
@@ -1082,14 +1082,13 @@ Map.prototype._onClusterEvent = function(eventName, markerClusterId, clusterId,
if (/^marker_/i.test(clusterId)) {
// regular marker
var marker = markerCluster.getMarkerById(clusterId);
- if (eventName === event.INFO_CLOSE ||
- eventName === event.INFO_OPEN) {
- marker.trigger(eventName, position);
+ if (eventName === event.MARKER_CLICK) {
+ markerCluster.trigger(eventName, position, marker);
} else {
- markerCluster.trigger(event.MARKER_CLICK, position, marker);
+ marker.trigger(eventName, position);
}
} else {
- // clusterred marker
+ // cluster marker
var cluster = markerCluster.getClusterByClusterId(clusterId);
if (cluster) {
markerCluster.trigger(eventName, cluster);

Bug fix: Marker INFO_CLICK event not firing when is applied on clicked marker in clusterer. #1692