[OpenLayers-Users] Can not Extract KML Attribute
OpenGSC
945070223 at qq.com
Sun Dec 2 18:14:05 PST 2012
ok,you can do it like this!
var vector_style = new OpenLayers.Style({
'fillColor': "#ffffff",
'fillOpacity': 0.5,
'strokeWidth': 1,
'strokeColor': "#0000ff",
'strokeOpacity': 4,
'label': '${state}',
'fontColor': "#ffffff",
'fontFamily': "sans-serif",
'fontSize': "15px",
'fontWeight': "bold"
},
{
context: {
state: function(feature){ return feature.attributes.State.value; }
}});
var vector_style_map = new OpenLayers.StyleMap({
'default': vector_style
});
var vectorlayer = new OpenLayers.Layer.Vector("ESTADO DA BAHIA", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: "kml/ba_uf_900913a.kml",
format: new OpenLayers.Format.KML({
extractStyles: false,
extractAttributes: true,
srsName: "EPSG:900913"
})
}),
styleMap:vector_style_map
});
you ought to use context which can fetch the attribute value from KML's
feature!
--
View this message in context: http://osgeo-org.1560.n6.nabble.com/Can-not-Extract-KML-Attribute-tp5019859p5020219.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
More information about the Users
mailing list