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 customizable contentColor.
  • SVG Shapes & Sizing: Choose between maptiler (pin), bubble-circle, bubble-square, circle, or square, across sizes from xs to l.
  • Color Layers & Shadows: Customize innerColor, outerColor, shadows (none to strong), 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();
});
Display simple marker on the map

Display marker

Tutorials

Learn how to add a default marker to your map.

Create a draggable marker

Create a draggable marker

Examples

Create a draggable marker and display its map coordinates.

Marker animations, transitions, and interactive UI states

Marker animations and states

Examples

Create animated markers with interactive UI states and transitions.

Marker collision management and priorities

Marker collision management

Examples

Manage dense markers and prevent cluttering using collision priorities and automatic decluttering in MapTiler SDK v5.

Was this helpful?