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.
Answer
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:
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()
.
No comments:
Post a Comment