Skip to content

Commit

Permalink
#4 title tap event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Oct 15, 2015
1 parent 85126f8 commit cf38d47
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ <h1>Mapbox test</h1>
},
function (result) {
console.log(JSON.stringify(result));
// let's add a callback for these markers
// let's add a callback for these markers - invoked when the callout is tapped (Android) or the (i) icon in the marker callout (iOS)
Mapbox.addMarkerCallback(function (selectedMarker) {
alert("Marker selected: " + JSON.stringify(selectedMarker));
});
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-mapbox"
version="1.0.2">
version="1.1.0">

<name>Mapbox</name>

Expand Down
1 change: 1 addition & 0 deletions src/ios/CDVMapbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

@property (retain) MGLMapView *mapView;
@property (retain) NSString *markerCallbackId;
@property (retain) MGLPointAnnotation *selectedAnnotation;

- (void) show:(CDVInvokedUrlCommand*)command;
- (void) hide:(CDVInvokedUrlCommand*)command;
Expand Down
23 changes: 17 additions & 6 deletions src/ios/CDVMapbox.m
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,26 @@ - (BOOL)mapView:(MGLMapView *)mapView annotationCanShowCallout:(id <MGLAnnotatio
// return annotationImage;
//}

- (void)mapView:(MGLMapView *)mapView didSelectAnnotation:(id <MGLAnnotation>)annotation {
- (nullable UIView *)mapView:(MGLMapView *)mapView rightCalloutAccessoryViewForAnnotation:(id <MGLAnnotation>)annotation {
if (self.markerCallbackId != nil) {
self.selectedAnnotation = annotation;
UIButton *butt = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[butt addTarget:self action:@selector(annotationInfoButtonTouched:) forControlEvents:UIControlEventTouchDown];
return butt;
} else {
return nil;
}
}

- (void) annotationInfoButtonTouched:(UIButton *)sender {
if (self.markerCallbackId != nil && self.selectedAnnotation != nil) {
NSMutableDictionary* returnInfo = [NSMutableDictionary dictionaryWithCapacity:4];
[returnInfo setObject:annotation.title forKey:@"title"];
if (annotation.subtitle != nil) {
[returnInfo setObject:annotation.subtitle forKey:@"subtitle"];
[returnInfo setObject:self.selectedAnnotation.title forKey:@"title"];
if (self.selectedAnnotation.subtitle != nil) {
[returnInfo setObject:self.selectedAnnotation.subtitle forKey:@"subtitle"];
}
[returnInfo setObject:[NSNumber numberWithDouble:annotation.coordinate.latitude] forKey:@"lat"];
[returnInfo setObject:[NSNumber numberWithDouble:annotation.coordinate.longitude] forKey:@"lng"];
[returnInfo setObject:[NSNumber numberWithDouble:self.selectedAnnotation.coordinate.latitude] forKey:@"lat"];
[returnInfo setObject:[NSNumber numberWithDouble:self.selectedAnnotation.coordinate.longitude] forKey:@"lng"];

CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:returnInfo];
[result setKeepCallbackAsBool:YES];
Expand Down

0 comments on commit cf38d47

Please sign in to comment.