Take a utility network offline

Starting with version 100.11, you can take certain utility network information offline. Associations, which are used to describe containment, structural attachment, and connection between features with non-coincident geometry, can be queried and displayed with offline data. Simple edits can also be made to utility network features while offline and synchronized back to ArcGIS Enterprise.

The following code takes a web map offline that contains a utility network. The utility network tables are automatically synced with a map when a utility network is detected within.

Expand
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
    func initializeOfflineMapTask() async {
        do {
            try await map.load()
            // Creates the offline map task with the web map.
            offlineMapTask = OfflineMapTask(onlineMap: map)
            await makeGenerateOfflineMapJob()
        } catch {
            print("Error loading map.")
        }
    }

    func makeGenerateOfflineMapJob() async {
        let areaOfInterest = Envelope(xMin: -13049000, yMin: 3861000, xMax: -13048000, yMax: 3861500, spatialReference: map.spatialReference)
        // Creates the default parameters for the offline map task.
        guard let parameters = await makeGenerateParameters(areaOfInterest: areaOfInterest) else { return }
        // Creates the generate offline map job based on the parameters.
        guard let offlineMapTask = offlineMapTask else { return }
        generateOfflineMapJob = offlineMapTask.makeGenerateOfflineMapJob(
            parameters: parameters,
            downloadDirectory: makeTemporaryDirectory()
        )
        // Starts the offline map job.
        generateOfflineMapJob.start()
        do {
            // Awaits the output of the job.
            let output = try await generateOfflineMapJob.output
            // Gets the first utility network in the offline map.
            let utilityNetwork = output.offlineMap.utilityNetworks.first
            try await utilityNetwork?.load()
        } catch {
            print("Error getting first utility network.")
        }
    }

    func makeGenerateParameters(areaOfInterest: Envelope) async -> GenerateOfflineMapParameters? {
        do {
            // Retrieves the default offline map parameters for an area of interest.
            let parameters = try await offlineMapTask?.makeDefaultGenerateOfflineMapParameters(areaOfInterest: areaOfInterest)
            parameters?.includesBasemap = false
            return parameters
        } catch {
            print("Error generating parameters.")
            return nil
        }
    }
Expand

The following code takes a utility network offline using a service geodatabase. The utility network tables only get synced when the sync mode in the generate geodatabase parameters is set to sync system tables.

Expand
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
    func initializeGeodatabaseSyncTask() async {
        do {
            try await map.load()
            // The URL must be to a feature service hosted on ArcGIS Enterprise 10.9 or later.
            let featureServiceURL = URL(string: "https://myserver.esri.com/server/rest/services/SDKTest/FeatureServer")!
            geodatabaseSyncTask = GeodatabaseSyncTask(url: featureServiceURL)
            await makeGenerateGeodatabaseJob()
        } catch {
            print("Error initializing geodatabase sync task.")
        }
    }

    func makeGenerateGeodatabaseJob() async {
        // Makes the default parameters with the area of interest.
        let areaOfInterest = Envelope(xMin: 473240, yMin: 3600000, xMax: 475000, yMax: 3605000, spatialReference: .init(wkid: WKID(26911)!))
        guard let parameters = await makeDefaultParameters(areaOfInterest: areaOfInterest) else { return }
        parameters.utilityNetworkSyncMode = .syncSystemTables
        // Creates a temporary directory to store the downloaded geodatabase.
        let downloadDirectory = makeTemporaryDirectory()
        generateGeodatabaseJob = geodatabaseSyncTask?.makeGenerateGeodatabaseJob(parameters: parameters, downloadFileURL: downloadDirectory)
        // Starts the geodatabase.
        generateGeodatabaseJob.start()
        do {
            // Prints the geodatabase's first utility network.
            let output = try await generateGeodatabaseJob.output
            guard let utilityNetwork = output.utilityNetworks.first else { return }
            print(utilityNetwork.name)
        } catch {
            print("Error getting first utility network.")
            return
        }
    }

    // Makes the default parameters with the area of interest.
    func makeDefaultParameters(areaOfInterest: Envelope) async -> GenerateGeodatabaseParameters? {
        do {
            return try await geodatabaseSyncTask?.makeDefaultGenerateGeodatabaseParameters(extent: areaOfInterest)
        } catch {
            return nil
        }
    }
Expand

For more information about offline workflows using ArcGIS Maps SDKs for Native Apps, see the Offline maps, scenes, and data topic.

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