OSMapView Class Reference
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 singlemapType
property.OSMapView
andOSOverlayView
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
andOSGridRect
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
-
delegate
property
Creating and using tile sources
-
tileSources
property -
+ webTileSourceWithAPIKey:openSpacePro:
Creates a tile source which loads images off the OpenSpace or OpenSpace Pro tile servers.
-
+ localTileSourceWithFileURL:
Creates a tile source which loads tiles from a local SQLite database.
-
+ localTileSourcesInDirectoryAtURL:
Calls localTileSourceWithFileURL: on all files in a directory and returns an array of the non-nil results.
Map scale view that gets automatically resized as the zoom changes, but does not pan
-
mapScaleView
property
Managing scrolling and zooming
-
zoomEnabled
property -
scrollEnabled
property -
visibleGridRect
property -
centerCoordinate
property -
region
property -
– setVisibleGridRect:animated:
-
– setVisibleGridRect:edgePadding:animated:
-
– setCenterCoordinate:animated:
-
– setRegion:animated:
-
– gridRectThatFits:
-
– gridRectThatFits:edgePadding:
-
– regionThatFits:
Current zoom level
-
metresPerPixel
property
User location
-
showsUserLocation
property -
userTrackingMode
property -
userLocation
property -
userLocationVisible
property -
– setUserTrackingMode:animated:
Managing annotations
-
annotations
property -
selectedAnnotations
property -
annotationVisibleRect
property -
– addAnnotation:
-
– addAnnotations:
-
– removeAnnotation:
-
– removeAnnotations:
-
– annotationsInGridRect:
-
– dequeueReusableAnnotationViewWithIdentifier:
-
– selectAnnotation:animated:
-
– deselectAnnotation:animated:
-
– viewForAnnotation:
Managing overlays
-
overlays
property -
– addOverlay:
-
– addOverlays:
-
– removeOverlay:
-
– removeOverlays:
-
– insertOverlay:atIndex:
-
– exchangeOverlayAtIndex:withOverlayAtIndex:
-
– insertOverlay:aboveOverlay:
-
– insertOverlay:belowOverlay:
-
– viewForOverlay:
Managing maps
-
– setMapProductCodes:
Sets the products to display by product code.
-
+ defaultMapStackProductCodes
- The default OpenSpace map stack, taken from
- http://www.ordnancesurvey.co.uk/oswebsite/support/web-services/about-os-openspace-layers-and-services.html *
- Does not include VectorMap District.
-
+ completeFreeMapStackProductCodes
- The complete OpenSpace (free) map stack, taken from
- http://www.ordnancesurvey.co.uk/oswebsite/support/web-services/about-os-openspace-layers-and-services.html *
- Identical to +defaultFreeMapStack plus VectorMap District.
-
+ zoomMapStackProductCodes
- The OpenSpace Pro zoom map stack.
Converting between coordinate systems
-
– convertCoordinate:toPointToView:
-
– convertGridPoint:toPointToView:
-
– convertPoint:toGridPointFromView:
-
– convertRegion:toRectToView:
Versioning
-
+ SDKVersion
Returns the current SDK version number as a string, e.g. “1.0”.
Other Methods
Properties
Class Methods
SDKVersion
Returns the current SDK version number as a string, e.g. “1.0”.
+ (NSString *)SDKVersion
Declared In
OSMapView.h
completeFreeMapStackProductCodes
- The complete OpenSpace (free) map stack, taken from
- http://www.ordnancesurvey.co.uk/oswebsite/support/web-services/about-os-openspace-layers-and-services.html *
- Identical to +defaultFreeMapStack plus VectorMap District.
+ (NSArray *)completeFreeMapStackProductCodes
Declared In
OSMapView.h
defaultMapStackProductCodes
- The default OpenSpace map stack, taken from
- http://www.ordnancesurvey.co.uk/oswebsite/support/web-services/about-os-openspace-layers-and-services.html *
- Does not include VectorMap District.
+ (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
Instance Methods
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:edgePadding:
- (OSGridRect)gridRectThatFits:(OSGridRect)gridRect edgePadding:(UIEdgeInsets)insets
insertOverlay:aboveOverlay:
- (void)insertOverlay:(id<OSOverlay>)overlay aboveOverlay:(id<OSOverlay>)overlay2
insertOverlay:belowOverlay:
- (void)insertOverlay:(id<OSOverlay>)overlay belowOverlay:(id<OSOverlay>)overlay2
mapRectThatFits:edgePadding:
- (OSMapRect)mapRectThatFits:(OSMapRect)mapRect edgePadding:(UIEdgeInsets)insets
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
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