Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
up vote 1 down vote accepted

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. = myStyle;

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

share|improve this answer
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()); – user1702401 Mar 5 '13 at 7:27
works like a champ, thanks! – user2106432 Mar 5 '13 at 17:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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