1

Is there a way to render overlapping polygons without holes in multipolygon in Leaflet?

I found Leaflet has an open issue.

codesandbox.io

I am asking because I have a bound polygon that contains inner polygons.

enter image description here

I would need to drag them all together, but it doesn't work in canvas mode. It could work if I can render this as a multipolygon. This is a follow-up question on my previous question and cross-post from SO.

1
  • 2
    A valid simple feature MultiPolygon cannot have overlapping parts. That does not prevent Leaflet from dealing with them. I do not know if it is possible.
    – user30184
    Mar 4, 2021 at 8:16

1 Answer 1

3

I'll just copy-paste my response to Leaflet bug #6173 :


I'm reading the OGC's Simple Feature Access specification (again), to remind myself about the formal definitions of Polygons and MultiPolygons. Let me quote page 31:

6.1.14 MultiPolygon
A MultiPolygon is a MultiSurface whose elements are Polygons.
The assertions for MultiPolygons are as follows.
a) The interiors of 2 Polygons that are elements of a MultiPolygon may not intersect.

Heck, it even comes with pretty pictures: enter image description here So, MultiPolygons which have overlapping members are not valid MultiPolygons. As such, I think Leaflet has no obligation to handle that invalid case.

See also #3763 (comment) (re: fillRule option for SVG renderer).

2
  • Thanks for your answer. I understand that multipolygon with overlapping polygons is not a valid polygon. However, I am wondering if there is a way to deal with that. I tried fillRule: 'nonzero' but it doesn't make any difference codesandbox.io
    – Matt
    Mar 4, 2021 at 13:42
  • 1
    Well, duh, the way to deal to invalid overlapping (multi)polygons is to turn them into valid geometries. Whether that needs a union approach or a difference approach depends on your use case and it's up to you (and not up to Leaflet). Otherwise, this is a case of GIGO. Mar 4, 2021 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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