Marker class

Creates a marker component @param {HTMLElement} element DOM element to use as a marker. The default is a light blue, droplet-shaped SVG marker. @param {string} anchor='center' A string indicating the part of the Marker that should be positioned closest to the coordinate set via {@link Marker#setLngLat}. Options are 'center', 'top', 'bottom', 'left', 'right', 'top-left', 'top-right', 'bottom-left', and 'bottom-right'. @param {PointLike} offset The offset in pixels as a {@link PointLike} object to apply relative to the element's center. Negatives indicate left and up. @param {string} color='#3FB1CE' The color to use for the default marker if element is not provided. The default is light blue. @param {boolean} draggable=false A boolean indicating whether or not a marker is able to be dragged to a new position on the map. @param {number} rotation=0 The rotation angle of the marker in degrees, relative to its respective {@link Marker#rotationAlignment} setting. A positive value will rotate the marker clockwise. @param {string} pitchAlignment='auto' map aligns the Marker to the plane of the map. viewport aligns the Marker to the plane of the viewport. auto automatically matches the value of rotationAlignment. @param {string} rotationAlignment='auto' map aligns the Marker's rotation relative to the map, maintaining a bearing as the map rotates. viewport aligns the Marker's rotation relative to the viewport, agnostic to map rotations. auto is equivalent to viewport.

var marker = mapboxgl.Marker()
  .setLngLat([30.5, 50.5])
  .addTo(map);

@see Add custom icons with Markers @see Create a draggable Marker

Inheritance

Constructors

Marker([MarkerOptions? options])
factory
Marker.fromJsObject(MarkerJsImpl jsObject)
Creates a new Marker from a jsObject.

Properties

hashCode int
The hash code for this object.
no setterinherited
jsObject → MarkerJsImpl
JS object.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addTo(MapboxMap map) Marker
Attaches the marker to a map @param {MapboxMap} map @returns {Marker} this
fire(Event event, [dynamic properties]) → dynamic
inherited
getElement() HtmlElement
Returns the Marker's HTML element. @returns {HtmlElement} element
getLngLat() LngLat
Get the marker's geographical location.
getOffset() Point
Get the marker's offset. @returns {Point}
getPitchAlignment() String
Returns the current pitchAlignment property of the marker. @returns {string}
getPopup() Popup
Returns the Popup instance that is bound to the Marker @returns {Popup} popup
getRotation() num
Returns the current rotation angle of the marker (in degrees). @returns {number}
getRotationAlignment() String
Returns the current rotationAlignment property of the marker. @returns {string}
isDraggable() bool
Returns true if the marker can be dragged @returns {boolean}
listens(String type) → dynamic
Returns a true if this instance of Evented or any forwardeed instances of Evented have a listener for the specified type.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
off(String type, [dynamic layerIdOrListener, Listener? listener]) MapboxMap
Removes a previously registered event listener.
inherited
on(String type, [dynamic layerIdOrListener, Listener? listener]) MapboxMap
Adds a listener to a specified event type.
inherited
once(String type, Listener listener) MapboxMap
Adds a listener that will be called only once to a specified event type.
inherited
remove() Marker
Removes the marker from a map @example var marker = new mapboxgl.Marker().addTo(map); marker.remove(); @returns {Marker} this
setDraggable(bool shouldBeDraggable) Marker
Sets the draggable property and functionality of the marker @param {boolean} shouldBeDraggable=false Turns drag functionality on/off @returns {Marker} this
setEventedParent([Evented? parent, dynamic data]) → dynamic
Bubble all events fired by this instance of Evented to this parent instance of Evented.
inherited
setLngLat(LngLat lnglat) Marker
Set the marker's geographical position and move it. @returns {Marker} this
setOffset(Point offset) Marker
Sets the offset of the marker @param {PointLike} offset The offset in pixels as a {@link PointLike} object to apply relative to the element's center. Negatives indicate left and up. @returns {Marker} this
setPitchAlignment(String alignment) Marker
Sets the pitchAlignment property of the marker. @param {string} alignment Sets the pitchAlignment property of the marker. If alignment is 'auto', it will automatically match rotationAlignment. @returns {Marker} this
setPopup(Popup popup) Marker
Binds a Popup to the Marker @param popup an instance of the Popup class. If undefined or null, any popup set on this Marker instance is unset @returns {Marker} this
setRotation(num rotation) Marker
Sets the rotation property of the marker. @param {number} rotation=0 The rotation angle of the marker (clockwise, in degrees), relative to its respective {@link Marker#rotationAlignment} setting. @returns {Marker} this
setRotationAlignment(String alignment) Marker
Sets the rotationAlignment property of the marker. @param {string} alignment='auto' Sets the rotationAlignment property of the marker. @returns {Marker} this
togglePopup() Marker
Opens or closes the bound popup, depending on the current state @returns {Marker} this
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited