For AI agents: a documentation index is available at /llms.txt. Markdown versions of all pages are available by appending .md to any URL.
Geocoding control v3 to v4 migration guide
MapTiler Geocoding Control v4 updates allowed dependency versions for supported mapping libraries (MapTiler SDK JS v5, MapLibre GL JS v6, and Leaflet 2), introduces a modern ES Module (ESM) CDN build for MapTiler SDK with import maps, adopts MapTiler SDK v5’s native marker system, and modernizes module resolution for Node.js and TypeScript.
This guide details all breaking changes and shows how to migrate your existing applications from version 3 to version 4 across each supported mapping library.
Summary of breaking changes
| Feature / Library | Version 3 (Legacy) | Version 4 (Current) |
|---|---|---|
| MapTiler SDK JS | Supported v3 & v4 | MapTiler SDK JS v5 (@maptiler/sdk ^5.0.0) |
| MapTiler SDK CDN | maptilersdk.umd.js with global maptilerGeocoder |
maptilersdk.cdn.mjs via <script type="module"> & importmap |
| SDK Marker API | MapLibre marker (color, scale: number) |
SDK Marker (outerColor, innerColor, scale: [x, y], map.addMarker()) |
| MapLibre GL JS | Supported v3, v4, v5 with maplibregl.umd.js |
MapLibre GL JS v6; maplibregl.umd.js removed (ESM only) |
| Leaflet | Supported v1.5–1.9 (L.map(), L.tileLayer()) |
Leaflet 2 only; requires new L.Map() and leaflet-global.js |
| OpenLayers | Directory imports in Node (ol/control) |
Explicit file imports (ol/control.js) |
Node.js require() |
CommonJS entrypoints | Loads ES module builds (requires Node.js 20.19+ or 22.12+) |
| POI Icons (npm) | dist/icons in npm package |
icons in npm package |
| TypeScript Target | ES2020 | ES2022, supports node16, nodenext, and bundler |
1. Upgrade installation
Update @maptiler/geocoding-control in your project dependencies:
npm install @maptiler/geocoding-control@^4.0.0
If you are using Node.js CommonJS (require("@maptiler/geocoding-control")), ensure your Node.js runtime is version 20.19+ or 22.12+.
2. MapTiler SDK JS migration
A. CDN and without a bundler
In v4, MapTiler SDK integration without a bundler embraces modern ES Modules (.mjs):
maptilersdk.cdn.mjsis an ES module build that bundles all internal dependencies while keeping@maptiler/sdkexternal.- Map
@maptiler/sdkto the MapTiler SDK CDN module using an<script type="importmap">, ensuring both your page and the control share a single SDK instance.
Version 3 (legacy 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>
<script src="https://cdn.maptiler.com/maptiler-geocoding-control/v3.1.0/maptilersdk.umd.js"></script>
</head>
<body>
<div id="map"></div>
<script>
maptilersdk.config.apiKey = 'YOUR_MAPTILER_API_KEY';
const map = new maptilersdk.Map({ container: 'map' });
const gc = new maptilerGeocoder.GeocodingControl();
map.addControl(gc, 'top-left');
</script>
</body>
Version 4 (modern ESM and import map)
<head>
<link href="https://cdn.maptiler.com/maptiler-sdk-js/v5.0.0/maptiler-sdk.css" rel="stylesheet" />
<script type="importmap">
{
"imports": {
"@maptiler/sdk": "https://cdn.maptiler.com/maptiler-sdk-js/v5.0.0/maptiler-sdk.min.mjs"
}
}
</script>
</head>
<body>
<div id="map"></div>
<script type="module">
import * as maptilersdk from "@maptiler/sdk";
import { GeocodingControl } from "https://cdn.maptiler.com/maptiler-geocoding-control/v4.1.0/maptilersdk.cdn.mjs";
maptilersdk.config.apiKey = 'YOUR_MAPTILER_API_KEY';
const map = new maptilersdk.Map({ container: 'map' });
const gc = new GeocodingControl();
map.addControl(gc, 'top-left');
</script>
</body>
Tip
If you still require classic <script> tags without ES modules, you can continue loading MapTiler SDK’s maptiler-sdk.umd.min.js and maptilersdk.umd.js.
B. MapTiler SDK marker system
MapTiler Geocoding Control v4 now uses MapTiler SDK v5’s native Marker implementation:
- Markers are added to the map internally using
map.addMarker(). - The
markerandshowResultMarkersoptions now accept MapTiler SDK marker options (MapTilerMarkerElementOptionsorMapTilerMarkerSVGOptions). - When customizing marker colors, use
outerColor/innerColorinstead of MapLibre’scolor. - Scale is specified as
[x, y]rather than a single number.
Version 3 (legacy marker options)
const gc = new GeocodingControl({
marker: {
color: "#ff0000",
scale: 1.2,
},
});
Version 4 (MapTiler SDK marker options)
const gc = new GeocodingControl({
marker: {
outerColor: "#ff0000",
innerColor: "#ffffff",
scale: [1.2, 1.2],
},
});
C. Evented and class hierarchy changes
In v4, the MapTiler SDK and MapLibre controls use a mixin pattern to provide event capabilities rather than inheriting directly from MapLibre’s Evented:
- All event methods (
.on(),.off(),.once(),.fire()) continue to work identically. - Type checks using
gc instanceof Eventedwill now evaluate tofalse. - Protected methods are exposed for advanced subclass customization:
createMarker,addMarker,setMarkerPopup, andadjustRequestUrl.
3. MapLibre GL JS migration
A. Removal of maplibregl.umd.js
MapLibre GL JS v6 is published exclusively as an ES module and no longer attaches a global window.maplibregl. Because of this:
- The UMD build
maplibregl.umd.jshas been removed in Geocoding Control v4. - Use the npm ES module build (
@maptiler/geocoding-control/maplibregl) with a bundler such as Vite or Webpack. - If you require classic
<script>tags without a bundler, migrate to MapTiler SDK JS, which provides both UMD and ESM CDN builds.
B. Bundler setup (Vite, Webpack)
In MapLibre GL JS v6, the web worker must be explicitly registered when bundled:
import * as maplibregl from "maplibre-gl";
import { setWorkerUrl } from "maplibre-gl";
import workerUrl from "maplibre-gl/dist/maplibre-gl-worker.mjs?worker&url";
import { GeocodingControl } from "@maptiler/geocoding-control/maplibregl";
import "maplibre-gl/dist/maplibre-gl.css";
// Configure web worker for MapLibre 6
setWorkerUrl(workerUrl);
const map = new maplibregl.Map({
container: "map",
style: "https://api.maptiler.com/maps/streets-v4/style.json?key=YOUR_MAPTILER_API_KEY",
});
const gc = new GeocodingControl({ apiKey: "YOUR_MAPTILER_API_KEY", maplibregl });
map.addControl(gc, "top-left");
4. Leaflet migration
Geocoding Control v4 supports Leaflet 2 only (beta and final releases). If you need to stay on Leaflet 1.x, keep using Geocoding Control v3.
The control itself is added the same way as before. The changes come from Leaflet 2:
- Removed factory functions: Leaflet 2 removed lowercase factory functions such as
L.map()andL.tileLayer(). Usenew L.Map()andnew L.TileLayer()instead. - Global UMD script: In Leaflet 2,
dist/leaflet.jsis an ES module. For classic<script>tags, loaddist/leaflet-global.js(it defines the globalL) beforeleaflet.umd.js.
Version 3 (Leaflet 1.9.4)
<head>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script src="https://cdn.maptiler.com/maptiler-geocoding-control/v3.1.1/leaflet.umd.js"></script>
</head>
<body>
<div id="map"></div>
<script>
const map = L.map("map").setView([0, 0], 2);
L.tileLayer("https://api.maptiler.com/maps/streets-v4/{z}/{x}/{y}.png?key=YOUR_MAPTILER_API_KEY", {
tileSize: 512,
zoomOffset: -1,
minZoom: 1,
crossOrigin: true
}).addTo(map);
const gc = new maptilerGeocoder.GeocodingControl({ apiKey: "YOUR_MAPTILER_API_KEY" });
map.addControl(gc);
</script>
</body>
Version 4 (Leaflet 2)
<head>
<link rel="stylesheet" href="https://unpkg.com/leaflet@2.0.0-beta.5/dist/leaflet.css" />
<!-- Use leaflet-global.js for global L in Leaflet 2 -->
<script src="https://unpkg.com/leaflet@2.0.0-beta.5/dist/leaflet-global.js"></script>
<script src="https://cdn.maptiler.com/maptiler-geocoding-control/v4.1.0/leaflet.umd.js"></script>
</head>
<body>
<div id="map"></div>
<script>
const map = new L.Map("map").setView([0, 0], 2);
new L.TileLayer("https://api.maptiler.com/maps/streets-v4/{z}/{x}/{y}.png?key=YOUR_MAPTILER_API_KEY", {
tileSize: 512,
zoomOffset: -1,
minZoom: 1,
crossOrigin: true
}).addTo(map);
const gc = new maptilerGeocoder.GeocodingControl({ apiKey: "YOUR_MAPTILER_API_KEY" });
map.addControl(gc);
</script>
</body>
5. OpenLayers migration
OpenLayers support remains compatible with OpenLayers v9.1 and v10:
- When using Node.js ES Modules or TypeScript under
node16/nodenext, OpenLayers imports now use explicit file extensions:
import Map from "ol/Map.js";
import View from "ol/View.js";
import TileLayer from "ol/layer/Tile.js";
import TileJSON from "ol/source/TileJSON.js";
import { GeocodingControl } from "@maptiler/geocoding-control/openlayers";
const map = new Map({
target: "map",
layers: [
new TileLayer({
source: new TileJSON({
url: "https://api.maptiler.com/maps/streets-v4/tiles.json?key=YOUR_MAPTILER_API_KEY",
tileSize: 512,
crossOrigin: "anonymous",
}),
}),
],
view: new View({
center: [0, 0],
zoom: 2,
}),
});
const gc = new GeocodingControl({ apiKey: "YOUR_MAPTILER_API_KEY" });
map.addControl(gc);
- When using CDN,
openlayers.umd.jscontinues to be available:
<script src="https://cdn.jsdelivr.net/npm/ol@v10.1.0/dist/ol.js"></script>
<script src="https://cdn.maptiler.com/maptiler-geocoding-control/v4.1.0/openlayers.umd.js"></script>
6. POI icons in npm package
In the npm package, POI icons were moved from dist/icons to icons:
node_modules/@maptiler/geocoding-control/icons/
If you configured your bundler or copy plugins to serve icons locally from node_modules/@maptiler/geocoding-control/dist/icons, update the source path to node_modules/@maptiler/geocoding-control/icons. The CDN location used by the default iconsBaseUrl is unchanged.
Need help?
If you encounter issues during migration:
- Review the Geocoding Control Examples.
- Check the API Reference.
- Visit the maptiler-geocoding-control GitHub repository.
- Contact support
- Migration guide (v2 to v3)