// Leaflet has native support for raster maps, So you can create a map with a few commands only! // The Leaflet map Object var map = L.map('my-map').setView([48.1500327, 11.5753989], 10); // The API Key provided is restricted to JSFiddle website // Get your own API Key on https://myprojects.geoapify.com var myAPIKey = "6dc7fb95a3b246cfa0f3bcef5ce9ed9a"; // Retina displays require different mat tiles quality var isRetina = L.Browser.retina; var baseUrl = "https://maps.geoapify.com/v1/tile/osm-bright/{z}/{x}/{y}.png?apiKey={apiKey}"; var retinaUrl = "https://maps.geoapify.com/v1/tile/osm-bright/{z}/{x}/{y}@2x.png?apiKey={apiKey}"; // Add map tiles layer. Set 20 as the maximal zoom and provide map data attribution. L.tileLayer(isRetina ? retinaUrl : baseUrl, { attribution: 'Powered by <a href="https://www.geoapify.com/" target="_blank">Geoapify</a> | © OpenStreetMap <a href="https://www.openstreetmap.org/copyright" target="_blank">contributors</a>', apiKey: myAPIKey, maxZoom: 20, id: 'osm-bright', }).addTo(map); //generate an 30 min transit isochrone from Munich center fetch(`https://api.geoapify.com/v1/isoline?lat=48.13736145&lon=11.574172059316222&type=time&mode=transit&range=1800&apiKey=${myAPIKey}`).then(data => data.json()).then(geoJSONFeatures => { //get hole polygons from geoJSOnFeatures const holePolygons = geoJSONFeatures.features[0].geometry.coordinates.map(poly => poly[0]); const mapCover = [ [-179.99, 89.99], [-179.99, 0], [-179.99, -89.99], [0, -89.99], [179.99, -89.99], [179.99, 0], [179.99, 89.99], [0, 89.99], [-179.99, 89.99] ]; const geoJSONPolygon = { "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [mapCover, ...holePolygons] } } L.geoJSON(geoJSONPolygon, { stroke: true, color: '#000', weight: 2, opacity: 0.7, fill: true, fillColor: '#000', fillOpacity: 0.3, smoothFactor: 0.5, interactive: false }).addTo(map); });
<div id="my-map"></div>
html, body, #my-map { width: 100%; height: 100%; margin: 0; }