For AI agents: a documentation index is available at /llms.txt. Markdown versions of all pages are available by appending .md to any URL.
Interface MLMarker
_addDragHandler: (e: MapMouseEventMLGL | MapTouchEventMLGL) => void;
_anchor: PositionAnchor;
_clickTolerance: number;
_color: string;
_defaultMarker: boolean;
_draggable: boolean;
_element: HTMLElement;
_eventedParent?: Evented<EventTypeMap>;
_eventedParentData?: EventedParentData | (() => EventedParentData);
_flatPos: Point;
_isDragging: boolean;
_keyboardDragActive: boolean;
_listeners?: Listeners<MarkerEventType>;
_lngLat: LngLat;
_map: MapMLGL;
_offset: Point;
_onBlur: () => void;
_onClick: (e: MouseEvent) => void;
_oneTimeListeners?: Listeners<MarkerEventType>;
_onKeyDown: (e: KeyboardEvent) => void;
_onKeyPress: (e: KeyboardEvent) => void;
_onKeyUp: (e: KeyboardEvent) => void;
_onMapClick: (e: MapMouseEventMLGL) => void;
_onMove: (e: MapMouseEventMLGL | MapTouchEventMLGL) => void;
_onUp: () => void;
_opacity: string;
_opacityWhenCovered: string;
_pitchAlignment: Alignment;
_pointerdownPos: Point;
_popup: PopupMLGL;
_pos: Point;
_positionDelta: Point;
_roleManaged: boolean;
_rotation: number;
_rotationAlignment: Alignment;
_scale: number;
_state: "active" | "inactive" | "pending";
_subpixelPositioning: boolean;
_tabIndexManaged: boolean;
_update: (
e?: {
type: "idle" | "move" | "moveend" | "terrain" | "projectiontransition";
},
) => void;
_updateCovered: () => Timeout;
_updateCoveredUnthrottled: () => void;
_endKeyboardDrag(): void;
_isCovered(terrain: Terrain): boolean;
_isInViewport(): boolean;
_updateAccessibilityRole(): void;
_updateOpacity(): void;
_updateTabIndex(): void;
addClassName(className: string): void;
addTo(map: MapMLGL): this;
fire(event: MarkerDragEvent | MarkerClickEvent): this;
fire(type: keyof MarkerEventType, properties?: object): this;
getElement(): HTMLElement;
getLngLat(): LngLat;
getOffset(): Point;
getPitchAlignment(): Alignment;
getPopup(): PopupMLGL;
getRotation(): number;
getRotationAlignment(): Alignment;
isDraggable(): boolean;
listens(type: keyof MarkerEventType): boolean;
off<T extends keyof MarkerEventType>(
type: T,
listener: (event: MarkerEventType[T]) => void,
): this;
on<T extends keyof MarkerEventType>(
type: T,
listener: (event: MarkerEventType[T]) => void,
): Subscription;
once<T extends keyof MarkerEventType>(type: T): Promise<MarkerEventType[T]>;
once<T extends keyof MarkerEventType>(
type: T,
listener: (event: MarkerEventType[T]) => void,
): this;
remove(): this;
removeClassName(className: string): void;
setDraggable(shouldBeDraggable?: boolean): this;
setEventedParent(
parent?: Evented<EventTypeMap> | null,
data?: EventedParentData | (() => EventedParentData),
): this;
setLngLat(lnglat: LngLatLike): this;
setOffset(offset: PointLike): this;
setOpacity(
opacity?: string | number,
opacityWhenCovered?: string | number,
): this;
setPitchAlignment(alignment?: Alignment): this;
setPopup(popup?: PopupMLGL | null): this;
setRotation(rotation?: number): this;
setRotationAlignment(alignment?: Alignment): this;
setSubpixelPositioning(value: boolean): this;
toggleClassName(className: string): boolean;
togglePopup(): this;
}
Hierarchy (View Summary)
- Evented<MarkerEventType>
- MLMarker
Index
Properties
Methods
Properties
_addDragHandler
_anchor
_clickTolerance
_color
_defaultMarker
_draggable
_element
Optional_eventedParent
Optional_eventedParentData
_flatPos
_isDragging
_keyboardDragActive
Optional_listeners
_lngLat
_map
_offset
_onBlur
_onClick
Optional_oneTimeListeners
_onKeyDown
Move a focused draggable default marker with the arrow keys
(1 screen pixel per keydown; 10 with Shift).
Mirrors the pointer drag gesture: the position updates before dragstart
fires on the first movement, every movement fires drag, and releasing
the arrow key (or losing focus) fires dragend. Holding a key down
produces repeated drag events within a single gesture.
_onKeyPress
_onKeyUp
_onMapClick
_onMove
_onUp
_opacity
_opacityWhenCovered
_pitchAlignment
_pointerdownPos
_popup
_pos
_positionDelta
_roleManaged
_rotation
_rotationAlignment
_scale
_state
_subpixelPositioning
_tabIndexManaged
_update
e?: {
type: "idle" | "move" | "moveend" | "terrain" | "projectiontransition";
},
) => void
_updateCovered
_updateCoveredUnthrottled
Methods
_endKeyboardDrag
Returns void
_isCovered
Parameters
- terrain: Terrain
Returns boolean
_isInViewport
_updateAccessibilityRole
Keep the default marker role aligned with interactivity. Default markers need a role because
aria-labelis set in Marker.addTo. Non-interactive markers userole=img; interactive ones (draggable or with a popup) userole=button. Click listeners are application-owned and do not automatically change the role. Custom marker elements are left alone so applications own their a11y tree. Explicit roles set by the application are preserved.Returns void
_updateOpacity
Returns void
_updateTabIndex
Keep the marker element focusable while it has built-in keyboard behavior. A popup makes any marker element interactive; dragging only manages focusability for the default marker so custom elements stay application-owned (#7790). A tabindex supplied by the application is never added, changed, or removed here.
Returns void
addClassName
addTo
Attaches the
Markerto aMapobject.Parameters
- map: MapMLGL
The MapLibre GL JS map to add the marker to.
Returns this
- map: MapMLGL
fire
Calls every listener registered for the event's type.
Parameters
- event: MarkerDragEvent | MarkerClickEvent
Returns this
Compatibility with the (type: string, properties: Object) signature from previous versions. See https://github.com/mapbox/mapbox-gl-js/issues/6522, https://github.com/mapbox/mapbox-gl-draw/issues/766
Parameters
- type: keyof MarkerEventType
Optionalproperties: object
Returns this
getElement
getLngLat
Get the marker's geographical location.
The longitude of the result may differ by a multiple of 360 degrees from the longitude previously set by
setLngLatbecauseMarkerwraps the anchor longitude across copies of the world to keep the marker on screen.Returns LngLat
A LngLat describing the marker's location.
getOffset
getPitchAlignment
Returns the current
pitchAlignmentproperty of the marker.Returns Alignment
The current pitch alignment of the marker in degrees.
getPopup
getRotation
Returns the current rotation angle of the marker (in degrees).
Returns number
The current rotation angle of the marker.
getRotationAlignment
Returns the current
rotationAlignmentproperty of the marker.Returns Alignment
The current rotational alignment of the marker.
isDraggable
Returns true if the marker can be dragged
Returns boolean
True if the marker is draggable.
listens
Returns a true if this instance of Evented or any forwardeed instances of Evented have a listener for the specified type.
Parameters
- type: keyof MarkerEventType
The event type
Returns boolean
trueif there is at least one registered listener for specified event type,falseotherwise- type: keyof MarkerEventType
off
- off<T extends keyof MarkerEventType>(
type: T,
listener: (event: MarkerEventType[T]) => void,
): thisRemoves a previously registered event listener.
Type Parameters
- T extends keyof MarkerEventType
Parameters
- type: T
The event type to remove listeners for.
- listener: (event: MarkerEventType[T]) => void
The listener function to remove.
Returns this
on
- on<T extends keyof MarkerEventType>(
type: T,
listener: (event: MarkerEventType[T]) => void,
): SubscriptionAdds a listener to a specified event type.
Type Parameters
- T extends keyof MarkerEventType
Parameters
- type: T
The event type to add a listen for.
- listener: (event: MarkerEventType[T]) => void
The function to be called when the event is fired. The listener function is called with the data object passed to
fire, extended withtargetandtypeproperties.
Returns Subscription
once
Adds a listener that will be called only once to a specified event type.
The listener will be called first time the event fires after the listener is registered.
Type Parameters
- T extends keyof MarkerEventType
Parameters
- type: T
The event type to listen for.
Returns Promise<MarkerEventType[T]>
a promise that resolves with the event
- once<T extends keyof MarkerEventType>(
type: T,
listener: (event: MarkerEventType[T]) => void,
): thisAdds a listener that will be called only once to a specified event type.
The listener will be called first time the event fires after the listener is registered.
Type Parameters
- T extends keyof MarkerEventType
Parameters
- type: T
The event type to listen for.
- listener: (event: MarkerEventType[T]) => void
The function to be called when the event is fired the first time.
Returns this
thiswhen a listener is provided
remove
removeClassName
setDraggable
Sets the
draggableproperty and functionality of the marker. A draggable default marker is also keyboard focusable and movable with the arrow keys (see MarkerOptions.draggable); custom marker elements keep their focusability and keyboard behavior application-owned.Parameters
OptionalshouldBeDraggable: booleanTurns drag functionality on/off
Returns this
setEventedParent
- setEventedParent(
parent?: Evented<EventTypeMap> | null,
data?: EventedParentData | (() => EventedParentData),
): thisBubble all events fired by this instance of Evented to this parent instance of Evented.
Parameters
Optionalparent: Evented<EventTypeMap> | nullOptionaldata: EventedParentData | (() => EventedParentData)
Returns this
setLngLat
Set the marker's geographical position and move it.
Parameters
- lnglat: LngLatLike
A LngLat describing where the marker should be located.
Returns this
- lnglat: LngLatLike
setOffset
setOpacity
Sets the
opacityandopacityWhenCoveredproperties of the marker. When called without arguments, resets opacity and opacityWhenCovered to defaultsParameters
Optionalopacity: string | numberSets the
opacityproperty of the marker.OptionalopacityWhenCovered: string | numberSets the
opacityWhenCoveredproperty of the marker.
Returns this
setPitchAlignment
Sets the
pitchAlignmentproperty of the marker.Parameters
Optionalalignment: AlignmentSets the
pitchAlignmentproperty of the marker. If alignment is 'auto', it will automatically matchrotationAlignment.
Returns this
setPopup
Parameters
Optionalpopup: PopupMLGL | null
Returns this
setRotation
Sets the
rotationproperty of the marker.Parameters
Optionalrotation: numberThe rotation angle of the marker (clockwise, in degrees), relative to its respective Marker.setRotationAlignment setting.
Returns this
setRotationAlignment
Sets the
rotationAlignmentproperty of the marker.Parameters
Optionalalignment: AlignmentSets the
rotationAlignmentproperty of the marker. defaults to 'auto'
Returns this
setSubpixelPositioning
toggleClassName
Add or remove the given CSS class on the marker element, depending on whether the element currently has that class.
Parameters
- className: string
Non-empty string with CSS class name to add/remove
Returns boolean
if the class was removed return false, if class was added, then return true
- className: string
Creates a marker component
Example
Example
Set options
See
Events
Event
dragstartof type MarkerDragEvent will be fired when dragging starts.Event
dragof type MarkerDragEvent will be fired while dragging.Event
dragendof type MarkerDragEvent will be fired when the marker is finished being dragged.Event
clickof type MarkerClickEvent will be fired when the marker is clicked.CSS Classes
CSS class
maplibregl-marker-coveredis toggled on the marker element when the marker is hidden behind 3D terrain or on the back of a globe. Use this class to apply custom styles to covered markers.Example