-
Notifications
You must be signed in to change notification settings - Fork 122
Platform bindings for runtime styling APIs on MapSnapshotter
#200
Comments
mapbox/mapbox-gl-native#16268 has yet to be released. In the meantime, I’ll update the submodule to master locally to work on the integration. |
Changes to mbgl’s public API in mapbox/mapbox-gl-native#16268 are forcing me to rewrite MGLMapSnapshotter. It’s a long-overdue rewrite. I think we’ll be able to clear away many of the pessimizations and unsafe thread safety patches we’ve applied to this class over the years by removing indirection and parallel state. The refactoring centers around passing the completion handler around in local scope without storing it as an ivar. It has been going well, except for one detail: if you pass a completion handler into As far as I can tell, we don’t document anywhere that the completion handler does get called in this situation, so it would be a backwards-compatible change. The developer has full control over what happens when they call |
For the actual runtime styling feature, I plan to add an “actions” or “style handler” block to either In this case, a block is more appropriate than a full-on delegate protocol, because we only expect the style to load a single time per snapshot. If we need to support the |
For consistency, From my perspective, it’s counterintuitive that a completion handler passed into an instance method would get called after the instance’s lifetime. The normal developer expectation is that the instance owns the completion handler, not the other way around. mapbox/mapbox-gl-native#12336 (comment) suggested keeping the snapshotter alive by capturing it in the completion handler. But the operation pattern actually calls for the snapshotter to be held by the surrounding class or placed in an operation queue. If the completion handler has any need for the snapshotter, it should be weakly referenced within the block. |
MKMapSnapshotter doesn’t call the completion handler when canceling, but it does call the completion handler when MKMapSnapshotter is only a local variable, so it must be retained by something while loading. This behavior is convenient for things like Swift playgrounds where storing an ivar feels like overkill. As far as I can tell, MapKit keeps the snapshotter alive by having a block capture the snapshotter. We could do that, but it might lead to the same muddled situation we’ve found ourselves in with the current MGLMapSnapshotter implementation. It’s far simpler to require the developer to hang onto the snapshotter, so I think we should go with that until we find a clean way to keep the snapshotter alive, which would be a seamless change. |
mapbox/mapbox-gl-native#16268
The text was updated successfully, but these errors were encountered: