Inherits from UIView
Declared in OSMapView.h

Overview

OSMapView provides an interface to Ordnance Survey OpenSpace maps, supporting the same mapping layers as the OpenSpace and OpenSpace Pro JavaScript APIs.

OSMapView is intended to provide a drop-in replacement for MapKit’s MKMapView and has a largely similar API. The API is as close as can it can be, while maintaintaining differentation with the use of the OS prefix (instead of MK) for all classes. In general, therefore, OSMapView is adequately documented by the MapKit documentation which cannot be reproduced here for copyright reasons. There are a few main differences:

  • OSMapView uses the OSGB36 National Grid map projection. Applications which have assumed a Mercator projection may have to take the different projection into account.
  • OSMapView does not support drawing maps outside the UK.
  • OSMapView requires an API key and a tile source to be set before using the online data source.
  • OSMapView supports many more map configurations than can be easily expressed with a single mapType property.
  • OSMapView and OSOverlayView do not use power-of-2 zoom levels.
  • OSMapView cannot be completely initialised from a NIB.
  • OSGridPoint is in a specified coordinate system: it’s is a National Grid reference in metres.
  • OSMapViewDelegate does not have map-loading callbacks.

Tile sources and API keys

OSMapView requires either an OS OpenSpace API key or a file containing map tiles in “OSTiles” format.

idOSTileSource tileSource = [OSMapView webTileSourceWithAPIKey:YOUR_API_KEY refererUrl:YOUR_PAGE_URL openSpacePro:false];
mapView.tileSources = [NSArray arrayWithObject:tileSource];

Coordinate conversions

OSGridPoint represents OSGB36 National Grid easting/northing (i.e. a “numeric-only” National Grid reference).

CLLocationCoordinate2D represents WGS84 latitude/longitude.

OSGB36 latitude/longitude is not currently supported. ETRS89 is not explicitly supported, but is closely approximated by WGS84.

Conversion between CLLocationCoordinate2D and OSGridPoint is largely handled internally — applications should not need to perform more conversions than with WGS84-based mapping APIs.

However, applications should be aware of the limitations of these conversions:

  • The conversion is approximate. It is usually correct to within 3m compared to OSTN02.
  • WGS84 lines of latitude/longitude are not aligned with National Grid. A consequence is that OSCoordinateRegion and OSGridRect represent different shapes, and thus cannot be interconverted accurately.
  • The conversions used are subject to change (in particular, accuracy may be improved).

Applications should avoid unnecessary conversions. Coordinates should be stored in their source coordinate system in order to benefit from future accuracy improvements.

Subclassing notes

OSMapView is not designed to be subclassed.

Tasks

Other Methods

Creating and using tile sources

Map scale view that gets automatically resized as the zoom changes, but does not pan

Managing scrolling and zooming

Current zoom level

User location

Managing annotations

Managing overlays

Managing maps

Converting between coordinate systems

Versioning

  • + SDKVersion

    Returns the current SDK version number as a string, e.g. “1.0”.

Other Methods

Properties

annotationVisibleRect

@property (nonatomic, readonly) CGRect annotationVisibleRect

annotations

@property (nonatomic, readonly) NSArray *annotations

centerCoordinate

@property (nonatomic, assign) CLLocationCoordinate2D centerCoordinate

delegate

@property (nonatomic, weak) id<OSMapViewDelegate> delegate

mapScaleView

@property (nonatomic, assign) OSMapScaleView *mapScaleView

metresPerPixel

@property (nonatomic, readonly) float metresPerPixel

overlays

@property (nonatomic, copy, readonly) NSArray *overlays

region

@property (nonatomic, assign) OSCoordinateRegion region

scrollEnabled

@property (nonatomic, assign) BOOL scrollEnabled

selectedAnnotations

@property (nonatomic, copy) NSArray *selectedAnnotations

showsUserLocation

@property (nonatomic, assign) bool showsUserLocation

tileSources

@property (nonatomic, copy) NSArray *tileSources

userLocation

@property (nonatomic, strong, readonly) OSUserLocation *userLocation

userLocationVisible

@property (nonatomic, assign, readonly, getter=isUserLocationVisible) bool userLocationVisible

userTrackingMode

@property (nonatomic, assign) OSUserTrackingMode userTrackingMode

visibleGridRect

@property (nonatomic, assign) OSGridRect visibleGridRect

visibleMapRect

@property (nonatomic) OSMapRect visibleMapRect

zoomEnabled

@property (nonatomic, assign) BOOL zoomEnabled

Class Methods

SDKVersion

Returns the current SDK version number as a string, e.g. “1.0”.

+ (NSString *)SDKVersion

Declared In

OSMapView.h

completeFreeMapStackProductCodes

+ (NSArray *)completeFreeMapStackProductCodes

Declared In

OSMapView.h

defaultMapStackProductCodes

+ (NSArray *)defaultMapStackProductCodes

Declared In

OSMapView.h

localTileSourceWithFileURL:

Creates a tile source which loads tiles from a local SQLite database.

+ (id<OSTileSource>)localTileSourceWithFileURL:(NSURL *)fileURL

Parameters

fileURL

The URL of the file to load. Must be a file URL.

Return Value

The tile source, or nil if an error occurs.

Discussion

The file should be in the “OSTiles” format and have extension .ostiles.

Declared In

OSMapView.h

localTileSourcesInDirectoryAtURL:

Calls localTileSourceWithFileURL: on all files in a directory and returns an array of the non-nil results.

+ (NSArray *)localTileSourcesInDirectoryAtURL:(NSURL *)directoryURL

Declared In

OSMapView.h

webTileSourceWithAPIKey:openSpacePro:

Creates a tile source which loads images off the OpenSpace or OpenSpace Pro tile servers.

+ (id<OSTileSource>)webTileSourceWithAPIKey:(NSString *)apiKey openSpacePro:(bool)isPro

Parameters

apiKey

Your OpenSpace or OpenSpace Pro API key

isPro

true if the API key is an OpenSpace Pro API key, false otherwise.

Declared In

OSMapView.h

zoomMapStackProductCodes

  • The OpenSpace Pro zoom map stack.
+ (NSArray *)zoomMapStackProductCodes

Declared In

OSMapView.h

Instance Methods

addAnnotation:

- (void)addAnnotation:(id<OSAnnotation>)annotation

addAnnotations:

- (void)addAnnotations:(NSArray *)annotations

addOverlay:

- (void)addOverlay:(id<OSOverlay>)overlay

addOverlays:

- (void)addOverlays:(NSArray *)overlays

annotationsInGridRect:

- (NSSet *)annotationsInGridRect:(OSGridRect)gridRect

annotationsInMapRect:

- (NSSet *)annotationsInMapRect:(OSMapRect)mapRect

convertCoordinate:toPointToView:

- (CGPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate toPointToView:(UIView *)view

convertGridPoint:toPointToView:

- (CGPoint)convertGridPoint:(OSGridPoint)gp toPointToView:(UIView *)view

convertPoint:toGridPointFromView:

- (OSGridPoint)convertPoint:(CGPoint)point toGridPointFromView:(UIView *)view

convertRegion:toRectToView:

- (CGRect)convertRegion:(OSCoordinateRegion)region toRectToView:(UIView *)view

dequeueReusableAnnotationViewWithIdentifier:

- (OSAnnotationView *)dequeueReusableAnnotationViewWithIdentifier:(NSString *)identifier

deselectAnnotation:animated:

- (void)deselectAnnotation:(id<OSAnnotation>)annotation animated:(BOOL)animated

exchangeOverlayAtIndex:withOverlayAtIndex:

- (void)exchangeOverlayAtIndex:(NSUInteger)index1 withOverlayAtIndex:(NSUInteger)index2

gridRectThatFits:

- (OSGridRect)gridRectThatFits:(OSGridRect)gridRect

gridRectThatFits:edgePadding:

- (OSGridRect)gridRectThatFits:(OSGridRect)gridRect edgePadding:(UIEdgeInsets)insets

insertOverlay:aboveOverlay:

- (void)insertOverlay:(id<OSOverlay>)overlay aboveOverlay:(id<OSOverlay>)overlay2

insertOverlay:atIndex:

- (void)insertOverlay:(id<OSOverlay>)overlay atIndex:(NSUInteger)index

insertOverlay:belowOverlay:

- (void)insertOverlay:(id<OSOverlay>)overlay belowOverlay:(id<OSOverlay>)overlay2

mapRectThatFits:

- (OSMapRect)mapRectThatFits:(OSMapRect)mapRect

mapRectThatFits:edgePadding:

- (OSMapRect)mapRectThatFits:(OSMapRect)mapRect edgePadding:(UIEdgeInsets)insets

regionThatFits:

- (OSCoordinateRegion)regionThatFits:(OSCoordinateRegion)region

removeAnnotation:

- (void)removeAnnotation:(id<OSAnnotation>)annotation

removeAnnotations:

- (void)removeAnnotations:(NSArray *)annotations

removeOverlay:

- (void)removeOverlay:(id<OSOverlay>)overlay

removeOverlays:

- (void)removeOverlays:(NSArray *)overlays

selectAnnotation:animated:

- (void)selectAnnotation:(id<OSAnnotation>)annotation animated:(BOOL)animated

setCenterCoordinate:animated:

- (void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate animated:(BOOL)animated

setMapProductCodes:

Sets the products to display by product code.

- (void)setMapProductCodes:(NSArray *)mapProductCodes

Parameters

mapProductCodes

The array of product codes. Does not need to be sorted.

Declared In

OSMapView.h

setRegion:animated:

- (void)setRegion:(OSCoordinateRegion)region animated:(BOOL)animated

setUserTrackingMode:animated:

- (void)setUserTrackingMode:(OSUserTrackingMode)userTrackingMode animated:(BOOL)animated

setVisibleGridRect:animated:

- (void)setVisibleGridRect:(OSGridRect)visibleGridRect animated:(BOOL)animated

setVisibleGridRect:edgePadding:animated:

- (void)setVisibleGridRect:(OSGridRect)visibleGridRect edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated

setVisibleMapRect:animated:

- (void)setVisibleMapRect:(OSMapRect)mapRect animated:(BOOL)animate

setVisibleMapRect:edgePadding:animated:

- (void)setVisibleMapRect:(OSMapRect)mapRect edgePadding:(UIEdgeInsets)insets animated:(BOOL)animate

viewForAnnotation:

- (OSAnnotationView *)viewForAnnotation:(id<OSAnnotation>)annotation

viewForOverlay:

- (OSOverlayView *)viewForOverlay:(id<OSOverlay>)overlay