Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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 want to display multiple polylines with different colors in openlayers. Can any one guide me regarding this.

I have done this in google maps. but i don't know how to do it in openlayers. I am newbie to Openlayers.

enter image description here

share|improve this question
up vote 13 down vote accepted

Every feature has a style property which is null by default because it inherits the parent vector layer's style. But you can set the style for each feature:


enter image description here


Code Example:

var myFirstLineStyle = OpenLayers.Util.applyDefaults(myFirstLineStyle,['default']);
myFirstLineStyle.strokeColor = "#ffffff";
myFirstLineStyle.strokeWidth = 8; = myFirstLineStyle;

var mySecondLineStyle = OpenLayers.Util.applyDefaults(mySecondLineStyle,['default']);
mySecondLineStyle.strokeColor = "#000000";
mySecondLineStyle.strokeWidth = 4; = mySecondLineStyle;

If you change the styles of the features after they've been added to the layer you must call layer.redraw().

More on Styling

share|improve this answer
working like a charm... – Ramesh Kotha Mar 14 '12 at 15:36
i have updated my question with image can u look into it and guide me according to that. – Ramesh Kotha Mar 14 '12 at 18:41
I don't see a question. Regardless, i would recommend you post a separate question and reference this one if you like. Changing questions after they have been answered and dragging them on is not good etiquette. I'll be happy to help, just post a new question and revert this one back to how it was. – CaptDragon Mar 14 '12 at 18:47

protected by whuber Sep 4 '12 at 11:29

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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