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

I'm loading a geojson file into openlayers to show some polygons. From this file I also create a list of all names of these polygons.

Now I want to change the color of a polygon when selected from the list (clicked on the name).

What I've tried is to create a style ( but I couldn't find out how to add this style to the polygon. How can I do that?

share|improve this question

You may just to create a style symbolizer hash set and assign it to your selected polygon before adding it to the layer:

var selected_polygon_style = {
    strokeWidth: 5,
    strokeColor: '#ff0000'
    // add more styling key/value pairs as your need
}; = selected_polygon_style;

At this page ( you can find much information about the style properties you can modify:

  • fillColor
  • fillOpacity
  • strokeColor
  • strokeOpacity
  • strokeWidth
  • strokeLinecap
  • strokeDashstyle
  • ...
share|improve this answer
But what if it's already on the layer? I found this solution : mylayer.drawFeature(mylayer.getFeatureById(id), {fillColor: "#00ffff", strokeColor: "#00ffff"}); – jlai79 Jan 28 '13 at 19:58
yes, you are right, you just redraw it with new style. – mfdev Jan 29 '13 at 7:13

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.