---
title: "Add a vector tile source | JavaScript maps SDK"
description: "Add and display custom vector tile sources on maps."
---

> For AI agents: a documentation index is available at [/llms.txt](https://docs.maptiler.com/llms.txt). Markdown versions of all pages are available by appending .md to any URL.

# Add a vector tile source

Enhance your map by incorporating a [vector source](https://docs.maptiler.com/gl-style-specification/sources/#vector).

With the help of the [MapTiler Engine](https://www.maptiler.com/engine/), you can convert your data into vector tiles effortlessly. These tiles can then be [uploaded to the MapTiler](https://docs.maptiler.com/guides/map-data/upload-files/) with just a simple click, allowing you to seamlessly integrate your data into all of your web mapping applications.

### NPM module setup

```bash
npm install --save @maptiler/sdk
```

#### main.js

```js
import { Map, MapStyle, config } from '@maptiler/sdk';
import '@maptiler/sdk/dist/maptiler-sdk.css';

config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';
const map = new Map({
    container: 'map',
    style: MapStyle.STREETS, 
    zoom: 13,
    center: [-122.447303, 37.753574]
});

map.on('load', function () {
    map.addSource('contours', {
        type: 'vector',
        url:
            `https://api.maptiler.com/tiles/contours/tiles.json`
    });
    map.addLayer({
        'id': 'terrain-data',
        'type': 'line',
        'source': 'contours',
        'source-layer': 'contour',
        'layout': {
            'line-join': 'round',
            'line-cap': 'round'
        },
        'paint': {
            'line-color': '#ff69b4',
            'line-width': 1
        }
    });
});
```

#### index.html

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="robots" content="noindex">
  <title>Add a vector tile source | NPM example</title>
  <link rel="stylesheet" href="./style.css">
</head>
<body>
  <div id="map"></div>
  <script type="module" src="./main.js"></script>
</body>
</html>
```

#### style.css

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

### Basic JavaScript setup

```html
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add a vector tile source</title>
<script src="https://cdn.maptiler.com/maptiler-sdk-js/v4.2.0/maptiler-sdk.umd.min.js"></script>
<link href="https://cdn.maptiler.com/maptiler-sdk-js/v4.2.0/maptiler-sdk.css" rel="stylesheet" />
<style>
  body {margin: 0; padding: 0;}
  #map {position: absolute; top: 0; bottom: 0; width: 100%;}
</style>
</head>
<body>
<div id="map"></div>
<script>
    maptilersdk.config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';
    const map = new maptilersdk.Map({
        container: 'map',
        style: maptilersdk.MapStyle.STREETS, 
        zoom: 13,
        center: [-122.447303, 37.753574]
    });

    map.on('load', function () {
        map.addSource('contours', {
            type: 'vector',
            url:
                `https://api.maptiler.com/tiles/contours/tiles.json`
        });
        map.addLayer({
            'id': 'terrain-data',
            'type': 'line',
            'source': 'contours',
            'source-layer': 'contour',
            'layout': {
                'line-join': 'round',
                'line-cap': 'round'
            },
            'paint': {
                'line-color': '#ff69b4',
                'line-width': 1
            }
        });
    });
</script>
</body>
</html>
```

## Related examples

### [Add a third party vector tile source](https://docs.maptiler.com/sdk-js/examples/third-party/)

Examples

Add and render third-party vector data sources on maps.

### [Custom map](https://docs.maptiler.com/sdk-js/examples/custom-map/)

Tutorials

Display your customized MapTiler map on any web page.
