Skip to content

Commit bf87738

Browse files
authored
Merge pull request #1468 from Esri/destiny/update-world-scale-AR-tutorial
Update WorldScaleSceneView tutorial
2 parents 6474fa3 + 42fac00 commit bf87738

9 files changed

Lines changed: 131 additions & 151 deletions

Sources/ArcGISToolkit/Documentation.docc/Resources/WorldScaleSceneView/WorldScaleSceneViewStep1.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import SwiftUI
44

55
struct WorldScaleExampleView: View {
66
var body: some View {
7-
WorldScaleSceneView(
8-
clippingDistance: 400
9-
)
7+
WorldScaleSceneView(provider: Provider) { _ in
8+
9+
} sceneView: { _ in
10+
11+
}
1012
}
1113
}

Sources/ArcGISToolkit/Documentation.docc/Resources/WorldScaleSceneView/WorldScaleSceneViewStep2.swift

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,14 @@ import ArcGISToolkit
33
import SwiftUI
44

55
struct WorldScaleExampleView: View {
6-
@State private var scene: ArcGIS.Scene = {
7-
// Creates an elevation source from Terrain3D REST service.
8-
let elevationServiceURL = URL(
9-
string: "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer"
10-
)!
11-
let elevationSource = ArcGISTiledElevationSource(url: elevationServiceURL)
12-
let surface = Surface()
13-
surface.addElevationSource(elevationSource)
14-
surface.backgroundGrid.isVisible = false
15-
surface.navigationConstraint = .unconstrained
16-
let scene = Scene(basemapStyle: .arcGISImagery)
17-
scene.baseSurface = surface
18-
return scene
19-
}()
6+
/// The world-tracking provider used by this example.
7+
@State private var provider = AppleWorldTracking(mode: .worldTracking)
208

219
var body: some View {
22-
WorldScaleSceneView(
23-
clippingDistance: 400
24-
) { _ in
25-
SceneView(scene: scene)
10+
WorldScaleSceneView(provider: provider) { context in
11+
12+
} sceneView: { _ in
13+
2614
}
2715
}
2816
}

Sources/ArcGISToolkit/Documentation.docc/Resources/WorldScaleSceneView/WorldScaleSceneViewStep3.swift

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,14 @@ import ArcGISToolkit
33
import SwiftUI
44

55
struct WorldScaleExampleView: View {
6-
@State private var scene: ArcGIS.Scene = {
7-
// Creates an elevation source from Terrain3D REST service.
8-
let elevationServiceURL = URL(
9-
string: "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer"
10-
)!
11-
let elevationSource = ArcGISTiledElevationSource(url: elevationServiceURL)
12-
let surface = Surface()
13-
surface.addElevationSource(elevationSource)
14-
surface.backgroundGrid.isVisible = false
15-
surface.navigationConstraint = .unconstrained
16-
let scene = Scene(basemapStyle: .arcGISImagery)
17-
scene.baseSurface = surface
18-
scene.baseSurface.opacity = 0
19-
return scene
20-
}()
6+
/// The world-tracking provider used by this example.
7+
@State private var provider = AppleWorldTracking(mode: .worldTracking)
218

229
var body: some View {
23-
WorldScaleSceneView(
24-
clippingDistance: 400
25-
) { _ in
26-
SceneView(scene: scene)
10+
WorldScaleSceneView(provider: provider) { context in
11+
AppleWorldTrackingCameraFeedView(context: context)
12+
} sceneView: { _ in
13+
2714
}
2815
}
2916
}
Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import ArcGIS
22
import ArcGISToolkit
3-
import CoreLocation
43
import SwiftUI
54

65
struct WorldScaleExampleView: View {
@@ -16,21 +15,17 @@ struct WorldScaleExampleView: View {
1615
surface.navigationConstraint = .unconstrained
1716
let scene = Scene(basemapStyle: .arcGISImagery)
1817
scene.baseSurface = surface
19-
scene.baseSurface.opacity = 0
2018
return scene
2119
}()
2220

21+
/// The world-tracking provider used by this example.
22+
@State private var provider = AppleWorldTracking(mode: .worldTracking)
23+
2324
var body: some View {
24-
WorldScaleSceneView(
25-
clippingDistance: 400
26-
) { _ in
25+
WorldScaleSceneView(provider: provider) { context in
26+
AppleWorldTrackingCameraFeedView(context: context)
27+
} sceneView: { _ in
2728
SceneView(scene: scene)
2829
}
29-
.task {
30-
let locationManager = CLLocationManager()
31-
if locationManager.authorizationStatus == .notDetermined {
32-
locationManager.requestWhenInUseAuthorization()
33-
}
34-
}
3530
}
3631
}
Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import ArcGIS
22
import ArcGISToolkit
3-
import CoreLocation
43
import SwiftUI
54

65
struct WorldScaleExampleView: View {
@@ -20,25 +19,14 @@ struct WorldScaleExampleView: View {
2019
return scene
2120
}()
2221

23-
/// The location datasource that is used to access the device location.
24-
@State private var locationDataSource = SystemLocationDataSource()
22+
/// The world-tracking provider used by this example.
23+
@State private var provider = AppleWorldTracking(mode: .worldTracking)
2524

2625
var body: some View {
27-
WorldScaleSceneView(
28-
clippingDistance: 400
29-
) { _ in
26+
WorldScaleSceneView(provider: provider) { context in
27+
AppleWorldTrackingCameraFeedView(context: context)
28+
} sceneView: { _ in
3029
SceneView(scene: scene)
3130
}
32-
.task {
33-
let locationManager = CLLocationManager()
34-
if locationManager.authorizationStatus == .notDetermined {
35-
locationManager.requestWhenInUseAuthorization()
36-
}
37-
38-
try? await locationDataSource.start()
39-
40-
// Retrieve initial location.
41-
guard let initialLocation = await locationDataSource.locations.first(where: { _ in true }) else { return }
42-
}
4331
}
4432
}

Sources/ArcGISToolkit/Documentation.docc/Resources/WorldScaleSceneView/WorldScaleSceneViewStep6.swift

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,46 +20,20 @@ struct WorldScaleExampleView: View {
2020
return scene
2121
}()
2222

23-
/// The location datasource that is used to access the device location.
24-
@State private var locationDataSource = SystemLocationDataSource()
25-
26-
/// The graphics overlay which shows a graphic around your initial location.
27-
@State private var graphicsOverlay = GraphicsOverlay()
23+
/// The world-tracking provider used by this example.
24+
@State private var provider = AppleWorldTracking(mode: .worldTracking)
2825

2926
var body: some View {
30-
WorldScaleSceneView(
31-
clippingDistance: 400
32-
) { _ in
33-
SceneView(scene: scene, graphicsOverlays: [graphicsOverlay])
27+
WorldScaleSceneView(provider: provider) { context in
28+
AppleWorldTrackingCameraFeedView(context: context)
29+
} sceneView: { _ in
30+
SceneView(scene: scene)
3431
}
3532
.task {
3633
let locationManager = CLLocationManager()
3734
if locationManager.authorizationStatus == .notDetermined {
3835
locationManager.requestWhenInUseAuthorization()
3936
}
40-
41-
try? await locationDataSource.start()
42-
43-
// Retrieve initial location.
44-
guard let initialLocation = await locationDataSource.locations.first(where: { _ in true }) else { return }
45-
46-
// Put a circle graphic around the initial location.
47-
let circle = GeometryEngine.geodeticBuffer(
48-
around: initialLocation.position,
49-
distance: 20,
50-
distanceUnit: .meters,
51-
maxDeviation: 1,
52-
curveType: .geodesic
53-
)
54-
graphicsOverlay.addGraphic(
55-
Graphic(
56-
geometry: circle,
57-
symbol: SimpleLineSymbol(
58-
color: .red,
59-
width: 3
60-
)
61-
)
62-
)
6337
}
6438
}
6539
}

Sources/ArcGISToolkit/Documentation.docc/Resources/WorldScaleSceneView/WorldScaleSceneViewStep7.swift

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,49 +20,25 @@ struct WorldScaleExampleView: View {
2020
return scene
2121
}()
2222

23-
/// The location datasource that is used to access the device location.
24-
@State private var locationDataSource = SystemLocationDataSource()
25-
26-
/// The graphics overlay which shows a graphic around your initial location.
27-
@State private var graphicsOverlay = GraphicsOverlay()
23+
/// The world-tracking provider used by this example.
24+
@State private var provider = AppleWorldTracking(mode: .worldTracking)
2825

2926
var body: some View {
30-
WorldScaleSceneView(
31-
clippingDistance: 400
32-
) { _ in
33-
SceneView(scene: scene, graphicsOverlays: [graphicsOverlay])
27+
WorldScaleSceneView(provider: provider) { context in
28+
AppleWorldTrackingCameraFeedView(context: context)
29+
} sceneView: { _ in
30+
SceneView(scene: scene)
3431
}
3532
.task {
3633
let locationManager = CLLocationManager()
3734
if locationManager.authorizationStatus == .notDetermined {
3835
locationManager.requestWhenInUseAuthorization()
3936
}
4037

41-
try? await locationDataSource.start()
38+
try? await provider.dataSource.start()
4239

4340
// Retrieve initial location.
44-
guard let initialLocation = await locationDataSource.locations.first(where: { _ in true }) else { return }
45-
46-
// Put a circle graphic around the initial location.
47-
let circle = GeometryEngine.geodeticBuffer(
48-
around: initialLocation.position,
49-
distance: 20,
50-
distanceUnit: .meters,
51-
maxDeviation: 1,
52-
curveType: .geodesic
53-
)
54-
graphicsOverlay.addGraphic(
55-
Graphic(
56-
geometry: circle,
57-
symbol: SimpleLineSymbol(
58-
color: .red,
59-
width: 3
60-
)
61-
)
62-
)
63-
64-
// Stop the location datasource after the initial location is retrieved.
65-
await locationDataSource.stop()
41+
guard let initialLocation = await provider.dataSource.locations.first(where: { @Sendable _ in true }) else { return }
6642
}
6743
}
6844
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import ArcGIS
2+
import ArcGISToolkit
3+
import CoreLocation
4+
import SwiftUI
5+
6+
struct WorldScaleExampleView: View {
7+
@State private var scene: ArcGIS.Scene = {
8+
// Creates an elevation source from Terrain3D REST service.
9+
let elevationServiceURL = URL(
10+
string: "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer"
11+
)!
12+
let elevationSource = ArcGISTiledElevationSource(url: elevationServiceURL)
13+
let surface = Surface()
14+
surface.addElevationSource(elevationSource)
15+
surface.backgroundGrid.isVisible = false
16+
surface.navigationConstraint = .unconstrained
17+
let scene = Scene(basemapStyle: .arcGISImagery)
18+
scene.baseSurface = surface
19+
scene.baseSurface.opacity = 0
20+
return scene
21+
}()
22+
23+
/// The graphics overlay which shows a graphic around your initial location.
24+
@State private var graphicsOverlay = GraphicsOverlay()
25+
26+
/// The world-tracking provider used by this example.
27+
@State private var provider = AppleWorldTracking(mode: .worldTracking)
28+
29+
var body: some View {
30+
WorldScaleSceneView(provider: provider) { context in
31+
AppleWorldTrackingCameraFeedView(context: context)
32+
} sceneView: { _ in
33+
SceneView(scene: scene)
34+
}
35+
.task {
36+
let locationManager = CLLocationManager()
37+
if locationManager.authorizationStatus == .notDetermined {
38+
locationManager.requestWhenInUseAuthorization()
39+
}
40+
41+
try? await provider.dataSource.start()
42+
43+
// Retrieve initial location.
44+
guard let initialLocation = await provider.dataSource.locations.first(where: { @Sendable _ in true }) else { return }
45+
46+
// Put a circle graphic around the initial location.
47+
let circle = GeometryEngine.geodeticBuffer(
48+
around: initialLocation.position,
49+
distance: 20,
50+
distanceUnit: .meters,
51+
maxDeviation: 1,
52+
curveType: .geodesic
53+
)
54+
graphicsOverlay.addGraphic(
55+
Graphic(
56+
geometry: circle,
57+
symbol: SimpleLineSymbol(
58+
color: .red,
59+
width: 3
60+
)
61+
)
62+
)
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)