My app, made with openlayers, displays building data called from overpass api.
var data_url = "http://overpass-api.de/api/interpreter?data=(way[building](bbox);node(w););out body;"; //main working url
var building = new OpenLayers.Layer.Vector("Building", {
strategies: [new OpenLayers.Strategy.BBOX({ratio:0.75})],
protocol: new OpenLayers.Protocol.HTTP({
url: data_url, //<-- relative or absolute URL to your .osm file
format: new OpenLayers.Format.OSM()
}),
projection: new OpenLayers.Projection("EPSG:4326")
});
Now i need to render them according the builing tag (commercial, yes, school etc). As of now i am using the Openlayers.Style to define each class.
var stylemap = new OpenLayers.StyleMap({
"default": new OpenLayers.Style({
strokeColor: "white",
strokeWidth: 1
}, {
rules: [
new OpenLayers.Rule({
filter: new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.EQUAL_TO,
property: "building",
value: "yes"
}),
symbolizer: {
fillColor: "olive"
}
})
]
})
})
The thing is i have made a sld file from the same data using Quantum GIS.
interpreter polygons
interpreter polygons
commercial
commercial
building
commercial
#a6611a
#000000
0.26
office
office
building
office
#d3ae69
#000000
0.26
school
school
building
school
#ece0c5
#000000
0.26
warehouse
warehouse
building
warehouse
#c6e5e0
#000000
0.26
yes
yes
building
yes
#66beb1
#000000
0.26
I want openlayers to read this sld file, parse and create a stylemap from it, and use the style in vector(building) layer.
P.S. I hve alread gone through the Openlayers Dev Example.
Edited: The full app
WebDRI
WEB DRI Building Structure Data Collection App Zoom In to view data
Answer
you need to assign the styles of sld to vector.
- Create a sld format object using OpenLayers.Format.SLD and Openlayers.Request.GET
assign the style to vector using style or stylemap
var format = new OpenLayers.Format.SLD();
OpenLayers.Request.GET({
url: "yoursldfile.sld",
success: sldparser
});
function sldparser(req) {
sld = format.read(req.responseXML || req.responseText);
styles = sld.namedLayers.interpreted.userStyles[0];
building_vec.styleMap.styles.default = styles;
}
No comments:
Post a Comment