@@ -16,27 +16,44 @@ import ArcGIS
1616import SwiftUI
1717
1818struct 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