Add a vector tile source
Enhance your map by incorporating a vector source.
With the help of the MapTiler Engine, you can convert your data into vector tiles effortlessly. These tiles can then be uploaded to the MapTiler with just a simple click, allowing you to seamlessly integrate your data into all of your web mapping applications.
NPM module setup
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_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
}
});
});
<!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>
body {margin: 0; padding: 0;}
#map {position: absolute; top: 0; bottom: 0; width: 100%;}
Related examples
Add a third party vector tile source
ExamplesAdd and render third-party vector data sources on maps.