Skip to content

[💰] Add option for PolygonLayer to have fill color around Polygons #2034

@JaffaKetchup

Description

@JaffaKetchup

What is the bug?

When attempting to display a Polygon that is large, it fails to display incorrectly with the new support for unbounded horizontal scrolling. When the polygon has a hole defined, the hole may be shown inverted in some cases, or not at all (culled incorrectly?) in others.

The issue lies in the new projectList method in the CRS.

List<Offset> projectList(List<LatLng> points, {LatLng? referencePoint}) {
late double previousX;
final worldWidth = getWorldWidth();
return List<Offset>.generate(
points.length,
(j) {
if (j == 0 && referencePoint != null) {
(previousX, _) = projectXY(referencePoint);
}
var (x, y) = projectXY(points[j]);
if (j > 0 || referencePoint != null) {
if (x - previousX > worldWidth / 2) {
x -= worldWidth;
} else if (x - previousX < -worldWidth / 2) {
x += worldWidth;
}
}
previousX = x;
return Offset(x, y);
},
growable: false,
);
}
}

(Originally reported in the Discord server: https://discord.com/channels/951867686378409984/1339879842610675794)

How can we reproduce it?

Use a polygon with a defined set of points creating a large area that spans nearly to the edge of the world, with a fill color.

If the Polygon's points are as such, then no polygon appears at all.

points: const [
  LatLng(-90, -180),
  LatLng(90, -180),
  LatLng(90, 180),
  LatLng(-90, 180),
],

If the points are as such, then the issue can be more clearly seen. The fill is applied to the areas between the worlds, outside of the polygon itself.

points: const [
  LatLng(-90, -180),
  LatLng(90, -180),
  LatLng(90, 180),
  LatLng(-90, 180),
],

On adding a hole, for example as so, then it may be shown correctly in some cases, or completely removed in others.

holePointsList: [
  [
    LatLng(51.5, -0.09),
    LatLng(51.5, -1.09),
    LatLng(52.5, -1.09),
    LatLng(52.5, -0.09),
  ]
],

Image

Do you have a potential solution?

No response


Bounty

This issue is eligible for a bounty!

This continues from #1582, and also includes a whole load of other work done since then to improve unbounded horizontal scrolling support.

Bounty Criteria

To be eligible to receive the bounty (as outlined in the meta information below), the solution must:

  • implement a parameter on the PolygonLayer to fill the space outside of any polygon with any color
  • provide the expected result (to be discussed in further detail during implementation) in a wide variety of cases, tested on the example application

The bounty is also awarded via this bounty for a number of other issue resolutions related to unbounded horizontal scrolling support.

Due to circumstances outside of the control of any contributor (bugs within Flutter), the solution does not need to work fully on the web platform.

The decision to award the bounty is entirely at the discretion of the maintainer team.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions