Add a WMS source

Add an external Web Map Service raster layer to the map using the addSource function’s tiles option. This will allow you to seamlessly integrate external content from the specified WMS URL into your map.

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: 8,
    center: [-74.5447, 40.6892]
});

map.on('load', function () {
    map.addSource('wms-test-source', {
        'type': 'raster',
        // use the tiles option to specify a WMS tile source URL
        // https://docs.maptiler.com/gl-style-specification/sources/
        'tiles': [
            'https://img.nj.gov/imagerywms/Natural2020?bbox={bbox-epsg-3857}&format=image/png&service=WMS&version=1.1.1&request=GetMap&srs=EPSG:3857&transparent=true&width=256&height=256&layers=Natural2020'
        ],
        'tileSize': 256
    });
    map.addLayer(
        {
            'id': 'wms-test-layer',
            'type': 'raster',
            'source': 'wms-test-source',
            'paint': {}
        },
        'Aeroway'
    );
});
Show raster image on the map

Raster layer

Tutorials

Add a raster image overlay to the map.

Add a raster tile source

Add a raster tile source

Examples

Add a third-party raster source to the map.

How to display your custom map on the web page.

Custom map

Tutorials

Display your customized MapTiler map on any web page.

Was this helpful?