Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Polygon holes working incorrect in case of intersection and out of polygon coordinates #1917

Closed
Sid775 opened this issue Jun 19, 2024 · 6 comments
Labels
bug This issue reports broken functionality or another error P: 3 (low) (Default priority for feature requests) S: core Scoped to the core flutter_map functionality

Comments

@Sid775
Copy link

Sid775 commented Jun 19, 2024

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.
case one
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.
case two

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
@Sid775 Sid775 added bug This issue reports broken functionality or another error needs triage This new bug report needs reproducing and prioritizing labels Jun 19, 2024
@JaffaKetchup
Copy link
Member

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).

@Sid775
Copy link
Author

Sid775 commented Jun 19, 2024

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 one
Case two:
case two

Also, on version 7.0.1 same code does not render holes at all:
701

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

@JaffaKetchup
Copy link
Member

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?

@Sid775
Copy link
Author

Sid775 commented Jun 19, 2024

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:
reversed sequence
Opacity still not affects anything

@JaffaKetchup
Copy link
Member

Requires reverification on v7.0.2. May be fixed by #1925.

@JaffaKetchup
Copy link
Member

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.

@JaffaKetchup JaffaKetchup added P: 3 (low) (Default priority for feature requests) S: core Scoped to the core flutter_map functionality and removed needs triage This new bug report needs reproducing and prioritizing labels Aug 7, 2024
@JaffaKetchup JaffaKetchup closed this as not planned Won't fix, can't repro, duplicate, stale Sep 29, 2024
@github-project-automation github-project-automation bot moved this from To do to Done in Development Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue reports broken functionality or another error P: 3 (low) (Default priority for feature requests) S: core Scoped to the core flutter_map functionality
Projects
Archived in project
Development

No branches or pull requests

2 participants