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.

I am trying to add kml to openlayers and i am getting error in firebug

  a is undefined: Line 92 openlayers.js

here is my code :

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>OpenLayers Basic Single WMS Example</title>

<script src="OpenLayers-2.12/lib/OpenLayers.js"></script>
<script type="text/javascript">
    var map, layer;
    function init(){
        map = new OpenLayers.Map( 'map' );
        layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
            "http://vmap0.tiles.osgeo.org/wms/vmap0",
            {layers: 'basic'} );

        var kml =  new OpenLayers.Layer.Vector("KML", {
            strategies: [new OpenLayers.Strategy.Fixed()],
            protocol: new OpenLayers.Protocol.HTTP({
                url: "data/carmax.anand.kml",
                format: new OpenLayers.Format.KML({
                    extractStyles: true, 
                    extractAttributes: true
                })
            })
        });
        map.addLayer(layer);
        map.addLayer(kml);
        map.zoomToMaxExtent();
    }
</script>
</head>
<body onload="init()">
<div id="map" class="smallmap" style="height:512px; width:512px"></div>
</body>
</html>
share|improve this question
    
I would go debugging into the line in your javascript that causes the error - try firebug or similar. I don't think its the cause of the error, but mind the invalid comma after extractAttributes: true. –  Chau Jan 4 '13 at 9:06
    
Use <script src="OpenLayers-2.12/lib/OpenLayers.js"></script>, this show which is the failing component. –  xamamano -jorix- Jan 4 '13 at 9:08
    
@ chau : thank you for pointing invalid comma and yes I am using firebug, which is only giving me this scripting error. @jorix : I used lib/openlayers.js and got this error : node is undefined : Line 625 –  anand Jan 4 '13 at 9:33
    
@anand In which js file? –  xamamano -jorix- Jan 4 '13 at 10:34
    
Is a error on lib/OpenLayers/Renderer/Elements.js, It can be an impropriety in the kml response, you can show a kml response from your server? –  xamamano -jorix- Jan 4 '13 at 10:49
show 7 more comments

3 Answers 3

Your code is correct, I've tried to read examples/kml/sundials.kml and no error. Can be a problem is the xml response.

NOTE: Remove the comma after extractAttributes: true, this causes problems with IE.

Use http://dev.openlayers.org/releases/OpenLayers-2.12/lib/OpenLayers.js to see a more specific error.

share|improve this answer
add comment

You have wrongly defined height and width of your map div. Change it to the following:

<div id="map" class="smallmap" style="height:512px; width:512px"></div>

This should work for the wms layer, you have added.

share|improve this answer
    
It is still giving same error in firebug –  anand Jan 4 '13 at 9:29
1  
As answered by xamamano, I have also tried with the local KML file. It is working. So there may be error in your kml file. You can check it through importing your KMl into Google Earth. –  thelastray Jan 4 '13 at 10:42
    
I can open my kml with Google earth without any problem. –  anand Jan 4 '13 at 12:26
add comment

If anyone else experiences same error I suggest adding maxExtent to OpenLayers.Map() options.

share|improve this answer
    
Welcome to GIS SE! Would you be able to expand upon your answer, because it was flagged up as low quality due to its length, please? –  PolyGeo Sep 24 '13 at 21:37
add comment

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.