Open mobile scene (scene package)

View on GitHubSample viewer app

Opens and displays a scene from a mobile scene package (.mspk).

Open mobile scene (scene package) sample

Use case

An .mspk file is an archive containing the data (specifically, basemaps and features), used to display an offline 3D scene.

How to use the sample

When the sample opens, it will automatically display the Scene in the Mobile Map Package.

How it works

This sample takes a Mobile Scene Package that was created in ArcGIS Pro, and displays an AGSScene from within the package in an AGSSceneView.

  1. Create an AGSMobileScenePackage object using the path to the local .mspk file.
  2. Load the mobile scene package withAGSMobileScenePackage.load(completion:) and check for any errors.
  3. When the AGSMobileScenePackage instance is loaded, obtain the first AGSScene object from the AGSMobileScenePackage.scenes property.
  4. Assign the scene to the scene view.

Relevant API

  • AGSMobileScenePackage
  • AGSSceneView

About the data

This mobile scene package was authored with ArcGIS Pro. It is downloaded from ArcGIS Online automatically.

This item is available on ArcGIS Online

Tags

offline, scene

Sample Code

OpenMobileSceneViewController.swift
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// Copyright © 2019 Esri.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import UIKit
import ArcGIS

/// A view controller that manages the interface of the Open Mobile Scene (Scene
/// Package) sample.
class OpenMobileSceneViewController: UIViewController {
    /// The mobile scene package used by the view controller.
    let mobileScenePackage: AGSMobileScenePackage = {
        let mobileScenePackageURL = Bundle.main.url(forResource: "philadelphia", withExtension: "mspk")!
        return AGSMobileScenePackage(fileURL: mobileScenePackageURL)
    }()

    /// The scene view managed by the view controller.
    @IBOutlet weak var sceneView: AGSSceneView!

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)

        mobileScenePackage.load { [weak self] _ in
            self?.mobileScenePackageDidLoad()
        }
    }

    /// Called in response to the mobile scene package load operation
    /// completing.
    func mobileScenePackageDidLoad() {
        loadViewIfNeeded()
        if let error = mobileScenePackage.loadError {
            presentAlert(error: error)
        } else {
            sceneView.scene = mobileScenePackage.scenes.first
        }
    }

    // MARK: UIViewController

    override func viewDidLoad() {
        super.viewDidLoad()

        // Add the source code button item to the right of navigation bar.
        (self.navigationItem.rightBarButtonItem as? SourceCodeBarButtonItem)?.filenames = ["OpenMobileSceneViewController"]
    }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.