diff --git a/src/ios/GoogleMaps/PluginMapViewController.m b/src/ios/GoogleMaps/PluginMapViewController.m index 4cf535280..c54fec1a9 100644 --- a/src/ios/GoogleMaps/PluginMapViewController.m +++ b/src/ios/GoogleMaps/PluginMapViewController.m @@ -64,12 +64,33 @@ - (void)mapView:(GMSMapView *)mapView didTapMyLocation:(CLLocationCoordinate2D)l [self execJS:jsString]; } +- (void)mapView:(GMSMapView *)mapView didTapOverlay:(GMSOverlay *)overlay { + NSLog(@"--> key = %@, did tap an overlay", overlay.title); + + if (![overlay.title hasPrefix:@"polyline_"]) { + return; + } + + NSArray *tmp = [overlay.title componentsSeparatedByString:@"_"]; + NSString *eventName = [NSString stringWithFormat:@"%@_click", [tmp objectAtIndex:0]]; + NSString *propertyId = [NSString stringWithFormat:@"polyline_property_%@", [tmp objectAtIndex:1]]; + NSDictionary *properties = [self.objects objectForKey: propertyId]; + + if (!properties) { + NSLog(@"--> object properties not found for key=%@", propertyId); + return; + } + + GMSCoordinateBounds *bounds = (GMSCoordinateBounds *)[properties objectForKey:@"bounds"]; + + [self triggerOverlayEvent: eventName overlayId: overlay.title coordinate: bounds.center]; +} + /** * @callback the my location button is clicked. */ - (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate { - if (self.activeMarker) { /* NSString *clusterId_markerId =[NSString stringWithFormat:@"%@", self.activeMarker.userData]; @@ -205,7 +226,7 @@ - (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D continue; } - if ([key hasPrefix:@"polyline_"]) { + /*if ([key hasPrefix:@"polyline_"]) { geodesic = (NSNumber *)[properties objectForKey:@"geodesic"]; path = (GMSPath *)[properties objectForKey:@"mutablePath"]; if ([geodesic boolValue] == YES) { @@ -216,14 +237,14 @@ - (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D continue; } } else { - touchPoint = [PluginUtil isPointOnTheLine:path coordinate:coordinate projection:self.map.projection]; - if (CLLocationCoordinate2DIsValid(touchPoint)) { + touchPoint = [PluginUtil isPointOnTheLine:path coordinate:coordinate projection:self.map.projection]; + if (CLLocationCoordinate2DIsValid(touchPoint)) { maxZIndex = zIndex; hitKey = [key stringByReplacingOccurrencesOfString:@"_property" withString:@""]; continue; } } - } + }*/ if ([key hasPrefix:@"polygon_"]) { path = (GMSPath *)[properties objectForKey:@"mutablePath"]; @@ -235,7 +256,6 @@ - (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D } } - if ([key hasPrefix:@"circle_"]) { key = [key stringByReplacingOccurrencesOfString:@"_property" withString:@""]; GMSCircle *circle = (GMSCircle *)[self.objects objectForKey:key]; diff --git a/src/ios/GoogleMaps/PluginPolyline.m b/src/ios/GoogleMaps/PluginPolyline.m index 3846952b2..e2cfe2f32 100644 --- a/src/ios/GoogleMaps/PluginPolyline.m +++ b/src/ios/GoogleMaps/PluginPolyline.m @@ -102,12 +102,12 @@ -(void)create:(CDVInvokedUrlCommand *)command // Since this plugin provide own click detection, // disable default clickable feature. - polyline.tappable = NO; + polyline.tappable = [[json valueForKey:@"clickable"] boolValue]; NSString *id = [NSString stringWithFormat:@"polyline_%@", idBase]; [self.mapCtrl.objects setObject:polyline forKey: id]; polyline.title = id; - + // Run the below code on background thread. [self.mapCtrl.executeQueue addOperationWithBlock:^{ @@ -121,7 +121,7 @@ -(void)create:(CDVInvokedUrlCommand *)command // Keep the properties //--------------------------- NSString *propertyId = [NSString stringWithFormat:@"polyline_property_%@", idBase]; - + // points NSMutableDictionary *properties = [[NSMutableDictionary alloc] init]; [properties setObject:mutablePath forKey:@"mutablePath"];