-
-
Notifications
You must be signed in to change notification settings - Fork 937
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 5 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 |
|---|---|---|
|
|
@@ -41,16 +41,24 @@ struct CameraUpdateItem { | |
| 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) | ||
| } | ||
| switch mode { | ||
| case .flight: | ||
| map.withMapView { mapView in | ||
| mapView.camera.fly(to: camera, duration: duration) | ||
| } | ||
| case .ease: | ||
| map.withMapView { mapView in | ||
| mapView.camera.ease(to: camera, duration: duration ?? 0, curve: .easeInOut, completion: nil) | ||
| } | ||
| case .linear: | ||
| map.withMapView { mapView in | ||
| mapView.camera.ease(to: camera, duration: duration ?? 0, curve: .linear, completion: nil) | ||
| } | ||
| default: | ||
| map.withMapboxMap { mapboxMap in | ||
| mapboxMap.setCamera(to: camera) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -87,8 +95,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) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -447,17 +457,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( | ||
|
|
@@ -528,8 +554,11 @@ open class RNMBXCamera : RNMBXMapComponentBase { | |
| return false | ||
| } | ||
|
|
||
| map.mapView.viewport.removeStatusObserver(self) | ||
| return super.removeFromMap(map, reason:reason) | ||
| withMapView { mapView in | ||
|
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'm not sure about this on remove. Maybe just
Collaborator
Author
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 don't understand the comment exactly -
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. First it should be Second if mapView of RNMBXMapView is null then what was the satusObserver was attached to? Why do we need to remove? So I think withMapView is unnecessary in this case. Likely not harmful but you have the check carefully as it could easily keep the camera object alive, until we'll have a mapView. Which doesn't sound right, but probably no leak here.
Collaborator
Author
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 don't have a strong sense of the implications of the callback architecture ( We can do but since |
||
| mapView.viewport.removeStatusObserver(self) | ||
| } | ||
|
|
||
| return super.removeFromMap(map, reason: reason) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -568,12 +597,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.