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

MapTiler SDK JS v4 to v5 migration guide

MapTiler SDK JS v5 is a major release that modernizes the library’s architecture. It updates the underlying rendering engine to MapLibre GL JS v6, embraces a modern ES Modules (ESM) ecosystem across both npm and CDN, introduces the new MapTiler Markers system.

This guide walks you through every breaking change and demonstrates how to update your existing code from version 4 to version 5 with before-and-after examples.

Summary of Breaking Changes

Change Version 4 (Legacy) Version 5 (Current)
Module Format UMD & ESM Pure ESM (.mjs / <script type="module">)
CDN Script maptiler-sdk.umd.min.js maptiler-sdk.min.mjs via <script type="module">
MapLibre Core MapLibre GL JS v5 MapLibre GL JS v6
Web Graphics WebGL1 & WebGL2 WebGL2 mandatory
Web Worker Bundled / inline Dedicated worker (auto-fetched from CDN or via bundler helper)
Markers MapLibre marker with color MapTiler Marker with innerColor, outerColor, and map.addMarker()
Missing Images map.on('styleimagemissing', ...) map.setMissingStyleImageResolver(...)
Camera & FOV map.transform.fov map.getVerticalFieldOfView() / map.setVerticalFieldOfView()

1. Upgrading Installation and Imports

A. npm and Modern Bundlers (Vite, Webpack, Next.js)

Update your dependency in package.json:


npm install @maptiler/sdk@^5.0.0

MapLibre Worker Configuration

In v5, the MapLibre web worker is loaded from a separate file:

  • Default behavior: The npm (ES) build automatically fetches the matching worker from the MapTiler CDN at runtime.
  • Content Security Policy (CSP): If your website has a CSP header, ensure worker-src includes https://cdn.maptiler.com:

    
    worker-src 'self' blob: https://cdn.maptiler.com;
    
  • Local Worker Helpers (No CDN requests for worker): If you prefer bundling the worker locally, import the bundler-specific helper at the entry point of your app:

// For Vite projects:
import "@maptiler/sdk/vite-worker";

// For Webpack projects:
import "@maptiler/sdk/webpack-worker";

// For Next.js projects:
import "@maptiler/sdk/next-worker";

B. CDN Usage in Browsers

MapTiler SDK v5 distributes a self-contained ES Module bundle on the CDN (maptiler-sdk.min.mjs). The previous practice of loading the UMD build via a synchronous <script src="..."> tag in the <head> is replaced by importing the SDK from a <script type="module">.

Before (v4 - UMD)


<head>
  <link href="https://cdn.maptiler.com/maptiler-sdk-js/v4.2.1/maptiler-sdk.css" rel="stylesheet" />
  <script src="https://cdn.maptiler.com/maptiler-sdk-js/v4.2.1/maptiler-sdk.umd.min.js"></script>
</head>
<body>
  <div id="map"></div>
  <script>
    maptilersdk.config.apiKey = 'YOUR_MAPTILER_API_KEY';
    const map = new maptilersdk.Map({
      container: 'map',
      style: maptilersdk.MapStyle.STREETS,
    });
  </script>
</body>

After (v5 - ESM)


<head>
  <link href="https://cdn.maptiler.com/maptiler-sdk-js/v5.0.0/maptiler-sdk.css" rel="stylesheet" />
</head>
<body>
  <div id="map"></div>
  <script type="module">
    import * as maptilersdk from "https://cdn.maptiler.com/maptiler-sdk-js/v5.0.0/maptiler-sdk.min.mjs";

    maptilersdk.config.apiKey = 'YOUR_MAPTILER_API_KEY';
    const map = new maptilersdk.Map({
      container: 'map',
      style: maptilersdk.MapStyle.STREETS,
    });
  </script>
</body>

2. New MapTiler Marker API

Version 5 introduces a redesigned MapTiler Marker with adaptive style colors, collision management, interactive states, and altitude support.

A. Color Options

The single color option has been replaced by granular color properties (innerColor, outerColor, contentColor, outlineColor).

Before (v4)


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

After (v5)


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

map.addMarker(marker);

B. Adding and Managing Markers on the Map

marker.addTo(map) is deprecated in favor of map.addMarker(marker). Markers are now directly tracked by the map instance:


// Adding a marker
map.addMarker(marker);

// Removing a marker
map.removeMarker(marker);

// Getting markers from the map
const marker = map.getMarker(markerId);

C. 2D Vector Scaling

In v5, scale is expressed as a 2D vector [x, y] rather than a single number:


// v4: scale: 1.5
// v5:
const marker = new maptilersdk.Marker({
  scale: [1.5, 1.5],
});

D. Legacy MapLibre Marker Fallback (MarkerMLGL)

If you want to keep using the plain MapLibre marker without changing any code, you can use the newly exported MarkerMLGL:


// Plain MapLibre marker (accepts 'color' and marker.addTo(map))
const legacyMarker = new maptilersdk.MarkerMLGL({ color: "#FF0000" })
  .setLngLat([16.6266, 49.2125])
  .addTo(map);

3. MapLibre GL JS v6 Breaking Changes

Because MapTiler SDK v5 is built on MapLibre GL JS v6, the following MapLibre breaking changes apply:

A. Missing Style Image Resolver (styleimagemissing removed)

The map.on('styleimagemissing', ...) event listener has been removed in favor of map.setMissingStyleImageResolver(resolver).

Before (v4)


map.on('styleimagemissing', (e) => {
  const id = e.id;
  map.addImage(id, generateImage(id));
});

After (v5)


map.setMissingStyleImageResolver((id) => {
  // id is received directly as an argument (not e.id)
  map.addImage(id, generateImage(id));
});

The resolver can also be an async function:


map.setMissingStyleImageResolver(async (id) => {
  const image = await map.loadImage(`/icons/${id}.png`);
  if (!map.hasImage(id)) {
    map.addImage(id, image.data);
  }
});

B. Camera API and Vertical Field of View (map.transform removed)

The internal map.transform property has been removed from the public API. Camera properties such as Field of View (FOV) must now be accessed through public Camera methods.

Before (v4)


// Reading FOV
const currentFov = map.transform.fov;

// Changing FOV
map.transform.fov = 45;
map.triggerRepaint();

After (v5)


// Reading FOV
const currentFov = map.getVerticalFieldOfView();

// Changing FOV
map.setVerticalFieldOfView(45);
map.triggerRepaint();

C. WebGL2 is Mandatory

MapLibre v6 completely drops WebGL1 support. If your application defines custom WebGL layers (CustomLayerInterface), your GLSL shaders and context calls must be compatible with WebGL2 (e.g., using in and out instead of attribute and varying).

D. Nested GeoJSON Properties

In v4, nested objects in GeoJSON properties were often coerced into serialized JSON strings. In v5, nested objects and arrays are preserved as genuine JavaScript objects:

Before (v4)


map.on('click', 'my-layer', (e) => {
  const props = e.features[0].properties;
  const metadata = typeof props.metadata === 'string' ? JSON.parse(props.metadata) : props.metadata;
  console.log(metadata.author);
});

After (v5)


map.on('click', 'my-layer', (e) => {
  const props = e.features[0].properties;
  // metadata is already a JavaScript object
  console.log(props.metadata.author);
});

4. Other API Changes and Cleanups

Direct MapLibre Class Re-exports

In v4, several MapLibre classes were wrapped in SDK subclasses. In v5, classes like Popup, GeolocateControl, NavigationControl, ScaleControl, and sources are re-exported directly from MapLibre. They accept the MapTiler Map instance directly:


import { Popup, NavigationControl } from "@maptiler/sdk";

const popup = new Popup().setText("Hello World");
map.addControl(new NavigationControl());

ml-types Removed

Internal types previously re-exported from ml-types have been removed. Use public types exported directly from @maptiler/sdk.

Strongly Typed Events

All custom SDK events (ready, loadWithTerrain, projection.change) and layer events (cubemaplayer:*, radialgradientlayer:*) are now fully typed in TypeScript across on(), once(), off(), and fire().

5. What’s New in SDK v5?

While updating your codebase, take advantage of the new capabilities introduced in version 5:

  • Routing / Directions API: Built-in module for calculating routes and directions:

    
    const route = await maptilersdk.directions.route({
      waypoints: [[16.626, 49.212], [16.606, 49.195]],
      profile: "car",
    });
    
  • Adaptive Marker Colors: Automatically match marker colors to the active map style:

    
    const colors = map.getAdaptiveColorsForCurrentStyle();
    
  • Marker Collision & Priority: Prevent overlapping markers with built-in collision management.
  • Marker Altitude: Raise markers above ground level or sea level in 3D terrain maps.

Need Help?

If you encounter an issue during migration:

Was this helpful?