How to make a halo around the line of one pixel using OpenLayers?

For example, the line (vector) has a blue color and its frame (one pixel) has a black color.

1 Answer 1


Use strokeWidth : 1 and strokeColor: '#000000' on the vector's style

Actually, after testing what I said, turns out it's not that simple.

Looks like lines don't use the fill property at all and instead only use stroke.

So the only way I was able to do it was by cloning the feature and modifying the style. So you have 2 features.

Here's the DEMO Demo LINK UPDATE

enter image description here

  • In demo i see 2 lines: black and white, without halo. I have an idea: draw two times the same line, only the second line will be slightly thicker than the first and will have a different color.
    – dedoki
    Jul 20, 2012 at 21:15
  • For fixing proposed example use the same geometry definition for both lines.
    – drnextgis
    Jul 21, 2012 at 16:47
  • Sorry, I put in the wrong DEMO link. Just updated it which should reflect what both of you (dedoki and drnextgis) are saying.
    – CaptDragon
    Jul 23, 2012 at 12:44
  • In terms of web map cartography, this has generally been the route used by the most popular engines. I remember using this technique when styling maps in Tilemill which uses Carto. Jul 23, 2012 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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