Get the draw status of your map view or scene view to know when all layers in the map or scene have finished drawing.
Use case
You may want to display a loading indicator while layers are loading, which could then be removed on completed.
How to use the sample
Pan and zoom around the map. Observe drawing status of the map in the toolbar.
How it works
Create an instance of AGSMapView.
Using KVO, add an observer for drawStatus of type AGSDrawStatus. It could either be inProgress or completed based on if the map is currently drawing or not.
Every time it changes the UIActivityIndicatorView is shown or hidden.
Relevant API
AGSDrawStatus
AGSMap
AGSMapView
Tags
draw, loading, map, render
Sample Code
MapViewDrawStatusViewController.swift
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
// Copyright 2016 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.import UIKit
import ArcGIS
classMapViewDrawStatusViewController: UIViewController{
@IBOutletprivateweakvar mapView: AGSMapView!
@IBOutletprivateweakvar activityIndicatorView: UIView!
privatevar map: AGSMap?
/// The observation of the map view's draw status.privatevar drawStatusObservation: NSKeyValueObservation?
overridefuncviewDidLoad() {
super.viewDidLoad()
// Add the source code button item to the right of navigation bar. (self.navigationItem.rightBarButtonItem as!SourceCodeBarButtonItem).filenames = ["MapViewDrawStatusViewController"]
// Instantiate the map with topographic basemap. map =AGSMap(basemapStyle: .arcGISTopographic)
// Add a feature layer.let featureTable =AGSServiceFeatureTable(url: URL(string: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/0")!)
let featureLayer =AGSFeatureLayer(featureTable: featureTable)
map?.operationalLayers.add(featureLayer)
// Assign the map to mapView. mapView.map = map
mapView.setViewpoint(AGSViewpoint(targetExtent: AGSEnvelope(xMin: -13639984, yMin: 4537387, xMax: -13606734, yMax: 4558866, spatialReference: .webMercator())))
}
overridefuncviewWillAppear(_animated: Bool) {
super.viewWillAppear(animated)
drawStatusObservation = mapView.observe(\.drawStatus, options: .initial) { [weakself] (mapView, _) inDispatchQueue.main.async {
self?.activityIndicatorView.isHidden = mapView.drawStatus == .completed
}
}
}
overridefuncviewDidDisappear(_animated: Bool) {
super.viewDidDisappear(animated)
drawStatusObservation =nil }
}