You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Camera animations do not respect map padding #5034
Expect the camera animation to respect the padding.
Actual behavior
The camera animation occurs but with respect to the visible area of the map, not regarding padding.
While on the topic, I'd also expect the map's projection getVisibleBounds to also take into account the padding. This seems to be how google maps behave.
I ended up having to write:
@NonNull
private LatLngBounds getVisibleBoundsIncludingPadding() {
// GetVisibleRegion doesn't take the padding into account, so we need to do our own
// calculations
Projection projection = mMap.getProjection();
int viewportWidth = mBinding.map.getWidth();
int viewportHeight = mBinding.map.getHeight();
viewportHeight = viewportHeight - mMap.getPadding()[1];
viewportHeight = viewportHeight - mMap.getPadding()[3];
viewportWidth = viewportWidth - mMap.getPadding()[0];
viewportWidth = viewportWidth - mMap.getPadding()[2];
LatLngBounds.Builder builder = new LatLngBounds.Builder();
LatLng topLeft = projection.fromScreenLocation(new PointF(0, 0));
LatLng topRight = projection.fromScreenLocation(new PointF(viewportWidth, 0));
LatLng bottomRight = projection.fromScreenLocation(new PointF(viewportWidth, viewportHeight));
LatLng bottomLeft = projection.fromScreenLocation(new PointF(0, viewportHeight));
builder.include(topLeft)
.include(topRight)
.include(bottomRight)
.include(bottomLeft);
return builder.build();
}
to compensate for this difference while porting a project away from Google maps.
This is a bug that makes migration from Google Maps more difficult since our API is not behaving the same way. 0e9f7ae & 9e1b82b fixes this behaviour to match the end developer expectations.
It did occur to me afterwards, that the getVisibleRegion() implementation may also need to account for the fact that the viewport won't always start at 0,0 on the screen, and must also take into account the top padding. Thanks for looking into this issue so quickly.
@nealsanche thanks for adding that remark. Without looking into it I'm currently thinking the x,y position is relative to the parent ViewGroup. In this case that would be MapView (extending FrameLayout) but I will definitely look into this before merging.
I'm doing some test with the MapPaddingActivitiy, added some markers in the padding area and see if getAnnotationsInBounds returns the correct markers. I'm currently not receiving the results I though I would get back. Not sure if this is an error in calculating the bounds or within LatLngBounds or something else. Will need to dig further to find out where this is coming from.
I have been debugging this and I started to notice that a map facing north doesn't have the issue mentioned above. I'm currently guessing the logic behind LatLngBounds works correctly when assumed the projection is rectangular. In the case I was looking into the projection is a parallelogram. If we also have tilt enabled this projection becomes a trapezoid. Since this is not related to the issue above. I'm going to merge the changes for padding and create a follow up ticket on this.
Activity
tobrun commentedon May 17, 2016
@nealsanche thank you for reaching out and reporting both issues.
tobrun commentedon May 17, 2016
In
LatLngBoundsActivity, I added some padding to the map:Without any fixes this results in the following screenshot where no extra padding was added:
After fixing this in the camera update method:
I'm seeing the padding being applied:
tobrun commentedon May 17, 2016
I resolved the second issue by introducing two new methods in the content padding part of MapView:
The
getContentWidthandgetContentHeightare now being used overgetHeightandgetWidth.[android] #5034 - LatLngBounds Camera update not taking map padding i…
[android] #5034 - padding not being included in getVisibleBounds
tobrun commentedon May 17, 2016
@bleege @zugaldia @cammace
How do you feel about including this in
4.1.0?This is a bug that makes migration from Google Maps more difficult since our API is not behaving the same way. 0e9f7ae & 9e1b82b fixes this behaviour to match the end developer expectations.
nealsanche commentedon May 17, 2016
It did occur to me afterwards, that the getVisibleRegion() implementation may also need to account for the fact that the viewport won't always start at 0,0 on the screen, and must also take into account the top padding. Thanks for looking into this issue so quickly.
tobrun commentedon May 18, 2016
@nealsanche thanks for adding that remark. Without looking into it I'm currently thinking the x,y position is relative to the parent ViewGroup. In this case that would be MapView (extending FrameLayout) but I will definitely look into this before merging.
tobrun commentedon May 20, 2016
I'm going to test out the remarks made above and see if we need to include a fix for it.
Afterwards I will rebase and merge #5051.
tobrun commentedon May 20, 2016
I'm doing some test with the
MapPaddingActivitiy, added some markers in the padding area and see ifgetAnnotationsInBoundsreturns the correct markers. I'm currently not receiving the results I though I would get back. Not sure if this is an error in calculating the bounds or withinLatLngBoundsor something else. Will need to dig further to find out where this is coming from.tobrun commentedon May 26, 2016
I have been debugging this and I started to notice that a map facing north doesn't have the issue mentioned above. I'm currently guessing the logic behind
LatLngBoundsworks correctly when assumed the projection is rectangular. In the case I was looking into the projection is a parallelogram. If we also have tilt enabled this projection becomes a trapezoid. Since this is not related to the issue above. I'm going to merge the changes for padding and create a follow up ticket on this.tobrun commentedon May 26, 2016
@nealsanche
You were right in #5034 (comment). I ended up using following code:
Thanks again for reaching out and reporting this issue!
nealsanche commentedon May 26, 2016
You are welcome. Thanks for getting this in!