fleaflet / flutter_map

A versatile mapping package for Flutter. Simple and easy to learn, yet completely customizable and configurable, it's the best choice for mapping in your Flutter app.
https://pub.dev/packages/flutter_map
BSD 3-Clause "New" or "Revised" License
2.68k stars 848 forks source link

[BUG] Alternative polygon renderer in 7.0 renderers multiple holes incorrectly #1899

Closed Elleo closed 4 weeks ago

Elleo commented 1 month ago

What is the bug?

If a polygon contains multiple holes and the useAltRendering property is set on the polygon layer, then the holes are cut out incorrectly (with vertices from different holes seemingly connecting to each other)

Expected output: Screenshot 2024-05-30 123727

Actual output: Screenshot 2024-05-30 123709

How can we reproduce it?

The following code can be used to reproduce this issue:

          FlutterMap(
            options: const MapOptions(
              initialCenter: LatLng(64.025, -1.132),
              initialZoom: 16,
            ),
            children: [
              PolygonLayer(
                useAltRendering: true,
                polygons: [
                  Polygon(
                      points: const [
                        LatLng(64.0283, -1.13083),
                        LatLng(64.0282, -1.130172),
                        LatLng(64.024794, -1.130862),
                        LatLng(64.0247, -1.13126),
                        LatLng(64.0247, -1.13183),
                        LatLng(64.025, -1.13274),
                        LatLng(64.0254, -1.13352),
                        LatLng(64.0259, -1.134093),
                        LatLng(64.027859, -1.135774),
                        LatLng(64.027915, -1.134542),
                        LatLng(64.028168, -1.132229),
                        LatLng(64.028284, -1.131658),
                        LatLng(64.0283, -1.13083)
                      ],
                      holePointsList: const [
                        [
                          LatLng(64.026675, -1.133183),
                          LatLng(64.026601, -1.133234),
                          LatLng(64.026534, -1.133158),
                          LatLng(64.026534, -1.13302),
                          LatLng(64.026601, -1.132944),
                          LatLng(64.026688, -1.13303),
                          LatLng(64.026675, -1.133183)
                        ],
                        [
                          LatLng(64.026226, -1.134005),
                          LatLng(64.0262, -1.134068),
                          LatLng(64.026149, -1.134059),
                          LatLng(64.02616, -1.133918),
                          LatLng(64.026211, -1.133933),
                          LatLng(64.026226, -1.134005)
                        ],
                        [
                          LatLng(64.025838, -1.13236),
                          LatLng(64.02578, -1.132496),
                          LatLng(64.025723, -1.132513),
                          LatLng(64.025669, -1.132476),
                          LatLng(64.025631, -1.132298),
                          LatLng(64.025695, -1.132169),
                          LatLng(64.025752, -1.132159),
                          LatLng(64.025804, -1.132202),
                          LatLng(64.025838, -1.13236)
                        ]
                      ],
                      label: "No 3",
                      color: Colors.lightBlue.withOpacity(0.5),
                      borderColor: Colors.lightBlue,
                      borderStrokeWidth: 1),
                ],
              ),
            ],
          ),

Do you have a potential solution?

No response

Platforms

Windows 11, iOS 17

Severity

Obtrusive: Prevents normal functioning but causes no errors in the console

JaffaKetchup commented 1 month ago

It's probably misinterpreting the output of dart_earcut, or maybe the code in dart_earcut is wrong. But more likely is the first one, as I had a hard time understanding the output myself (despite it being me that ported that library!).

JaffaKetchup commented 1 month ago

It probably starts at this line, which then throws the whole triangulation off:

https://github.com/fleaflet/flutter_map/blob/b69a0d7cc0997c36e4ae501b37c402345501f359/lib/src/layer/polygon_layer/polygon_layer.dart#L177-L180

I knew there would be issues when I wrote it, but none of my test cases included multiple holes!