Skip to main content

Add a WMS source

Add an external Web Map Service raster layer to the map using addSource’s tiles option. Requires Trimble Maps v3.0.0 or later.

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <link rel="stylesheet" href="https://maps-sdk.trimblemaps.com/v4/trimblemaps-4.2.3.css" />
        <script src="https://maps-sdk.trimblemaps.com/v4/trimblemaps-4.2.3.js"></script>
        <style>
            body { margin: 0; padding: 0; }

            #map {
                position: absolute;
                top: 0;
                bottom: 0;
                width: 100%;
            }
        </style>
    </head>
    <body>
    <div id="map"></div>
    <script>
    TrimbleMaps.setAPIKey('YOUR_API_KEY_HERE');
    const map = window.map = new TrimbleMaps.Map({
    container: 'map',
    zoom: 16,
    center: [-74.0447, 40.6892],
    style: TrimbleMaps.Common.Style.TRANSPORTATION,
    hash: true
    });
      map.on('load', () => {
          map.addSource('wms-test', {
              'type': 'raster',
              'tiles': [
                  'https://img.nj.gov/imagerywms/Natural2015?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=Natural2015',
                ],
              'tileSize': 256
          });

          map.addLayer({
              'id': 'wms-test-layer',
              'type': 'raster',
              'source': 'wms-test',
              'paint': {}
          });
      });
    </script>
  </body>
</html>
Last updated June 26, 2025.