Class Marker
Hierarchy (View Summary)
Index
Constructors
Methods
Constructors
constructor
Parameters
Optionaloptions: MarkerOptionsthe options
Returns Marker
Methods
addClassName
addTo
Attaches the
Markerto aMapobject.Parameters
- map: MapLibreMap
The MapLibre GL JS map to add the marker to.
Returns this
- map: MapLibreMap
fire
Parameters
- event: string | Event
Optionalproperties: any
Returns this
getElement
Returns the
Marker's HTML element.Returns HTMLElement
element
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: string
The event type
Returns boolean
trueif there is at least one registered listener for specified event type,falseotherwise- type: string
off
Removes a previously registered event listener.
Parameters
- type: string
The event type to remove listeners for.
- listener: Listener
The listener function to remove.
Returns this
- type: string
on
Adds a listener to a specified event type.
Parameters
- type: string
The event type to add a listen for.
- listener: Listener
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
- type: string
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.
Parameters
- type: string
The event type to listen for.
Optionallistener: ListenerThe function to be called when the event is fired the first time.
Returns Marker | Promise<any>
thisor a promise if a listener is not provided- type: string
remove
removeClassName
setDraggable
Sets the
draggableproperty and functionality of the markerParameters
OptionalshouldBeDraggable: booleanTurns drag functionality on/off
Returns this
setEventedParent
Bubble all events fired by this instance of Evented to this parent instance of Evented.
Parameters
Optionalparent: Evented | nullOptionaldata: any
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: Popup | 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 Event will be fired when dragging starts.Event
dragof type Event will be fired while dragging.Event
dragendof type Event will be fired when the marker is finished being dragged.Event
clickof type Event 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