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:
OSMapViewuses the OSGB36 National Grid map projection. Applications which have assumed a Mercator projection may have to take the different projection into account.OSMapViewdoes not support drawing maps outside the UK.OSMapViewrequires an API key and a tile source to be set before using the online data source.OSMapViewsupports many more map configurations than can be easily expressed with a singlemapTypeproperty.OSMapViewandOSOverlayViewdo not use power-of-2 zoom levels.OSMapViewcannot be completely initialised from a NIB.OSGridPointis 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
OSCoordinateRegionandOSGridRectrepresent 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
-
delegateproperty
Creating and using tile sources
-
tileSourcesproperty -
+ 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
-
mapScaleViewproperty
Managing scrolling and zooming
-
zoomEnabledproperty -
scrollEnabledproperty -
visibleGridRectproperty -
centerCoordinateproperty -
regionproperty -
– setVisibleGridRect:animated: -
– setVisibleGridRect:edgePadding:animated: -
– setCenterCoordinate:animated: -
– setRegion:animated: -
– gridRectThatFits: -
– gridRectThatFits:edgePadding: -
– regionThatFits:
Current zoom level
-
metresPerPixelproperty
User location
-
showsUserLocationproperty -
userTrackingModeproperty -
userLocationproperty -
userLocationVisibleproperty -
– setUserTrackingMode:animated:
Managing annotations
-
annotationsproperty -
selectedAnnotationsproperty -
annotationVisibleRectproperty -
– addAnnotation: -
– addAnnotations: -
– removeAnnotation: -
– removeAnnotations: -
– annotationsInGridRect: -
– dequeueReusableAnnotationViewWithIdentifier: -
– selectAnnotation:animated: -
– deselectAnnotation:animated: -
– viewForAnnotation:
Managing overlays
-
overlaysproperty -
– 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
-
+ SDKVersionReturns 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 *)SDKVersionDeclared In
OSMapView.hcompleteFreeMapStackProductCodes
- 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 *)completeFreeMapStackProductCodesDeclared In
OSMapView.hdefaultMapStackProductCodes
- 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 *)defaultMapStackProductCodesDeclared In
OSMapView.hlocalTileSourceWithFileURL:
Creates a tile source which loads tiles from a local SQLite database.
+ (id<OSTileSource>)localTileSourceWithFileURL:(NSURL *)fileURLParameters
- 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.hlocalTileSourcesInDirectoryAtURL:
Calls localTileSourceWithFileURL: on all files in a directory and returns an array of the non-nil results.
+ (NSArray *)localTileSourcesInDirectoryAtURL:(NSURL *)directoryURLDeclared In
OSMapView.hwebTileSourceWithAPIKey:openSpacePro:
Creates a tile source which loads images off the OpenSpace or OpenSpace Pro tile servers.
+ (id<OSTileSource>)webTileSourceWithAPIKey:(NSString *)apiKey openSpacePro:(bool)isProParameters
- apiKey
Your OpenSpace or OpenSpace Pro API key
- isPro
trueif the API key is an OpenSpace Pro API key,falseotherwise.
Declared In
OSMapView.hInstance Methods
convertCoordinate:toPointToView:
- (CGPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate toPointToView:(UIView *)viewconvertGridPoint:toPointToView:
- (CGPoint)convertGridPoint:(OSGridPoint)gp toPointToView:(UIView *)viewconvertPoint:toGridPointFromView:
- (OSGridPoint)convertPoint:(CGPoint)point toGridPointFromView:(UIView *)viewconvertRegion:toRectToView:
- (CGRect)convertRegion:(OSCoordinateRegion)region toRectToView:(UIView *)viewdequeueReusableAnnotationViewWithIdentifier:
- (OSAnnotationView *)dequeueReusableAnnotationViewWithIdentifier:(NSString *)identifierdeselectAnnotation:animated:
- (void)deselectAnnotation:(id<OSAnnotation>)annotation animated:(BOOL)animatedexchangeOverlayAtIndex:withOverlayAtIndex:
- (void)exchangeOverlayAtIndex:(NSUInteger)index1 withOverlayAtIndex:(NSUInteger)index2gridRectThatFits:edgePadding:
- (OSGridRect)gridRectThatFits:(OSGridRect)gridRect edgePadding:(UIEdgeInsets)insetsinsertOverlay:aboveOverlay:
- (void)insertOverlay:(id<OSOverlay>)overlay aboveOverlay:(id<OSOverlay>)overlay2insertOverlay:belowOverlay:
- (void)insertOverlay:(id<OSOverlay>)overlay belowOverlay:(id<OSOverlay>)overlay2mapRectThatFits:edgePadding:
- (OSMapRect)mapRectThatFits:(OSMapRect)mapRect edgePadding:(UIEdgeInsets)insetsselectAnnotation:animated:
- (void)selectAnnotation:(id<OSAnnotation>)annotation animated:(BOOL)animatedsetCenterCoordinate:animated:
- (void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate animated:(BOOL)animatedsetMapProductCodes:
Sets the products to display by product code.
- (void)setMapProductCodes:(NSArray *)mapProductCodesParameters
- mapProductCodes
The array of product codes. Does not need to be sorted.
Declared In
OSMapView.hsetUserTrackingMode:animated:
- (void)setUserTrackingMode:(OSUserTrackingMode)userTrackingMode animated:(BOOL)animatedsetVisibleGridRect:animated:
- (void)setVisibleGridRect:(OSGridRect)visibleGridRect animated:(BOOL)animatedsetVisibleGridRect:edgePadding:animated:
- (void)setVisibleGridRect:(OSGridRect)visibleGridRect edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated