Instance Method


Draws the overlay’s contents at the specified location on the map.


- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context;



The map rectangle that needs to be updated. Your drawing code should avoid drawing outside of this rectangle.


The current zoom factor applied to the map content. You can use this value for configuring the stroke width of lines or other attributes that might be affected by the scale of the map’s contents.


The graphics context to use for drawing the overlay’s contents.


The default implementation of this method does nothing. Subclasses are expected to override this method and use it to draw the overlay’s contents.

When determining where to draw content, make your initial calculations relative to the map itself. In other words, compute the position and size of any overlay content using map points and map rectangles, convert those values to regular CGPoint and CGRect types using the methods of this class, and then pass the converted points to any drawing primitives.

It is recommended that you use Core Graphics to draw any content for your overlays. If you choose to draw using UIKit classes and methods instead, you must push the specified graphics context onto the context stack (using the UIGraphicsPushContext function) before making any drawing calls. When you are done drawing, you must similarly pop the graphics context off the stack using the UIGraphicsPopContext. Overlay drawing typically occurs on background threads to improve performance, so do not manipulate UIKit views or other objects that can only be manipulated on the app’s main thread.

To improve drawing performance, the map view may divide your overlay into multiple tiles and render each one on a separate thread. Your implementation of this method must therefore be capable of safely running from multiple threads simultaneously. In addition, you should avoid drawing the entire contents of the overlay each time this method is called. Instead, always take the mapRect parameter into consideration and avoid drawing content outside that rectangle.

See Also

Drawing the Overlay

- canDrawMapRect:zoomScale:

Returns a Boolean value indicating whether the overlay view is ready to draw its content.

- setNeedsDisplay

Invalidates the entire contents of the overlay for all zoom scales.

- setNeedsDisplayInMapRect:

Invalidates the specified portion of the overlay at all zoom scales

- setNeedsDisplayInMapRect:zoomScale:

Invalidates the specified portion of the overlay but only at the specified zoom scale.