Skip to content
Add a Vector Tile Source

Add a Vector Tile Source

Add a vector tile source to the map and style its layers.

const API_KEY = 'toursprung';

    const map = new maptoolkit.Map({
        container: 'map',
        style: `https://static.maptoolkit.net/styles/toursprung/terrain.json?api_key=${API_KEY}`,
        center: [13.0, 47.5],
        zoom: 7,
        attributionControl: { compact: false }
    });

    map.addControl(new maptoolkit.NavigationControl(), 'top-right');

    map.on('load', () => {
        map.addSource('urban-areas', {
            type: 'geojson',
            data: 'https://maplibre.org/maplibre-gl-js/docs/assets/ne_50m_urban_areas.geojson'
        });

        map.addLayer({
            id: 'urban-areas-fill',
            type: 'fill',
            source: 'urban-areas',
            paint: {
                'fill-color': '#f08',
                'fill-opacity': 0.4
            }
        });
    });
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Add a Vector Tile Source – Maptoolkit Maps JS</title>
    <meta property="og:description" content="Add a vector tile source to the map and style its layers." />
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://unpkg.com/@maptoolkit/maps@11.0.0-beta.2/dist/maptoolkit.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/@maptoolkit/maps@11.0.0-beta.2/dist/maptoolkit.css" />
    <style>
        html, body { width: 100%; height: 100%; margin: 0; padding: 0; }
        #map { width: 100%; height: 100%; }
    </style>
</head>
<body>
<div id="map"></div>
<script>
    const API_KEY = 'toursprung';

    const map = new maptoolkit.Map({
        container: 'map',
        style: `https://static.maptoolkit.net/styles/toursprung/terrain.json?api_key=${API_KEY}`,
        center: [13.0, 47.5],
        zoom: 7,
        attributionControl: { compact: false }
    });

    map.addControl(new maptoolkit.NavigationControl(), 'top-right');

    map.on('load', () => {
        map.addSource('urban-areas', {
            type: 'geojson',
            data: 'https://maplibre.org/maplibre-gl-js/docs/assets/ne_50m_urban_areas.geojson'
        });

        map.addLayer({
            id: 'urban-areas-fill',
            type: 'fill',
            source: 'urban-areas',
            paint: {
                'fill-color': '#f08',
                'fill-opacity': 0.4
            }
        });
    });
</script>
</body>
</html>