Skip to content
Advertisement

SVG path with stroke fills the svg element

I have a set of coordinates that can be used to create a polygon in google maps. I used the mercantor-projection formula described in this answer to convert it into a set of points (x,y) that can be used in an svg . The conversion was successful and it was rendered properly.

The snippet below renders well without the setting the stroke property in the element. If you un-comment line 29 where it sets the stroke property to red, it will fill up the entire svg element instead of outlining the element with red which highlights the main problem of this post.

JavaScript
JavaScript

Why does setting the stroke property fills the SVG element with the specified stroke color?

It would be great if anyone can point out how to solve the problem of the snippet above.

Advertisement

Answer

The problem is related to the scaling of your SVG. Setting the stroke width to a small value like 0.0025 fixes it.

JavaScript
JavaScript
Advertisement