Using a polygon id, I want to highlight a polygon, while the mouse is outside of the map area. I can identify the polygon using the following approach:

x = 53;
for(i=0; i<vector_layer.features.length; i++){
        y = vector_layer.features[i].attributes.id
        if(x == y){
            vector_layer.features[i].style = ??

However, I can't figure out how to highlight the polygon even though I know which one it is. I have previously defined a style for when the mouse hovers over the polygon and it is selected, but I don't know how to apply this style to the chosen polygon.

  • how are you planning to select the polygon ID ? – Glenn Plas Nov 9 '12 at 22:53
  • In this case, I know what the polygon id is through user selection, outside of the map. – djq Nov 10 '12 at 0:33
  • 2
    check this link out: stackoverflow.com/questions/8832029/… – Glenn Plas Nov 10 '12 at 2:40
  • 1
    Thanks @GlennPlas - that link pointed out that selection can be done using selectFeature.select(this.vlayer.features[i]); when selectFeature is defined as a control. Not sure if you can move your comment to answer, but I could mark as the answer if so. – djq Nov 12 '12 at 22:30
  • It will be a short answer, but It's good to be able to close a question, GIS has a lower answer rate than SO. – Glenn Plas Nov 13 '12 at 7:56

The possible solution to this problem can be extracted from this SO entry. That link points out that selection can be done using:


when selectFeature is defined as a control.


There is no problem with your code but you have to redraw your layer after changing its style. Put this line into your loop:


i hope it helps you...

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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