Using KMZ file in Leaflet Map

Abdul Rehman Yawar Khan picture Abdul Rehman Yawar Khan · Mar 8, 2016 · Viewed 8.5k times · Source

I have to use KMZ files in my Leaflet Map. I found good plugins and tutorials to use KML files in Leaflet Maps but couldn't find a way to use KMZ files.

One of the plugin for using KML is : Leaflet-Omnivore. For KML all I have to do is(My Leaflet Map is in my ExtJs Application) :

var myMap =  Ext.ComponentQuery.query("leaflet")[0];
myMap.getMap().addLayer(omnivore.kml('http://url/doc.kml'))

Can any one guide me about how to use KMZ instead of KML in Leaflet?

If it is not possible then is there a way to convert KMZ to KML using JavaScript?

Answer

ghybs picture ghybs · Mar 8, 2016

A KMZ file is just a zipped KML file, possibly with associated embedded images, icons, etc.

So any program that supports KMZ files internally unzips them to access their KML files.

That may be a reason why many open source programs do not bother supporting KMZ once KML support is implemented: you just need to use an additional unzipping library of your choice, to convert the KMZ to KML.

The linked posts give some JavaScript-based solutions for unzipping.