MKOverlayRenderer class defines the basic behavior associated with all map-based overlays. An overlay renderer draws the visual representation of an overlay object—that is, an object that conforms to the
MKOverlay protocol. This class defines the drawing infrastructure used by the map view. Subclasses are expected to override the
draw(_:zoomScale:in:) method to draw the contents of the overlay.
- iOS 7.0+
- macOS 10.9+
- tvOS 9.2+
The Map Kit framework provides several concrete instances of overlay renderers. Specifically, it provides renderers for each of the concrete overlay objects. You can use one of these existing renderers or define your own subclasses if you want to draw the overlay contents differently.
You can subclass
MKOverlayRenderer to create overlays based on custom shapes, content, or drawing techniques. The only method subclasses are expected to override is the
draw(_:zoomScale:in:) method. However, if your class contains content that may not be ready for drawing right away, you should also override the
canDraw(_:zoomScale:) method and use it to report when your class is ready and able to draw.
The map view may tile large overlays and distribute the rendering of each tile to separate threads. Therefore, the implementation of your
draw(_:zoomScale:in:) method must be safe to run from background threads and from multiple threads simultaneously.