G
G
Goobert Crypto2020-07-09 20:04:01
leaflet
Goobert Crypto, 2020-07-09 20:04:01

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);
                });


This connection of this KML does not work, please help me figure it out.
THANK YOU SO MUCH in advance =)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question