-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Accessor for visible annotation views in the viewport #5467
Comments
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 |
My problem is that I cannot access instance of my MGLAnnotationView to change the transparency, and |
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.
|
Thanks @andrewstay. A |
This was done in #6061 and will be in the next ios 3.4.0 beta release. |
@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 |
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: for (id<MGLAnnotation> annotation in self.mapView.visibleAnnotations) {
MGLAnnotationView *view = [self.mapView viewForAnnotation:annotation];
} Relatedly, note that there is a performance improvement coming to |
Beta 2 is available now with the new APIs and performance improvements mentioned in #5467 (comment) |
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:
or
The first one is more preferable as it will not require the client to reallocate MGLAnnotationView
The text was updated successfully, but these errors were encountered: