For AI agents: a documentation index is available at /llms.txt. Markdown versions of all pages are available by appending .md to any URL.
Customize and create marker shapes interactively
This example demonstrates how to configure and display diverse MapTiler markers using the built-in SVG vector shape system and content rendering in SDK v5:
- Initial Markers Loaded: Explore 5 distinct draggable markers scattered across the map featuring a pin with a letter (
"A"), bubble circles and squares with icons and numbers ("☕","1"), and geometric shapes with emojis ("⭐","🚀"). - Embedded Content (
content): Render single characters, letters, numbers, or emojis directly inside the marker silhouette with customizablecontentColor. - SVG Shapes & Sizing: Choose between
maptiler(pin),bubble-circle,bubble-square,circle, orsquare, across sizes fromxstol. - Color Layers & Shadows: Customize
innerColor,outerColor, shadows (nonetostrong), and outline strokes independently. - Interactive Dragging: Every marker on the map is draggable (
draggable: true), allowing you to reposition any marker at will.
Use the control panel on the left to customize options and click Create Marker at Center to generate your own draggable marker at the current map view center.
NPM module setup
npm install --save @maptiler/sdk
import { Map, MapStyle, config, Popup, Marker } from "@maptiler/sdk";
import "@maptiler/sdk/dist/maptiler-sdk.css";
config.apiKey = "YOUR_MAPTILER_API_KEY";
const map = new Map({
container: "map",
style: MapStyle.STREETS,
center: [14.425, 50.083],
zoom: 13,
});
// Initial diverse markers loaded on the map (all draggable)
const initialMarkersData = [
{
lngLat: [14.415, 50.088],
shape: "maptiler",
size: "m",
content: "A",
contentColor: "#FFFFFF",
innerColor: "#0070F3",
outerColor: "#FFFFFF",
shadow: "medium",
title: "Marker A (Pin with letter)",
},
{
lngLat: [14.432, 50.089],
shape: "bubble-circle",
size: "l",
content: "☕",
contentColor: "#FFFFFF",
innerColor: "#F59E0B",
outerColor: "#FFFFFF",
outline: true,
shadow: "soft",
title: "Café Spot (Bubble with emoji)",
},
{
lngLat: [14.418, 50.076],
shape: "square",
size: "m",
content: "⭐",
contentColor: "#FFFFFF",
innerColor: "#8B5CF6",
outerColor: "#FFFFFF",
shadow: "strong",
title: "Star Landmark (Square with emoji)",
},
{
lngLat: [14.438, 50.077],
shape: "bubble-square",
size: "m",
content: "1",
contentColor: "#FFFFFF",
innerColor: "#10B981",
outerColor: "#FFFFFF",
outline: true,
shadow: "medium",
title: "Checkpoint 1 (Bubble Square)",
},
{
lngLat: [14.425, 50.083],
shape: "circle",
size: "m",
content: "🚀",
contentColor: "#FFFFFF",
innerColor: "#E11D48",
outerColor: "#FFFFFF",
shadow: "medium",
title: "Center Point (Circle with emoji)",
},
];
// Add the initial markers
initialMarkersData.forEach((item) => {
const marker = new Marker({
shape: item.shape,
size: item.size,
content: item.content,
contentColor: item.contentColor,
innerColor: item.innerColor,
outerColor: item.outerColor,
shadow: item.shadow,
outline: item.outline ?? false,
draggable: true,
})
.setLngLat(item.lngLat)
.setPopup(
new Popup({ offset: 30 }).setHTML(
`<strong>${item.title}</strong><br>Shape: <code>${item.shape}</code> | Content: <code>${item.content}</code><br><em>Draggable marker</em>`,
),
);
map.addMarker(marker);
});
// Function to create a custom marker from panel inputs
function createMarkerFromPanel(lngLat) {
const shape = document.getElementById("marker-shape").value;
const size = document.getElementById("marker-size").value;
const content = document.getElementById("marker-content").value || undefined;
const innerColor = document.getElementById("marker-inner-color").value;
const contentColor = document.getElementById("marker-content-color").value;
const outerColor = document.getElementById("marker-outer-color").value;
const shadow = document.getElementById("marker-shadow").value;
const outline = document.getElementById("marker-outline").checked;
const marker = new Marker({
shape: shape,
size: size,
content: content,
contentColor: contentColor,
innerColor: innerColor,
outerColor: outerColor,
shadow: shadow,
outline: outline,
draggable: true,
})
.setLngLat(lngLat)
.setPopup(
new Popup({ offset: 30 }).setHTML(
`<strong>Custom Marker</strong><br>Shape: <code>${shape}</code> | Content: ${content ? `<code>${content}</code>` : "none"}<br><em>Draggable marker</em>`,
),
);
map.addMarker(marker);
return marker;
}
// Create new draggable marker on button click
document.getElementById("btn-create").addEventListener("click", () => {
const currentCenter = map.getCenter();
const marker = createMarkerFromPanel(currentCenter);
marker.togglePopup();
});
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="robots" content="noindex" />
<title>Marker shapes, icons, and customization</title>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<div id="map"></div>
<div class="panel">
<h3>Create Marker</h3>
<div class="form-row">
<label for="marker-shape">Shape</label>
<select id="marker-shape">
<option value="maptiler" selected>Pin (maptiler)</option>
<option value="bubble-circle">Bubble Circle</option>
<option value="bubble-square">Bubble Square</option>
<option value="circle">Circle</option>
<option value="square">Square</option>
</select>
</div>
<div class="form-row">
<label for="marker-content">Content (Text/Emoji)</label>
<input type="text" id="marker-content" value="🎯" maxlength="4" />
</div>
<div class="form-row">
<label for="marker-size">Size</label>
<select id="marker-size">
<option value="xs">Extra Small (xs)</option>
<option value="s">Small (s)</option>
<option value="m" selected>Medium (m)</option>
<option value="l">Large (l)</option>
</select>
</div>
<div class="form-row">
<label for="marker-inner-color">Inner Color</label>
<input type="color" id="marker-inner-color" value="#0070F3" />
</div>
<div class="form-row">
<label for="marker-content-color">Content Color</label>
<input type="color" id="marker-content-color" value="#FFFFFF" />
</div>
<div class="form-row">
<label for="marker-outer-color">Outer Color</label>
<input type="color" id="marker-outer-color" value="#FFFFFF" />
</div>
<div class="form-row">
<label for="marker-shadow">Shadow</label>
<select id="marker-shadow">
<option value="none">None</option>
<option value="soft">Soft</option>
<option value="medium" selected>Medium</option>
<option value="strong">Strong</option>
</select>
</div>
<div class="form-row checkbox-row">
<label for="marker-outline">Outline</label>
<input type="checkbox" id="marker-outline" checked />
</div>
<button id="btn-create">Create Marker at Center</button>
</div>
<script type="module" src="./main.js"></script>
</body>
</html>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
.panel {
position: absolute;
top: 10px;
left: 10px;
z-index: 10;
background: rgba(255, 255, 255, 0.95);
border-radius: 8px;
padding: 12px 14px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
font-family:
system-ui,
-apple-system,
sans-serif;
font-size: 13px;
display: flex;
flex-direction: column;
gap: 8px;
width: 240px;
}
.panel h3 {
margin: 0 0 2px 0;
font-size: 14px;
color: #0f172a;
}
.form-row {
display: flex;
justify-content: space-between;
align-items: center;
gap: 8px;
}
.form-row label {
color: #475569;
font-size: 12px;
font-weight: 500;
}
.form-row select,
.form-row input[type="text"],
.form-row input[type="color"] {
padding: 3px 6px;
border: 1px solid #cbd5e1;
border-radius: 4px;
font-size: 12px;
background: #f8fafc;
}
.form-row input[type="text"] {
width: 90px;
}
.form-row input[type="color"] {
width: 36px;
height: 24px;
padding: 1px;
cursor: pointer;
}
.form-row.checkbox-row {
justify-content: flex-start;
gap: 10px;
}
.form-row.checkbox-row input {
cursor: pointer;
}
#btn-create {
background: #0070f3;
color: #fff;
border: none;
border-radius: 6px;
padding: 8px 12px;
cursor: pointer;
font-size: 13px;
font-weight: 600;
transition: background 0.2s;
margin-top: 4px;
}
#btn-create:hover {
background: #0051b3;
}
Related examples
Marker animations and states
ExamplesCreate animated markers with interactive UI states and transitions.
Marker collision management
ExamplesManage dense markers and prevent cluttering using collision priorities and automatic decluttering in MapTiler SDK v5.