Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
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

Closed

Description

@eimantas

Platform: iOS

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?

Activity

  1. added
    iOS
    on Dec 7, 2016
  2. boundsj commented on Dec 7, 2016

    @boundsj
    Contributor

    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.

  3. eimantas commented on Dec 8, 2016

    @eimantas
    ContributorAuthor

    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.

  4. piohhmy commented on Jan 8, 2017

    @piohhmy

    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:

    1. It's slower
    2. Special logic is needed to keep the currently selected callout after the remove/add annotation logic
    3. 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?

  5. added
    annotations
    and removed on Jan 8, 2017
  6. added this to the milestone on Jan 8, 2017
  7. boundsj commented on Jan 8, 2017

    @boundsj
    Contributor

    @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).

  8. modified the milestones: ios-v3.5.0, ios-v3.4.1 on Jan 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

annotationsiOS

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions