Skip to content

Add a default marker

Replicates the MapLibre example Add a default marker. The upstream new maplibregl.Marker().setLngLat(...).addTo(map) is one markers: entry — and unlike a layer, it’s a real DOM marker, exactly what the imperative API creates.

add-a-default-marker.yaml
# yaml-language-server: $schema=https://docs.maplibre-yaml.org/schema/latest/map.schema.json
# Gallery twin of https://maplibre.org/maplibre-gl-js/docs/examples/add-a-default-marker/
# The whole new-Marker-addTo dance is one markers: entry.
type: map
id: add-a-default-marker
config:
center: [12.55, 55.665]
zoom: 8
mapStyle: "https://demotiles.maplibre.org/style.json"
markers:
- at: [12.55, 55.665]
  • markers: entries are DOM markers live; on mlym emit --with-fallbacks they lower to a symbol layer with a generated pin sprite (the format’s first construct that exports with a fallback — see Export classes).
  • --strict refuses marker documents: a DOM marker and a symbol layer are close, not identical, and strict means nothing visual changes.