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.

Accessor for visible annotation views in the viewport #5467

Closed

Description

@andrewstay

After MGLAnnotationView was introduced, it became possible to implement advanced presentations for annotations in the map. One of the possibilities is to adjust transparency of some layers in multilayered image depending on the zoom level (which is important feature for Stay.com).
At the same time to achieve such effect client needs to re-add the same annotations on every event that may trigger the need to refresh the UI (pan/zoom).

Please consider adding the following methods:

-[MGLMapView visibleAnnotationViewsInBounds:]

or

-[MGLMapView reloadAnnotationsinBounds:]

The first one is more preferable as it will not require the client to reallocate MGLAnnotationView

Activity

  1. 1ec5 commented on Jun 24, 2016

    @1ec5
    Contributor

    You should be able to vary the transparency of an annotation view based on the zoom level in -[MGLMapView mapViewDidFinishRenderingFrame:fullyRendered:], which gets called immediately after repositioning annotation views. This method gets called very frequently as the viewport animates; a less frequently called method is -mapView:didChangeRegionAnimated:.

    As far as knowing the visible annotations within the bounds, I agree that MGLMapView should expose a -visibleAnnotationViews method. This should be pretty straightforward since we already have logic for that in the internal -updateAnnotationViews method.

    /cc @boundsj

  2. added
    iOS
    annotations
    on Jun 24, 2016
  3. andrewstay commented on Jun 24, 2016

    @andrewstay
    Author

    My problem is that I cannot access instance of my MGLAnnotationView to change the transparency, and
    -[MGLMapView mapViewDidFinishRenderingFrame:fullyRendered:] is not going to help with that.

  4. boundsj commented on Jun 24, 2016

    @boundsj
    Contributor

    @andrewstay My problem is that I cannot access instance of my MGLAnnotationView to change the transparency

    As a workaround, for now, would it be possible for you to keep a reference (i.e. an array) to the annotation view(s) your map view delegate creates? Then, adjusting the transparency as @1ec5 suggests would be possible. Alternatively, you could consider using the annotations property on the map view combined with the new viewForAnnotation API that'll be in our beta.2 release later today.

  5. andrewstay commented on Jun 24, 2016

    @andrewstay
    Author

    I cannot hold a reference because MGLAnnotationView is reused by the map.
    Alternative in beta.2 would help, but I would still need smth like -visibleAnnotationsInBounds:
    But then it is 2 steps flow - get visible annotations, get views for those annotations instead of previously suggested by me 1 step approach with

    -[MGLMapView visibleAnnotationViewsInBounds:]
    
  6. added this to the ios-v3.4.0 milestone on Jun 28, 2016
  7. boundsj commented on Jun 28, 2016

    @boundsj
    Contributor

    Thanks @andrewstay. A visibleAnnotationViewsInBounds: API will work better once #5165 lands (and MGLMapView itself is updated to use the changes in #5165). I also agree adding this API makes sense in a future release.

  8. changed the title [-][iOS] Add methods to simplify access to MGLAnnotationView owned by a MapView[/-] [+]Accessor for visible annotation views in the viewport[/+] on Jul 8, 2016
  9. self-assigned this
    on Aug 12, 2016
  10. boundsj commented on Oct 27, 2016

    @boundsj
    Contributor

    This was done in #6061 and will be in the next ios 3.4.0 beta release.

  11. andrewstay commented on Nov 1, 2016

    @andrewstay
    Author

    @boundsj Please note that #6061 does not fix this issue. That fix has only implementation for the annotations, and therefore to obtain an actual instance of the view which renders that annotation I need to walk through the dequeue/reuse mechanism. This is not a very good approach both performance and logic wise.

    The very instance of the MGLMapView should already own all the views for the annotations in the visible view port, so it should not be that hard to return that array to the client.

  12. boundsj commented on Nov 1, 2016

    @boundsj
    Contributor

    Thanks for the feedback @andrewstay. "annotations" can be represented visually by native views and images/sprites at the GL level. And now, with runtime styling nearing completion, there is another mechanism for adding visual elements to the map. I was thinking that a specific "view for annotation" API may be confusing.

    to obtain an actual instance of the view which renders that annotation I need to walk through the dequeue/reuse mechanism

    Unless I'm missing something I don't think this is true and we certainly don't intend for application code to access the reuse queue directly other than the main case of dequeuing. Instead, you can write:

    for (id<MGLAnnotation> annotation in self.mapView.visibleAnnotations) {
        MGLAnnotationView *view = [self.mapView viewForAnnotation:annotation];
    }

    Relatedly, note that there is a performance improvement coming to viewForAnnotation: in #5987 (specifically this). 5987 will land in the release branch today and will be in the beta 2 release expected this week.

  13. boundsj commented on Nov 2, 2016

    @boundsj
    Contributor

    Beta 2 is available now with the new APIs and performance improvements mentioned in #5467 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

annotationsfeatureiOS

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions