Skip to content

Add a WMS Source

WMS is a standard protocol for serving georeferenced map images from a remote server, commonly used by government and scientific data providers. In Maptoolkit Maps JS, you connect a WMS endpoint as a raster tile source by constructing the required GetMap request URL template. Use this to overlay cadastral data, environmental monitoring layers, or any WMS-compatible spatial dataset on your map.

const API_KEY = 'YOUR_API_KEY';

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

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

    map.on('load', () => {
        map.addSource('wms-source', {
            type: 'raster',
            tiles: [
                'https://ows.terrestris.de/osm/service?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&LAYERS=OSM-WMS&WIDTH=256&HEIGHT=256&SRS=EPSG%3A3857&STYLES=&BBOX={bbox-epsg-3857}'
            ],
            tileSize: 256
        });

        map.addLayer({
            id: 'wms-layer',
            type: 'raster',
            source: 'wms-source',
            paint: { 'raster-opacity': 0.6 }
        });
    });
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Add a WMS Source - Maptoolkit Maps JS</title>
    <meta property="og:description" content="Add a WMS (Web Map Service) raster source to the map." />
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://unpkg.com/@maptoolkit/[email protected]/dist/maptoolkit.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/@maptoolkit/[email protected]/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 = 'YOUR_API_KEY';

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

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

    map.on('load', () => {
        map.addSource('wms-source', {
            type: 'raster',
            tiles: [
                'https://ows.terrestris.de/osm/service?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&LAYERS=OSM-WMS&WIDTH=256&HEIGHT=256&SRS=EPSG%3A3857&STYLES=&BBOX={bbox-epsg-3857}'
            ],
            tileSize: 256
        });

        map.addLayer({
            id: 'wms-layer',
            type: 'raster',
            source: 'wms-source',
            paint: { 'raster-opacity': 0.6 }
        });
    });
</script>
</body>
</html>

Use the prompt below with any LLM to get the same result. Make sure the Maptoolkit MCP server is connected first — check out AI Integration & MCP to get started.

Use the Maptoolkit Connector. Create an interactive map with zoom level 6, centered around [13.0, 47.5]. Add a WMS raster overlay from https://ows.terrestris.de/osm/service (OSM-WMS layer).