-
-
Notifications
You must be signed in to change notification settings - Fork 915
Fix camera method and address deprecations #3602
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
base: main
Are you sure you want to change the base?
Changes from all commits
89d57ba
c470fa3
23c237c
1234883
c602be7
5823880
5290700
762c1e7
42e6726
8582e6b
bc011ab
715adf7
67183ff
2f46a22
0aaa177
6c91f71
ea208d8
30b0065
8878aba
afdd2a6
ac598a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,16 +40,18 @@ struct CameraUpdateItem { | |
| if let center = camera.center { | ||
| try center.validate() | ||
| } | ||
|
|
||
| switch mode { | ||
| case .flight: | ||
| map.mapView.camera.fly(to: camera, duration: duration) | ||
| case .ease: | ||
| map.mapView.camera.ease(to: camera, duration: duration ?? 0, curve: .easeInOut, completion: nil) | ||
| case .linear: | ||
| map.mapView.camera.ease(to: camera, duration: duration ?? 0, curve: .linear, completion: nil) | ||
| default: | ||
| map.mapboxMap.setCamera(to: camera) | ||
|
|
||
| map.withMapView { mapView in | ||
| switch mode { | ||
| case .flight: | ||
| mapView.camera.fly(to: camera, duration: duration) | ||
| case .ease: | ||
| mapView.camera.ease(to: camera, duration: duration ?? 0, curve: .easeInOut, completion: nil) | ||
| case .linear: | ||
| mapView.camera.ease(to: camera, duration: duration ?? 0, curve: .linear, completion: nil) | ||
| default: | ||
| mapView.mapboxMap.setCamera(to: camera) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -87,8 +89,10 @@ open class RNMBXMapComponentBase : UIView, RNMBXMapComponent { | |
| } | ||
|
|
||
| func withMapView(_ callback: @escaping (_ mapView: MapView) -> Void) { | ||
| withRNMBXMapView { mapView in | ||
| callback(mapView.mapView) | ||
| withRNMBXMapView { map in | ||
| map.withMapView { mapView in | ||
| callback(mapView) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -444,17 +448,33 @@ open class RNMBXCamera : RNMBXMapComponentBase { | |
|
|
||
| withMapView { map in | ||
| #if RNMBX_11 | ||
| let bounds = [sw, ne] | ||
| do { | ||
| let bounds: [CLLocationCoordinate2D] = [sw, ne] | ||
| camera = try map.mapboxMap.camera( | ||
| for: bounds, | ||
| camera: .init(cameraState: .init( | ||
| center: .init(), | ||
| padding: .zero, | ||
| zoom: zoom ?? 0, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've found that I have more consistant results by using
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mfazekas @naftalibeder I'll aim to make a demo this afternoon of why i've highlighted this.. but when moving the camera with setCamera from a centerCoordinates position to setCamera with bounds it seems that zoom is applied to the final position. Adding this |
||
| bearing: heading ?? map.mapboxMap.cameraState.bearing, | ||
| pitch: pitch ?? map.mapboxMap.cameraState.pitch | ||
| )), | ||
| coordinatesPadding: padding, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we use coordinatePadding and not camera padding? |
||
| maxZoom: nil, | ||
| offset: nil | ||
| ) | ||
| } catch { | ||
| Logger.log(level: .error, message: "RNMBXCamera.toUpdateItem: Failed to build camera configuration: \(error)") | ||
| } | ||
| #else | ||
| 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 | ||
| ) | ||
| #endif | ||
| } | ||
| } else { | ||
| camera = CameraOptions( | ||
|
|
@@ -525,8 +545,8 @@ open class RNMBXCamera : RNMBXMapComponentBase { | |
| return false | ||
| } | ||
|
|
||
| map.mapView.viewport.removeStatusObserver(self) | ||
| return super.removeFromMap(map, reason:reason) | ||
| map._mapView.viewport.removeStatusObserver(self) | ||
| return super.removeFromMap(map, reason: reason) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -565,12 +585,12 @@ extension RNMBXCamera : ViewportStatusObserver { | |
| return "compass" | ||
| case .course: | ||
| return "course" | ||
| case .some(let bearing): | ||
| case .some(_): | ||
| return "constant" | ||
| case .none: | ||
| return "normal" | ||
| } | ||
| } else if let state = state as? OverviewViewportState { | ||
| } else if let _ = state as? OverviewViewportState { | ||
| return "overview" | ||
| } else { | ||
| return "custom" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.