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

Marker migration guide (v4 to v5)

MapTiler SDK JS v5 introduces a redesigned MapTiler Marker engine. The new architecture provides built-in SVG vector shapes, granular layer coloring, automatic style-aware adaptive palettes, collision management, interactive UI states, and lifecycle animations.

This guide details all breaking changes introduced in version 5, provides before-and-after code comparisons, and explains the MarkerMLGL fallback for drop-in backward compatibility.

Quick summary of changes

Feature / Behavior SDK v4 (Legacy) SDK v5 (Modern)
Adding to map marker.addTo(map) (deprecated) map.addMarker(marker) or { lngLat, ... }
Removing from map marker.remove() map.removeMarker(marker)
Color property Single color string Granular: innerColor, outerColor, contentColor, outlineColor
Scaling Scalar number: scale: 1.5 2D vector: scale: [1.5, 1.5]
Legacy MapLibre compatibility Default behavior of Marker Dedicated class: maptilersdk.MarkerMLGL
Collisions Not supported natively collisionBehaviour, priority, minimizedOptions
Adaptive style colors Not supported map.getAdaptiveColorsForCurrentStyle()

Instant legacy escape hatch: MarkerMLGL

If you are upgrading a large application and want to retain your existing marker code without refactoring, MapTiler SDK v5 exports MarkerMLGL. This class is a direct re-export of the upstream MapLibre GL JS marker, which continues to accept the legacy color property and the marker.addTo(map) method.


// CDN usage:
const legacyMarker = new maptilersdk.MarkerMLGL({ color: "#FF0000" })
  .setLngLat([14.42076, 50.08804])
  .addTo(map);

// NPM usage:
import { MarkerMLGL } from "@maptiler/sdk";

const legacyMarker = new MarkerMLGL({ color: "#FF0000" })
  .setLngLat([14.42076, 50.08804])
  .addTo(map);

Using MarkerMLGL allows you to upgrade to SDK v5 immediately and migrate to the new Marker API at your own pace.


Breaking changes and migration steps

1. Adding and managing markers on the map

In v5, the map instance directly manages the lifecycle and collision detection of registered markers. The legacy marker.addTo(map) method is deprecated in favor of map.addMarker().

Before (v4)


const marker = new maptilersdk.Marker()
  .setLngLat([14.42076, 50.08804])
  .addTo(map);

After (v5)


const marker = new maptilersdk.Marker()
  .setLngLat([14.42076, 50.08804]);

map.addMarker(marker);

Managing multiple markers

The Map instance now provides dedicated registry methods:


// Add multiple markers at once
map.addMarkers([marker1, marker2, marker3]);

// Retrieve a marker by its ID
const marker = map.getMarker(markerId);

// Remove a specific marker
map.removeMarker(marker);

// Remove all markers registered on the map
map.removeMarkers();

Adding markers with configuration objects (declarative syntax)

In SDK v5, both map.addMarker() and map.addMarkers() accept plain configuration objects with a lngLat property directly, removing the need to instantiate Marker:


// Add a single marker using a config object
map.addMarker({
  lngLat: [14.42076, 50.08804],
  innerColor: "#FF0000",
  shape: "circle",
});

// Add multiple markers directly from raw data or API responses
map.addMarkers([
  { lngLat: [14.42, 50.08], innerColor: "#0070F3" },
  { lngLat: [14.43, 50.09], innerColor: "#10B981" },
]);

2. Granular color options

The single color option has been replaced by granular color properties, giving you independent control over each part of the marker:

  • innerColor: The fill color of the inner shape.
  • outerColor: The fill color of the outer pin / bubble border.
  • contentColor: The fill color of the embedded icon or content.
  • outlineColor: The color of the outline stroke.

Before (v4)


const marker = new maptilersdk.Marker({
  color: "#FF0000",
})
  .setLngLat([14.42076, 50.08804])
  .addTo(map);

After (v5)


const marker = new maptilersdk.Marker({
  innerColor: "#FF0000",
  outerColor: "#FFFFFF",
})
  .setLngLat([14.42076, 50.08804]);

map.addMarker(marker);

3. 2D vector scaling

In v5, marker scale is expressed as a two-dimensional vector [x, y] rather than a single scalar number.

Before (v4)


const marker = new maptilersdk.Marker({
  scale: 1.5,
})
  .setLngLat([14.42076, 50.08804])
  .addTo(map);

After (v5)


const marker = new maptilersdk.Marker({
  scale: [1.5, 1.5],
})
  .setLngLat([14.42076, 50.08804]);

map.addMarker(marker);

4. Attaching popups to markers

Attaching a Popup instance continues to use .setPopup(popup). Combine it with map.addMarker(marker):

Before (v4)


const popup = new maptilersdk.Popup({ offset: 25 }).setText("Hello world!");

const marker = new maptilersdk.Marker()
  .setLngLat([14.42076, 50.08804])
  .setPopup(popup)
  .addTo(map);

After (v5)


const popup = new maptilersdk.Popup({ offset: 25 }).setText("Hello world!");

const marker = new maptilersdk.Marker()
  .setLngLat([14.42076, 50.08804])
  .setPopup(popup);

map.addMarker(marker);

New features in SDK v5 Marker

Once you have updated your markers to v5, you can take advantage of the following new capabilities:

Built-in SVG shapes and sizes

Configure marker silhouettes and sizes without writing custom HTML or CSS:


const marker = new maptilersdk.Marker({
  shape: "bubble-circle", // "maptiler" | "maptiler-full" | "circle" | "square" | "bubble-circle" | "bubble-square"
  size: "l",              // "xs" | "s" | "m" | "l"
  shadow: "medium",       // "none" | "soft" | "medium" | "strong"
  outline: true,          // Draws a border stroke
  outlineColor: "#333333",
})
  .setLngLat([14.42076, 50.08804]);

map.addMarker(marker);

Style-aware adaptive colors

Markers can dynamically match the color scheme of the active basemap style (e.g. switching between light, dark, and satellite themes) using map.getAdaptiveColorsForCurrentStyle():


const adaptiveColors = map.getAdaptiveColorsForCurrentStyle();

const marker = new maptilersdk.Marker({
  innerColor: adaptiveColors.primary,
  outerColor: adaptiveColors.secondary,
})
  .setLngLat([14.42076, 50.08804]);

map.addMarker(marker);

Collision handling and priority

Prevent clutter by setting collision behaviors and priority levels:


const marker = new maptilersdk.Marker({
  collisionBehaviour: "hide-by-priority", // "none" | "hide-by-priority" | "minimize-by-priority"
  priority: 5,                          // Higher values take visual precedence
  collisionRadius: 20,
})
  .setLngLat([14.42076, 50.08804]);

map.addMarker(marker);

UI states and transitions

Apply declarative styles for user interactions (hover, focus, active, dragging) with smooth transitions:


const marker = new maptilersdk.Marker({
  states: {
    hover: {
      scale: [1.3, 1.3],
      innerColor: "#FF4500",
    },
    active: {
      scale: [1.1, 1.1],
    },
  },
  transitions: {
    scale: { duration: 200, easing: "ease-out" },
    innerColor: { duration: 150 },
  },
})
  .setLngLat([14.42076, 50.08804]);

map.addMarker(marker);

Was this helpful?