Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

My OpenLayers map was working fine before, showing a KML overlay. Suddenly it broke. Now I see this error in my browser error console.

TypeError: 'undefined' is not a constructor (evaluating 'new OpenLayers.Layer.GML')

My code looks like this:

var kmllayer = new OpenLayers.Layer.GML("KML", "./my-kml-file.kml", 
   {    
    format: OpenLayers.Format.KML, 
    formatOptions: {
      extractStyles: true, 
      extractAttributes: true,
      maxDepth: 2
    }
   });
map.addLayer(kmllayer);
share|improve this question

1 Answer 1

Change it to look like this

var kmllayer = new OpenLayers.Layer.Vector("KML", {
     strategies: [new OpenLayers.Strategy.Fixed()],
           protocol: new OpenLayers.Protocol.HTTP({
                url: "./my-kml-file.kml",
                format: new OpenLayers.Format.KML({
                    extractStyles: true, 
                    extractAttributes: true,
                    maxDepth: 2
          })
     })
})

OpenLayers.Layer.GML was deprecated and then removed in version 3.0 of OpenLayers which was released recently. If you simply include the latest OpenLayers with script tag pointing like this...

<script src="http://www.openlayers.org/api/OpenLayers.js"></script>

...then things can break when features are deprecated, though this shouldn't happen too often. An alternative is to download a particular version of the javascript library and host this yourself.

share|improve this answer
2  
OpenLayers is on version 2.12, not 3. I would always use a local version, not only can you make sure things still work when there are upgrades but you can also customize your version of OpenLayers depending on what you want, potentially making your OpenLayers JS smaller and simpler. –  Rob Quincey Aug 1 '12 at 7:53
2  
Plus, you avoid bandwidth leeching :). Building your own OpenLayers JavaScript file with Python is quick and easy even on Windows machines, just don't try to use the wrong Python version like I did (that is, use Python 2.x and not 3.x) –  SAnderka Aug 1 '12 at 10:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.