[OpenLayers-Users] sld with wfs
Brenningmeyer, Todd
tbrenningmeyer at maryville.edu
Sun Aug 10 09:50:20 EDT 2008
Hello,
I am trying to symbolize my data using an sld file with the tazmania-sld example as a template. So far I haven't had too much success. The sld document loads and symbolizes the way I want when I open it in udig to validate it but when I display it in openlayers the points display using the default orange. This is still listed as the default when I check the code in firebug and my symbology is listed under rules. I'm not quite sure what I'm missing but any suggestions are welcome. I will paste the sld and openlayers page below (it's pretty basic and just a reduced version of the tazmanian sld example).
Thanks,
Todd
__________________________OpenLayers Page___________________________________________
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
<style type="text/css">
#map {
width: 800px;
height: 475px;
border: 1px solid black;
background: #ccddff;
}
</style>
<script src="OpenLayers-2.6/lib/OpenLayers.js"></script>
<script type="text/javascript">
var map, sld, wfsLayers;
var lon = 544134;
var lat = 4183845;
var zoom = 18;
var format = new OpenLayers.Format.SLD();
function init() {
map = new OpenLayers.Map( 'map', {
maxResolution: 200,
maxExtent: new OpenLayers.Bounds(426367,3991789,756976,4312918),
units: 'm',
projection: 'EPSG:32634'
} );
map.addControl(new OpenLayers.Control.LayerSwitcher());
OpenLayers.loadURL("amap2.xml", null, null, complete);
}
baseLayer = new OpenLayers.Layer.WMS( "Greece",
"http://localhost/cgi-bin/mapserv.exe", {
layers: "ocean,country,hillshade_mask,provinces_utm,roads_utm",
map: "../htdocs/amap/amap.map",
transparent: "false",
format: "image/png" },
{singleTile: false}
);
function getDefaultStyle(sld, layerName) {
var styles = sld.namedLayers[layerName].userStyles;
var style;
for(var i=0; i<styles.length; ++i) {
style = styles[i];
if(style.isDefault) {
break;
}
}
return style;
}
function complete(req) {
sld = format.read(req.responseXML || req.responseText);
/*var hoverStyle = sld.namedLayers["Villages"].userStyles[1];
//alert(sld.namedLayers["Villages"].userStyles[1].name);
hoverStyle.defaultStyle = OpenLayers.Util.extend(
{}, OpenLayers.Feature.Vector.style["select"]
);
*/
wfsLayers = [
// use the sld UserStyle named "Default Styler"
new OpenLayers.Layer.WFS( "villages",
"http://localhost/cgi-bin/mapserv.exe",
{typename: "villages",
map:"../htdocs/amap/sites_wfs.map"},
{extractAttributes: true},
{styleMap: new OpenLayers.StyleMap({
"default": getDefaultStyle(sld, "Villages")//,
//"select": hoverStyle
})
}
)
];
map.addLayers(wfsLayers);
map.addLayer(baseLayer);
map.zoomToExtent(new OpenLayers.Bounds(426367,3991789,756976,4312918));
//map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
// var hover = new OpenLayers.Control.SelectFeature(
// wfsLayers[1], {hover: true}
// );
//map.addControl(hover);
//hover.activate();
}
// set a new style when the radio button changes
function setStyle(index) {
wfsLayers[0].styleMap.styles["default"] = sld.namedLayers["Villages"].userStyles[index];
// change the style of the features of the WaterBodies layer
wfsLayers[0].redraw();
}
</script>
</head>
<body onload="init()">
<div id="map"></div>
<p>This example uses a <a target="_blank" href="tasmania/sld-tasmania.xml">SLD
file</a> to style the vector features. To construct layers that use styles
from SLD, create a StyleMap for the layer that uses one of the userStyles in the
namedLayers object of the return from format.read().</p>
<p>Select a new style for the WaterBodies layer below:</p>
<form>
<input type="radio" name="style" onclick="setStyle(this.value)" checked="checked" value="0">Default Styler (zoom in to see more features)</input><br/>
<input type="radio" name="style" onclick="setStyle(this.value)" value="3">Styler Test PropertyIsEqualTo</input><br/>
<input type="radio" name="style" onclick="setStyle(this.value)" value="4">Styler Test WATER_TYPE</input><br/>
<input type="radio" name="style" onclick="setStyle(this.value)" value="5">Styler Test PropertyIsGreaterThanOrEqualTo</input><br/>
<input type="radio" name="style" onclick="setStyle(this.value)" value="6">Styler Test PropertyIsLessThanOrEqualTo</input><br/>
<input type="radio" name="style" onclick="setStyle(this.value)" value="7">Styler Test PropertyIsGreaterThan</input><br/>
<input type="radio" name="style" onclick="setStyle(this.value)" value="8">Styler Test PropertyIsLessThan</input><br/>
<input type="radio" name="style" onclick="setStyle(this.value)" value="9">Styler Test PropertyIsLike</input><br/>
<input type="radio" name="style" onclick="setStyle(this.value)" value="10">Styler Test PropertyIsBetween</input><br/>
<input type="radio" name="style" onclick="setStyle(this.value)" value="11">Styler Test FeatureId</input><br/>
</form>
</body>
</html>
___________________________________SLD FILE_________________________________________
<?xml version="1.0" encoding="UTF-8"?>
<sld:StyledLayerDescriptor
xmlns:sld="http://www.opengis.net/sld"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:gml="http://www.opengis.net/gml" version="1.0.0">
<sld:NamedLayer>
<sld:Name>Villages</sld:Name>
<sld:UserStyle>
<sld:Name>Default Styler</sld:Name>
<sld:Title>Default Styler</sld:Title>
<sld:Abstract>sld for amap</sld:Abstract>
<sld:IsDefault>1</sld:IsDefault>
<sld:FeatureTypeStyle>
<sld:Name>simple</sld:Name>
<sld:Title>title</sld:Title>
<sld:Abstract>abstract</sld:Abstract>
<sld:FeatureTypeName>Feature</sld:FeatureTypeName>
<sld:SemanticTypeIdentifier>generic:geometry</sld:SemanticTypeIdentifier>
<sld:Rule>
<sld:Name>name</sld:Name>
<sld:Title>title</sld:Title>
<sld:Abstract>Abstract</sld:Abstract>
<sld:MaxScaleDenominator>3000000</sld:MaxScaleDenominator>
<sld:PointSymbolizer>
<sld:Graphic>
<sld:Mark>
<sld:WellKnownName>circle</sld:WellKnownName>
<sld:Fill>
<sld:CssParameter name="fill">
<ogc:Literal>#0000FF</ogc:Literal>
</sld:CssParameter>
<sld:CssParameter name="fill-opacity">
<ogc:Literal>1.0</ogc:Literal>
</sld:CssParameter>
</sld:Fill>
</sld:Mark>
</sld:Graphic>
</sld:PointSymbolizer>
</sld:Rule>
</sld:FeatureTypeStyle>
</sld:UserStyle>
</sld:NamedLayer>
</sld:StyledLayerDescriptor>
More information about the Users
mailing list