Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tap on polyline #2847

Open
wants to merge 8 commits into
base: multiple_maps
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions src/ios/GoogleMaps/PluginMapViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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) {
Expand All @@ -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"];
Expand All @@ -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];
Expand Down
6 changes: 3 additions & 3 deletions src/ios/GoogleMaps/PluginPolyline.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. If you set polyline.tappable = YES, this plugin can not get clicked latlng.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you, but the code to try to find if the click is on the polyline don't work see my git project example in #2845


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:^{

Expand All @@ -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"];
Expand Down