Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[iOS] No identifier for annotation #3036

Closed
rsimenok opened this issue Nov 14, 2015 · 4 comments
Closed

[iOS] No identifier for annotation #3036

rsimenok opened this issue Nov 14, 2015 · 4 comments
Labels
iOS Mapbox Maps SDK for iOS

Comments

@rsimenok
Copy link

  1. I have many annotations, i need to present unique callout but in leftCalloutAccessoryView and rightCalloutAccessoryViewForAnnotation i can't identify annotation, only by title or subtitle, but what if i have the same titles or subtitles, it's not very good. Please add some property to store annotation identifier.

  2. And it's will be very great if i can show custom callout view, not only left or right part but whole view. For example i need to press on callout and present another viewController, but i can't do these now. I can't add button to rightCalloutAccessoryViewForAnnotation but i can't execute button selector.

Thank you.

@rsimenok rsimenok changed the title No identifier for annotation [iOS] No identifier for annotation Nov 14, 2015
@1ec5
Copy link
Contributor

1ec5 commented Nov 14, 2015

Please add some property to store annotation identifier.

There’s no such thing as an “annotation identifier”. (There is a reuse identifier for annotation images, but your application can give a single annotation different images at different times.) Instead, your view controller should store a reference to the annotation you want to identify, then check whether the annotation parameter is equal to that annotation.

And it's will be very great if i can show custom callout view, not only left or right part but whole view.

This is being tracked in #2211.

I can't add button to rightCalloutAccessoryViewForAnnotation but i can't execute button selector.

If the right callout accessory view is a descendant of UIControl, such as a UIButton, your map view delegate can implement -mapView:annotation:calloutAccessoryControlTapped:.

@1ec5 1ec5 added the iOS Mapbox Maps SDK for iOS label Nov 14, 2015
@rsimenok
Copy link
Author

  1. I have 457 annotations now, each annotation should have their own image, and i can't identify annotation to set correct image to it, or show correct calloutView. Now i identify annotation only by title, it's not very good. Annotation must have identifier! Please :)

  2. And there are no clustering for annotations as i understand, yes?

  3. Is there any method called when i tap whole callout, not only right or left view based on UIControl?

@1ec5
Copy link
Contributor

1ec5 commented Nov 15, 2015

I have 457 annotations now, each annotation should have their own image, and i can't identify annotation to set correct image to it, or show correct calloutView.

In general, if you need to manage a few annotations after adding them to the map view, your view controller should store that annotation in an instance variable.

However, in your case, it sounds like the image would be considered part of the data for an annotation, rather than mere decoration. So instead of adding a series of MGLPointAnnotations or MGLPolygons to the map view:

  1. Create a subclass of MGLPointAnnotation or MGLPolygon, or create a class that conforms to the MGLAnnotation protocol. In that class, implement your own identifier property. (It can be anything.)
  2. Add instances of that class to the map view via -addAnnotation: or -addAnnotations:.
  3. In methods such as -mapView:rightCalloutAccessoryViewForAnnotation:, cast the annotation to your custom class and get its identifier.

In other words, MGLPointAnnotation is a convenience class for the most common case where the title and subtitle represent the essence of an annotation. But if the annotation’s data model should be represented by something else, you should subclass.

And there are no clustering for annotations as i understand, yes?

Correct. We’re planning to implement it for #320.

Is there any method called when i tap whole callout, not only right or left view based on UIControl?

-mapView:tapOnCalloutForAnnotation: was added in #2596 and will appear in the next release. If you need it sooner, you can install a prerelease:

  • If you’re using CocoaPods, point your Podfile to https://raw.githubusercontent.com/mapbox/mapbox-gl-native/ios-v3.0.0-pre.5/ios/Mapbox-iOS-SDK.podspec.
  • Otherwise, install one of the top two ZIP files here.

I hope this helps!

@rsimenok
Copy link
Author

Subclassing is good solution, thank you!

And thank you for -mapView:tapOnCalloutForAnnotation:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

No branches or pull requests

2 participants