flutter_map icon indicating copy to clipboard operation
flutter_map copied to clipboard

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

Open JosefWN opened this issue 3 years ago • 7 comments

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

  • [X] I agree to follow this project's Code of Conduct
  • [X] My Flutter/Dart installation is unaltered, and flutter doctor finds no relevant issues
  • [X] I am using the latest stable version of this package
  • [X] I have checked the FAQs section on the documentation website
  • [X] I have checked for similar issues which may be duplicates

JosefWN avatar Aug 27 '22 04:08 JosefWN

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

JaffaKetchup avatar Aug 27 '22 05:08 JaffaKetchup

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.

JosefWN avatar Aug 29 '22 12:08 JosefWN

(preventing staleness from setting in)

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

JaffaKetchup avatar Sep 22 '22 20:09 JaffaKetchup

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] avatar Oct 23 '22 02:10 github-actions[bot]

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] avatar Nov 23 '22 02:11 github-actions[bot]

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] avatar Dec 24 '22 01:12 github-actions[bot]

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

github-actions[bot] avatar Dec 29 '22 01:12 github-actions[bot]