Answer the question
In order to leave comments, you need to log in
How to connect KML to Leaflet maps?
There is a map of the city with loaded local tiles. I tried to connect KML from the site there
(I translated KMZ into KML, and tested it on google earth, everything is displayed as it should without loss)
In the Leaflet documentation, after looking at the connection of this KML, I could not implement
map.addLayer(osm);
// Load kml file
fetch('assets/example1.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);
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question