I am trying to lock the heading of the camera on a SceneView to North as the user scrolls around the map.
I can't see any option to do that other than a .onChanged modifier to the camera. The problem with this is if you listen for changes to camera and change the heading back to North each time, you both lose the momentum scroll and also it will mess up other camera functionality like allowing the user to go to present position.
Is there any way at all to lock the camera heading on North or any other heading as the user scrolls around the 3D sceneView other than listening to Camera changes and replacing the camera each time?
Being new to this I also have noticed that the Camera properties are get only so each time you need to assign a new Camera to the SceneView if you want to change the heading programmatically which is why the listener approach does not work well.
I've added the compass but I don't see any functionality on the SceneView other than rotating to a heading that I provide it. I had a compass before that did that. Am I missing some functionality with the compass? I see there is a mapViewProxy argument but not a sceneViewProxy. Not sure if it has additional functionality on a MapView. But on a sceneView it seems like just a nice image of a compass.
Consider this snippet
import ArcGIS
import ArcGISToolkit
import SwiftUI
/// An example demonstrating how to use a compass with a scene view.
struct ContentView: View {
@State private var scene = Scene(basemapStyle: .arcGISOceans)
/// Allows for communication between the Compass and MapView or SceneView.
@State private var viewpoint = Viewpoint(
center: Point(latitude: 34.05723, longitude: -117.19494),
scale: 5e7,
rotation: -45
)
var body: some View {
SceneViewReader { proxy in
SceneView(scene: scene, viewpoint: viewpoint)
.onViewpointChanged(kind: .centerAndScale) { viewpoint = $0 }
.overlay(alignment: .topTrailing) {
Compass(rotation: viewpoint.rotation) {
Task {
await proxy.setViewpoint(viewpoint.withRotation(.zero), duration: 0.2)
}
}
.padding()
}
}
}
}
A few things to notice
1. onViewpointChanged is needed to get the latest view point from the scene view
2. Use setViewpoint(_:duration:) for the animated viewpoint change. Note you need to pass it to the "action" block of the Compass, which is what the compass does in react to a tap action.
Check out the attached video.
Thanks. That's working now. Hopefully the fixed North feature will be available soon.
We've created a tracking issue for this request and are weighing on different options. It might not be part of the upcoming release as our 3D team is assigned some tasks with priority, or it may be supported in an alternative form.
A side note: please check out the "Ideas" board for Esri Community and for the native SDKs . The user requests coming from these sources will have an internal referencing number so they gain more exposure when we plan for the next release. No worries this time, I've got you covered on this request!
Thanks very much. I will have a look at the ideas board for future requests. Thx.