ClassMapView

An interactive instance of a map attached to the DOM.

Call Map.attach to create instances of this class.

MapView#camerachange - Fired when the camera position, heading, or span changes.

MapView#click - Fired when the user clicks on the map. The event is a MapMouseEvent with map coordinates.

MapView#dblclick - Fired when the user double-clicks on the map. The event is a standard MouseEvent.

Hierarchy

Camera Properties

  • get heading(): number
  • The heading of the camera, in degrees relative to true north.

    Returns number

  • get mapPoint(): MapPoint
  • The map point at the centre of the map view.

    Returns MapPoint

  • get mapSpan(): number
  • The span of the map view in map units.

    Returns number

    The map span represents the distance in map units between the edges of the screen in the smaller axis. For example, this would be the distance between the top edge and the bottom edge of the map view for map views which were wider than they were tall.

  • get span(): number
  • The span of the map view in metres.

    Returns number

    The span represents the physical distance between the edges of the screen in the smaller axis. For example, this would be the distance between the top edge and the bottom edge of the map view for map views which were wider than they were tall.

Configuration

mouseWheelEventsRequireModifierKey: boolean = false

Whether the shift or control key needs to be held down for mouse wheel events to affect the map view.

If a mouse wheel event is handled by the map view, MapLayr will prevent the event's default action, stopping the browser window from scrolling. If the host web page contains custom scrolling logic, it is recommended that it checks that the event's defaultPrevented property is still false before it decides to apply that logic.

mouseWheelZoomsMap: boolean = false

Whether the mouse wheel zooms the map.

If set to false, and neither the alt nor meta/command keys are held down, mouse wheel events will scroll the map instead of panning the map.

If the control key is held down, the map always zooms in regardless of this property.

Managing Map Layers

  • Adds the given map layer to the map.

    Parameters

    • mapLayer: MapLayer

      The map layer to add to the map view.

    Returns void

    The resulting map layer will appear on top of all other map layers.

  • Removes the given map layer from the map view.

    Parameters

    • mapLayer: MapLayer

      The map layer to remove.

    Returns void

Other

  • Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.

    The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.

    When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.

    When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in ยง 2.8 Observing event listeners.

    When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.

    If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.

    The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.

    MDN Reference

    Parameters

    • type: string
    • callback: null | EventListenerOrEventListenerObject
    • Optionaloptions: boolean | AddEventListenerOptions

    Returns void

  • Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.

    MDN Reference

    Parameters

    Returns boolean

  • Removes the event listener in target's event listener list with the same type, callback, and options.

    MDN Reference

    Parameters

    • type: string
    • callback: null | EventListenerOrEventListenerObject
    • Optionaloptions: boolean | EventListenerOptions

    Returns void

Removing from Page

  • Detaches this map view from its container element.

    Returns void

    Once a map view is detached, it can no longer be useful and any remaining references to it should be removed to allow the garbage collector to deallocate it.

Setting the Camera

  • Adjusts the camera using the specified options with an optional animation.

    Parameters

    • options: MoveCameraOptions

      The new properties of the camera. A missing property indicates that that property of the camera shouldn't be affected.

    Returns void

Shapes

  • get shapes(): Shape[]
  • The shapes which are drawn on the map.

    Returns Shape[]

  • Adds the given shape to the map.

    Parameters

    • shape: Shape

      The shape to add to the map view.

    Returns void

    The resulting shape will be rendered on the map and updated when the shape's properties change. Shapes are drawn in the order they are added, so later shapes will appear on top.

  • Removes the given shape from the map view.

    Parameters

    • shape: Shape

      The shape to remove.

    Returns void

User Location Markers

  • Adds the given user location marker to the map.

    Parameters

    Returns void

    The resulting marker will be rendered on the map and updated when the map view is redrawn. Markers are drawn in the order they are added, so later markers will appear on top.

  • Removes the given user location marker from the map view.

    Parameters

    Returns void