[OpenLayers-Users] Change style only for one feature on a layer

Eric Lemoine eric.c2c at gmail.com
Wed Jul 9 13:01:12 EDT 2008


You can still use the old-style way:

feature.style = { /* your style */};

then call drawFeature. With this the feature style should persist. Eric

2008/7/9, Arnd Wippermann <arnd.wippermann at web.de>:
> This works, but after a redraw the feature are drawn in the style of the
> layer.
>
> Is there a way to preserve the style for the feature?
>
> Arnd
>
> -----Ursprüngliche Nachricht-----
> Von: eric.c2c at gmail.com [mailto:eric.c2c at gmail.com]
> Gesendet: Mittwoch, 9. Juli 2008 10:34
> An: Arnd Wippermann
> Cc: users at openlayers.org
> Betreff: Re: [OpenLayers-Users] Change style only for one feature on a layer
>
> On Tue, Jul 8, 2008 at 11:11 PM, Arnd Wippermann <arnd.wippermann at web.de>
> wrote:
>> Hi,
>>
>> How can I change the style only for a single feature on a layer.
>>
>> Using the below code I change the style for all features on a layer.
>> But I have no clue, how to do this only for one feature. I hope
>> someone can help me.
>>
>> var feature=vlayer.features[vlayer.features.length-1];
>>
>> var obj=feature.layer.styleMap.styles.default.defaultStyle;
>>
>> obj.fillColor=strokeColor;
>> obj.fillOpacity=fillOpacity;
>> obj.strokeColor=strokeColor;
>> obj.pointRadius=pointRadius;
>> obj.strokeWidth=strokeWidth;
>>
>> vlayer.drawFeature(feature);}
>
> vlayer.drawFeature(feature, {
>     'fillColor':
>     'fillOpacity':
>     ...
> });
>
> --
> Eric
>
>


More information about the Users mailing list