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.
[Android] 4.2.0-beta.3, 4: moveCamera() is ignored if map is not displayed #6855
Android SDK 4.2.0-beta.3, beta.4
At least Android 6.0, 7.0
Since beta.3 (beta.1 definitely ok, beta.2 very likely OK) MapBox methods to move the camera requires that the map is displayed. Otherwise the requests are ignored.
If the activity is done in such way that the MapView is not viewed when the activity is first displayed, the request is ignored. In the application I work with, the interface is tabbed and the map is not default.
I have not found a callback that I can use when the map is displayed, so the mapBoxMap.moveCamera() is periodically attempted until position is no longer 0,0.
If not fixed, there should be a better workaround (that is documented).
Steps to trigger behavior
Create MapBox view but do not display the map view.
Call mapBoxMap.moveCamera() in the onMapReady() callout.
(same for other camera position related calls).
You can use the master branch of RunnerUp to recreate too:
@gerhardol thank you for reaching out, we recently changed the way the OnMapReadyCallback is invoked to align it correctly with a loaded style. The reason why moveCamera-LatLngBounds is not working now is that the MapView itself isn't measured yet and uses width = 0 when calculating the bounds. This issue is being tracked in #6769 and a workaround for this is to post you moveCamera(latlngbounds) to a runnable as shown here. Closing as a duplicate. Thank your for reaching out.
If I revert the OnGlobalLayoutListener workaround and log mapView.getMeasuredWidth() I get the following: Moving camera with mapWidth: 0.0, mapViewMeasuredWidth: 0.0
Edit:
I get two occurrences alternating randomly it seems: Moving camera with mapWidth: 1017.0, mapViewMeasuredWidth: 1017.0 Moving camera with mapWidth: 0.0, mapViewMeasuredWidth: 0.0
It is pretty clear camera updates are ignored when the width reports 0
It's fair to mention that I'm using my own View which loaded into a hierarchy managed by React Native. I do however call the required lifecycle methods similar to a Fragment based implementation. The rest of the MapView seems to work fine, only the camera is currently showing this strange behavior.
Activity
[-]Android[/-][+][Android] 4.2.0-beta.3, 4: moveCamera() is ignored if map is not displayed[/+]tobrun commentedon Oct 31, 2016
@gerhardol thank you for reaching out, we recently changed the way the OnMapReadyCallback is invoked to align it correctly with a loaded style. The reason why moveCamera-LatLngBounds is not working now is that the MapView itself isn't measured yet and uses width = 0 when calculating the bounds. This issue is being tracked in #6769 and a workaround for this is to post you moveCamera(latlngbounds) to a runnable as shown here. Closing as a duplicate. Thank your for reaching out.
4.2 update
4.2 update
gerhardol commentedon Mar 23, 2017
Still occurs in 5.0.1, so #6769, #6999 does not seem to be solved correctly.
In my case, the mapview is hidden when the main view is opened.
tobrun commentedon Mar 24, 2017
Please use a mapfragment for this use-case
mattijsf commentedon Jun 13, 2017
I also still experience the issue using
5.1.0-beta.3. Sometimes the camera is working and sometimes not. I'm moving the camera inonMapReadyusingI do notice that the logged width is sometimes 0 when
onMapReadyoccurs.My workaround is to wrap
.getMapAsyncin aOnGlobalLayoutListenerwhich ensures the view has dimensions before setting up the map. Not pretty at all.tobrun commentedon Jun 13, 2017
@mattijsf what happensif you replace
map.getWidth()withmapView.getMeasuredWidth()?mattijsf commentedon Jun 13, 2017
If I revert the
OnGlobalLayoutListenerworkaround and logmapView.getMeasuredWidth()I get the following:Moving camera with mapWidth: 0.0, mapViewMeasuredWidth: 0.0Edit:
I get two occurrences alternating randomly it seems:
Moving camera with mapWidth: 1017.0, mapViewMeasuredWidth: 1017.0Moving camera with mapWidth: 0.0, mapViewMeasuredWidth: 0.0It is pretty clear camera updates are ignored when the width reports 0
mattijsf commentedon Jun 13, 2017
It's fair to mention that I'm using my own View which loaded into a hierarchy managed by React Native. I do however call the required lifecycle methods similar to a Fragment based implementation. The rest of the MapView seems to work fine, only the camera is currently showing this strange behavior.