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

fix: 1338 - longitude +-180 with correct polylines and polygons #1969

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

monsieurtanuki
Copy link
Contributor

@monsieurtanuki monsieurtanuki commented Sep 22, 2024

What

  • This PR deals with polylines and polygons (with or without holes) across longitudes +-180 (cf. [BUG] Crossing W/E Extremity With Polyline Results In Unexpected Lines #1338)
  • The main issue was that longitudes -179 and 179 were projected in opposite sides of the world, although they are geographically nearby.
  • The solution is to build incrementally the list of projected points: if two consecutive projected points are obviously too far away (more than half a world away), we add/remove one world width to the latter point.
  • Doing so, we avoid jumping around -180 and +180, and we ensure the continuity among the points.
  • The PR doesn't deal with the "teleportation" effect. This will be done in another PR, once we're confident with that "add/remove a world width" strategy.

Screenshots

Polyline: before / after
Screenshot_1727023511
Screenshot_1727023556
Polygon with hole: before / after
Screenshot_1727023664
Screenshot_1727023641

Impacted files

  • crs.dart: new methods getHalfWorldWidth and projectList
  • painter.dart: refactored using pre-computed List<Double>
  • polygon.dart: added an example around longitude 180
  • polyline.dart: added an example around longitude 180
  • polyline_layer.dart: we don't cull polylines that go beyond longitude 180
  • projected_polygon.dart: using new method Projection.projectList
  • projected_polyline.dart: using new method Projection.projectList

monsieurtanuki and others added 3 commits September 22, 2024 18:51
Impacted files
* `crs.dart`: new methods `getHalfWorldWidth` and `projectList`
* `painter.dart`: refactored using pre-computed `List<Double>`
* `polygon.dart`: added an example around longitude 180
* `polyline.dart`: added an example around longitude 180
* `polyline_layer.dart`: we don't cull polylines that go beyond longitude 180
* `projected_polygon.dart`: using new method `Projection.projectList`
* `projected_polyline.dart`: using new method `Projection.projectList`
Copy link
Contributor

@josxha josxha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pull request @monsieurtanuki! I did some quick testing and your added examples work like intended (thanks for adding them).

Some additional thoughts:
The main use case of line wrapping are paths that cross the -180/180 longitude for example when we want to display flights. We need to figure out a solution when the user follows a polyline or polygon accross the world border. Currently the line suddenly disapears. This, of course, is not in scope for this this pull request. (:

line.wrapping.mp4

);

/// Returns true if the points stretch on different versions of the world.
bool goesBeyondTheUniverse(double halfWorldWidth) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As much as I like this name, a declarative name would be more understandable in the future. 😄

@monsieurtanuki
Copy link
Contributor Author

Some additional thoughts: The main use case of line wrapping are paths that cross the -180/180 longitude for example when we want to display flights. We need to figure out a solution when the user follows a polyline or polygon accross the world border. Currently the line suddenly disapears. This, of course, is not in scope for this this pull request. (:

Oh it's a bug then! Probably related to the "teleportation" issue.
I'll have a look at it, and I may fix that in the current PR.
I keep you posted.

@josxha
Copy link
Contributor

josxha commented Sep 27, 2024

Oh it's a bug then! Probably related to the "teleportation" issue.
I'll have a look at it, and I may fix that in the current PR.

I actually don't think it's an bug. The line just moves to the new world that comes into center. So the line is still active but basically on the other side of the world. If you plan to look into this as well how it can get improved that's awesome of couse. (:

@monsieurtanuki
Copy link
Contributor Author

@josxha Your description is correct: it's the "teleportation" issue (I can see a unique polyline jumping from world to world on the same zoom 0 map) but when the zoom is high - the "other" world is not visible.

I still think it's a bug, probably not a new bug, but a fair user expectation is to see at least one polyline.

Working on it. The current PR is relatively small (7 files changed), so I'll see how review-able it would become when including that bug fix.

Impacted files:
* `offsets.dart`: new method `getAddedWorldWidth`, used to add/subtract a world width in order to display visible polylines
* `painter.dart`: minor fix, as now we may unproject coordinates from the wrong world
@monsieurtanuki
Copy link
Contributor Author

@josxha Fixed! One visible copy of the polyline, with a small or a large zoom.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

2 participants