Bug fix: can not close htmlInfoWindow if you tap on the map
MODIFY
src/android/plugin/google/maps/PluginMap.java
src/android/plugin/google/maps/PluginMap.java
@@ -97,7 +97,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
public HashMap<String, PluginEntry> plugins = new HashMap<String, PluginEntry>();
final int DEFAULT_CAMERA_PADDING = 20;
private Projection projection = null;
- private Marker activeMarker = null;
+ public Marker activeMarker = null;
private boolean isDragging = false;
@@ -2004,6 +2004,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
@Override
public void onInfoWindowClose(Marker marker) {
this.onMarkerEvent("info_close", marker);
+ activeMarker = null;
}
@@ -2023,6 +2024,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
String markerId = "marker_" + marker.getId();
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);
+ Log.d(TAG, js);
jsCallback(js);
}
public void syncInfoWndPosition() {
@@ -2449,6 +2451,10 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
@Override
public void onPostExecute(HashMap<String, Object> boundsHitList) {
+ if (activeMarker != null) {
+ onInfoWindowClose(activeMarker);
+
+ }
String key;
Map.Entry<String, Object> entry;

MODIFY
src/ios/GoogleMaps/GoogleMapsViewController.h
src/ios/GoogleMaps/GoogleMapsViewController.h
@property (nonatomic, strong) GMSMapView* map;
@property (nonatomic) BOOL clickable;
@property (nonatomic) BOOL isRenderedAtOnce;
+@property (nonatomic) GMSMarker* activeMarker;
@property (nonatomic, readwrite, strong) NSString *mapDivId;

MODIFY
src/ios/GoogleMaps/GoogleMapsViewController.m
src/ios/GoogleMaps/GoogleMapsViewController.m
*/
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate {
+ if (self.activeMarker) {
+ [self triggerMarkerEvent:@"info_close" marker:self.activeMarker];
+ self.map.selectedMarker = nil;
+ self.activeMarker = nil;
+ }
+
NSArray *pluginNames =[self.plugins allKeys];
NSString *pluginName, *key;
NSDictionary *properties;
disableAutoPan = [[properties objectForKey:@"disableAutoPan"] boolValue];
if (disableAutoPan) {
self.map.selectedMarker = marker;
+ self.activeMarker = marker;
return YES;
}
}
- (void)mapView:(GMSMapView *)mapView didCloseInfoWindowOfMarker:(nonnull GMSMarker *)marker {
[self triggerMarkerEvent:@"info_close" marker:marker];
+ self.map.selectedMarker = nil;
+ self.activeMarker = nil;
}

MODIFY
src/ios/GoogleMaps/PluginMarker.m
src/ios/GoogleMaps/PluginMarker.m
GMSMarker *marker = [self.objects objectForKey:hashCode];
if (marker) {
self.mapCtrl.map.selectedMarker = marker;
+ self.mapCtrl.activeMarker = marker;
}
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
self.mapCtrl.map.selectedMarker = nil;
+ self.mapCtrl.activeMarker = nil;
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
return ;
}
self.mapCtrl.map.selectedMarker = marker;
+ self.mapCtrl.activeMarker = marker;
}];
}

MODIFY
www/HtmlInfoWindow.js
www/HtmlInfoWindow.js
var utils = require('cordova/utils'),
+ event = require('./event'),
common = require('./Common'),
BaseClass = require('./BaseClass');
@@ -173,6 +174,7 @@ HTMLInfoWindow.prototype.close = function() {
map.off("infoPosition_changed");
marker.off("icon_changed");
marker.off("infoWindowAnchor_changed");
+ marker.off(event.INFO_CLOSE, self.close);
map.set("active_marker_id", null);
var div = map.getDiv();
@@ -203,12 +205,14 @@ HTMLInfoWindow.prototype.open = function(marker) {
var map = marker.getMap();
var self = this;
+
map.fromLatLngToPoint(marker.getPosition(), function(point) {
map.set("infoPosition", {x: point[0], y: point[1]});
map.bindTo("infoPosition", self);
marker.bindTo("infoWindowAnchor", self);
marker.bindTo("icon", self);
+ marker.on(event.INFO_CLOSE, self.close.bind(self));
self.set("marker", marker);
map.set("active_marker_id", marker.getId());
self.trigger("infoWindowAnchor_changed");

MODIFY
www/Marker.js
www/Marker.js
@@ -48,7 +48,10 @@ var Marker = function(map, id, markerOptions) {
//-----------------------------------------------
// Sets event listeners
//-----------------------------------------------
- this.on(event.INFO_OPEN, function() {
+
+ if (markerOptions.infoWindow) {
+ console.log("[deprecated] the infoWindow option is deprecated. Please use event listener.");
+ self.on(event.INFO_OPEN, function() {
if (map.get("active_marker_id") === id) {
return;
}
@@ -58,16 +61,13 @@ var Marker = function(map, id, markerOptions) {
markerOptions.infoWindow.open(self);
}
});
- this.on(event.INFO_CLOSE, function() {
+ self.on(event.INFO_CLOSE, function() {
map.set('active_marker_id', undefined);
if (markerOptions.infoWindow) {
markerOptions.infoWindow.close(self);
}
});
-
- if (markerOptions.infoWindow) {
- console.log("[deprecated] the infoWindow option is deprecated. Please use event listener.");
self.on(event.MARKER_CLICK, function() {
self.trigger(event.INFO_OPEN);
});

Bug fix: can not close htmlInfoWindow if you tap on the map