Offline routing

View inQMLC++
View on GitHub
Sample viewer app

This sample demonstrates how to solve a route on-the-fly using offline data.

screenshot

Use case

You can use an offline network to enable routing in disconnected scenarios. For example, you could provide offline location capabilities to field workers repairing critical infrastructure in a disaster when network availability is limited.

How to use the sample

Click near a road to start adding a stop to the route, click again to place it on the map. A number graphic will show its order in the route. After adding at least 2 stops, a route will display. Choose "Fastest" or "Shortest" to control how the route is optimized. To move a stop, click on the graphic, and while continuing to press on the graphic, move the mouse to reposition. Release the mouse to set the new position. The route will update on-the-fly while moving stops. The green box marks the boundary of the route geodatabase.

How it works

To display a Route using a RouteTask with offline data:

  1. Create the map's Basemap from a local tile package using a TileCache and ArcGISTiledLayer
  2. Create a RouteTask with an offline locator geodatabase
  3. Get the RouteParameters using routeTask.createDefaultParameters()
  4. Create Stops and add them to the route task's parameters.
  5. Solve the Route using routeTask.solveRoute(routeParameters)
  6. Create a graphic with the route's geometry and a SimpleLineSymbol and display it on another GraphicsOverlay.

Relevant API

  • RouteParameters
  • RouteResult
  • RouteTask
  • Stop
  • TravelMode

Offline data

The data used by this sample is available on ArcGIS Online.

Link Local Location
San Diego Streets TPKX <userhome>/ArcGIS/Runtime/Data/tpkx/san_diego

About the data

This sample uses a pre-packaged sample dataset consisting of a geodatabase with a San Diego road network and a tile package with a streets basemap.

Tags

connectivity, disconnected, fastest, locator, navigation, network analysis, offline, routing, shortest, turn-by-turn

Sample Code

OfflineRouting.qmlOfflineRouting.cppOfflineRouting.h
                                                            
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
60
// [WriteFile Name=OfflineRouting, Category=Routing]
// [Legal]
// Copyright 2020 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.
// [Legal]

import QtQuick 2.6
import QtQuick.Controls 2.6
import Esri.Samples 1.0
import QtQuick.Layouts 1.11

Item {
    // add a mapView component
    MapView {
        id: view
        anchors.fill: parent
    }

    RowLayout {
        anchors {
            left: parent.left
            top: parent.top
        }

        ComboBox {
            id: comboBox
            Layout.fillWidth: true
            model: routingModel.travelModeNames
            onCurrentIndexChanged: {
                routingModel.travelModeIndex = currentIndex;
                routingModel.findRoute();
            }
        }

        Button {
            Layout.fillWidth: true
            Layout.fillHeight: true
            text: "Reset"
            onClicked: {
                routingModel.resetMap();
            }
        }
    }

    // Declare the C++ instance which creates the scene etc. and supply the view
    OfflineRoutingSample {
        id: routingModel
        mapView: view
    }
}

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