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.
Why is annotation a read-only property on annotation view? #7321
I don't understand the motivation behind making the annotation property a read-only in MGLAnnotationView class. Apple's MapKit provides an annotation view's initialiser that accepts both the reuse identifier and annotation. This moves the view setup into the view class and doesn't pollute the delegate method with view setup code. Do mapbox developers imply that the view setup should be done in mapView:viewForAnnotation: delegate's method?
Hi @eimantas. Because of view reuse, the annotation instance sent to mapView:viewForAnnotation: when a view is first created (for a particular reuse identifier) is not necessarily the same annotation instance that will be returned from a call to annotation view's annotation property later on, after reuse.
I'm not sure how this restricts view setup to the mapView:viewForAnnotation: delegate implementation, especially if you subclass MGLAnnotationView.
Because of view reuse, the annotation instance sent to mapView:viewForAnnotation: when a view is first created (for a particular reuse identifier) is not necessarily the same annotation instance that will be returned from a call to annotation view's annotation property later on, after reuse.
If this method is called with annotation passed in, this means I'm not interested in annotation that is set for the reused view. This is where the trouble comes in, due to lack of the setter, I can't "reset" the annotation for the reused view and make it display data related to the passed in annotation.
This is why the view setup is restricted to the delegate's method.
I believe I too am running into this issue. There are times I want to be able to update an existing annotations title/subtile. In MapKit I can simply set the annotation on the AnnotationView to render the updated values. With Mapbox, since it is a read-only property, I find I have to remove the annotation from the MapView and then re-add the updated annotation to the MapView. This isn't ideal as I've seen:
It's slower
Special logic is needed to keep the currently selected callout after the remove/add annotation logic
The callout blinks off and on rather than just animating the updated values.
Is there another mechanism to update the annotation for a MGLAnnotationView that I'm missing? If not, are you open to a PR to make the annotation read-write to match the MapKit interface and avoid these issues?
@eimantas@piohhmy we are close to a release candidate for our 3.4.0 release with runtime styling. I've added this issue to the 3.4.1 milestone (next release).
Activity
boundsj commentedon Dec 7, 2016
Hi @eimantas. Because of view reuse, the annotation instance sent to
mapView:viewForAnnotation:when a view is first created (for a particular reuse identifier) is not necessarily the same annotation instance that will be returned from a call to annotation view'sannotationproperty later on, after reuse.I'm not sure how this restricts view setup to the
mapView:viewForAnnotation:delegate implementation, especially if you subclassMGLAnnotationView.eimantas commentedon Dec 8, 2016
If this method is called with annotation passed in, this means I'm not interested in annotation that is set for the reused view. This is where the trouble comes in, due to lack of the setter, I can't "reset" the annotation for the reused view and make it display data related to the passed in annotation.
This is why the view setup is restricted to the delegate's method.
piohhmy commentedon Jan 8, 2017
I believe I too am running into this issue. There are times I want to be able to update an existing annotations title/subtile. In MapKit I can simply set the
annotationon the AnnotationView to render the updated values. With Mapbox, since it is a read-only property, I find I have to remove the annotation from the MapView and then re-add the updated annotation to the MapView. This isn't ideal as I've seen:Is there another mechanism to update the annotation for a
MGLAnnotationViewthat I'm missing? If not, are you open to a PR to make the annotation read-write to match the MapKit interface and avoid these issues?boundsj commentedon Jan 8, 2017
@eimantas @piohhmy we are close to a release candidate for our 3.4.0 release with runtime styling. I've added this issue to the 3.4.1 milestone (next release).
Remove hack of removing/adding annotations
Remove hack of removing/adding annotations