mapboxgl-Map

Methods

addListenerForLayer(layerId, eventType, listener) → {function}

Add a listener to the map concerning the layer layerId. The listener should test whether the specific event is for the layer or not.

Events will be fired from top to bottom (following pseudo-z-index) and only if the originalEvent.cancelBubble is falsy.

Parameters:
Name Type Description
layerId string

the layer id.

eventType string

the event type.

listener function

the listener which will be called with a mapbox event.

Returns:
function -

a wrapped listener, original listener could be found in the originalListener property.

fire(event) → {Map}

Fires an event of the specified type.

Respect the bubble effect.

Parameters:
Name Type Description
event object

event data

Returns:
Map -

this

See:

getListenersForLayer(layerId) → {object}

Get all (wrapped) listeners for the specified layer id.

Parameters:
Name Type Description
layerId string

the layer id

Returns:
object -

object with all listeners as property.

Evented._listeners or empty object.

See:

off(type, layerIdOrListeneropt, layerListeneropt) → {Map}

Removes an event listener (eventually for layer-specific events) previously added with on method.

Parameters:
Name Type Attributes Default Description
type string

one of the available types.

layerIdOrListener string | function <optional>
null

A style layer id from which you want to remove the listener.

Otherwise, the listener to remove.

layerListener function <optional>
null

The listener to remove if not defined in the previous parameter.

Returns:
Map -

this

on(type, layerIdOrListeneropt, layerListeneropt) → {Map}

Enhance on method for registering an event.

The following special map event type could be registerd:

  • mousedown
  • mouseup
  • click
  • dblclick
  • mousemove
  • mouseenter / mouseover: the cursor enters a visible portion of the specified layer from outside that layer or outside the map canvas.
  • mouseleave: the cursor leaves a visible portion of the specified layer or leaves the map canvas.
  • mouseout: the cursor leaves the map canvas.
  • contextmenu
  • touchstart
  • touchend
  • touchcancel

Events will be fired from top to bottom (following the bubble effect) and only if the originalEvent can propagate (bubbles getter is falsy or stopPropagation has not been called on it).

Parameters:
Name Type Attributes Default Description
type string

one of the available types.

layerIdOrListener string | function <optional>
null

A style layer id if you want to restrict events to the visible features of a layer.

Otherwise, a listener which takes a mapboxgl event as argument.

The event object has three more properties:

  • originalEvent: the DOM event
  • target: the DOM target
  • type: the event type
layerListener function <optional>
null

The listener if not defined in the previous parameter.

Returns:
Map -

this

removeListenerFromLayer(layerId, eventType, listener)

Remove a listener from a layer. The listener could be a real or a wrapper listener.

Parameters:
Name Type Description
layerId string

the layer id corresponding to the listener.

eventType string

the event type.

listener function

the listener to remove.