-
-
Notifications
You must be signed in to change notification settings - Fork 853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zoom level not applied correctly when switching from setting camera with centerCoordinate
to bounds
#3488
Comments
camera.setCamera
with centerCoordinate
param and next time with bounds
param. camera.setCamera
with centerCoordinate
param and next time with bounds
param.
camera.setCamera
with centerCoordinate
param and next time with bounds
param. centerCoordinate
to bounds
In RNMBXCamera.siwft, If I reset the camera state before applying new bounds the padding error goes away and the zoom is applied as expected. Screen recording showing expected behavior: Example code that fix the bug. I am not sure if this is the right way of doing it.
|
@mfazekas is it relates to mapbox/mapbox-maps-ios#2170 ? Can you suggest a hot fix? Thanks @RyszardRzepa for a solution, but camera jumps unpleasantly |
@RyszardRzepa fyi after some research I found that replacing deprecated method to the new API is fixed this bug diff --git a/node_modules/@rnmapbox/maps/ios/RNMBX/RNMBXCamera.swift b/node_modules/@rnmapbox/maps/ios/RNMBX/RNMBXCamera.swift
index 261245c..d70b480 100644
--- a/node_modules/@rnmapbox/maps/ios/RNMBX/RNMBXCamera.swift
+++ b/node_modules/@rnmapbox/maps/ios/RNMBX/RNMBXCamera.swift
@@ -452,12 +452,21 @@ open class RNMBXCamera : RNMBXMapComponentBase {
let bounds = CoordinateBounds(southwest: sw, northeast: ne)
#endif
- camera = map.mapboxMap.camera(
- for: bounds,
- padding: padding,
- bearing: heading ?? map.mapboxMap.cameraState.bearing,
- pitch: pitch ?? map.mapboxMap.cameraState.pitch
- )
+ do {
+ camera = try map.mapboxMap.camera(
+ for: bounds,
+ camera: CameraOptions(
+ padding: padding,
+ bearing: heading ?? map.mapboxMap.cameraState.bearing,
+ pitch: pitch ?? map.mapboxMap.cameraState.pitch
+ ),
+ coordinatesPadding: nil,
+ maxZoom: nil,
+ offset: nil
+ )
+ } catch let error {
+ Logger.log(level: .error, message: "RNMBXCamera.toUpdateItem: MapError: \(error.localizedDescription)")
+ }
}
} else {
camera = CameraOptions( |
Mapbox Implementation
Mapbox
Mapbox Version
11.3.0
React Native Version
0.72.4
Platform
iOS, Android
@rnmapbox/maps
version10.1.19
Standalone component to reproduce
Observed behavior and steps to reproduce
I see warning in Xcode when the bug happens:
[Warning, maps-core]: {}[General]: Unable to calculate camera for given bounds/geometry, padding is greater than map's width or height.
We set the camera position and zoom level by using two methods, depends on what the user click.
If user click a marker in the map, we call
zoomToPosition
function where we setcenterCoordinate
with the marker position and the padding.If user click on the fence we call
zoomToBounds
function where we usebounds
param to set the camera in the center with the correct zoom.The problem is that when we call
zoomToPosition
and the camera zoom in to the marker and later we callzoomToBounds
the camera centers correctly but the zoom level is not applied to show all the markers within the bounds.Simulator.Screen.Recording.-.iPhone.Xs.-.2024-05-13.at.11.27.06.mp4
Screen recording. Here we can see that clicking on the marker zoom in the camera, when we navigate back the
zoomToBounds
is called and it should zoom out the camera to show all the markers, but instead the zoom level don't change.https://github.com/rnmapbox/maps/assets/13038459/bc2d5116-047d-49f7-b33b-d01ca54c2ae0
Expected behavior
Zoom level should be applied correctly to show all the markers within the bounds when calling first
and calling after that
setCamera
withbounds
Zoom level is not applied correctly when we use
Notes / preliminary analysis
We render the bottom sheet on the map. We use the bottom sheet height to calculate bottom padding, to make sure we center the camera in the visible part of the map.
It appears that this zoom issue is gone when we set the padding to the static value example: 30, but this will not center the camera in the visible part of the map.
Additional links and references
No response
Related issue #3354
The text was updated successfully, but these errors were encountered: