You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am new to leaflet, and trying to use the code below to add an online kml file to leaflet. The background map shows, but the kml layer is not added. I am new to leaflet, please help:
<script src="http://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="./L.KML.js"></script>
<script type="text/javascript">
// Make basemap
const map = new L.Map('map', { center: new L.LatLng(10, 0.0), zoom: 3});
const osm = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png');
map.addLayer(osm);
// Load kml file
fetch('https://www.cpc.ncep.noaa.gov/products/international/gefs/gefs_week1_af_precip_obs.kml')
.then(res => res.text())
.then(kmltext => {
// Create new kml overlay
const parser = new DOMParser();
const kml = parser.parseFromString(kmltext, 'text/xml');
const track = new L.KML(kml);
map.addLayer(track);
// Adjust map to show the kml
const bounds = track.getBounds();
map.fitBounds(bounds);
});
</script>
</body>
The text was updated successfully, but these errors were encountered:
Hello,
I am new to leaflet, and trying to use the code below to add an online kml file to leaflet. The background map shows, but the kml layer is not added. I am new to leaflet, please help:
<script src="http://unpkg.com/[email protected]/dist/leaflet.js"></script> <script src="./L.KML.js"></script> <script type="text/javascript"> // Make basemap const map = new L.Map('map', { center: new L.LatLng(10, 0.0), zoom: 3}); const osm = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png');The text was updated successfully, but these errors were encountered: