Skip to main content

Add a raster tile source

Add a third-party raster source to the map.


<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Add a raster tile source</title>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <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;
      }
      html,
      body,
      #map {
        height: 100%;
      }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <script>
      TrimbleMaps.setAPIKey('YOUR_API_KEY_HERE');
      // Initialize a new TrimbleMaps.Map object
      const map = new TrimbleMaps.Map({
        container: 'map', // Specifies the ID of the HTML element where the map will be displayed
        style: {
          'version': 8, // Required by TrimbleMaps style specification
          'sources': {

			// Define a raster tile source for OpenStreetMap data
            'osm-raster-tiles': {
              'type': 'raster', // Specifies the source type as raster tiles
              'tiles': [
                // URL template for OpenStreetMap standard raster tiles.
                // {z}, {x}, {y} are placeholders for zoom level, x-coordinate, and y-coordinate respectively.
                'https://tile.openstreetmap.org/{z}/{x}/{y}.png'
              ],
              'tileSize': 256, // The size of the tiles in pixels
              // **IMPORTANT**: Attribution for OpenStreetMap data is mandatory.
              // Always display this on your map when using OSM tiles.
              'attribution': '© OpenStreetMap contributors'
            }
          },
          'layers': [
            // Define a layer to display the raster tiles from the source
            {
              'id': 'osm-simple-tiles', // Unique ID for this layer
              'type': 'raster', // Specifies the layer type as raster
              'source': 'osm-raster-tiles', // Links this layer to the 'osm-raster-tiles' source defined above
              'minzoom': 0, // Minimum zoom level at which this layer will be visible
              'maxzoom': 19 // Maximum zoom level at which this layer will be visible.
                            // Standard OpenStreetMap tiles are typically available up to zoom level 19.
            }
          ]
        },
        // Initial map view settings:
        // 'center' sets the map's starting geographical center point [longitude, latitude].
        // This example centers on an approximate point for the contiguous USA.
        center: [-98.5, 39.8],
        // 'zoom' sets the initial zoom level. A zoom of 4 is suitable for viewing the USA/North America region.
        zoom: 4
    });
    </script>
  </body>
</html>
Last updated June 26, 2025.