MZMapViewController

open class MZMapViewController: UIViewController, LocationManagerDelegate

MZMapViewController is the main class utilized for displaying Mapzen maps on iOS. It aims to provide the full set of features a developer would want for mapping-related tasks, such as displaying routes, results of a search, or the device’s current location (and any combination therein.)

MZMapViewController wraps the underlying TGMapViewController from Tangram-es and handles adding it to the view hierarchy. It exposes this in the tgViewController property and allows for additional customization there using the Tangram-es iOS framework. Documentation on that is available here.

  • Default initializer. Sets up the find me button and initializes the TGMapViewController as part of startup.

    Declaration

    Swift

    public init()

    Return Value

    A fully formed MZMapViewController.

  • Default required initializer for storyboard creation.

    Declaration

    Swift

    required public init?(coder aDecoder: NSCoder)

    Return Value

    A fully formed MZMapViewController.

  • Default required initializer for nib-based creation.

    Declaration

    Swift

    public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?)

    Return Value

    A fully formed MZMapViewController.

  • Direct access to the underlying TGMapViewController’s view.

    Declaration

    Swift

    open var mapView : GLKView
  • The height of our enclosing tab bar controller’s tab bar if it is translucent.

    Declaration

    Swift

    open var tabBarOffset : CGFloat
  • Animates the map to a particular position using the default easing type (Cubic).

    Declaration

    Swift

    open func animate(toPosition position: TGGeoPoint, withDuration seconds: Float)

    Parameters

    position

    The position to animate to.

    seconds

    How long the animation should last.

  • Animates the map to a particular position using the provided easing type.

    Declaration

    Swift

    open func animate(toPosition position: TGGeoPoint, withDuration seconds: Float, with easeType: TGEaseType)

    Parameters

    position

    The position to animate to.

    seconds

    How long the animation should last.

    easeType

    The animation easing style to use.

  • Animates the map to a particular zoom level using the default easing type (Cubic).

    Declaration

    Swift

    open func animate(toZoomLevel zoomLevel: Float, withDuration seconds: Float)

    Parameters

    zoomLevel

    The zoom level to animate to.

    seconds

    How long the animation should last.

  • Animates the map to a particular zoom level using the provided easing type.

    Declaration

    Swift

    open func animate(toZoomLevel zoomLevel: Float, withDuration seconds: Float, with easeType: TGEaseType)

    Parameters

    zoomLevel

    The zoom level to animate to.

    seconds

    How long the animation should last.

    easeType

    The animation easing style to use.

  • Animates the map to rotate using the default easing type (Cubic).

    Declaration

    Swift

    open func animate(toRotation radians: Float, withDuration seconds: Float)

    Parameters

    radians

    How far the map should rotate in radians.

    seconds

    How long the animation should last.

  • Animates the map to rotate using the provided easing type.

    Declaration

    Swift

    open func animate(toRotation radians: Float, withDuration seconds: Float, with easeType: TGEaseType)

    Parameters

    radians

    How far the map should rotate in radians.

    seconds

    How long the animation should last.

    easeType

    The animation easing style to use.

  • Animates the map to tilt using the default easing type (Cubic).

    Declaration

    Swift

    open func animate(toTilt radians: Float, withDuration seconds: Float)

    Parameters

    radians

    How far the map should tilt in radians.

    seconds

    How long the animation should last.

  • Animates the map to tile using the provided easing type.

    Declaration

    Swift

    open func animate(toTilt radians: Float, withDuration seconds: Float, with easeType: TGEaseType)

    Parameters

    radians

    How far the map should tilt in radians.

    seconds

    How long the animation should last.

    easeType

    The animation easing style to use.

  • Adds a marker to the map. A marker can only be added to one map at a time.

    Declaration

    Swift

    open func addMarker(_ marker: GenericMarker)

    Parameters

    marker

    The marker to add to map.

  • Removes a marker from the map.

    Declaration

    Swift

    open func removeMarker(_ marker: GenericMarker)

    Parameters

    marker

    The marker to remove from map.

  • Removes all existing markers on the map.

    Declaration

    Swift

    open func markerRemoveAll()
  • Loads a map style synchronously on the main thread. Use the async methods instead of these in production apps.

    Throws

    A MZError apiKeyNotSet error if an API Key has not been sent on the MapzenManager class.

    Declaration

    Swift

    open func loadStyle(_ style: MapStyle) throws

    Parameters

    style

    The map style to load.

  • Loads a map style synchronously on the main thread. Use the async methods instead of these in production apps.

    Throws

    A MZError apiKeyNotSet error if an API Key has not been sent on the MapzenManager class.

    Declaration

    Swift

    open func loadStyle(_ style: MapStyle, locale: Locale) throws

    Parameters

    style

    The map style to load.

    locale

    The locale to use for the map’s language.

  • Loads a map style synchronously on the main thread. Use the async methods instead of these in production apps.

    Throws

    A MZError apiKeyNotSet error if an API Key has not been sent on the MapzenManager class.

    Declaration

    Swift

    open func loadStyle(_ style: MapStyle, sceneUpdates: [TGSceneUpdate]) throws

    Parameters

    style

    The map style to load.

    sceneUpdates

    The scene updates to make while loading the map style.

  • Loads a map style synchronously on the main thread. Use the async methods instead of these in production apps.

    Throws

    A MZError apiKeyNotSet error if an API Key has not been sent on the MapzenManager class.

    Declaration

    Swift

    open func loadStyle(_ style: MapStyle, locale l: Locale, sceneUpdates: [TGSceneUpdate]) throws

    Parameters

    style

    The map style to load.

    l

    The locale to use for the map’s language.

    sceneUpdates

    The scene updates to make while loading the map style.

  • Loads the map style asynchronously. Recommended for production apps. If you have scene updates to apply, either use the other version of this method that allows you to pass in scene updates during load, or wait until onSceneLoaded is called to apply those updates.

    Throws

    A MZError apiKeyNotSet error if an API Key has not been sent on the MapzenManager class.

    Declaration

    Swift

    open func loadStyleAsync(_ style: MapStyle, onStyleLoaded: OnStyleLoaded?) throws

    Parameters

    style

    The map style to load.

    onStyleLoaded

    Closure called on scene loaded.

  • Loads the map style asynchronously. Recommended for production apps. If you have scene updates to apply, either use the other version of this method that allows you to pass in scene updates during load, or wait until onSceneLoaded is called to apply those updates.

    Throws

    A MZError apiKeyNotSet error if an API Key has not been sent on the MapzenManager class.

    Declaration

    Swift

    open func loadStyleAsync(_ style: MapStyle, locale: Locale, onStyleLoaded: OnStyleLoaded?) throws

    Parameters

    style

    The map style to load.

    locale

    The locale to use for the map’s language.

    onStyleLoaded

    Closure called on scene loaded.

  • Loads the map style asynchronously. Recommended for production apps. If you have scene updates to apply, either pass in the scene updates at the initial call, or wait until onSceneLoaded is called to apply those updates.

    Throws

    A MZError apiKeyNotSet error if an API Key has not been sent on the MapzenManager class.

    Declaration

    Swift

    open func loadStyleAsync(_ style: MapStyle, sceneUpdates: [TGSceneUpdate], onStyleLoaded: OnStyleLoaded?) throws

    Parameters

    style

    The map style to load.

    sceneUpdates

    The scene updates to make while loading the map style.

    onStyleLoaded

    Closure called on scene loaded.

  • Loads the map style asynchronously. Recommended for production apps. If you have scene updates to apply, either pass in the scene updates at the initial call, or wait until onSceneLoaded is called to apply those updates.

    Throws

    A MZError apiKeyNotSet error if an API Key has not been sent on the MapzenManager class.

    Declaration

    Swift

    open func loadStyleAsync(_ style: MapStyle, locale l: Locale, sceneUpdates: [TGSceneUpdate], onStyleLoaded: OnStyleLoaded?) throws

    Parameters

    style

    The map style to load.

    l

    The locale to use for the map’s language.

    sceneUpdates

    The scene updates to make while loading the map style.

    onStyleLoaded

    Closure called on scene loaded.

  • Loads a map style synchronously on the main thread. Use the async methods instead of these in production apps.

    Throws

    A MZError apiKeyNotSet error if an API Key has not been sent on the MapzenManager class.

    Declaration

    Swift

    open func loadStyleSheet(_ styleSheet: StyleSheet) throws

    Parameters

    styleSheet

    The map style to load.

  • Loads a map style synchronously on the main thread. Use the async methods instead of these in production apps.

    Throws

    A MZError apiKeyNotSet error if an API Key has not been sent on the MapzenManager class.

    Declaration

    Swift

    open func loadStyleSheet(_ styleSheet: StyleSheet, locale: Locale ) throws

    Parameters

    styleSheet

    The map style to load.

    locale

    The locale to use for the map’s language.

  • Loads the map style asynchronously. Recommended for production apps. Uses the system’s current locale.

    Throws

    A MZError apiKeyNotSet error if an API Key has not been sent on the MapzenManager class.

    Declaration

    Swift

    open func loadStyleSheetAsync(_ styleSheet: StyleSheet, onStyleLoaded: OnStyleLoaded?) throws

    Parameters

    styleSheet

    The map style / theme combination to load.

    onStyleLoaded

    Closure called on scene loaded.

  • Loads the map style asynchronously. Recommended for production apps.

    Throws

    A MZError apiKeyNotSet error if an API Key has not been sent on the MapzenManager class.

    Declaration

    Swift

    open func loadStyleSheetAsync(_ styleSheet: StyleSheet, locale: Locale, onStyleLoaded: OnStyleLoaded?) throws

    Parameters

    styleSheet

    The map style / theme combination to load.

    locale

    The locale to use for the map’s language.

    onStyleLoaded

    Closure called on scene loaded.

  • Sets the locale used to determine the map’s language.

    Declaration

    Swift

    open func updateLocale(_ l: Locale)
  • Queue a scene update using a yaml string path. It’s recommended to use the other version of this that uses the TGSceneUpdate objects. Try to queue as many scene updates as you can in one pass as each applySceneUpdates() call can require a re-parse of the yaml and a re-render of the map. It is required to call applySceneUpdates() to activate the updated that have been enqueued.

    Declaration

    Swift

    open func queueSceneUpdate(_ componentPath: String, withValue value: String)

    Parameters

    componentPath

    The yaml path to the component to change.

    value

    The value to update the component to.

  • Queue an array of scene updates. Try to queue as many scene updates as you can in one pass as each applySceneUpdates() call can require a re-parse of the yaml and a re-render of the map. It is required to call applySceneUpdates() to activate the updated that have been enqueued.

    Declaration

    Swift

    open func queue(_ sceneUpdates: [TGSceneUpdate])

    Parameters

    sceneUpdates

    An array of TGSceneUpdate objects to update the map.

  • Convenience function that converts TGGeoPoints to UIKit screen coordinates.

    Declaration

    Swift

    open func lngLat(toScreenPosition lngLat: TGGeoPoint) -> CGPoint

    Parameters

    lngLat

    TGGeoPoint to convert

    Return Value

    The CGPoint in screen space.

  • Convenience function that converts UIKit screen coordinates to a lat/long pair.

    Declaration

    Swift

    open func screenPosition(toLngLat screenPosition: CGPoint) -> TGGeoPoint

    Parameters

    screenPosition

    The screen coordinate to convert.

    Return Value

    A TGGeoPoint in lat/long for the screen coordinate.

  • Resets the camera on the current location, as well as the zoom and tilt.

    Declaration

    Swift

    open func resetCameraOnCurrentLocation(_ tilt: Float = 0.0, zoomLevel: Float = 16.0, animationDuration: Float = 1.0) -> Bool

    Parameters

    tilt

    The tilt to reset to. Defaults to 0.

    zoomLevel

    The zoom to reset to. Defaults to 0.

    animationDuration

    The length to animate the reset to. Passing in 0 makes the change happen immediately.

    Return Value

    Whether or not the map was centered on the device’s current location

  • Handles state for the find me button.

    Declaration

    Swift

    open func showFindMeButon(_ shouldShow: Bool)

    Parameters

    shouldShow

    Shows or hides the button

  • Shows or hides the current location of the device. This starts the location request process and will prompt the user the first time its called.

    Declaration

    Swift

    open func showCurrentLocation(_ shouldShow: Bool) -> Bool

    Parameters

    shouldShow

    Whether or not we should show the current location.

    Return Value

    Whether or not current location was shown

  • Enables / Disables the entire current location layer.

    Declaration

    Swift

    open func enableLocationLayer(_ enabled: Bool)

    Parameters

    enabled

    True if we should enable the location layer. False disables it.

  • Adds an array of annotations to the map.

    Throws

    A MZError generalError if the underlying map fails to add any of the annotations.

    Declaration

    Swift

    open func add(_ annotations: [PeliasMapkitAnnotation]) throws

    Parameters

    annotations

    An array of annotations to add.

  • Removes a single annotation

    Throws

    A MZError annotationDoesNotExist error.

    Declaration

    Swift

    open func remove(_ annotation: PeliasMapkitAnnotation) throws

    Parameters

    annotation

    The annotation to remove

  • Removes all currents annotations.

    Throws

    A MZError annotationDoesNotExist error if it encounters an annotation that no longer exists.

    Declaration

    Swift

    open func removeAnnotations() throws
  • Removes all currents annotations.

    Declaration

    Swift

    open func removeMapAnnotations()
  • Displays a routing result on the map. This currently only supports single start and endpoint routes. If there’s an existing route it will be silently replaced.

    Throws

    A MZError generalError if the map can’t add the route.

    Declaration

    Swift

    open func display(_ route: OTRRoutingResult) throws

    Parameters

    route

    The route to display.

  • Removes the route from the map

    Throws

    A MZError routeDoesNotExist error if there isn’t a current route or the map can’t find one to remove.

    Declaration

    Swift

    open func removeRoute() throws