Customizing Mapbox Callout with HTML on iOS

184 views Asked by At

I am trying to implement a custom callout using MapBox on iOS. When the user presses on the marker I would like a callout to display a UIWebView rather than a left and right accessory view and the title with text only.

I have searched through the SDK documentation and cannot find a simple way to access the view of the annotation title so I can set it to a UIWebView.

I started off by trying to access the annotation layer to see if I could make changes, such as:

RMAnnotation *annotation = [[RMAnnotation alloc] initWithMapView:mapView coordinate:CLLocationCoordinate2DMake(56.0,-4.0) andTitle:@"test"];
annotation.userInfo = @"test";

RMMapLayer *layer = annotation.layer;
layer.backgroundColor = [UIColor blackColor].CGColor;

However, when I press on the marker the annotation bubble is still white.

I have searched through the SDK to try to understand the relationship between the RMAnnotation and RMMarker classes and how they interact but think my understanding is flawed and hence I am not getting anywhere.

If anyone can help point me in the right direction that would be appreciated!

1

There are 1 answers

0
Milly On

Ok, I figured out a way to make this work. Its a little of a 'hack' but it works really well for my purposes so I thought I would share. Please comment if you have a better idea and also tell me if this is not a great way to do it.

I checked the SDK source code and the RMMapView passes the SMCalloutView object the title, subtitle and left/right accessory views. When I checked the SMCalloutView code there is the ability to provide a custom callout by passing a UIView to contentView, but the RMMapView doesn't provide for passing this. My fix was to synthesize the SMCallout (_currentCallout) so that I can access contentView from my ViewController and set contentView to a UIWebView. I chose to create a new delegate method in RMMapViewDelegate called aboutToDisplayAnnotation that provides me with the opportunity to swap in my UIWebView before the callout is drawn to the screen, but I guess a better way might have been to rewrite the selectAnnotation method in RMMapView.