Hi all,<br><br>I have a Vector layer being initialized with a default style. I am then adding new vector features (Points) dynamically via Ajax calls and GeoJSON data.<br><br>Anyway, if I try to apply a non-default style to a Point dynamically using something similar to this code:<br>
<br>{{{<br> /* init code */<br><br> var defaultStyle = new OpenLayers.Style({<br> pointRadius: "${radius}",<br> fillColor: "#00ddff",<br> fillOpacity: 1,<br>
strokeColor: "#008899",<br> strokeWidth: 1,<br> strokeOpacity: 1,<br> }, {<br> context: {<br> radius: function(feature) {<br> var pix = 3;<br>
if (feature.cluster) {<br> pix = Math.min(feature.attributes.count, 5);<br> }<br> return pix;<br> },<br> width: function(feature) {<br>
return (feature.cluster) ? 3 : 1;<br> }<br> }<br> })<br><br> var layer = new OpenLayers.Layer.Vector("the name", {<br> strategies: strat, // Cluster, Fixed<br>
protocol: new OpenLayers.Protocol.HTTP({<br> url: data.url, // the URL<br> format: frmt // GeoJSON<br> }),<br> projection: new OpenLayers.Projection('EPSG:4326'),<br>
styleMap: new OpenLayers.StyleMap({<br> "default": defaultStyle,<br> "select": {<br> fillColor: "#8aeeef",<br> strokeColor: "#32a8a9"<br>
}<br> })<br> })<br><br> map.addLayer(layer); // ==> map.layers[2]<br><br> /* problem code */<br><br> // map.layers[2].features[0] is the first point (in thousands of points) in this layer<br>
map.layers[2].features[0].style = new OpenLayers.Style({<br> pointRadius: "${radius}",<br> fillColor: "#7766ff",<br> fillOpacity: 1,<br> strokeColor: "#2222ff",<br>
strokeWidth: 1,<br> strokeOpacity: 1<br> }, {<br> context: {<br> radius: function(feature) {<br> var pix = 3;<br> if (feature.cluster) {<br>
pix = Math.min(feature.attributes.count, 5);<br> }<br> return pix;<br> },<br> width: function(feature) {<br> return (feature.cluster) ? 3 : 1;<br>
}<br> }<br> });<br>}}}<br><br>the Point in this layer disappears. What I want to do is change the style to anything I want.<br><br>I must be missing something or misunderstanding how styles are applied in OpenLayers. Thanks in advance for any and all help. I really appreciate it.<br clear="all">
<br>-- <br>Jonathan Sawyer<br>Geographic Information Network of Alaska (GINA)<br>University of Alaska Fairbanks<br>