The function that I am trying to work on is: click on a feature and change its color. I tried to approach this by first recreating the feature with custom style:

layer.drawFeature(feature, myStyle);

this gave me the desired shape but it was lost after layer redraw.

Then I tried to use a clone of the feature:

layer.drawFeature(feature.clone(), myStyle);

this time the new shape would not disappear but it's not sync with the map, i.e. it does not resize/ move with the map.

I do notice that the following post was about a similar issue. I wonder if there's a way without creating an extra overlay? I could live with the cloned feature thing if that can be put to work.

Openlayers - Losing selection or style on layer redraw

Any suggestions will be greatly appreciated!

1 Answer 1


The drawFeature function does not save the style. The feature is redrawn with the layer style again when the layer is redrawn. You may assign the style to the feature, and drawFeature again. Now when redrawing the feature, the assigned style will be used.

feature.style = myStyle;

Have a look at the drawFeature documentation. It gives more detailed information.

  • That's correct. You have to change style of feature, then call drawFeature to update style on screen. And don't try layer.drawFeature(feature.clone()); Mar 5, 2013 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.