Vlad Z.
Vlad Z.

Reputation: 3451

Custom callout (mapBox iOS sdk)

i want to create callout with custom view - such as this one enter image description here
(source: arcgis.com)

But i can't find any workaround to do this stuff, only solution i find is to use following code:

- (RMMapLayer *)mapView:(RMMapView *)mapView layerForAnnotation:(RMAnnotation *)annotation

         ... 
        marker = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"marker.png"]]; 
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
        CalloutViewController* callout = [storyboard instantiateViewControllerWithIdentifier:@"callout"]; 
        [marker setLabel:callout.view];
}

but result not quite what i want, because when I set the label property of the marker, the view appears without tapping on the marker.

Any idea how to solve this problem? Or maybe there's some other approaches to achieve this?

EDIT:

also i find this article on github, but i can't figure out how to implement it.

Upvotes: 1

Views: 2664

Answers (2)

incanus
incanus

Reputation: 5128

This is outside the scope of the SDK, as it's done in the SMCalloutView dependent project. Since both are open source, you can add this behavior but it's currently not possible.

(I wrote the SDK in question).

Upvotes: 1

Daij-Djan
Daij-Djan

Reputation: 50109

look at https://github.com/iNima/mapbox-ios-sdk/blob/91d8614fa4549b25dd8b647d82f270382c279a8c/MapView/Map/RMMapView.m

it tells you that on click the RMMapView class will handle showing a callout for you given your marker's layer has canShowCallout == YES and title != nil set on it

if your marker fulfils this you get the same callout as with MapKit :)

set contentView or left- or right- CalloutView variables to modify that callout view

- (RMMapLayer *)mapView:(RMMapView *)mapView layerForAnnotation:(RMAnnotation *)annotation

     ... 
    marker = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"marker.png"]]; 
    [marker setCanShowCallout:YES];
    [marker setTitle"Test"];

    //Following only works with iNimas version
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
    CalloutViewController* callout = [storyboard instantiateViewControllerWithIdentifier:@"callout"]; 
    [marker setContentView:callout.view];

    return marker ; 
}

Upvotes: 2

Related Questions