MKOverlayPathRenderer Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/MapKit.framework
Availability
Available in iOS 7.0 and later.
Companion guide
Declared in
MKOverlayPathRenderer.h

Overview

The MKOverlayPathRenderer class draws a map overlay whose shape is represented by a CGPathRef data type. The default drawing behavior of this class is to apply the object’s current fill attributes, fill the path, apply the current stroke attributes, and then stroke the path.

You can use this class as-is or subclass to define additional drawing behaviors. If you subclass, you should override the createPath method and use that method to build the appropriate path object. To change the path, invalidate it and recreate the path using whatever new data your subclass has obtained.

Tasks

Accessing the Drawing Attributes

Creating and Managing the Path

Drawing the Path

Properties

fillColor

The fill color to use for the path.

@property(strong) UIColor *fillColor
Availability
  • Available in iOS 7.0 and later.
Declared In
MKOverlayPathRenderer.h

lineCap

The line cap style to apply to the open ends of the path.

@property CGLineCap lineCap
Discussion

The line cap style is applied to the start and end points of any open subpaths. This property does not affect closed subpaths. The default line cap style is kCGLineCapRound.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKOverlayPathRenderer.h

lineDashPattern

An array of numbers specifying the dash pattern to use for the path.

@property(copy) NSArray *lineDashPattern
Discussion

The array contains one or more NSNumber objects that indicate the lengths (measured in points) of the line segments and gaps in the pattern. The values in the array alternate, starting with the first line segment length, followed by the first gap length, followed by the second line segment length, and so on.

This property is set to nil by default, which indicates no line dash pattern.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKOverlayPathRenderer.h

lineDashPhase

The offset (in points) at which to start drawing the dash pattern.

@property CGFloat lineDashPhase
Discussion

Use this property to start drawing a dashed line partway through a segment or gap. For example, a phase value of 6 for the patter 5-2-3-2 would cause drawing to begin in the middle of the first gap.

The default value of this property is 0.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKOverlayPathRenderer.h

lineJoin

The line join style to apply to corners of the path.

@property CGLineJoin lineJoin
Discussion

The default line join style is kCGLineJoinRound.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKOverlayPathRenderer.h

lineWidth

The stroke width to use for the path.

@property CGFloat lineWidth
Discussion

The default value of this property is 0.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKOverlayPathRenderer.h

miterLimit

The limiting value that helps avoid spikes at junctions between connected line segments.

@property CGFloat miterLimit
Discussion

The miter limit helps you avoid spikes in paths that use the kCGLineJoinMiter join style. If the ratio of the miter length—that is, the diagonal length of the miter join—to the line thickness exceeds the miter limit, the joint is converted to a bevel join. The default miter limit is 10, which results in the conversion of miters whose angle at the joint is less than 11 degrees.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKOverlayPathRenderer.h

path

The path representing the overlay’s shape.

@property CGPathRef path
Discussion

Getting the value of this property causes the path to be created (using the createPath method) if it does not already exist. You can assign a path object to this property explicitly. When assigning a new path object to this property, the overlay renderer stores a strong reference to the path you provide.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKOverlayPathRenderer.h

strokeColor

The stroke color to use for the path.

@property(strong) UIColor *strokeColor
Availability
  • Available in iOS 7.0 and later.
Declared In
MKOverlayPathRenderer.h

Instance Methods

applyFillPropertiesToContext:atZoomScale:

Applies the receiver’s current fill-related drawing properties to the specified graphics context.

- (void)applyFillPropertiesToContext:(CGContextRef)context atZoomScale:(MKZoomScale)zoomScale
Parameters
context

The graphics context used to draw the view’s contents.

zoomScale

The current zoom scale used for drawing.

Discussion

This is a convenience method for applying all of the drawing properties used when filling a path. This method applies the current fill color to the specified graphics context.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKOverlayPathRenderer.h

applyStrokePropertiesToContext:atZoomScale:

Applies the receiver’s current stroke-related drawing properties to the specified graphics context.

- (void)applyStrokePropertiesToContext:(CGContextRef)context atZoomScale:(MKZoomScale)zoomScale
Parameters
context

The graphics context used to draw the view’s contents.

zoomScale

The current zoom scale used for drawing.

Discussion

This is a convenience method for applying all of the drawing properties used when stroking a path. This method applies the stroke color, line width, line join, line cap, miter limit, line dash phase, and line dash attributes to the specified graphics context. This method applies the scale factor in the zoomScale parameter to the line width and line dash pattern automatically so that lines scale appropriately.

This method does not save the current graphics state before applying the new attributes. If you want to preserve the existing state, you must save it yourself and restore it later when you finish drawing.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKOverlayPathRenderer.h

createPath

Creates the path for the overlay.

- (void)createPath
Discussion

The default implementation of this method does nothing. Subclasses should override it and use it to create the CGPathRef data type to be used for drawing. After creating the path, your implementation should assign it to the path property.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKOverlayPathRenderer.h

fillPath:inContext:

Fills the area enclosed by the specified path.

- (void)fillPath:(CGPathRef)path inContext:(CGContextRef)context
Parameters
path

The path to fill.

context

The graphics context in which to draw the path.

Discussion

You must set the current fill color before calling this method. Typically you do this by calling the applyFillPropertiesToContext:atZoomScale: method prior to drawing. If the fillColor property is currently nil, this method does nothing.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKOverlayPathRenderer.h

invalidatePath

Updates the path associated with the overlay renderer.

- (void)invalidatePath
Discussion

Call this method when a change in the path information would require you to recreate the overlay’s path. This method sets the path property to nil and tells the overlay renderer to redisplay its contents.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKOverlayPathRenderer.h

strokePath:inContext:

Draws a line along the specified path.

- (void)strokePath:(CGPathRef)path inContext:(CGContextRef)context
Parameters
path

The path to draw.

context

The graphics context in which to draw the path.

Discussion

You must set the current stroke color before calling this method. Typically you do this by calling the applyStrokePropertiesToContext:atZoomScale: method prior to drawing. If the strokeColor property is currently nil, this method does nothing.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKOverlayPathRenderer.h