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, "<");
}
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<br></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