2

I have a .kmz file and want to display the data on a map.
If I unzip the file, and extract the .kml file and use that, I can get the map to display the data. However, as the .kmz file is hosted somewhere else, I need to read that file and ideally wouldn't have to parse it locally each time it is updated.

My sample for parsing the .kml file is

var phase1 = new OpenLayers.Layer.Vector("phase1", {
    projection: new OpenLayers.Projection("EPSG:4326"),
    strategies: [new OpenLayers.Strategy.Fixed()],
    protocol: new OpenLayers.Protocol.HTTP({
        url: "data.kml",
        format: new OpenLayers.Format.KML({
            extractStyles: true,
            extractAttributes: true
        })
    })
});

Is there something in the above that needs changing to read the .kmz file?

I know Google Maps is able to use the .kmz file directly to display the data, but is it possible for OpenLayers to use the .kmz file directly? Or would it be necessary to parse the .kmz file someway to extract the .kml to display?

CodeMonkey
  • 22,825
  • 4
  • 35
  • 75
Beast-a-tron
  • 503
  • 10
  • 28
  • A kmz file is just a kml file that has been zipped. So, you would need to create a class that extended OpenLayers.Format.KML that added the extra step of unzipping the file first. – John Powell Oct 30 '14 at 12:16

1 Answers1

2

You have to unzip the file first.

  • Either do it on the server (which is what Google Maps do).
  • Or use something like JSZip to do it on the client side. You will probably need to write your own format for this.
lexicore
  • 42,748
  • 17
  • 132
  • 221
  • one of the problems though is when you unzip it, it seems like a lot of references get lost. are there any guides towards editing the kml inside, or smartly unziping the files to the correct spaces – Phil Mar 28 '19 at 23:27