flutter_map
flutter_map copied to clipboard
[BUG] Polygon holes working incorrect in case of intersection and out of polygon coordinates
What is the bug?
My case is polygon with a lot of holes, it two corner case that I found, based on same problem in code, I believe, please correct me if I'm wrong and it working as designed.
First case: is when I try to make hole in polygon but coordinates of this hole places outside of polygon. I expect that hole in this case will be ignored but it appears part of polygon there.
Second case: is when I try to make holes in polygon that overlaps. I expect that holes will not affect each other or will merge but second hole create part of polygon in first hole.
How can we reproduce it?
To reproduce First case:
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Map Screen'),
),
body: FlutterMap(
mapController: _mapController,
options: const MapOptions(
initialCenter: LatLng(51.028614, 4.480293),
),
children: [
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'com.example.flutter_map_example',
),
PolygonLayer(polygons: _polygonsToReproduce()),
],
),
);
}
_polygonsToReproduce() {
return [
Polygon(points: [
LatLng(51.033747, 4.463339),
LatLng(51.034415, 4.499677),
LatLng(51.017839, 4.502306),
LatLng(51.017736, 4.467479)
],
color: Colors.black38,
isFilled: true,
holePointsList: [[
LatLng(51.037110, 4.474967),
LatLng(51.037173, 4.479665),
LatLng(51.035156, 4.479965),
LatLng(51.035156, 4.475367),
]]
)
];
}
To reproduce Second case:
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Map Screen'),
),
body: FlutterMap(
mapController: _mapController,
options: const MapOptions(
initialCenter: LatLng(51.028614, 4.480293),
),
children: [
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'com.example.flutter_map_example',
),
PolygonLayer(polygons: _polygonsToReproduce()),
],
),
);
}
_polygonsToReproduce() {
return [
Polygon(
points: [
LatLng(51.033747, 4.463339),
LatLng(51.034415, 4.499677),
LatLng(51.017839, 4.502306),
LatLng(51.017736, 4.467479)
],
color: Colors.black38,
isFilled: true,
holePointsList: [
[
LatLng(51.028643, 4.478061),
LatLng(51.028613, 4.483917),
LatLng(51.024223, 4.483965),
LatLng(51.024254, 4.477917),
],
[
LatLng(51.025434, 4.474413),
LatLng(51.025404, 4.482141),
LatLng(51.023103, 4.482717),
LatLng(51.023224, 4.477485),
]
])
];
}```
### Do you have a potential solution?
_No response_
### Platforms
iOS (Iphone 14 pro emulator)
### Severity
Obtrusive: Prevents normal functioning but causes no errors in the console
Hi @Sid775, Thanks for the report! It would be great if you could confirm whether v7 (pinned, not v7.0.1) has the desired behaviour, and whether opacity affects the result (on v7.0.1 and v7).
Hi @JaffaKetchup,
Thanks for fast response!
Pinned version 7.0.0 like this: flutter_map: 7.0.0 and tried both cases.
Pretty the same picture.
Opacity Is not affects it, pretty the same problems.
Case one:
Case two:
Also, on version 7.0.1 same code does not render holes at all:
It's only help to use parameter useAltRendering, then in first case "hole" outside of polygon(first case) disappears, but, hole inside polygon (second case) is strange. I think it's related to issue #1899.
Thanks for testing! I believe the reason holes aren't shown in v7.0.1 is because it requires the points to be in a certain winding direction. Can you try reversing the hole points?
You are right, changing sequence of coordinates to this:
holePointsList: [
[
LatLng(51.024223, 4.483965), //3
LatLng(51.028613, 4.483917), //2
LatLng(51.028643, 4.478061), //1
LatLng(51.024254, 4.477917), //4
],
[
LatLng(51.023103, 4.482717), //3
LatLng(51.025404, 4.482141), //2
LatLng(51.025434, 4.474413), //1
LatLng(51.023224, 4.477485), //4
]
]
but result the same:
Opacity still not affects anything
Requires reverification on v7.0.2. May be fixed by #1925.
I believe this could be considered the correct behaviour, however it is not well documented and a little unexpected. However, there could be considered a bug in that the alternative renderer does not handle this in the same way: it gives results closer to what you were expecting.
If you need to manipulate polygons to merge them toegther, which should avoid holes cutting into each other, you can try using polybool.
For now, I'm going to mark this as low priority.