fleaflet / flutter_map

A versatile mapping package for Flutter. Simple and easy to learn, yet completely customizable and configurable, it's the best choice for mapping in your Flutter app.
https://pub.dev/packages/flutter_map
BSD 3-Clause "New" or "Revised" License
2.77k stars 862 forks source link

[BUG] Double bounding boxes in `OverlayImageLayer` cause incorrect size #1347

Open JosefWN opened 2 years ago

JosefWN commented 2 years ago

What is the bug?

I have discovered a couple of edge cases where having a bounding box:

class OverlayImage extends BaseOverlayImage {
  final LatLngBounds bounds;
  // ...

... in addition to the bounding box I added to support polar projections:

Positioned buildPositionedForOverlay(FlutterMapState map) {
  // northWest is not necessarily upperLeft depending on projection
  final bounds = Bounds<num>(
    map.project(this.bounds.northWest) - map.pixelOrigin,
    map.project(this.bounds.southEast) - map.pixelOrigin,
  );
  // ...

... will create a bounding box of incorrect size / incorrect position. Not way off, but noticeably.

What is the expected behaviour?

Image positioning issues should not occur.

How can we reproduce this issue?

Trying the EPSG:3413 example reprojected in EPSG:3996

Do you have a potential solution?

In my fork I solved this by changing bounds to a List<LatLng>. This would be a breaking API change. Should I make a PR for 3.0.0?

Can you provide any other information?

No response

Platforms Affected

MacOS

Severity

Obtrusive: Prevents normal functioning but causes no errors in the console

Frequency

Consistently: Always occurs at the same time and location

Requirements

JaffaKetchup commented 2 years ago

Hi @JosefWN, Can you try using the LatLngBounds.fromPoints constructor, and see if that makes a difference?

JosefWN commented 2 years ago

Same problem. Here is a minimal snippet (EPSG:3996) reproducing it:

final topLeft = LatLng(74.60299799700462, -170.9997690385578);
final bottomRight = LatLng(77.77365255354441, 91.91349368273093);

final bounds = LatLngBounds(topLeft, bottomRight);
final projBounds1 = Bounds<num>(
  map.project(bounds.northWest) - map.pixelOrigin,
  map.project(bounds.southEast) - map.pixelOrigin,
);

final projBounds2 = Bounds<num>(
  map.project(topLeft) - map.pixelOrigin,
  map.project(bottomRight) - map.pixelOrigin,
);

final bounds2 = LatLngBounds.fromPoints([topLeft, bottomRight]);
final projBounds3 = Bounds<num>(
  map.project(bounds2.northWest) - map.pixelOrigin,
  map.project(bounds2.southEast) - map.pixelOrigin,
);

print('projBounds1 (current):');
print('topLeft: ${projBounds1.topLeft}');
print('bottomRight: ${projBounds1.bottomRight}');

print('topLeft: ${map.unproject(projBounds1.topLeft + map.pixelOrigin)}');
print('bottomRight: ${map.unproject(projBounds1.bottomRight + map.pixelOrigin)}');

print('projBounds2 (proposed):');
print('topLeft: ${projBounds2.topLeft}');
print('bottomRight: ${projBounds2.bottomRight}');

print('topLeft: ${map.unproject(projBounds2.topLeft + map.pixelOrigin)}');
print('bottomRight: ${map.unproject(projBounds2.bottomRight + map.pixelOrigin)}');

print('projBounds3 (LatLngBounds.fromPoints):');
print('topLeft: ${projBounds3.topLeft}');
print('bottomRight: ${projBounds3.bottomRight}');

print('topLeft: ${map.unproject(projBounds3.topLeft + map.pixelOrigin)}');
print('bottomRight: ${map.unproject(projBounds3.bottomRight + map.pixelOrigin)}');

This returns:

[        ] flutter: projBounds1 (current):
[        ] flutter: topLeft: CustomPoint (588.0229903084105, -381.9199091615926)
[        ] flutter: bottomRight: CustomPoint (1781.8419762539538, 414.2663707511856)
[        ] flutter: topLeft: LatLng(latitude:77.773653, longitude:-170.999769)
[        ] flutter: bottomRight: LatLng(latitude:74.602998, longitude:91.913494)
[        ] flutter: projBounds2 (proposed):
[        ] flutter: topLeft: CustomPoint (553.5052798486024, -599.8504701739987)
[        ] flutter: bottomRight: CustomPoint (1561.317779848603, 421.633904826002)
[        ] flutter: topLeft: LatLng(latitude:74.602998, longitude:-170.999769)
[        ] flutter: bottomRight: LatLng(latitude:77.773653, longitude:91.913494)
[        ] flutter: projBounds3 (LatLngBounds.fromPoints):
[        ] flutter: topLeft: CustomPoint (588.0229903084105, -381.9199091615926)
[        ] flutter: bottomRight: CustomPoint (1781.8419762539538, 414.2663707511856)
[        ] flutter: topLeft: LatLng(latitude:77.773653, longitude:-170.999769)
[        ] flutter: bottomRight: LatLng(latitude:74.602998, longitude:91.913494)

It seems some corner coordinates are swapped around in the assumption that topLeft is southWest and bottomRight is northEast.

JaffaKetchup commented 2 years ago

(preventing staleness from setting in)

Thanks, we'll have a look at this when we get a moment.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 1 year ago

This issue was closed because it has been stalled for 5 days with no activity.