mapbox / leaflet-omnivore

universal format parser for Leaflet & Mapbox.js
https://www.mapbox.com/mapbox.js/example/v1.0.0/omnivore-gpx/
Other
651 stars 126 forks source link

KMZ file. #63

Closed bestpika closed 9 years ago

bestpika commented 9 years ago

Could this plugin load kmz file?

tmcw commented 9 years ago

It cannot: this a combination of the fact that KMZ files are zip files and are difficult to process in browsers, and that they typically contain KML content with NetworkLinks, which are themselves not supportable.

pmusaraj commented 6 years ago

You could use a library like JSZIP (https://stuk.github.io/jszip/) to extract the contents of the KMZ file and then feed it to the map:

          fetch(layer.content)
          .then(function (response) {
            if (response.status === 200 || response.status === 0) {
              return Promise.resolve(response.blob());
            } else {
              return Promise.reject(new Error(response.statusText));
            }
          })
          .then(JSZip.loadAsync)
          .then(function (zip) {
            return zip.file("doc.kml").async("string");
          })
          .then(function success(kml) {
            overlayLayer = omnivore.kml.parse(kml);
            overlayLayer.options = {interactive: false};
            controls.addOverlay(overlayLayer, layer.name);
            overlayLayer.addTo(map);
          });