Maps SDK with TypeScript

Create a map using the SDK based on TypeScript. Benefit from features like code completion, type safety, accurate documentation, and backward compatibility. Save time on your project by reducing typos and mistakes. No need to worry about changes to API endpoints and how they may affect your code.

Choose from a wide range of bundlers to find the best solution for your project. Whether you prefer Parcel, Webpack, Rollup, Turbopack, or any other bundler, you have plenty of options to choose from.

  1. Install the npm package.

    
     npm install --save @maptiler/sdk
    
  2. 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>
    
  3. Include the following code in your TypeScript main.ts file.

    
     import { config, Map, MapOptions } from '@maptiler/sdk';
    
     import "@maptiler/sdk/dist/maptiler-sdk.css";
    
     config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';
    
     const options: MapOptions = {
       container: document.getElementById("map") as HTMLElement, // container's id or the HTML element in which SDK will render the map
     }
    
     // Instanciating a map
     const map: Map = new Map(options);
    
  4. Replace YOUR_MAPTILER_API_KEY_HERE with your own API key. Make sure to secure the key before you publish it.

  5. Create the map containter style. Add the map containter style to you stylesheet style.css. The div must have non-zero height. In this case we are going to make a fullscreen map.

    
     body { margin: 0; padding: 0; }
    
     #map { position: absolute; top: 0; bottom: 0; width: 100%; }
    

Check out the tutorial How to create a map with TypeScript and Parcel.

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.

Was this helpful?