Display drawing status

View on GitHubSample viewer app

Get the draw status of your map view or scene view to know when all layers in the map or scene have finished drawing.

Image of display drawing status

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

  1. Create an instance of AGSMapView.
  2. 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.
  3. 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

class MapViewDrawStatusViewController: UIViewController {
    @IBOutlet private weak var mapView: AGSMapView!
    @IBOutlet private weak var activityIndicatorView: UIView!

    private var map: AGSMap?
    /// The observation of the map view's draw status.
    private var drawStatusObservation: NSKeyValueObservation?

    override func viewDidLoad() {
        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())))
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        drawStatusObservation = mapView.observe(\.drawStatus, options: .initial) { [weak self] (mapView, _) in
            DispatchQueue.main.async {
                self?.activityIndicatorView.isHidden = mapView.drawStatus == .completed
            }
        }
    }

    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        drawStatusObservation = nil
    }
}

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