[OpenLayers-Users] How Can I Extract KML Attibutes

OpenGSC 945070223 at qq.com
Thu Nov 29 00:06:41 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/How-Can-I-Extract-KML-Attibutes-tp5019364p5019501.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list