[BUG] Polygon holes working incorrect in case of intersection and out of polygon coordinates
Sid775 opened this issue · comments
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.
![useAltRendering](https://private-user-images.githubusercontent.com/15926893/341160331-d85ff06a-04c0-4d8c-a32c-9d3b0762ed90.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE4NzAzNjUsIm5iZiI6MTcyMTg3MDA2NSwicGF0aCI6Ii8xNTkyNjg5My8zNDExNjAzMzEtZDg1ZmYwNmEtMDRjMC00ZDhjLWEzMmMtOWQzYjA3NjJlZDkwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzI1VDAxMTQyNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWY2MDFjMzg4NjM5OTcwNWY4MGM2MDhiNTk1ODA3MjY2MzkxOGMwNWVmY2NlOTk3MWNmY2U5ODM0NWJlMTJiOGImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.MAyaJWOmhYAr4NX3pocf56rP8hGvHv6edRvMv1clF6A)
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
]
]