Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Accessor for visible annotation views in the viewport #5467

Closed
andrewstay opened this issue Jun 24, 2016 · 9 comments
Closed

Accessor for visible annotation views in the viewport #5467

andrewstay opened this issue Jun 24, 2016 · 9 comments
Assignees
Labels
annotations Annotations on iOS and macOS or markers on Android feature iOS Mapbox Maps SDK for iOS
Milestone

Comments

@andrewstay
Copy link

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

@1ec5
Copy link
Contributor

1ec5 commented Jun 24, 2016

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

@1ec5 1ec5 added iOS Mapbox Maps SDK for iOS annotations Annotations on iOS and macOS or markers on Android labels Jun 24, 2016
@andrewstay
Copy link
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.

@boundsj
Copy link
Contributor

boundsj commented Jun 24, 2016

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

@andrewstay
Copy link
Author

andrewstay commented Jun 24, 2016

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:]

@boundsj boundsj added this to the ios-v3.4.0 milestone Jun 28, 2016
@boundsj
Copy link
Contributor

boundsj commented Jun 28, 2016

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.

@1ec5 1ec5 changed the title [iOS] Add methods to simplify access to MGLAnnotationView owned by a MapView Accessor for visible annotation views in the viewport Jul 8, 2016
@boundsj boundsj self-assigned this Aug 12, 2016
@boundsj
Copy link
Contributor

boundsj commented Oct 27, 2016

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

@boundsj boundsj closed this as completed Oct 27, 2016
@andrewstay
Copy link
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.

@boundsj
Copy link
Contributor

boundsj commented Nov 1, 2016

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.

@boundsj
Copy link
Contributor

boundsj commented Nov 2, 2016

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
annotations Annotations on iOS and macOS or markers on Android feature iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

No branches or pull requests

3 participants