Show Polygon Data from GeoJSON on the Map
This tutorial shows how to add a GeoJSON overlay to the map.
-
Copy the following code, paste it into your favorite text editor, and save it as a
.html
file. -
Replace YOUR_MAPTILER_API_KEY_HERE with your actual MapTiler API key.
-
The next is up to you. You can start the map in a different place by modifying the
starting position
andstarting zoom
, and you can change the look of the map to any of our styles, or yours, by updating thesource URL
. See what’s available here. -
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);
OpenLayers
Examples
Video tutorials
Other maps libraries
On this page