Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

LatLngBounds of visible region incorrect when map rotated #12135

Closed
kjkrum opened this issue Jun 13, 2018 · 3 comments · Fixed by #12255
Closed

LatLngBounds of visible region incorrect when map rotated #12135

kjkrum opened this issue Jun 13, 2018 · 3 comments · Fixed by #12255
Labels
Android Mapbox Maps SDK for Android

Comments

@kjkrum
Copy link

kjkrum commented Jun 13, 2018

MapboxMap.getProjection().getVisibleRegion().latLngBounds is wildly incorrect when the map is rotated past a certain angle. The angle at which the calculation goes off the rails is the angle of the diagonal of the MapView.

To demonstrate this, in my camera idle listener, I get the LatLngBounds as above and draw a thick red polyline around their perimeter, removing the old polyline if present. When the map is oriented north-south, half the width of the polyline is visible all around the edge of the map, exactly as you would expect. When it's rotated less than the angle of the diagonal, just a bit of the polyline is visible in the corners, again as you would expect. But as soon as it's rotated past the angle of the diagonal, it's evident that east and west are being set from the wrong corners. In this screenshot, the west edge of the bounds is being set from the bottom right corner, when it should be the bottom left.

device-2018-06-12-233157

Using 6.1.2. Also tested with 5.5.3.

@LukasPaczos LukasPaczos added the Android Mapbox Maps SDK for Android label Jun 13, 2018
@kjkrum
Copy link
Author

kjkrum commented Jun 14, 2018

Only the VisibleRegion.latLngBounds field is bogus. The corners of the visible region are correct. This method returns the correct bounds at any rotation angle:

private LatLngBounds getVisibleBounds() {
	final VisibleRegion v = mMap.getProjection().getVisibleRegion();
	LatLngBounds.Builder b = new LatLngBounds.Builder();
	b.include(v.nearLeft);
	b.include(v.nearRight);
	b.include(v.farLeft);
	b.include(v.farRight);
	return b.build();
}

@LukasPaczos
Copy link
Contributor

Thanks for reporting this issue @kjkrum. I'm seeing that #11309 introduced this issue while fixing incorrect bounds generated by the builder when crossing IDL. @osana what do you think about bringing back the builder for the visible region bounds generation but fixing it over IDL instead of the solution proposed in #11309? I feel like it brings too much complication and another approach to doing the same thing.

@osana
Copy link
Contributor

osana commented Jun 21, 2018

@LukasPaczos @kjkrum I believe the hard use case is when Map is very zoomed out showing almost the entire world with IDL in the middle and map is rotated. Using includes() as suggested above will not work as it will do the shortest bounds to include those points.

I think we will have to use LatLngBounds.from() but it is not easy to figure out which value is north, south, east and west.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants