[OpenLayers-Users] Change style of particular feature

Andreas Hocevar ahocevar at opengeo.org
Mon Nov 21 04:41:21 EST 2011


If you want to set a symbolizer on a feature directly, don't give it
an OpenLayers.Style instance, but a symbolizer object literal, like
so:

layer.features[1].style.fillColor = "#DFDFFF";
layer.redraw();

Style instances are for use in StyleMap. And yes, this is awkward, and
if there wasn't KML which sets styles on features directly,
feature.style would be deprecated.

The modern way to do what you want to achieve here would be a Style
with a FeatureID filter in the layer's StyleMap.

Andreas.

On Mon, Nov 21, 2011 at 3:19 AM, Denis Rykov <rykovd at gmail.com> wrote:
> Could anyone explain one confusing things.
> I want to change style of particular one of many features in the layer.
>
> Why this syntax works:
>
> layer.features[1].style = new OpenLayers.Style();
> layer.features[1].style.fillColor = "#DFDFFF";
> layer.redraw();
>
> But this no give expected result:
>
> layer.features[1].style = new OpenLayers.Style({fillColor: "#DFDFFF"});
> layer.redraw();
>
> Thanks!
>
>
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
>



-- 
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.


More information about the Users mailing list