Add a Custom Marker
Pass a DOM element to maplibregl.Marker to render any HTML or styled div as the marker. The element is positioned and moved with the map automatically.
import { MaptoolkitLogoControl } from 'https://cdn.jsdelivr.net/npm/@maptoolkit/maplibre-gl-logo/+esm';
const map = new maplibregl.Map({ container: 'map', attributionControl: { customAttribution: '' }, style: 'https://styles.maptoolkit.org/summer.json', center: [4.9041, 52.3676], zoom: 12 }); // Amsterdam
const el = document.createElement('div');
el.className = 'custom-marker';
new maplibregl.Marker({ element: el }).setLngLat([4.9041, 52.3676]).addTo(map);
map.addControl(new MaptoolkitLogoControl());<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/maplibre-gl.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/maplibre-gl.css" />
<style>
html, body { width: 100%; height: 100%; margin: 0; padding: 0; }
#map { width: 100%; height: 100%; }
.custom-marker { width:26px; height:26px; border-radius:50% 50% 50% 0; background:#e8551a; transform:rotate(-45deg); border:3px solid #fff; box-shadow:0 1px 4px rgba(0,0,0,.4); cursor:pointer; }
</style>
</head>
<body>
<div id="map"></div>
<script type="module">
import { MaptoolkitLogoControl } from 'https://cdn.jsdelivr.net/npm/@maptoolkit/maplibre-gl-logo/+esm';
const map = new maplibregl.Map({ container: 'map', attributionControl: { customAttribution: '' }, style: 'https://styles.maptoolkit.org/summer.json', center: [4.9041, 52.3676], zoom: 12 }); // Amsterdam
const el = document.createElement('div');
el.className = 'custom-marker';
new maplibregl.Marker({ element: el }).setLngLat([4.9041, 52.3676]).addTo(map);
map.addControl(new MaptoolkitLogoControl());
</script>
</body>
</html>