-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[Android] 4.2.0-beta.3, 4: moveCamera() is ignored if map is not displayed #6855
Comments
@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. |
with beta.3 and later a workaround is needed to zoom to activity when opening. The workaround (so far) is to try move the camera at view updates as long as position is 0,0 mapbox/mapbox-gl-native#6855 (comment) (and related issues) beta.2 works fine (4.1.1 had marker issues) but beta.5 should be better
with beta.3 and later a workaround is needed to zoom to activity when opening. The workaround (so far) is to try move the camera at view updates as long as position is 0,0 mapbox/mapbox-gl-native#6855 (comment) (and related issues) beta.2 works fine (4.1.1 had marker issues) but beta.5 should be better
Please use a mapfragment for this use-case |
I also still experience the issue using
I do notice that the logged width is sometimes 0 when My workaround is to wrap |
@mattijsf what happensif you replace |
If I revert the Edit: 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. |
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.
Workaround here:
https://github.com/gerhardol/runnerup/blob/mapbox-4.2-beta4-update/app/latest/java/org/runnerup/util/MapWrapper.java#L241
Note: The app has a separate build for Android versions before 4.0, the MapBox calls are in a Wrapper.
The calls are from a normal AppCompatActivity. (if you delay the moveCamera() call enough (with sleep) to be able to switch tabs, the camera moves).
https://github.com/gerhardol/runnerup/blob/mapbox-4.2-beta4-update/app/src/org/runnerup/view/DetailActivity.java#L148
I looked at the source, did not see any obvious.
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:
Expected behavior
Camera position to move
Actual behavior
Nothing
The text was updated successfully, but these errors were encountered: