1

Is it possible to input a zipped .kml file (.kmz) int Leaflet?

I was trying the code:

fetch('Cov.kmz')
      .then( res => res.text() )
      .then( kmltext => {

            // Create new kml overlay
            parser = new DOMParser();
            kml = parser.parseFromString(kmltext,"text/xml");

            console.log(kml)

            const track = new L.KML(kml)
            map.addLayer(track)

            // Adjust map to show the kml
            const bounds = track.getBounds()
            map.fitBounds( bounds )

      })

But it doesn't appear on the map at all.

There is the plugin for that:

https://github.com/engrabid411/kmzol3

which doesn't work for the time being.

I also found an advice here:

https://stackoverflow.com/questions/57147510/kml-layer-fetch-error

But to be honest, extracting .kmz file into .kml and another ones, comprising of the .kmz file not help me enough.

  • What error message(s) are you seeing? – IvanSanchez Sep 5 at 8:06
  • There is no error itself. Simply code isn't working. – Mariusz Krukar Sep 5 at 8:18
  • No network errors, even? Add a debugger statement and inspect the values of kmltext and track, see if everything looks like it should. Add a catch branch for error handling as well. – IvanSanchez Sep 5 at 8:32
  • Could you write it down for me as an example? I am not perfect in this coding so far I am afraid. Thank you in advance. – Mariusz Krukar Sep 5 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.