For AI agents: a documentation index is available at /llms.txt. Markdown versions of all pages are available by appending .md to any URL.

Class MarkerMaptiler

MapLibre's Marker extended with 2-D scale, named shapes, colour tokens, and batched DOM updates.

Hierarchy (View Summary)

Index

Constructors

Properties

"[MarkerElementSymbol]": HTMLElement

The DOM element *

"[MeasuredElementSizeSymbol]": Vector2 | null = null

Unscaled CSS pixel size of a custom element, measured once at registration. null until measured; unused for built-in SVG markers.

"[PendingUpdatesSymbol]": PendingMarkerUpdates = {}

Property updates waiting to be flushed to the DOM on the next animation frame.

id: string = ...

UUID that uniquely identifies this marker instance.

Construction-time options snapshot — not updated by setters.

Accessors

  • get classList(): DOMTokenList

    The classList of the marker's wrapper element — the inner transform wrapper of a built-in marker, or the custom element itself. Read-only reference; add and remove classes through the returned list.

    Returns DOMTokenList

Methods

  • Per-frame altitude hook, called by MarkerManager for every altitude-active marker. Returns the elevated point's camera depth (used to rank z-index among altitude-active markers), or null when off-screen/behind the camera.

    Parameters

    Returns number | null

  • Applies the collision engine's display-state decision.

    Every transition fades. Hide/show fade in place; visible<->minimized fades through zero (dip out, swap at the invisible midpoint, fade back in).

    Returns void

  • Attaches the marker to a map, and plays the configured enter animation (if any) once attached. Called only by MarkerManager during registration.

    Parameters

    • map: Map

      Target map instance.

    Returns this

  • Blurs the marker's focusable element. Called by MarkerManager on map click.

    Returns void

  • Resolves the marker's screen footprint for collision detection. Always full-size, even minimized.

    Returns MarkerFootprint

  • Removes the marker from the DOM directly, bypassing MarkerManager.

    Returns void

  • Applies all pending property updates to the marker element and clears the batch. Called by MarkerManager on the next animation frame.

    Returns void

  • Queues re-resolving every unset colour against the current map style.

    Returns void

  • Adds a CSS class to the marker element.

    Parameters

    • className: string

      on-empty string with CSS class name to add to marker element

    Returns void

    let marker = new Marker()
    marker.addClassName('some-class')
    
  • Adds the marker to a map. Equivalent to map.addMarker(marker), which it delegates to.

    Parameters

    • map: Map

      Target map instance.

    Returns this

    Use map.addMarker(marker) instead. Kept for MapLibre-style call sites and will be removed in a future major version.

  • Stamps altitude/altitudeReference/altitudeEngaged onto every dragstart/drag/dragend event.

    Parameters

    • event: string | { type: string }
    • Optionalproperties: Record<string, unknown>

    Returns Marker

  • Returns the current altitude in meters, or 0 if never set.

    Returns number

  • Returns the current content string.

    Returns string | undefined

  • Returns the content colour currently in effect — the explicit contentColor, else the default for the map's style.

    Returns string

  • Returns whether the debug overlay is currently enabled.

    Returns boolean

  • Returns the inner area colour currently in effect — the explicit innerColor, else the default for the map's style.

    Returns string

  • 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 setLngLat because Marker wraps the anchor longitude across copies of the world to keep the marker on screen.

    Returns LngLat

    A LngLat describing the marker's location.

    // Store the marker's longitude and latitude coordinates in a variable
    let lngLat = marker.getLngLat();
    // Print the marker's longitude and latitude values in the console
    console.log('Longitude: ' + lngLat.lng + ', Latitude: ' + lngLat.lat )
    
  • Returns the outer body colour currently in effect — the explicit outerColor, else the default for the map's style.

    Returns string

  • Returns the current outline value (true, a pixel width, or undefined).

    Returns number | true | undefined

  • Returns the outline stroke colour currently in effect — the explicit outlineColor, else the default for the map's style.

    Returns string

  • Returns the Popup instance that is bound to the Marker.

    Returns PopupMLGL

    popup

    let marker = new Marker()
     .setLngLat([0, 0])
     .setPopup(new Popup().setHTML("<h1>Hello World!</h1>"))
     .addTo(map);
    
    console.log(marker.getPopup()); // return the popup instance
    
  • Returns the current inner-shell rotation in degrees.

    Returns number

    Rotation in degrees; 0 if never set.

  • Returns the current 2-D scale. Defaults to [1, 1].

    Returns Vector2 | undefined

  • Returns the current title string.

    Returns string | undefined

  • True from the first setAltitude call onward.

    Returns boolean

  • Returns true if the marker can be dragged

    Returns boolean

    True if the marker is draggable.

  • Returns a true if this instance of Evented or any forwardeed instances of Evented have a listener for the specified type.

    Parameters

    Returns boolean

    true if there is at least one registered listener for specified event type, false otherwise

  • Removes an event listener previously added with Marker.on or Marker.once. Accepts the MapLibre events as well as the SDK events (see MaptilerMarkerEventType).

    Type Parameters

    • T extends (keyof MarkerEventType) | (keyof MaptilerMarkerEventType)

    Parameters

    Returns this

  • Adds a listener that will be called only once to a specified event type. Accepts the MapLibre events as well as the SDK events (see MaptilerMarkerEventType).

    Type Parameters

    • T extends (keyof MarkerEventType) | (keyof MaptilerMarkerEventType)

    Parameters

    • type: T

    Returns Promise<MarkerEventTypeSDK[T]>

  • 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) | (keyof MaptilerMarkerEventType)

    Parameters

    • type: T

      The event type to listen for.

    • listener: (ev: MarkerEventTypeSDK[T]) => void

      The function to be called when the event is fired the first time.

    Returns this

    this when a listener is provided

  • Removes the marker, playing the configured exit animation first (if any) before detaching from the DOM.

    Returns this

  • Removes a CSS class from the marker element.

    Parameters

    • className: string

      Non-empty string with CSS class name to remove from marker element

    Returns void

    let marker = new Marker()
    marker.removeClassName('some-class')
    
  • Sets altitude in meters above the ground plane (negative is fine — below ground/sea level), faked via a per-frame pixel offset. options.relativeTo (default "ground") picks what the meters are measured from. There is deliberately no fast path for meters: 0: MapLibre's native marker position is already terrain-elevated whenever the map has terrain, so doing nothing at 0 would leave the marker on the terrain, not at ground/sea level.

    Pass false to unset: deregisters and clamps to MapLibre's own native (terrain-aware) position, same as a marker that never called this.

    Parameters

    • meters: false

      Altitude in meters, measured per options.relativeTo, or false to unset altitude entirely.

    Returns this

  • Sets altitude in meters above the ground plane (negative is fine — below ground/sea level), faked via a per-frame pixel offset. options.relativeTo (default "ground") picks what the meters are measured from. There is deliberately no fast path for meters: 0: MapLibre's native marker position is already terrain-elevated whenever the map has terrain, so doing nothing at 0 would leave the marker on the terrain, not at ground/sea level.

    Pass false to unset: deregisters and clamps to MapLibre's own native (terrain-aware) position, same as a marker that never called this.

    Parameters

    • meters: number

      Altitude in meters, measured per options.relativeTo, or false to unset altitude entirely.

    • Optionaloptions: SetAltitudeOptions

      See SetAltitudeOptions. Ignored when meters is false.

    Returns this

  • Sets the text content displayed inside the marker body.

    Parameters

    • content: string | undefined

      Label string, or undefined to clear.

    Returns void

  • Sets the colour applied to the marker content (icon, text, etc.).

    Parameters

    • color: string | undefined

      Any valid CSS colour string, or undefined to return to the map-style default.

    Returns void

  • Shows or hides the debug overlay, which renders the marker's bounding box and center point on top of the marker element.

    Parameters

    • debug: boolean | undefined

      true to show the overlay, false/undefined to hide it.

    Returns void

  • Sets the draggable property 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: boolean

      Turns drag functionality on/off

    Returns this

  • Toggles a dashed line from the marker down (or up) to its ground point. Off by default. See .maptiler-marker-groundline in the SDK stylesheet and GroundLineOptions.className.

    Parameters

    • enabled: boolean

      Whether to show the line.

    • options: GroundLineOptions = {}

      Optional extra CSS class for styling.

    Returns this

  • Sets an explicit fill colour for the inner area of the marker, replacing the map-style default.

    Parameters

    • color: string | undefined

      Any valid CSS colour string, or undefined to return to the map-style default.

    Returns void

  • Sets the marker's screen-space pixel offset. Composes with altitude (see writeOffset) rather than replacing it.

    Parameters

    • offset: PointLike

      Offset in pixels (+y down).

    Returns this

  • Sets the opacity and opacityWhenCovered properties of the marker. When called without arguments, resets opacity and opacityWhenCovered to defaults

    Parameters

    • Optionalopacity: string | number

      Sets the opacity property of the marker.

    • OptionalopacityWhenCovered: string | number

      Sets the opacityWhenCovered property of the marker.

    Returns this

  • Sets the fill colour of the outer body of the marker.

    Parameters

    • color: string | undefined

      Any valid CSS colour string, or undefined to return to the map-style default.

    Returns void

  • Sets the outline stroke width on the marker body.

    Parameters

    • outline: number | true | undefined

      true for the default width, a positive number for an explicit pixel width, or undefined to remove the outline.

    Returns void

  • Sets the stroke colour of the marker outline. Has no visible effect unless setOutline is also called.

    Parameters

    • color: string | undefined

      Any valid CSS colour string, or undefined to return to the map-style default.

    Returns void

  • Sets the pitchAlignment property of the marker.

    Parameters

    • Optionalalignment: Alignment

      Sets the pitchAlignment property of the marker. If alignment is 'auto', it will automatically match rotationAlignment.

    Returns this

  • Sets the rendering priority.

    Parameters

    • priority: number | MarkerPriorityExpression | undefined

      Numeric priority, a MapLibre-style expression, or undefined to restore DOM-order stacking.

    Returns void

  • Rotates the marker's inner shell element in degrees, via the CSS scale(x, y) rotate(deg) transform on the inner wrapper — independent of MapLibre's own rotation on the outer container.

    Parameters

    • rotation: number

      Clockwise rotation in degrees.

    Returns this

  • Sets the rotationAlignment property of the marker.

    Parameters

    • Optionalalignment: Alignment

      Sets the rotationAlignment property of the marker. defaults to 'auto'

    Returns this

  • Sets the 2-D scale of the marker as [x, y].

    Parameters

    • scaleVector: Vector2

      Scale factors for the x and y axes.

    Returns void

  • Sets the drop-shadow intensity.

    Parameters

    • shadow: MapTilerMarkerShadow | undefined

      Shadow intensity preset, or undefined to reset to the default ("medium"). Use "none" to disable.

    Returns void

  • Sets the marker shape. Applies the new anchor offset (see applyShapeAnchorOffset).

    Parameters

    Returns void

  • Set the option to allow subpixel positioning of the marker by passing a boolean

    Parameters

    • value: boolean

      when set to true, subpixel positioning is enabled for the marker.

    Returns this

    let marker = new Marker()
    marker.setSubpixelPositioning(true);
    
  • Sets the title attribute on the marker's root element (native tooltip).

    Parameters

    • title: string | undefined

      Tooltip string, or undefined to remove the attribute.

    Returns void

  • 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

    let marker = new Marker()
    marker.toggleClassName('toggleClass')
    
  • Opens or closes the Popup instance that is bound to the Marker, depending on the current state of the Popup.

    Returns this

    let marker = new Marker()
     .setLngLat([0, 0])
     .setPopup(new Popup().setHTML("<h1>Hello World!</h1>"))
     .addTo(map);
    
    marker.togglePopup(); // toggle popup open or closed
    
Was this helpful?