Skip to content

Commit 41aa4da

Browse files
committed
Add sample source code.
1 parent a4a149c commit 41aa4da

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

Shared/Samples/Display scene from mobile scene package/DisplaySceneFromMobileScenePackageView.swift

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,44 @@ import ArcGIS
1616
import SwiftUI
1717

1818
struct DisplaySceneFromMobileScenePackageView: View {
19-
/// The view model for the sample.
20-
@StateObject private var model = Model()
19+
/// The scene used to create the scene view.
20+
@State private var scene = ArcGIS.Scene()
21+
22+
/// A Boolean value indicating whether the error alert is showing.
23+
@State private var errorAlertIsShowing = false
24+
25+
/// The error shown in the error alert.
26+
@State private var error: Error? {
27+
didSet { errorAlertIsShowing = error != nil }
28+
}
2129

2230
var body: some View {
23-
MapView(map: model.map)
24-
.alert(isPresented: $model.errorAlertIsShowing, presentingError: model.error)
31+
// Create a scene view with the scene.
32+
SceneView(scene: scene)
33+
.task {
34+
do {
35+
// Create a mobile scene package using a URL to a .mspk file.
36+
let mobileScenePackage = MobileScenePackage(fileURL: .philadelphia)
37+
38+
// Load the package.
39+
try await mobileScenePackage.load()
40+
41+
// Get the first scene from the package.
42+
guard let scene = mobileScenePackage.scenes.first else { return }
43+
44+
// Use the scene to update the scene view.
45+
self.scene = scene
46+
} catch {
47+
self.error = error
48+
}
49+
}
50+
.alert(isPresented: $errorAlertIsShowing, presentingError: error)
2551
}
2652
}
2753

28-
private extension DisplaySceneFromMobileScenePackageView {
29-
/// The view model for the sample.
30-
class Model: ObservableObject {
31-
/// A map with a topographic basemap.
32-
let map = Map(basemapStyle: .arcGISTopographic)
33-
34-
/// A Boolean value indicating whether the error alert is showing.
35-
@Published var errorAlertIsShowing = false
36-
37-
/// The error shown in the error alert.
38-
@Published var error: Error? {
39-
didSet { errorAlertIsShowing = error != nil }
40-
}
54+
private extension URL {
55+
/// A URL to the local mobile scene package of Philadelphia, PA, USA.
56+
static var philadelphia: URL {
57+
Bundle.main.url(forResource: "philadelphia", withExtension: "mspk")!
4158
}
4259
}

0 commit comments

Comments
 (0)