iOS Developer Library — Pre-Release

Developer

MapKit Framework Reference MKTileOverlay Class Reference

Options
Deployment Target:

On This Page
Language:

MKTileOverlay

The MKTileOverlay class implements an overlay that is optimized for covering an area of the map using individual bitmap tiles. (In general, a map tile is a prerendered map image that covers a specific geographic area.) You can use tile overlay objects to represent your own tile-based content and to coordinate the display of that content in a map view. Your tiles can supplement the underlying map content or replace it completely. A tile overlay object coordinates the loading and management of the tiles while a corresponding MKTileOverlayRenderer object handles the actual drawing of the tiles on the map. More...

Inheritance


Conforms To


Import Statement


Swift

import MapKit

Objective-C

@import MapKit;

Availability


Available in iOS 7.0 and later.
  • Initializes and returns a tile overlay object using the specified tile-access template.

    Declaration

    Swift

    init!(URLTemplate URLTemplate: String!)

    Objective-C

    - (instancetype)initWithURLTemplate:(NSString *)URLTemplate

    Parameters

    URLTemplate

    A string that can be used to build a URL to access your tile images. The string you specify can point to a local file or to an image on a remote server. To facilitate retrieving multiple tiles using the string, use the placeholder values {x}, {y}, {z}, and {scale} as stand-ins for the x and y tile indexes, the zoom level, and the resolution of the tile image. If this parameter is nil, you must provide custom implementations for the tile-loading methods of this class.

    Return Value

    An initialized tile overlay object.

    Discussion

    The default tile overlay object uses the template string you specify to request tiles. This template string should incorporate the {x}, {y}, {z}, and {scale} placeholder strings to facilitate the creation of a URL for requesting the appropriate tile. For example, if you have a server that vends tiles when you provide a URL of the form http://myserver/tile?x=0&y=0&z=0&scale=1.0, you would specify a template string of http://myserver/tile?x={x}&y={y}&z={z}&scale={scale}. The tile overlay object substitutes actual index values in for your template’s placeholders before requesting the actual tile.

    Import Statement

    Swift

    import MapKit

    Availability

    Available in iOS 7.0 and later.

  • tileSize tileSize Property

    The size (in pixels) of your tile images.

    Declaration

    Swift

    var tileSize: CGSize

    Objective-C

    @property CGSize tileSize

    Discussion

    On Retina displays, the images are rendered pixel for pixel and are not scaled. This means that if the tile size is 256 x 256 pixels and the scale factor is 2.0, the image would be rendered as if it were 128 x 128 points in size. This behavior causes the tile to appear smaller but preserves the original image data.

    The default tile size is set to 256 x 256 pixels.

    Import Statement

    Swift

    import MapKit

    Availability

    Available in iOS 7.0 and later.

  • A Boolean value that indicates the orientation of tile indexes along the y axis.

    Declaration

    Swift

    var geometryFlipped: Bool

    Objective-C

    @property(getter=isGeometryFlipped) BOOL geometryFlipped

    Discussion

    When set to NOfalse, tile indexes start in the upper-left corner of the map and proceed down and to the right. Thus, the tile at (0, 0)is in the upper-left corner of the map, the tile at (1, 0) is to its immediate right and the tile at (0, 1) is immediately below it. Setting this property to YEStrue causes the map to start indexes at the lower-left corner of the map and proceed up and to the right.

    The default value of this property is NOfalse.

    Import Statement

    Swift

    import MapKit

    Availability

    Available in iOS 7.0 and later.

  • minimumZ minimumZ Property

    The minimum zoom level supported by the tiles of this overlay object.

    Declaration

    Swift

    var minimumZ: Int

    Objective-C

    @property NSInteger minimumZ

    Discussion

    If you use different overlay objects to represent different tiles at different zoom levels, use this property to specify the minimum zoom level supported by this overlay’s tiles. At zoom level 0, tiles cover the entire world map; at zoom level 1, tiles cover 1/4 of the world; at zoom level 2, tiles cover 1/16 of the world, and so on. The map never tries to load tiles for a zoom level less than the value specified by this property.

    The default value of this property is 0.

    Import Statement

    Swift

    import MapKit

    Availability

    Available in iOS 7.0 and later.

    See Also

    maximumZ

  • maximumZ maximumZ Property

    The maximum zoom level supported by the tiles of this overlay object.

    Declaration

    Swift

    var maximumZ: Int

    Objective-C

    @property NSInteger maximumZ

    Discussion

    If you use different overlay objects to represent different tiles at different zoom levels, use this property to specify the maximum zoom level supported by this overlay’s tiles. At zoom level 0, tiles cover the entire world map; at zoom level 1, tiles cover 1/4 of the world; at zoom level 2, tiles cover 1/16 of the world, and so on. The map never tries to load tiles for a zoom level greater than the value specified by this property.

    The default value of this property is 21. Setting the value of this property to a number greater than the default does not guarantee the use of those extra zoom levels.

    Import Statement

    Swift

    import MapKit

    Availability

    Available in iOS 7.0 and later.

    See Also

    minimumZ

  • A Boolean value that indicates whether the tile content is fully opaque.

    Declaration

    Swift

    var canReplaceMapContent: Bool

    Objective-C

    @property(nonatomic) BOOL canReplaceMapContent

    Discussion

    If the tile content you provide can cover the entire drawing area with opaque content, set this property to YEStrue. Doing so serves as a hint to the map view that it does not need to draw any additional content underneath your tiles. Set this property to NOfalse if your tiles contain any transparency.

    The default value for this property is NOfalse.

    Import Statement

    Swift

    import MapKit

    Availability

    Available in iOS 7.0 and later.

  • The template for generating tile image URLs. (read-only)

    Declaration

    Swift

    var URLTemplate: String! { get }

    Objective-C

    @property(readonly) NSString *URLTemplate

    Discussion

    You specify this string at initialization time.

    Import Statement

    Swift

    import MapKit

    Availability

    Available in iOS 7.0 and later.

  • Returns the URL to use to access the specified tile.

    Declaration

    Swift

    func URLForTilePath(_ path: MKTileOverlayPath) -> NSURL!

    Objective-C

    - (NSURL *)URLForTilePath:(MKTileOverlayPath)path

    Parameters

    path

    The path structure that identifies the specific tile you want. This structure incorporates the tile’s X-Y coordinate at a given zoom level and scale factor.

    Return Value

    The URL to use to retrieve the tile.

    Discussion

    The default implementation of this method uses the template string you provided at initialization time to build a URL to the specified tile image. Subclasses can override this method and use a different scheme to provide URLs for tiles. Tiles can be located either on a local file system or on a remote server.

    Import Statement

    Swift

    import MapKit

    Availability

    Available in iOS 7.0 and later.

  • Loads the specified tile asynchronously.

    Declaration

    Swift

    func loadTileAtPath(_ path: MKTileOverlayPath, result result: ((NSData!, NSError!) -> Void)!)

    Objective-C

    - (void)loadTileAtPath:(MKTileOverlayPath)path result:(void (^)(NSData *tileData, NSError *error))result

    Parameters

    path

    The path structure that identifies the specific tile you want. This structure incorporates the tile’s X-Y coordinate at a given zoom level and scale factor.

    result

    The completion block to call when the tile data is available. This block is executed on your app’s main thread and takes the following parameters:

    • The tileData parameter contains the raw data loaded from the corresponding image file. You can use this data to initialize an image object. If an error occurred, this parameter is nil.

    • The error parameter contains an error object if there was a problem loading the tile image. If no errors occurred, this parameter is nil.

    Discussion

    The default implementation of this method uses the URLForTilePath: method to retrieve the URL for the specified tile and then loads that tile into memory asynchronously using an NSURLConnection object. The specified tile may be located either on the local file system or on a remote server. Subclasses may override this method and implement their own custom tile-loading behavior.

    When a tile overlay renderer (that is, an instance of MKTileOverlayRenderer) needs to display tiles, it uses this method to request the data for each tile.

    Import Statement

    Swift

    import MapKit

    Availability

    Available in iOS 7.0 and later.