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.

  3. You need an IDE for Flutter - we recommend VS Code.

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. Open the project you created by completing 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

Add 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 (.mmpk) for distribution with your app.

  1. Create or download the MahouRivieraTrails.mmpk mobile map package. Complete the Create a mobile map package tutorial to create the package yourself. Otherwise, download the solution file: MahouRivieraTrails.mmpk.

  2. In VS Code, create a new folder: assets. Place the mobile map package file within this folder, for example: assets/MahouRivieraTrails.mmpk.

  3. Open pubspec.yaml and add an asset entry for the mobile map package.

    pubspec.yaml
    # ...
    flutter:
    uses-material-design: true
    assets:
    - assets/MahouRivieraTrails.mmpk

Import additional library and packages

As part of this tutorial, you will need to access resources packaged with the app. You will add core dependencies: dart:io and services.dart. dart:io provides access to an API to deal with files and directories, while services.dart will allow you to access the mobile map package file that is packaged with the app. In addition, you’ll add the path_provider package to access local files on the device.

  1. In VS Code, double-click lib\main.dart to open the file.

  2. From the menu bar, select View > Terminal to open a new terminal.

  3. Add the path_provider package to the project as a dependency running the following command:

    flutter pub add path_provider
  4. Import dart:io, services.dart, and path_provider into main.dart.

    main.dart
    import 'dart:io';
    import 'package:flutter/services.dart';
    import 'package:path_provider/path_provider.dart';
    import 'package:flutter/material.dart';
    import 'package:arcgis_maps/arcgis_maps.dart';
    void main() {

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 controller. Use the MobileMapPackage class to access the mobile map package and load it to read its contents.

  1. In lib\main.dart, navigate to the onMapViewReady() and remove all the code contained within the method.

    main.dart
    void onMapViewReady() {
    final map = ArcGISMap.withBasemapStyle(BasemapStyle.arcGISTopographic);
    _mapViewController.arcGISMap = map;
    _mapViewController.setViewpoint(
    Viewpoint.withLatLongScale(
    latitude: 34.02700,
    longitude: -118.80500,
    scale: 72000,
    ),
    );
    }
  2. Within onMapViewReady() define a constant to hold the name of the mobile map package.

    main.dart
    void onMapViewReady() {
    const mobileMapPackageName = 'MahouRivieraTrails.mmpk';
    }
  3. Use rootBundle to load the mobile map package from the project’s assets directory and store the reference within a final variable mobileMapPackageData. In addition, update the onMapViewReady() method signature to denote the method as asynchronous.

    main.dart > onMapViewReady()
    void onMapViewReady() async {
    const mobileMapPackageName = 'MahouRivieraTrails.mmpk';
    // Retrieve the mobile map package from the asset bundle.
    final mobileMapPackageData = await rootBundle.load(
    'assets/$mobileMapPackageName',
    );
    }
  4. Create a path to a temporary directory on the device to write and store the mobile map package.

    main.dart > onMapViewReady()
    // Retrieve the mobile map package from the asset bundle.
    final mobileMapPackageData = await rootBundle.load(
    'assets/$mobileMapPackageName',
    );
    // Path to a temporary directory on the device.
    // NOTE: This location is not backed up and is suitable for storing
    // caches of downloaded files, in this case, your mobile map package.
    final platformTempDir = await getTemporaryDirectory();
    // Define the path on the device to the mobile map package.
    final pathToFile = '${platformTempDir.absolute.path}/$mobileMapPackageName';
    // Create a new file using the path to the mobile map package.
    final mobileMapPackageFile = File(pathToFile);
    // Synchronously write the mobile map package to the file
    // on the device.
    mobileMapPackageFile.writeAsBytesSync(
    mobileMapPackageData.buffer.asUint8List(),
    flush: true,
    );
  5. Create a MobileMapPackage with the path to the file on the device and load it.

    main.dart > onMapViewReady()
    // Synchronously write the mobile map package to the file
    // on the device.
    mobileMapPackageFile.writeAsBytesSync(
    mobileMapPackageData.buffer.asUint8List(),
    flush: true,
    );
    // Create a mobile map package using the Uri to the mobile map package file.
    final mobileMapPackage = MobileMapPackage.withFileUri(
    mobileMapPackageFile.uri,
    );
    // Load the metadata for the mobile map package.
    await mobileMapPackage.load();
  6. Set the map view controller’s ArcGIS map property to the first map in the mobile map package.

    main.dart > onMapViewReady()
    // Load the metadata for the mobile map package.
    await mobileMapPackage.load();
    // Check that the mobile map package is not empty.
    if (mobileMapPackage.maps.isNotEmpty) {
    // Display the first map in the mobile map package in the map
    // view controller.
    _mapViewController.arcGISMap = mobileMapPackage.maps.first;
    }

Run the app

Follow these steps to run the application.

  1. In VS Code’s terminal, run:

    flutter pub upgrade
  2. Run:

    dart run arcgis_maps install
  3. Make sure you have an Android emulator, iOS simulator or physical device configured and running.

  4. In VS Code, select Run > Run Without Debugging.

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 project in VS code.

Run the application

Follow these steps to run the application.

  1. In VS Code’s terminal, run:

    flutter pub upgrade
  2. Run:

    dart run arcgis_maps install
  3. Make sure you have an Android emulator, iOS simulator or physical device configured and running.

  4. In VS Code, select Run > Run Without Debugging.

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.