Hi Todd,

I have some to share. My WFS layer contains line features ( roads ) and 
they have different color depending on their type ( Local road, Highway, 
etc ). I hope this can be of any help :

============= otherfile.js =============

// prepare to style the data
var oStyleMap = new OpenLayers.StyleMap();

// Array of symbolizer and other values for ROL_CO_CLA attribute
// this will be used to create a html select list and will be used
// as the symbolizer array for the addUniqueValueRules function
// sorry, there's some french words here :)
var aRoadType = new Array();
aRoadType = {
AUT: {
text: "Autoroute",
strokeColor: "#ff0000", strokeWidth: 3 },
NAT: {
text: "Nationale",
strokeColor:"#ff8c00", strokeWidth: 2 },
REG: {
text: "Régionale - Reg",
strokeColor:"#ff8c00", strokeWidth: 2 },
COL: {
text: "Régionale - Col",
strokeColor:"#ff8c00", strokeWidth: 2 },
ACC: {
text: "Locale - Acc",
strokeColor:"#d2b48c", strokeWidth: 2 },
LOC: {
text: "Locale - Loc",
strokeColor:"#d2b48c", strokeWidth: 2 },
ACH: {
text: "Chemin forestier - Ach",
strokeColor:"#734c00", strokeWidth: 2 },
MRN: {
text:"Chemin forestier - Mrn",
strokeColor:"#734c00", strokeWidth: 2 }
}

// a style will applies to each drawned vector feature depending on
// the ROL_CO_CLA attribute value. It will match the good value and applies
// the corresponding symbolizers
oStyleMap.addUniqueValueRules("default", "ROL_CO_CLA", aRoadType);

// If no rules applies to the current vector feature, that means it's
// not a road, but an other type of feature like a circle for drag
// control. The "elseFilter: true" is used to display those vectors.
var rules = [new OpenLayers.Rule({
symbolizer: {strokeColor:"#FF0000",strokeWidth: 2},
elseFilter: true
})];
oStyleMap.styles["default"].addRules(rules);

============= yourHTMLFile.html =============

--- inside your <head> section ---
<script src="otherfile.js"></script>

--- inside your init() function ---

OpenLayers.Feature.Vector.style['default']['strokeWidth'] = '2';

// then some variables... map definition... base layer ... some WMS 
layers ... and :

olWFSRoads = new OpenLayers.Layer.WFS(
"Roads - WFS", sMSURL,
{ typename: "roads", map: sMapPath },
{ extractAttributes: true, minScale: 49999,
typename: "roads", styleMap: oStyleMap
}
);

// then addlayers, controls, etc. and your <body>

Brenningmeyer, Todd wrote:
> Hello,
> Does anyone have an example code snippet that shows how to use a stylemap 
> with wfs data that is being served as vectors (I'm trying to serve up 
> points).  I've been trying to get this to work using some of the examples on 
> the wiki but I can't quite get the syntax to work properly.  If anyone has 
> ideas or an example that would be great.  
> Thanks,
> Todd
> _______________________________________________
> Users mailing list
> [email protected]
> http://openlayers.org/mailman/listinfo/users
>   


-- 
Alexandre Dubé
Mapgears
www.mapgears.com

_______________________________________________
Users mailing list
[email protected]
http://openlayers.org/mailman/listinfo/users

Reply via email to