[OpenLayers-Users] Changing single vector feature style overwrites other default values

Ian iansgis at gmail.com
Thu Jul 24 20:24:44 EDT 2008


After drawing point features in a vector layer, when a single style
attribute is changed for a point it appears that its default values are
being overwritten. Specifically, if I only change the fillColor of a point
its default values are erased or changed. Example:

var myFeatures = new OpenLayers.Layer.Vector("My Features");

var testPt1 = new OpenLayers.Feature.Vector(new
OpenLayers.Geometry.Point(-118, 35));
var testPt2 = new OpenLayers.Feature.Vector(new
OpenLayers.Geometry.Point(-117, 35));
myFeatures.addFeatures([testPt1,testPt2]);

testPt2.style = {fillColor: 'red'};
myFeatures.drawFeature(testPt2);

Firebug output:
<circle id="OpenLayers.Geometry.Point_145" cx="350.12444444444463" cy="
341.0222222222221" r="0" fill="red" fill-opacity="1" stroke="none"/>
<circle id="OpenLayers.Geometry.Point_143" cx="304.6133333333337" cy="
341.0222222222221" r="6" fill="#ee9900" fill-opacity="0.4" stroke="#ee9900"
stroke-opacity="1" stroke-width="1" stroke-linecap="round" pointer-events="
visiblePainted" cursor=""/>

The pointRadius is changed to 0, the fillOpacity is changed to 1,
strokeColor is changed to "none", and other default attributes are gone
causing the symbol not to display in the map. Trying:

myFeatures.drawFeature(testPt2, {fillColor: 'red'});

gives two identical points with no attributes changed for the second point.
In my actual code I am changing a point's fillColor dynamically when a user
selects it from a list (after the map loading function has completed):

myFeatures.drawFeature(myFeatures.features[key], {fillColor: 'red'});

and like the first example the pointRadius is changed to 0, the fillOpacity
is changed to 1, strokeColor is changed to "none", but unlike the first
example other default values remain as is.

These are three very different outcomes, and the behavior I expected was
that only attributes I explicitly changed would change while all other
default/set values would remain unchanged. If this is a bad assumption on my
part or there is some documentation I've missed please let me know,
otherwise this may be a bug.

Thanks,
Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20080724/e3e9a65e/attachment.html


More information about the Users mailing list