Mapbox-gl-native: Prevent annotation deselection when panning/zooming map

Created on 18 Mar 2016  Â·  1Comment  Â·  Source: mapbox/mapbox-gl-native

In the iOS SDK - (void)mapView:(MGLMapView *)mapView didDeselectAnnotation:(id<MGLAnnotation>)annotation is called whenever the user pans or zooms the MGLMapView. It would be great to have a way to prevent annotation deselection when panning or zooming the MGLMapView.

In the project I am currently working on we swap out the annotation image when an annotation is selected (we do not show a callout) to indicate the selected state of the annotation and would like to retain that selection state when the user pans/zooms the map. We are currently working around the issue by keeping track of the selected annotation in our own property and we ignore the deselection callback. The disadvantage to this approach is that we have no way of deselecting our annotation when a user taps outside of the annotation since the deselection callback does not allow us differentiate between a deselection due to a pan/zoom vs deselection due to a tap outside of the currently selected annotation.

I realize this has implications to how callout functionality would work as you would want the callout to dismiss when the user pans/zooms even if you do want the annotation to remain selected in that case. Since the callout state and the selection state are coupled, decoupling the callout may be necessary in order to implement this feature properly.

iOS

Most helpful comment

Once #3154 is fixed, that method won’t get called as soon as the user pans or zooms the map. Your approach to tracking selection – with a property on a custom subclass of MGLPointAnnotation – would be a good approach in general.

>All comments

Once #3154 is fixed, that method won’t get called as soon as the user pans or zooms the map. Your approach to tracking selection – with a property on a custom subclass of MGLPointAnnotation – would be a good approach in general.

Was this page helpful?
0 / 5 - 0 ratings