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.
Workaround for now is posting the update on the main thread:
newHandler().post(newRunnable() {
@Overridepublicvoidrun() {
// Move camera to the bounds with added paddingintpadding = (int) getResources().getDimension(R.dimen.coordinatebounds_margin);
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, padding));
}
});
Ideally this is fixed with a more robust camera system in #6532 (+ improvement over current implementation in #4796). One solution for now would be post every CameraUpdate we receive or selectively delay it for LatLngBoundsUpdate. The other option of forcing a measure on MapView didn't work since it triggers a render on core.
Capturing from @ivovandongen to do a small test with the reverted OnMapReadyCallback (hooking into DID_FINISH_LOADING_MAP instead). This correctly animates the map:
From the (duplicate) #6855
The workaround with post does not work for me (probably because the map is not visible at creation). I have to retry a couple of times (as described in the duplicate issue).
While I believe the final solution will work, the workaround may not work for everybody.
@gerhardol I would suggest using a addOnGlobalLayoutListener. When you receive this callback you are sure the view is measured and you can execute the LatLngBounds Camera update.
//Since MapBox 4.2.0-beta.3 moving the camera in onMapReady is not working if map is not visible
//The workaround (so far) is to try move the camera at view updates as long as position is 0,0
//https://github.com/mapbox/mapbox-gl-native/issues/6855#event-841575956 (and related issues)
mapView.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@SuppressWarnings("deprecation")
// We check which build version we are using.
@Override
public void onGlobalLayout() {
if (map.getCameraPosition().target.getLatitude() != 0 ||
map.getCameraPosition().target.getLongitude() != 0) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
mapView.getViewTreeObserver()
.removeGlobalOnLayoutListener(this);
} else {
mapView.getViewTreeObserver()
.removeOnGlobalLayoutListener(this);
}
}
map.moveCamera(initialCameraPosition);
}
});
In #6919 I'm introducing the runnable around the camera methods for another issue (running an animation in onFinish). To completely resolve this issue we need to optimise the OnMapReadyCallback to take in account if style is loaded but also if the view is measured yet.
Activity
tobrun commentedon Oct 20, 2016
Noticing that viewportheight is 0, which means the MapView hasn't been measured yet.
[-]LatLngBounds not applied[/-][+]LatLngBounds not applied in OnMapReady[/+]tobrun commentedon Oct 20, 2016
Workaround for now is posting the update on the main thread:
tobrun commentedon Oct 20, 2016
Ideally this is fixed with a more robust camera system in #6532 (+ improvement over current implementation in #4796). One solution for now would be post every
CameraUpdatewe receive or selectively delay it for LatLngBoundsUpdate. The other option of forcing a measure on MapView didn't work since it triggers a render on core.cc @mapbox/android
tobrun commentedon Oct 25, 2016
Capturing from @ivovandongen to do a small test with the reverted OnMapReadyCallback (hooking into DID_FINISH_LOADING_MAP instead). This correctly animates the map:
gerhardol commentedon Nov 1, 2016
From the (duplicate) #6855
The workaround with post does not work for me (probably because the map is not visible at creation). I have to retry a couple of times (as described in the duplicate issue).
While I believe the final solution will work, the workaround may not work for everybody.
tobrun commentedon Nov 1, 2016
@gerhardol I would suggest using a
addOnGlobalLayoutListener. When you receive this callback you are sure the view is measured and you can execute the LatLngBounds Camera update.gerhardol commentedon Nov 1, 2016
Thanks
The following works for me
tobrun commentedon Nov 10, 2016
In #6919 I'm introducing the runnable around the camera methods for another issue (running an animation in onFinish). To completely resolve this issue we need to optimise the OnMapReadyCallback to take in account if style is loaded but also if the view is measured yet.
tobrun commentedon Dec 6, 2016
#6999 is the issue tracking the solution for this. Closing as a duplicate