How to use the MapTiler SDK JS

Learn how to generate and showcase an interactive map on a web page using MapTiler with this comprehensive tutorial. The step-by-step guide will walk you through the entire process.

By following these steps, you will be able to harness the power of MapTiler SDK JS to effortlessly develop web mapping applications. Experiment with different map styles, customizations, and functionalities to create an exceptional mapping experience for your web application users.

NPM module setup

  1. Install the npm package.

    
     npm install --save @maptiler/sdk
    
  2. 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%;
     }
    
  3. 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>
    
  4. Include the CSS file.

    If you have a bundler that can handle CSS, you can import the CSS

    
     import "@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.1.0/maptiler-sdk.css' rel='stylesheet' />
    
  5. 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_HERE';
     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
     });
    
  6. Replace YOUR_MAPTILER_API_KEY_HERE with your own API key. Make sure to secure the key before you publish it.

Display simple marker on the map

Display marker

Tutorials

Learn how to add a default marker to your map.

Display a 3D terrain map

3D terrain map

Tutorials

Create and display 3D terrain maps on web pages.

How to migrate/switch from Mapbox to MapTiler

Switch from Mapbox

Tutorials

Guide for migrating from Mapbox GL JS to MapTiler SDK.

How to migrate/switch from MapLibre to MapTiler

Switch from MapLibre

Tutorials

Steps to switch from MapLibre GL JS to MapTiler SDK.