I'm working on an app that is heavily map-based, and I'm using the MBXMapKit framework (built over MapKit) in order to display custom Mapbox map tiles in my MapView instead of the default Apple maps. However, while Apple's maps are vector, Mapbox's are still raster image tiles, so they're displayed as overlays by the MBXMapKit framework.
This is all well and fine, until I go to draw a polyline on the map using an MKOverlay
. As I understand it, pre-iOS 7, you would provide an MKOverlayView
to the MapView delegate which would be rendered onto the map, but now in iOS 7, that has been deprecated in favor of MKOverlayRenderer
, which if I understand correctly, functions more like a drawRect
of sorts, where I directly draw into a context with the result being displayed on the map (I realize this isn't exactly how it works but the point is that I no longer have access to a plain old UIView
, which is where my problems arise).
The first problem is that it appears that when my overlay is drawn to the map, it's drawn tile-by-tile. This is fine, except that the overlay tiles seem to be composited with the underlying Mapbox image tiles. This results in being able to visibly see a simply polyline with 3 or 4 points take a solid half-second to render (on an A7 iPad Air), and you can see it appear in 'chunks' as each tile is redrawn. It also for some reason causes all of the unaffected Mapbox tiles to reload (they all flash for a split second). Obviously from a UX perspective this looks like a joke and is totally unacceptable.
The second issue is that, because I no longer have access to a UIView
like I would have in iOS 6, I don't see how I can animate the overlay- what I'd like is to fade the polyline in instead of displaying it instantly (though at this point I'd take displaying the whole thing instantly over watching it render tile-by-tile like it's being spit out of a dot matrix printer, but you get my point).
So my main question would be, am I missing something, or is MKOverlayRenderer
FAR less flexible and useful than MKOverlayView
? Logically speaking you would expect to be able to treat a layer on a map as an individual object that can be manipulated, have events bound to it, etc., rather than some raster pixel data that you burn into the map and can never again modify or interact with (without redrawing the whole thing), and threads like this seem to suggest that Apple has essentially removed the ability to do a lot of things with overlays that you used to be able to do quite easily.
As MKOverlayView
is now deprecated and thus the corresponding delegate methods are no longer called, is there any solution to these issues? As it stands now I'm unable to use it for a production application due to the performance issues and the lack of animation ability.
Edit: Another performance issue I noticed when drawing an MKOverlay
is that it affects other animations that happen as the drawing takes place- when I tap a map annotation, a tooltip pops open animated at the same time that the polyline rendering starts- sure enough, the rendering causes the tooltip animation to drop frames.
The short answer is Yes, it's worse.
See discussion here https://github.com/mapbox/mbxmapkit/issues/39 as incanus (author of the MBXMapKit) suggested in https://stackoverflow.com/a/22769258/2924596
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With