Skip to content

Commit

Permalink
Fix #124: Cannot detect GMSCircle when tapping the circle.
Browse files Browse the repository at this point in the history
  • Loading branch information
wf9a5m75 committed Jul 12, 2014
1 parent b141bbf commit c1a6743
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/ios/GoogleMaps/Circle.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ -(void)createCircle:(CDVInvokedUrlCommand *)command

NSString *id = [NSString stringWithFormat:@"circle_%lu", (unsigned long)circle.hash];
[self.mapCtrl.overlayManager setObject:circle forKey: id];

circle.title = id;

NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
[result setObject:id forKey:@"id"];
Expand Down
1 change: 1 addition & 0 deletions src/ios/GoogleMaps/GoogleMaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@
- (void)resizeMap:(CDVInvokedUrlCommand *)command;
- (void)setDiv:(CDVInvokedUrlCommand *)command;
- (void)isAvailable:(CDVInvokedUrlCommand *)command;
- (void)clear:(CDVInvokedUrlCommand*)command;
@end
12 changes: 12 additions & 0 deletions src/ios/GoogleMaps/GoogleMaps.m
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,16 @@ -(void)isAvailable:(CDVInvokedUrlCommand *)command
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

/**
* Clear all markups
*/
- (void)clear:(CDVInvokedUrlCommand *)command {
[self.mapCtrl.overlayManager removeAllObjects];
[self.mapCtrl.map clear];

CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

@end
23 changes: 9 additions & 14 deletions src/ios/GoogleMaps/GoogleMapsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,12 @@ - (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker {

- (void)mapView:(GMSMapView *)mapView didTapOverlay:(GMSOverlay *)overlay {
NSString *overlayClass = NSStringFromClass([overlay class]);
if([overlayClass isEqualToString:@"GMSPolygon"]) {
[self triggerOverlayEvent:@"overlay_click" type:@"polygon" overlay:overlay];
}
if([overlayClass isEqualToString:@"GMSPolyline"]) {
[self triggerOverlayEvent:@"overlay_click" type:@"polyline" overlay:overlay];
}
if([overlayClass isEqualToString:@"GMSCircle"]) {
[self triggerOverlayEvent:@"overlay_click" type:@"circle" overlay:overlay];
}
if([overlayClass isEqualToString:@"GMSGroundOverlay"]) {
[self triggerOverlayEvent:@"overlay_click" type:@"groundOverlay" overlay:overlay];
NSLog(@"clicked = %@", overlay.title);
if ([overlayClass isEqualToString:@"GMSPolygon"] ||
[overlayClass isEqualToString:@"GMSPolyline"] ||
[overlayClass isEqualToString:@"GMSCircle"] ||
[overlayClass isEqualToString:@"GMSGroundOverlay"]) {
[self triggerOverlayEvent:@"overlay_click" id:overlay.title];
}
}

Expand Down Expand Up @@ -332,10 +327,10 @@ - (void)triggerMarkerEvent: (NSString *)eventName marker:(GMSMarker *)marker
/**
* Involve App._onOverlayEvent
*/
- (void)triggerOverlayEvent: (NSString *)eventName type:(NSString *) type overlay:(GMSOverlay *)overlay
- (void)triggerOverlayEvent: (NSString *)eventName id:(NSString *) id
{
NSString* jsString = [NSString stringWithFormat:@"plugin.google.maps.Map._onOverlayEvent('%@', '%@_%lu');",
eventName, type, (unsigned long)overlay.hash];
NSString* jsString = [NSString stringWithFormat:@"plugin.google.maps.Map._onOverlayEvent('%@', '%@');",
eventName, id];
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
}

Expand Down
1 change: 1 addition & 0 deletions src/ios/GoogleMaps/GroundOverlay.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ -(void)createGroundOverlay:(CDVInvokedUrlCommand *)command

NSString *id = [NSString stringWithFormat:@"groundOverlay_%lu", (unsigned long)layer.hash];
[self.mapCtrl.overlayManager setObject:layer forKey: id];
layer.title = id;

NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
[result setObject:id forKey:@"id"];
Expand Down
1 change: 0 additions & 1 deletion src/ios/GoogleMaps/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

@interface Map : CDVPlugin<MyPlgunProtocol>
@property (nonatomic, strong) GoogleMapsViewController* mapCtrl;
- (void)clear:(CDVInvokedUrlCommand*)command;
- (void)setTilt:(CDVInvokedUrlCommand*)command;
- (void)setCenter:(CDVInvokedUrlCommand*)command;
- (void)setZoom:(CDVInvokedUrlCommand*)command;
Expand Down
11 changes: 0 additions & 11 deletions src/ios/GoogleMaps/Map.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@ -(void)setGoogleMapsViewController:(GoogleMapsViewController *)viewCtrl
self.mapCtrl = viewCtrl;
}

/**
* Clear all markups
*/
- (void)clear:(CDVInvokedUrlCommand *)command {
[self.mapCtrl.map clear];

CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}


/**
* Move the center of the map
*/
Expand Down
3 changes: 2 additions & 1 deletion src/ios/GoogleMaps/Polygon.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ -(void)createPolygon:(CDVInvokedUrlCommand *)command

// Create the polygon, and assign it to the map.
GMSPolygon *polygon = [GMSPolygon polygonWithPath:path];
polygon.title = @"polygon";

if ([[json valueForKey:@"visible"] boolValue]) {
polygon.map = self.mapCtrl.map;
Expand All @@ -51,7 +52,7 @@ -(void)createPolygon:(CDVInvokedUrlCommand *)command

NSString *id = [NSString stringWithFormat:@"polygon_%lu", (unsigned long)polygon.hash];
[self.mapCtrl.overlayManager setObject:polygon forKey: id];

polygon.title = id;


NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
Expand Down
2 changes: 1 addition & 1 deletion src/ios/GoogleMaps/Polyline.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ -(void)createPolyline:(CDVInvokedUrlCommand *)command

NSString *id = [NSString stringWithFormat:@"polyline_%lu", (unsigned long)polyline.hash];
[self.mapCtrl.overlayManager setObject:polyline forKey: id];

polyline.title = id;

NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
[result setObject:id forKey:@"id"];
Expand Down

0 comments on commit c1a6743

Please sign in to comment.