For AI agents: a documentation index is available at /llms.txt. Markdown versions of all pages are available by appending .md to any URL.
How to use the MapTiler SDK JS
This example shows the minimal code needed to display a map with MapTiler SDK JS: loading the SDK, adding a map container to your page, and initializing the map with an API key.
NPM module setup
-
Install the npm package.
npm install --save @maptiler/sdk -
Create the map style. Add the map style to your stylesheet. The div must have non-zero height.
body { margin: 0; padding: 0; } #map { position: absolute; top: 0; bottom: 0; width: 100%; } -
Create a
<div>element with a certain id where you want your map to be.Add
<div>tag into your page. This div will be the container where the map will be loaded.<div id="map"></div> -
Include the CSS file.
If you have a bundler that can handle CSS, you can
importthe CSSimport "@maptiler/sdk/dist/maptiler-sdk.css";or include it with a
<link />in the head of the document via the CDN<link href='https://cdn.maptiler.com/maptiler-sdk-js/v4.2.0/maptiler-sdk.css' rel='stylesheet' /> -
Finally, load the map with the style. Include the following code in your JavaScript.
import { Map, MapStyle, config } from '@maptiler/sdk'; config.apiKey = 'YOUR_MAPTILER_API_KEY'; const map = new Map({ container: 'map', // container's id or the HTML element in which SDK will render the map style: MapStyle.STREETS, center: [16.62662018, 49.2125578], // starting position [lng, lat] zoom: 14 // starting zoom }); -
Replace
YOUR_MAPTILER_API_KEYwith your own API key. Make sure to secure the key before you publish it.
npm install --save @maptiler/sdk
import { Map, MapStyle, config } from "@maptiler/sdk";
import "@maptiler/sdk/dist/maptiler-sdk.css";
config.apiKey = "YOUR_MAPTILER_API_KEY";
const map = new Map({
container: "map", // container's id or the HTML element in which the SDK will render the map
style: MapStyle.STREETS,
center: [16.62662018, 49.2125578], // starting position [lng, lat]
zoom: 14, // starting zoom
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex">
<title>How to use the MapTiler SDK JS | NPM example</title>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<div id="map"></div>
<script type="module" src="./main.js"></script>
</body>
</html>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}