How can I render a doughnut polygon?

1,054 views
Skip to first unread message

Tord Axelsson

unread,
Dec 13, 2012, 4:41:44 AM12/13/12
to leafl...@googlegroups.com
Hi,

Is it possible to render a polygon with holes in it?
I have a big multipolygon with holes i want to cut out.
I tried rendering a MultiPolygon with the input of a array of an array of latlngs.
But they just end up over each other, I even tried the way google does it by changing the orientation order for the "hole" polygons.

Does any one have a solution to my problem?

Regards,
Tord

Eric Theise

unread,
Dec 14, 2012, 8:54:29 PM12/14/12
to leafl...@googlegroups.com
Hi Tord,

I took your question as an excuse to devote some time to jsFiddle,
thank you. You can visit "Leaflet: Simple GeoJSON MultiPolygons
(Square Donut & Swiss Cheese)" at
http://jsfiddle.net/erictheise/VaGy5/

Clearly what you want to do is possible, it just sounds to me as if
you aren't correctly nesting your arrays. One of the benefits of
GeoJSON is that it helps to show the structure of features more
clearly; you might also want to look at the resources I mention in the
fiddle, the GeoJSON spec (http://geojson.org/geojson-spec.html) and
the Wikipedia page about WKT
(http://en.wikipedia.org/wiki/Well-known_text).

(Bu a drawback of GeoJSON is that it orders things x,y (LngLat),
whereas Leaflet orders things LatLng, so the coordinate order in the
GeoJSON is opposite that of the map constructor. Confusing.)

Hope that helps some.

--Eric

Tord Axelsson

unread,
Dec 17, 2012, 1:40:54 AM12/17/12
to leafl...@googlegroups.com
Okej, thank you for your reply. I have a look at GeoJSON...

// Tord

Andrew Thomas

unread,
Jul 1, 2013, 7:30:37 PM7/1/13
to leafl...@googlegroups.com
Any thoughts on how to create a donut circle?

There are several directions I could head if there isn't a way using existing functions:

1. Create inner and outer Polygons that are nearly round. I guess the best way would be to write a function that takes centre coordinates and a radius and returns an array of perimeter lat longs. Or is there a way I can generate the array from a Circle object?

2. Canvas?

3. Write a Custom shape that extends existing shapes

4. Use a super wide stroke width. As weight is in pixel widths, it would need to be dynamic and change width based on zoom level.

5. ??

Cheers

Andrew
Reply all
Reply to author
Forward
0 new messages