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.
Accessor for visible annotation views in the viewport #5467
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
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.
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.
@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.
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
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.
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
@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.
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.
Activity
1ec5 commentedon 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
andrewstay commentedon Jun 24, 2016
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 commentedon Jun 24, 2016
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 commentedon 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
boundsj commentedon 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.[-][iOS] Add methods to simplify access to MGLAnnotationView owned by a MapView[/-][+]Accessor for visible annotation views in the viewport[/+]boundsj commentedon Oct 27, 2016
This was done in #6061 and will be in the next ios 3.4.0 beta release.
andrewstay commentedon Nov 1, 2016
@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
MGLMapViewshould 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 commentedon 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.
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:
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 commentedon Nov 2, 2016
Beta 2 is available now with the new APIs and performance improvements mentioned in #5467 (comment)