[OpenLayers-Users] How to read a kml file into Open Layers - issue

christian bleau christian.bleau at gmail.com
Mon Jun 25 09:36:22 PDT 2012


Hi,

 I use the following code get from kml openlayer example.

It work very well  http://pofableau.com/openlayer/kml2.html here 

but not with your kml file
http://students.cse.tamu.edu/jsc6064/projects/temp/georeferences.kml

:((((((((

If I compare the head of the files 

*georeferences.kml*

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document xmlns="">

*and this of openlayer example*:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>

Is there somebody whose can give us an explanation?

Thanks

Christian


 // code ---- kml -----
  
          var kml = new OpenLayers.Layer.Vector("KML", {
                projection: map.displayProjection,
                strategies: [new OpenLayers.Strategy.Fixed()],
                protocol: new OpenLayers.Protocol.HTTP({
                    url: "sundials.kml",
                    format: new OpenLayers.Format.KML({
                        extractStyles: true,
                        extractAttributes: true
                    })
                })
            });	
            
            select = new OpenLayers.Control.SelectFeature(kml);
            
            kml.events.on({
                "featureselected": onFeatureSelect,
                "featureunselected": onFeatureUnselect
            });

            map.addControl(select);
            select.activate();
            
            function onPopupClose(evt) {
            select.unselectAll();
        	}
            
            function onFeatureSelect(event) {
            var feature = event.feature;
            // Since KML is user-generated, do naive protection against
            // Javascript.
            var content = "
"+feature.attributes.name + "
" + feature.attributes.description;
            if (content.search("<script") != -1) {
                content = "Content contained Javascript! Escaped
content below.<br>" + content.replace(/</g, "<");
            }
            popup = new OpenLayers.Popup.FramedCloud("chicken", 
                                    
feature.geometry.getBounds().getCenterLonLat(),
                                     new OpenLayers.Size(100,100),
                                     content,
                                     null, true, onPopupClose);
            feature.popup = popup;
            map.addPopup(popup);
        	}	
            
            function onFeatureUnselect(event) {
            var feature = event.feature;
            if(feature.popup) {
                map.removePopup(feature.popup);
                feature.popup.destroy();
                delete feature.popup;
            	}
        	}			
				

--
View this message in context: http://osgeo-org.1560.n6.nabble.com/How-to-read-a-kml-file-into-Open-Layers-issue-tp4983286p4983692.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list