Learn how to download and display an offline map for a user-defined geographical area of a web map .
Offline maps allow users to continue working when network connectivity is poor or lost. If a web map is enabled for offline use, a user can request that ArcGIS generates an offline map for a specified geographic area of interest.
In this tutorial, you will download an offline map for an area of interest from the web map of the stormwater network within Naperville, IL, USA. You can then use this offline map without a network connection.
Prerequisites The following are required for this tutorial:
An ArcGIS account to access your API keys . If you don't have an account, sign up for free . Your system meets the system requirements . Steps Open the Xcode project To start the tutorial, complete the Display a web map tutorial or download and unzip the solution.
Open the .xcodeproj
file in Xcode .
If you downloaded the solution project, set your API key.
More info An API Key enables access to services , web maps , and web scenes hosted in ArcGIS Online .
Go to your developer dashboard to get your API key .
For these tutorials, use your default API key. It is scoped to include all of the services demonstrated in the tutorials.
In Xcode , in the Project Navigator , click AppDelegate.swift .
In the editor , set the APIKey
property on the AGSArcGISRuntime Environment
with your API key .
AppDelegate.swift
Expand
Use dark colors for code blocks Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā
Change line
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
func application ( _ application : UIApplication ,
didFinishLaunchingWithOptions launchOptions : [ UIApplication . LaunchOptionsKey : Any ] ? ) -> Bool {
// Note: it is not best practice to store API keys in source code.
// The API key is referenced here for the convenience of this tutorial.
AGSArcGISRuntimeEnvironment .apiKey = "YOUR_API_KEY"
return true
}
Get the web map item ID You can use ArcGIS tools to create and view web maps . Use the Map Viewer to identify the web map item ID . This item ID will be used later in the tutorial.
Go to the Naperville water network in the Map Viewer in ArcGIS Online . This web map displays a stormwater network within Naperville, Illinois, USA.
Make a note of the item ID at the end of the browser's URL.
More info The item ID should be 5a030a31e42841a89914bd7c5ecf4d8f .
Display the web map You can display a web map using the web map's item ID . Create an AGSMap
from the web map's AGSPortal Item
, and display it in your app's AGSMap View
.
In Xcode , in the Project Navigator , click ViewController.swift .
In the editor , modify the setup Map()
function. Provide the web map's item ID.
More info The code creates an AGSPortal Item
using the AGSPortal
that references ArcGIS Online , and the web map's item I D
. The portal Item
is used to create an AGSMap
that is displayed in the app's AGSMap View
.
ViewController.swift
Expand
Use dark colors for code blocks 33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
33
32
31
30
29
29
29
29
29
30
31
32
33
34
35
36
37
38
39
40
40
40
40
39
38
37
36
35
34
33
32
31
30
29
28
27
27
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
5
5
4
3
2
1
0
-1
-2
-3
-4
-5
-6
-7
-8
-9
-10
-11
-12
-13
-14
-15
-16
-17
-18
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
-19
Change line Change line Change line Change line Change line Change line Change line
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
private func setupMap () {
let map = AGSMap (
item: AGSPortalItem (
portal: AGSPortal .arcGISOnline(withLoginRequired: false ),
itemID: "5a030a31e42841a89914bd7c5ecf4d8f"
)
)
mapView.map = map
}
Setup the UI Setup your UI with a button that allows your users to select an area to download using an AGSGenerate Offline M a p Job
. Then, add a UIProgress View
that reports the job's progress to your user.
Create a method named user Selected Download Offline M a p: ()
and assign it the @objc
keyword. The @objc
method keyword exposes the method to Objective-C, a necessary step for using the UIBar Button Item
API. For now, leave the body of the method blank.
ViewController.swift
Expand
Use dark colors for code blocks 86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
85
84
83
82
82
82
82
82
82
82
82
82
82
82
82
82
82
82
82
82
82
82
81
80
79
77
75
73
71
69
67
65
63
62
61
61
61
60
59
58
57
56
55
54
53
52
51
50
49
48
47
46
45
44
43
42
41
40
39
39
39
40
41
42
42
42
42
42
42
42
42
42
42
42
43
43
42
41
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
-1
-2
-3
-4
-4
Add line. Add line. Add line. Add line.
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
@objc
func userSelectedDownloadOfflineMap ( _ sender : UIBarButtonItem ) {
}
Create a private method to setup the app's UI. Within it, create a UIProgress View
and assign it to navigation Item.title View
.
ViewController.swift
Expand
Use dark colors for code blocks 47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
46
45
44
43
43
43
43
43
43
43
43
43
43
43
43
43
43
43
43
43
43
43
44
45
46
46
46
46
46
46
46
46
46
47
47
47
47
46
45
44
43
42
41
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
25
25
25
25
25
24
23
22
21
20
19
18
17
16
15
15
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
-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
-32
Add line. Add line. Add line. Add line.
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
private func setupUI () {
navigationItem.titleView = UIProgressView ()
}
Reveal the navigation controller's toolbar and create a UIBar Button Item
that allows your user to select an area of the map to take offline.
More info The code creates an array of three UIBar Button Item
objects. The first and last objects reserve flexible space within the toolbar and the middle object is the download button. The button's title reads, "Download Map Area"
, and tapping it performs the method user Selected Download Offline M a p: ()
.
ViewController.swift
Expand
Use dark colors for code blocks 47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
47
46
45
44
43
43
43
43
43
43
43
43
43
43
43
43
43
43
43
43
43
43
43
44
45
46
47
48
49
50
51
52
53
54
55
55
55
55
54
53
52
51
50
49
48
47
46
45
44
43
42
41
40
39
38
37
36
35
34
33
33
33
33
33
33
32
31
30
29
28
27
26
25
24
23
23
23
22
21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
-1
-2
-3
-4
-5
-6
-7
-8
-9
-10
-11
-12
-13
-14
-15
-16
-17
-18
-19
-20
-21
-22
-23
-24
-24
Add line. Add line. Add line. Add line. Add line. Add line. Add line.
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
private func setupUI () {
navigationItem.titleView = UIProgressView ()
navigationController ? .isToolbarHidden = false
let items = [
UIBarButtonItem (barButtonSystemItem: .flexibleSpace, target: nil , action: nil ),
UIBarButtonItem (title: "Download Map Area" , style: .plain, target: self , action: #selector(userSelectedDownloadOfflineMap)),
UIBarButtonItem (barButtonSystemItem: .flexibleSpace, target: nil , action: nil )
]
setToolbarItems(items, animated: true )
}
In the view D i d Load()
method, call setup UI()
.
ViewController.swift
Expand
Use dark colors for code blocks 20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
21
22
23
24
25
26
27
27
27
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
6
6
6
6
6
5
4
3
2
1
0
-1
-2
-3
-4
-4
-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
-51
Add line.
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
override func viewDidLoad () {
super .viewDidLoad()
setupMap()
setupUI()
}
In Xcode , in the Project Navigator , click Main.storyboard .
In the editor , select View Controller
, and in the menu bar , click Editor > Embed In > Navigation Controller .
More info Embedding View Controller
within a Navigation Controller will place a navigation bar at the top of View Controller
. Inside the navigation bar you will find the progress view.
Setup the offline area graphics A graphics overlay is a container for graphics . A graphic is added to display the selected offline area on the map .
In Xcode , in the Project Navigator , click ViewController.swift .
In the editor , create a private AGSGraphics Overlay
property to contain an offline area graphic.
ViewController.swift
Expand
Use dark colors for code blocks 62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
61
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
61
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
61
61
61
61
61
61
60
59
58
57
56
55
54
53
52
51
51
51
50
49
48
47
46
45
44
43
42
41
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
4
Add line.
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
private let graphicsOverlay = AGSGraphicsOverlay ()
Define a private method to setup the graphics overlay. In the method, create an AGSSimple Renderer
to render graphics. Define a symbol for the renderer using an AGSSimple Fill Symbol
and an AGSSimple Line Symbol
.
ViewController.swift
Expand
Use dark colors for code blocks 62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
61
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
77
77
77
77
76
76
76
76
76
76
75
74
73
72
71
70
69
68
67
66
66
66
65
64
63
62
61
60
59
58
57
56
55
54
53
52
51
50
49
48
47
46
45
44
43
42
41
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
20
19
19
Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line.
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
private let graphicsOverlay = AGSGraphicsOverlay ()
private func setupGraphicsOverlay () {
graphicsOverlay.renderer = AGSSimpleRenderer (
symbol: AGSSimpleFillSymbol (
style: .solid,
color: .clear,
outline: AGSSimpleLineSymbol (
style: .solid,
color: .red,
width: 3
)
)
)
mapView.graphicsOverlays.add(graphicsOverlay)
}
Define a private method named that adds a graphic to the graphics overlay for the supplied offline Area
geometry.
ViewController.swift
Expand
Use dark colors for code blocks 62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
62
61
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
81
81
81
81
81
81
80
79
78
77
76
75
74
73
72
71
71
71
70
69
68
67
66
65
64
63
62
61
60
59
58
57
56
55
54
53
52
51
50
49
48
47
46
45
44
43
42
41
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
24
Add line. Add line. Add line. Add line.
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
private let graphicsOverlay = AGSGraphicsOverlay ()
private func setupGraphicsOverlay () {
graphicsOverlay.renderer = AGSSimpleRenderer (
symbol: AGSSimpleFillSymbol (
style: .solid,
color: .clear,
outline: AGSSimpleLineSymbol (
style: .solid,
color: .red,
width: 3
)
)
)
mapView.graphicsOverlays.add(graphicsOverlay)
}
private func addGraphic ( for offlineArea : AGSGeometry ) {
let graphic = AGSGraphic (geometry: offlineArea, symbol: nil )
graphicsOverlay.graphics.add(graphic)
}
In the view D i d Load()
method, call setup Graphics Overlay()
.
ViewController.swift
Expand
Use dark colors for code blocks 20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
21
22
23
24
25
26
27
28
29
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
30
29
28
27
26
25
24
23
22
21
20
20
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
-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
-27
Add line.
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
override func viewDidLoad () {
super .viewDidLoad()
setupMap()
setupUI()
setupGraphicsOverlay()
}
Download the map for offline use When a user specifies an area of the web map to take offline, a number of tasks are performed.
Create a private computed URL
property named temporary Directory URL
. This computed property will generate a unique URL
at which to store the offline map on the device.
ViewController.swift
Expand
Use dark colors for code blocks 86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
87
88
89
89
89
89
89
89
89
89
89
89
89
90
91
92
93
94
95
96
96
96
96
95
94
93
92
91
90
89
88
87
86
85
84
83
82
81
80
79
78
77
76
75
74
73
72
71
70
69
68
67
66
65
64
63
62
61
60
59
58
57
57
Add line. Add line. Add line. Add line.
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
@objc
func userSelectedDownloadOfflineMap ( _ sender : UIBarButtonItem ) {
}
private var temporaryDirectoryURL: URL {
FileManager .default.temporaryDirectory
.appendingPathComponent( ProcessInfo ().globallyUniqueString)
}
Create a private, optional AGSOffline M a p Task
property named offline M a p Task
. The offline map task is used to create an AGSGenerate Offline M a p Job
, provided a few parameters, and a geometry .
ViewController.swift
Expand
Use dark colors for code blocks 101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
101
100
99
98
97
96
95
94
93
92
91
91
91
92
93
94
95
96
97
97
96
95
94
93
92
91
90
89
88
87
86
85
84
83
82
81
80
79
78
77
76
75
74
73
72
71
70
69
68
67
66
65
64
63
62
61
60
59
58
57
57
Add line.
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
private var temporaryDirectoryURL: URL {
FileManager .default.temporaryDirectory
.appendingPathComponent( ProcessInfo ().globallyUniqueString)
}
private var offlineMapTask: AGSOfflineMapTask ?
Create a private, optional AGSGenerate Offline M a p Job
property named offline M a p Job
. The offline map job handles transactions with the service to download an area of the web map offline.
ViewController.swift
Expand
Use dark colors for code blocks 86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
87
88
89
89
89
89
89
89
89
89
89
89
89
90
91
92
93
94
95
96
97
98
99
99
98
97
96
95
94
93
92
91
90
89
88
87
86
85
84
83
82
81
80
79
78
77
76
75
74
73
72
71
70
69
68
67
66
65
64
63
62
61
61
Add line.
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
@objc
func userSelectedDownloadOfflineMap ( _ sender : UIBarButtonItem ) {
}
private var temporaryDirectoryURL: URL {
FileManager .default.temporaryDirectory
.appendingPathComponent( ProcessInfo ().globallyUniqueString)
}
private var offlineMapTask: AGSOfflineMapTask ?
private var offlineMapJob: AGSGenerateOfflineMapJob ?
Define a private method to perform the download. This method receives two parameters, an AGSGeometry
defining the offline area and a URL
at which to store the downloaded map.
ViewController.swift
Expand
Use dark colors for code blocks 108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
107
106
105
104
103
102
101
100
99
98
98
98
98
98
98
98
98
98
98
99
100
101
102
102
102
102
102
102
102
102
102
102
102
102
102
102
102
102
102
102
102
102
102
102
102
102
102
102
102
102
102
102
102
102
102
102
102
103
103
103
Add line. Add line. Add line.
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
private var offlineMapJob: AGSGenerateOfflineMapJob ?
private func downloadOfflineMap ( with offlineArea : AGSGeometry , at downloadDirectory : URL ) {
}
Create an AGSOffline M a p Task
by supplying the web map in the constructor.
ViewController.swift
Expand
Use dark colors for code blocks 108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
107
106
105
104
103
102
101
100
99
98
98
98
98
98
98
98
98
98
98
99
100
101
102
103
104
105
105
105
105
105
105
105
105
105
105
105
105
105
105
105
105
105
105
105
105
105
105
105
105
105
105
105
105
105
105
105
105
106
106
106
Add line. Add line.
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
private var offlineMapJob: AGSGenerateOfflineMapJob ?
private func downloadOfflineMap ( with offlineArea : AGSGeometry , at downloadDirectory : URL ) {
guard let map = mapView.map else { return }
offlineMapTask = AGSOfflineMapTask (onlineMap: map)
}
Use the offline map task to generate offline map job parameters by supplying the offline area geometry.
ViewController.swift
Expand
Use dark colors for code blocks 110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
109
108
107
106
105
104
103
102
101
100
100
100
100
100
100
100
100
100
100
100
100
101
102
103
104
105
106
107
108
109
109
109
109
109
109
109
109
109
109
109
109
109
109
109
109
109
109
109
109
109
109
109
109
109
109
110
111
112
112
112
Add line. Add line. Add line. Add line. Add line.
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
private func downloadOfflineMap ( with offlineArea : AGSGeometry , at downloadDirectory : URL ) {
guard let map = mapView.map else { return }
offlineMapTask = AGSOfflineMapTask (onlineMap: map)
offlineMapTask ? .defaultGenerateOfflineMapParameters(withAreaOfInterest: offlineArea) { [ weak self ] parameters, error in
guard let self = self else { return }
guard let offlineMapTask = self .offlineMapTask else { return }
}
}
Create the generate offline map job by supplying the offline map task with AGSGenerate Offline M a p Parameters
. Use the offline map parameters to specify your preferences for the offline map. Finally, set the job's progress
to the progress view's observed Progress
property and start the job.
More info The offline map job is specified with two parameters.
Set the update Mode
to .no Updates
ensures that the offline map remains read-only. Set the esri Vector Tiles Download Option
to .use Reduced Fonts Service
to reduce the download size by stripping unused language characters from fonts. ViewController.swift
Expand
Use dark colors for code blocks 110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
110
109
108
107
106
105
104
103
102
101
100
100
100
100
100
100
100
100
100
100
100
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
137
137
Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line.
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
private func downloadOfflineMap ( with offlineArea : AGSGeometry , at downloadDirectory : URL ) {
guard let map = mapView.map else { return }
offlineMapTask = AGSOfflineMapTask (onlineMap: map)
offlineMapTask ? .defaultGenerateOfflineMapParameters(withAreaOfInterest: offlineArea) { [ weak self ] parameters, error in
guard let self = self else { return }
guard let offlineMapTask = self .offlineMapTask else { return }
if let parameters = parameters {
parameters.updateMode = .noUpdates
parameters.esriVectorTilesDownloadOption = .useReducedFontsService
let job = offlineMapTask.generateOfflineMapJob(with: parameters, downloadDirectory: downloadDirectory)
( self .navigationItem.titleView as! UIProgressView ).observedProgress = job.progress
var n = 0
job.start(statusHandler: { _ in
while n < job.messages.count {
print ( "Job message \(n) : \(job.messages[n].message) " )
n += 1
}
}, completion: { [ weak self ] result, error in
guard let self = self else { return }
if let result = result {
self .mapView.map = result.offlineMap
} else if let error = error {
print ( "Error downloading the offline map: \(error) " )
return
}
})
self .offlineMapJob = job
} else if let error = error {
print ( "Error fetching default parameters for the area of interest: \(error.localizedDescription) " )
}
}
}
In the user Selected Download Offline M a p: ()
method, use the map view 's visible area geometry to download the map.
ViewController.swift
Expand
Use dark colors for code blocks 86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
87
88
89
90
91
91
91
91
91
91
91
91
91
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
92
Add line.
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
@objc
func userSelectedDownloadOfflineMap ( _ sender : UIBarButtonItem ) {
guard let offlineArea = mapView.visibleArea else { return }
}
Disable the button after the user has selected an area of the map to take offline.
ViewController.swift
Expand
Use dark colors for code blocks 86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
87
88
89
90
91
92
93
93
93
93
93
93
93
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
94
Add line.
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
@objc
func userSelectedDownloadOfflineMap ( _ sender : UIBarButtonItem ) {
guard let offlineArea = mapView.visibleArea else { return }
sender.isEnabled = false
}
Create a graphic for the selected offline area.
ViewController.swift
Expand
Use dark colors for code blocks 86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86
86