Show Polygon Data from GeoJSON on the Map

This tutorial shows how to add a GeoJSON overlay to the map.

  1. Copy the following code, paste it into your favorite text editor, and save it as a .html file.

  2. Replace YOUR_MAPTILER_API_KEY_HERE with your actual MapTiler API key.

  3. The next is up to you. You can start the map in a different place by modifying the starting position and starting zoom, and you can change the look of the map to any of our styles, or yours, by updating the source URL. See what’s available here.

  4. Create GeoJSON layer. The following snippet creates GeoJSON layer from GeoJSON which is hosted on MapTiler Cloud.

    
         });
       const layer = new ol.layer.Vector({
         source: new ol.source.Vector({
           url: `https://api.maptiler.com/data/YOUR_MAPTILER_DATASET_ID_HERE/features.json?key=${key}`,
           format: new ol.format.GeoJSON(),
         }),
         }),
         style: new ol.style.Style({
           stroke: new ol.style.Stroke({
             color: 'rgba(0, 136, 136, 0.8)',
           }),
           fill: new ol.style.Fill({
             color: 'rgba(0, 136, 136, 0.8)',
           }),
         })
       });
       map.addLayer(layer);