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

Eric Lemoine eric.c2c at gmail.com
Fri Jul 25 01:31:51 EDT 2008


Hi. Try passing this to drawFeature:

OpenLayers.Util.ApplyDefaults({'fillColor': 'red'},
OpenLayers.Feature.Vector.style['default']);

What you could do is define your own 'select' renderIntent at the
layer level and pass that render intent to drawFeature when you're to
highlight a feature:

layer.drawFeature(feature, 'select');

Hope this helps,

Eric

2008/7/25, Ian <iansgis at gmail.com>:
> 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
>



More information about the Users mailing list