Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
add comment

1 Answer 1

up vote 11 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:

DEMO

enter image description here

DEMO LINK

Code Example:

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

var mySecondLineStyle = OpenLayers.Util.applyDefaults(mySecondLineStyle, OpenLayers.Feature.Vector.style['default']);
mySecondLineStyle.strokeColor = "#000000";
mySecondLineStyle.strokeWidth = 4;
secondFeature.style = 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
add comment

protected by whuber Sep 4 '12 at 11:29

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

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.