The KML file has no attributes for the displayed features (Placemark). Only
the document and the folder has attributes, but this one not added to the
feature(s).

That will work:

<Placemark>
<name>La Roquebrussanne</name>
<description>Provence</description>
<Point>
<coordinates>665231.4570703981,5363853.803594344</coordinates></Point></Plac
emark> 

Arnd

-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Wyo
Gesendet: Sonntag, 9. Januar 2011 13:25
An: [email protected]
Betreff: [OpenLayers-Users] Empty extended attributs in KML vector layer

I've KML file in a vector layer (http://www.orpatec.ch/osm/tools/test2.php)
which has "extractAttributes: true" but doesn't show the feature attributs.
When I set a breakpoint with firebug in onFeatureSelect and check the
content of the feature, the attributes exist but is empty. Where's my error
or is there something missing in the KML file (see below)?

         layers[i] = new OpenLayers.Layer.Vector (canals[i][1], {
           strategies: [new OpenLayers.Strategy.Fixed()],
           protocol: new OpenLayers.Protocol.HTTP({
           url: "data/relation_"+canals[i][0]+".kml",
           format: new OpenLayers.Format.KML({extractAttributes: true,
                                              extractStyles: false})
           }),
           projection: map.displayProjection,
           eventListeners: {
             "featureselected": onFeatureSelect,
             "featureunselected": onFeatureUnselect,
             scope: this
           },
           styleMap: styles
         });

       styles = new OpenLayers.StyleMap ({
                    "default": new OpenLayers.Style({
                        label: "${name}",
                        fillColor: "#ffcc66",
                        strokeColor: "red",
                        strokeWidth: 3
                    }),
                    "select": new OpenLayers.Style({
                        label: "${name}",
                        fillColor: "#66ccff",
                        strokeColor: "blue",
                        strokeWidth: 5
                    })
                  });

     function onFeatureSelect(event) {
       var feature = event.feature;
       // Since KML is user-generated, do naive protection against
Javascript.
       var content = "<h2>"+feature.attributes.name + "</h2>";
       if (content.search("<script") != -1) {
         content = "containes Javascript! />" + content.replace(/</g,
"&lt;");
       }
       popup = new OpenLayers.Popup.FramedCloud ("test",
 
feature.geometry.getBounds().getCenterLonLat(),
                                new OpenLayers.Size(100,100),
                                content,
                                null, true, onPopupClose);
       feature.popup = popup;
       map.addPopup (popup);
     }

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <kml
xmlns="http://earth.google.com/kml/2.1";>
     <Document>
         <name>Relation 1075685</name>
         <description></description>
         <Folder>
             <name>Segment 0&lt;br&gt;</name>
             <visibility>true</visibility>
             <open>true</open>
             <description>Way IDs: 39028795, 39028794, ...</description>
             <Placemark>
                 <Style>
                     <LineStyle>
                         <color>FF0000FF</color>
                         <width>3.0</width>
                     </LineStyle>
                 </Style>
                 <LineString>
                     <coordinates>-1.6329761,48.1968307, ...</coordinates>
                 </LineString>
             </Placemark>
         </Folder>
     </Document>
</kml>

_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users

_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users

Reply via email to