Try to apply a stylemap to your vector layer.<div><div><br></div><div>// Creation of a stylemap</div></div><div><div>myStyles&nbsp;= new OpenLayers.StyleMap({</div><div>&nbsp;&nbsp; &nbsp; &nbsp; "default": new OpenLayers.Style({</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strokeColor: "${getFillColor}",</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fillColor: "${getFillColor}",</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strokeWidth: 2,</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strokeOpacity: 1,</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fillOpacity: 0.7,</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pointRadius: 5</div><div>&nbsp;&nbsp; &nbsp; &nbsp; },{</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; context: {</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getFillColor:function(feature) {</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (feature.attributes.state == true)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return '#00FF00';</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else if (feature.attributes.state == false)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return '#FF0000';</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; })</div><div>&nbsp;&nbsp; &nbsp; &nbsp; ,"select": new OpenLayers.Style({</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fillColor: "#00000FF",</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strokeColor: "#0000FF",</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pointRadius: 6</div><div>&nbsp;&nbsp; &nbsp; &nbsp; }),</div><div>&nbsp;&nbsp; &nbsp; &nbsp; "hover": new OpenLayers.Style({</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fillColor: "#CCCCCC",</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strokeColor: "#999999",</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pointRadius: 6</div><div>&nbsp;&nbsp; &nbsp; &nbsp; })</div><div>&nbsp;&nbsp; });</div><div><br></div><div><div>// Create a vector layer and give it your style map.</div><div>var points = new OpenLayers.Layer.Vector(</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'Points', {styleMap: myStyles}</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;);</div><div><br></div><div>if you still have problems, please send you script, i'll try to debug</div><div><br></div><div>Jérome</div><div><br></div><div><br></div></div><div><div>Le 1 sept. 09 à 15:48, AlessioDL (via Nabble) a écrit :</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi Jerome, &nbsp; <br><br>probably I don't understood exactly how to apply your suggestion... <br><br>If I use "new OpenLayers.Style" I can't apply any style to my features. <br>The only way to style them appear to be: <br>OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']) <br><br>So I need to do something like <br><br>//Vector layer style <br>var area_style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']); <br><br>if (feature.attributes.myattribute == 'myvalue') { <br>&nbsp; &nbsp; &nbsp;area_style.strokeWidth = 1.5; <br>&nbsp; &nbsp; &nbsp;area_style.strokeColor = "#ff0000"; <br>&nbsp; &nbsp; &nbsp;area_style.fillOpacity = 0.75; <br>} else { <br>... <br>} <br><br>but it does not work (feature is undefined)... </blockquote></div><br></div>
<br><hr align="left" width="300">
View this message in context: <a href="http://n2.nabble.com/Style-WFS-layer-by-attributes-tp3559456p3560660.html">Re: [OpenLayers-Users] Style WFS layer by attributes</a><br>
Sent from the <a href="http://n2.nabble.com/OpenLayers-Users-f1822463.html">OpenLayers Users mailing list archive</a> at Nabble.com.<br>