ArcGIS Runtime SDK for .NET

Open a mobile scene package from ArcGIS Pro

If your users' devices need to operate in a disconnected or offline capacity, use an offline scene in your ArcGIS Runtime app.

For use in ArcGIS Runtime apps, offline scenes must be created in ArcGIS Pro and saved as mobile scene packages (.mspk files). For information on creating and saving .mspk files in ArcGIS Pro, see Create Mobile Scene Package in the ArcGIS Pro tool reference.

You can distribute .mspk files to your users, for use in your app, by:

  • Uploading and sharing the files in your organization (with ArcGIS Online or your portal)

  • Delivering the files to individual devices through common file sharing methods (network share, email, and so on)

Offline scenes can include basemaps, operational layers, 3D scene layers, tiled layers (.tpk), tables, relationship classes, locators and elevation sources as tiled data. Raster elevation sources are not supported.

For details on using scenes while connected (for viewing, interacting with, and analysis), see Display a scene. This type of scene is known as a web scene.

Open an .mspk file in your app

Most mobile scene packages can be accessed directly by instantiating the MobileScenePackage object from the .mspk file. However, raster data that's an operational or basemap layer cannot be read directly from an .mspk file, so it's recommended you always perform a check. To perform this check, follow the steps below.

  1. Make sure the .mspk file gets added to your users' devices. For example, you can have your users download it from ArcGIS Online or your portal to their device when connected.
  2. Check whether the mobile scene package file supports direct reading by calling the MobileScenePackage.IsDirectReadSupportedAsync() method.
  3. If the file can be read directly, skip to step 5.
  4. If the file cannot be read directly, then unpack the .mspk file in an output directory. Before unpacking the file, confirm that the device has sufficient space for the file using the device's native API. An unpacked .mspk file occupies a similar amount of space as the original packaged file. After the unpacking operation completes, you can delete the original .mspk file to save space (unless you need the file for another purpose).

    Tip:

    To avoid having to unpack the .mspk file, instead of adding raster data to an .mspk file as an operational or basemap layer, you can create a .tpk file from the raster data and add that to the scene before creating the .mspk file.

  5. Instantiate the MobileScenePackage object from the .mspk file or output directory.
  6. Load the MobileScenePackage.

    Once you have instantiated and loaded the .mspk file, you can access any of its scenes for display.

  7. To display a scene, pass it to the scene view.

    // Open the scene package.
    await myScenePackage.LoadAsync();
    
    // Check that there is at least one scene.
    if (myScenePackage.Scenes.Count > 0)
    {
      // Display the first scene in the package.
      MySceneView.Scene = myScenePackage.Scenes.First();
    }

Code sample:

// Get the path to the mobile scene package.
string filepath = @"C:\Temp\MobileScenePackages\Data\squaw_valley_raster.mspk";

// Check whether the mobile scene package supports direct read.
bool canBeRead = await MobileScenePackage.IsDirectReadSupportedAsync(filepath);

if (canBeRead == true) // Mobile scene package supports direct read.
{
  // Create an instance of the scene package.
  MobileScenePackage customScenePackage = new MobileScenePackage(filepath);

  try
  {
    // Open the scene package.
    await customScenePackage.LoadAsync();

    // Check that there is at least one scene.
    if (customScenePackage.Scenes.Count > 0)
    {
      // Display the first scene in the package.
      MySceneView.Scene = customScenePackage.Scenes.First();
    }
  }
  catch (Exception ex)
  {
    MessageBox.Show(ex.ToString(), "Error");
  }
}
else // Direct read of the mobile scene package not supported.
{
  // Unpack the scene package to it atomic parts on disk. Note: this should be a new, empty folder location. 
  await MobileScenePackage.UnpackAsync(filepath, @"C:\Temp\MobileScenePackages\Data\UNPACK");

  // Create an instance of the scene package. Note: The scene package will not being accessed by it's 
  // .mspk file extension; provide the path to where the mobile scene package was unpacked.
  MobileScenePackage myScenePackage = new MobileScenePackage(@"C:\Temp\MobileScenePackages\Data\UNPACK");

  try
  {
    // Open the scene package.
    await myScenePackage.LoadAsync();

    // Check that there is at least one scene.
    if (myScenePackage.Scenes.Count > 0)
    {
      // Display the first scene in the package.
      MySceneView.Scene = myScenePackage.Scenes.First();
    }
  }
  catch (Exception ex)
  {
    MessageBox.Show(ex.ToString(), "Error");
  }
}