Bug fix: HtmlInfoWindow strange behavior
MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="cluster-20170728-1500" 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-20170729-0150" 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/ios/GoogleMaps/GoogleMapsViewController.m
src/ios/GoogleMaps/GoogleMapsViewController.m
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate {
if (self.activeMarker) {
+ NSString *clusterId_markerId =[NSString stringWithFormat:@"%@", self.activeMarker.userData];
+ NSArray *tmp = [clusterId_markerId componentsSeparatedByString:@"_"];
+ NSString *className = [tmp objectAtIndex:0];
+ if ([className isEqualToString:@"markercluster"]) {
+ [self triggerClusterEvent:@"info_close" marker:self.activeMarker];
+ } else {
[self triggerMarkerEvent:@"info_close" marker:self.activeMarker];
+ }
+
//self.map.selectedMarker = nil;
self.activeMarker = nil;
}
}
- (void) syncInfoWndPosition {
- CLLocationCoordinate2D position = self.map.selectedMarker.position;
+ if (self.activeMarker == nil) {
+ NSLog(@"-->no active marker");
+ return;
+ }
+ CLLocationCoordinate2D position = self.activeMarker.position;
CGPoint point = [self.map.projection
pointForCoordinate:CLLocationCoordinate2DMake(position.latitude, position.longitude)];
NSString* jsString = [NSString
stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@', {evtName: 'syncPosition', callback: '_onSyncInfoWndPosition', args: [{x: %f, y: %f}]});",
self.mapId, point.x, point.y ];
- //NSLog(@"--->%@", jsString);
[self execJS:jsString];
}
*/
- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker {
- NSString *markerId = [NSString stringWithString:marker.userData];
- NSArray *tmp = [markerId componentsSeparatedByString:@"_"];
- NSString *className = [tmp objectAtIndex:0];
+ NSString *clusterId_markerId = [NSString stringWithString:marker.userData];
- if ([className isEqualToString:@"marker"]) {
- [self triggerMarkerEvent:@"marker_click" marker:marker];
+ if ([clusterId_markerId containsString:@"markercluster_"]) {
+ if ([clusterId_markerId containsString:@"-marker_"]) {
+ NSLog(@"--->activeMarker = %@", marker.userData);
+ self.map.selectedMarker = marker;
+ self.activeMarker = marker;
}
-
- if ([className isEqualToString:@"markercluster"]) {
[self triggerClusterEvent:@"cluster_click" marker:marker];
+ } else {
+ [self triggerMarkerEvent:@"marker_click" marker:marker];
+ NSLog(@"--->activeMarker = %@", marker.userData);
+ self.map.selectedMarker = marker;
+ self.activeMarker = marker;
}
+ NSArray *tmp = [clusterId_markerId componentsSeparatedByString:@"_"];
+ NSString *className = [tmp objectAtIndex:0];
+
// Get the marker plugin
NSString *pluginId = [NSString stringWithFormat:@"%@-%@", self.mapId, className];
CDVPlugin<MyPlgunProtocol> *plugin = [self.plugins objectForKey:pluginId];
if ([properties objectForKey:@"disableAutoPan"] != nil) {
disableAutoPan = [[properties objectForKey:@"disableAutoPan"] boolValue];
if (disableAutoPan) {
- self.map.selectedMarker = marker;
- self.activeMarker = marker;
return YES;
}
}
cameraWithTarget:marker.position zoom:self.map.camera.zoom];
[self.map animateToCameraPosition:cameraPosition];
- return YES;
+ return NO;
}
- (void)mapView:(GMSMapView *)mapView didCloseInfoWindowOfMarker:(nonnull GMSMarker *)marker {
self.mapId, eventName, sourceArrayString];
[self execJS:jsString];
- if (self.activeMarker) {
[self syncInfoWndPosition];
}
-}
- (void)execJS: (NSString *)jsString {
if ([self.webView respondsToSelector:@selector(stringByEvaluatingJavaScriptFromString:)]) {
NSString *clusterId = [tmp objectAtIndex:0];
NSString *markerId = [tmp objectAtIndex:1];
+ // Get the marker plugin
NSString* jsString = [NSString
stringWithFormat:@"javascript:cordova.fireDocumentEvent('%@', {evtName: '%@', callback: '_onClusterEvent', args: ['%@', '%@', new plugin.google.maps.LatLng(%f, %f)]});",
self.mapId, eventName, clusterId, markerId,

MODIFY
src/ios/GoogleMaps/PluginMap.m
src/ios/GoogleMaps/PluginMap.m
}];
}
+- (void)setActiveMarkerId:(CDVInvokedUrlCommand*)command {
+
+ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
+
+ NSString *markerId = [command.arguments objectAtIndex:0];
+ GMSMarker *marker = [self.objects objectForKey:markerId];
+ if (marker != nil) {
+ self.mapCtrl.map.selectedMarker = marker;
+ self.mapCtrl.activeMarker = marker;
+ }
+
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
+ [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ }];
+}
+
- (void)toDataURL:(CDVInvokedUrlCommand *)command {

MODIFY
src/ios/GoogleMaps/PluginMarker.m
src/ios/GoogleMaps/PluginMarker.m
}];
}
-- (void)setActiveMarkerId:(CDVInvokedUrlCommand*)command {
-
- [[NSOperationQueue mainQueue] addOperationWithBlock:^{
-
- NSString *markerId = [command.arguments objectAtIndex:0];
- GMSMarker *marker = [self.objects objectForKey:markerId];
- if (marker == nil) {
- return ;
- }
- self.mapCtrl.map.selectedMarker = marker;
- self.mapCtrl.activeMarker = marker;
-
- CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
- [(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
- }];
-}
-
/**
* Remove the specified marker
* @params markerId

MODIFY
www/Map.js
www/Map.js
@@ -45,7 +45,7 @@ var Map = function(id) {
if (prevId in self.MARKERS) {
self.MARKERS[prevId].trigger.call(self.MARKERS[prevId], event.INFO_CLOSE);
}
- exec(null, null, self.id + "-marker", 'setActiveMarkerId', [newId]);
+ exec(null, null, self.id, 'setActiveMarkerId', [newId]);
});
};
@@ -926,7 +926,7 @@ Map.prototype.addMarker = function(markerOptions, callback) {
var self = this;
markerOptions = common.markerOptionsFilter(markerOptions);
exec(function(result) {
- var marker = new Marker(self, result.id, markerOptions, "marker");
+ var marker = new Marker(self, result.id, markerOptions, "Marker");
self.MARKERS[result.id] = marker;
self.OVERLAYS[result.id] = marker;
@@ -966,7 +966,7 @@ Map.prototype.addMarkerCluster = function(markerClusterOptions, callback) {
markerOptions = common.markerOptionsFilter(markerOptions);
var markerId = markerOptions.id || "marker_" + idx;
- var marker = new Marker(self, markerId, markerOptions, "markercluster");
+ var marker = new Marker(self, markerId, markerOptions, "MarkerCluster");
marker.set("isAdded", false, true);
marker.set("geocell", geocell, true);
marker.set("position", markerOptions.position, true);
@@ -974,6 +974,9 @@ Map.prototype.addMarkerCluster = function(markerClusterOptions, callback) {
return result.id + "-" + markerId;
};
markerMap[markerId] = marker;
+
+ self.MARKERS[marker.getId()] = marker;
+ self.OVERLAYS[marker.getId()] = marker;
});
var markerCluster = new MarkerCluster(self, result.id, {
@@ -1027,7 +1030,12 @@ 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);
+ } else {
markerCluster.trigger(event.MARKER_CLICK, position, marker);
+ }
} else {
// clusterred marker
var cluster = markerCluster.getClusterByClusterId(clusterId);

MODIFY
www/Marker.js
www/Marker.js
@@ -23,7 +23,7 @@ var Marker = function(map, id, markerOptions, className) {
writable: false
});
Object.defineProperty(self, "type", {
- value: "Marker",
+ value: className,
writable: false
});
@@ -31,7 +31,7 @@ var Marker = function(map, id, markerOptions, className) {
Object.defineProperty(self, "getPluginName", {
writable: false,
value: function() {
- return this.map.getId() + "-" + className;
+ return this.map.getId() + "-" + className.toLowerCase();
}
});

Bug fix: HtmlInfoWindow strange behavior