You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Interacting with annotation points in style layer #6505
Platform: iOS 10, Swift 3 Mapbox SDK version: 3.4.0-alpha.4
First: Let me thank the Mapbox community. I'm using Mapbox since more than a week and may have seen just the tip of the iceberg, still learning a lot of things everyday, and I'm really impressed about the fast responsiveness of this community.
While I'm currently building an app for a client using the Mapbox iOS SDK, knowing that there a lot of features to come in the future (especially runtime styling), I often miss a few things that'd be great for future releases (and that's why I'm always writing down my thoughts and ideas which can help improve Mapbox for iOS. Because of the lack of documentation for the newest version of Mapbox iOS SDK, I first check in code, if there is a possible solution to my problem, if not, I check if there's a planned feature/issue written down in the repo, if not, I'm going to write an issue).
Now to my question: Is there a way to interact with annotation points in a style layer coming from a style URL? Because public func mapView(_ mapView: MGLMapView, didSelect annotation: MGLAnnotation) isn't called when I touch a point in a style layer.
Unlike annotations, style layers don’t come with interactivity and callout views out of the box. Instead, you have to build it yourself: install your own tap gesture recognizer, call MGLMapView.visibleFeatures(at:styleLayerIdentifiers:), and position your own custom callout view over the feature’s coordinate (using convert(_:toPointTo:). Hide the callout view in mapView(_:regionWillChange:), or update its location continuously in mapView(_:regionIsChanging:) and mapView(_:regionDidChange:).
I know this sounds like a lot of work. #6181 would make annotations more like style layers, in the process adding a lot of annotation-like functionality to style layers in general. That’s quite a ways off, however. #6515 would make the gesture recognition part a little easier, and we could add an API for displaying callout views for non-annotations as part of #4392. Meanwhile, under the hood, annotations are already implemented using style layers to some extent; once #6097 lands, you’ll be able to use an annotation but otherwise treat it like part of a style layer, more or less.
Activity
1ec5 commentedon Sep 29, 2016
Unlike annotations, style layers don’t come with interactivity and callout views out of the box. Instead, you have to build it yourself: install your own tap gesture recognizer, call
MGLMapView.visibleFeatures(at:styleLayerIdentifiers:), and position your own custom callout view over the feature’s coordinate (usingconvert(_:toPointTo:). Hide the callout view inmapView(_:regionWillChange:), or update its location continuously inmapView(_:regionIsChanging:)andmapView(_:regionDidChange:).I know this sounds like a lot of work. #6181 would make annotations more like style layers, in the process adding a lot of annotation-like functionality to style layers in general. That’s quite a ways off, however. #6515 would make the gesture recognition part a little easier, and we could add an API for displaying callout views for non-annotations as part of #4392. Meanwhile, under the hood, annotations are already implemented using style layers to some extent; once #6097 lands, you’ll be able to use an annotation but otherwise treat it like part of a style layer, more or less.
rmnblm commentedon Sep 30, 2016
Works perfectly, thanks for your help @1ec5. Here's how I did it (for others):
rmnblm commentedon Sep 30, 2016
Maybe found a bug with the solution above, see issue #6538