Learn how to display a map A map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more from a mobile map package (MMPK) A mobile map package (MMPK) is a standalone file that contains one or more map definitions, including the basemap layers, data layers, layer styles, and pop-up styles for use in offline applications built with ArcGIS Maps SDKs for Native Apps. Learn more .

display a map from a mobile map package

In this tutorial you will display a fully interactive map A map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more from a mobile map package (MMPK) A mobile map package (MMPK) is a standalone file that contains one or more map definitions, including the basemap layers, data layers, layer styles, and pop-up styles for use in offline applications built with ArcGIS Maps SDKs for Native Apps. Learn more . The map contains a basemap layer A basemap layer is the layer in a map or scene that displays basemap data. The data source for a basemap layer is typically a basemap service. Learn more and data layers A data layer is a layer that references geographic data from a file or a service and is used to visualize the data in a map or scene. Learn more and does not require a network connection.

Prerequisites

Before starting this tutorial:

  1. You need an ArcGIS Location Platform or ArcGIS Online account.

  2. Your system meets the system requirements.

Develop or Download

You have two options for completing this tutorial:

  1. Option 1: Develop the code or
  2. Option 2: Download the completed solution

Option 1: Develop the code

  1. Complete the Display a map tutorial.
  2. Continue with the following instructions to display a map from a mobile map package (.mmpk) file.

Add a mobile map package

You will add a mobile map package (MMPK) A mobile map package (MMPK) is a standalone file that contains one or more map definitions, including the basemap layers, data layers, layer styles, and pop-up styles for use in offline applications built with ArcGIS Maps SDKs for Native Apps. Learn more to your Xcode project. To get an .mmpk file, you can complete the Create a mobile map package tutorial or download its solution.

Once you have the mobile map package:

  1. In Xcode’s app menu, click File > Add Files to ”…”.
  2. Navigate to and select the .mmpk file. If you used the tutorial solution, it will be named MahouRivieraTrails.mmpk.
  3. Choose Show Options, select the Copy items if needed checkbox, and ensure the project target is selected in Add to targets. Click Add.

Open the mobile map package and display a map

Select a map A map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more from the maps contained in a mobile map package A mobile map package (MMPK) is a standalone file that contains one or more map definitions, including the basemap layers, data layers, layer styles, and pop-up styles for use in offline applications built with ArcGIS Maps SDKs for Native Apps. Learn more , and display it in a map view. Use the MobileMapPackage class to access the mobile map package, and load it to read its contents.

  1. In Xcode, in the Project Navigator, click ContentView.swift.

  2. Update the map variable to initialize a simple map object. Setting a basemap and initial viewpoint is not needed in this scenario.

    ContentView.swift
    struct ContentView: View {
    @State private var map = Map()
    var body: some View {
    MapView(map: map)
    }
    }
  3. Create a function called loadMobileMapPackage() to set the MobileMapPackage referencing the mobile map package A mobile map package (MMPK) is a standalone file that contains one or more map definitions, including the basemap layers, data layers, layer styles, and pop-up styles for use in offline applications built with ArcGIS Maps SDKs for Native Apps. Learn more you added to the project.

    ContentView.swift
    struct ContentView: View {
    @State private var map = Map()
    private func loadMobileMapPackage() async throws {
    guard let mobileMapPackage = MobileMapPackage(name: "MahouRivieraTrails", bundle: .main) else { return }
    }
    }
  4. Load the MobileMapPackage and check that it loads without error. Set the first map A map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more in the package to the @State map.

    ContentView.swift
    private func loadMobileMapPackage() async throws {
    guard let mobileMapPackage = MobileMapPackage(name: "MahouRivieraTrails", bundle: .main) else { return }
    try await mobileMapPackage.load()
    guard let map = mobileMapPackage.maps.first else { return }
    self.map = map
    }
  5. Lastly, as the MapView is being built, use the .task view modifier to asynchronously call the loadMobileMapPackage().

    ContentView.swift
    32 collapsed lines
    // Copyright 2024 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
    //
    // https://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 SwiftUI
    import ArcGIS
    struct ContentView: View {
    @State private var map = Map()
    private func loadMobileMapPackage() async throws {
    guard let mobileMapPackage = MobileMapPackage(name: "MahouRivieraTrails", bundle: .main) else { return }
    try await mobileMapPackage.load()
    guard let map = mobileMapPackage.maps.first else { return }
    self.map = map
    }
    var body: some View {
    MapView(map: map)
    .task {
    do {
    try await loadMobileMapPackage()
    } catch {
    print(error)
    }
    }
    }
    2 collapsed lines
    }

Run the solution

Press Command + R to run the app.

You should see a map A map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more of trail heads, trails, and parks for the area south of the Santa Monica mountains. You will be able to pinch (to zoom and rotate), drag, and double-tap the map view to explore the map.

Alternatively, you can download the tutorial solution, as follows.

Option 2: Download the solution

  1. Click the Download solution link under Solution and unzip the file to a location on your machine.

  2. Open the .xcodeproj file in Xcode.

Run the solution

Press Command + R to run the app.

You should see a map A map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more of trail heads, trails, and parks for the area south of the Santa Monica mountains. You will be able to pinch (to zoom and rotate), drag, and double-tap the map view to explore the map.

What’s next?

Learn how to use additional API features, ArcGIS location services, and ArcGIS tools in these tutorials: