0

I am trying to load a KML file into my Openlayers map. I added the following line of Code to my JS file and it throws an error. My map won't even load after I add this line:

var layer = new OpenLayers.Layer.GML("KML", "kml/mykml.kml", {format: OpenLayers.Format.KML});

I copied it from here and just changed the path to the KML file to match my own. It seems like plenty of people out there are using it just fine. What am I missing?

John Powell
  • 12,253
  • 6
  • 59
  • 67
user1794398
  • 61
  • 1
  • 8

1 Answers1

0

GML layer is deprecated, documentation states it's going to be removed in 3.0 and there is no api documentation for GML layer for version 2.12, so it might be somehow broken and probably it's better to use Vector layer with Protocol.HTTP and Strategy.Fixed.

This code (literally taken from KML example with filename correction) should do the work:

var layer = new OpenLayers.Layer.Vector("KML", {
    strategies: [new OpenLayers.Strategy.Fixed()],
    protocol: new OpenLayers.Protocol.HTTP({
        url: "kml/mykml.kml",
        format: new OpenLayers.Format.KML({
            extractStyles: true, 
            extractAttributes: true,
            maxDepth: 2
        })
    })
})
mrówa
  • 5,671
  • 3
  • 27
  • 39