Try to apply a stylemap to your vector layer.<div><div><br></div><div>// Creation of a stylemap</div></div><div><div>myStyles = new OpenLayers.StyleMap({</div><div> "default": new OpenLayers.Style({</div><div> strokeColor: "${getFillColor}",</div><div> fillColor: "${getFillColor}",</div><div> strokeWidth: 2,</div><div> strokeOpacity: 1,</div><div> fillOpacity: 0.7,</div><div> pointRadius: 5</div><div> },{</div><div> context: {</div><div> getFillColor:function(feature) {</div><div> if (feature.attributes.state == true)</div><div> return '#00FF00';</div><div> else if (feature.attributes.state == false)</div><div> return '#FF0000';</div><div> }</div><div> } </div><div> })</div><div> ,"select": new OpenLayers.Style({</div><div> fillColor: "#00000FF",</div><div> strokeColor: "#0000FF",</div><div> pointRadius: 6</div><div> }),</div><div> "hover": new OpenLayers.Style({</div><div> fillColor: "#CCCCCC",</div><div> strokeColor: "#999999",</div><div> pointRadius: 6</div><div> })</div><div> });</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> 'Points', {styleMap: myStyles}</div><div> );</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, <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> area_style.strokeWidth = 1.5; <br> area_style.strokeColor = "#ff0000"; <br> 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>