Map reference scale

View on GitHubSample viewer app

Set the map's reference scale and which feature layers should honor the reference scale.

Image of Map Image of Map Settings

Use case

Setting a reference scale on a map fixes the size of symbols and text to the desired height and width at that scale. As you zoom in and out, symbols and text will increase or decrease in size accordingly. When no reference scale is set, symbol and text sizes remain the same size relative to the map view.

Map annotations are typically only relevant at certain scales. For instance, annotations to a map showing a construction site are only relevant at that construction site's scale. So, when the map is zoomed out that information shouldn't scale with the map view, but should instead remain scaled with the map.

How to use the sample

When the sample loads, tap the "Settings" button. Tap the "Reference Scale" row, and use the picker to set the map's reference scale (1:500,000 1:250,000 1:100,000 1:50,000). Then tap the "Set to Reference Scale" button to set the map scale to the reference scale.

Tap the "Layers" row to show a list of the map's feature layers. Tap a row to toggle whether that layer should honor the reference scale. Tap "Done" button to dismiss the settings page.

How it works

  1. Get and set the referenceScale property on the AGSMap object.
  2. Get and set the scaleSymbols property on individual AGSFeatureLayer objects.

Relevant API

  • AGSFeatureLayer
  • AGSMap

Additional information

The map reference scale should normally be set by the map's author and not exposed to the end user like it is in this sample.

Tags

map, reference scale, scene

Sample Code

MapReferenceScaleLayerSelectionViewController.swiftMapReferenceScaleLayerSelectionViewController.swiftMapReferenceScaleSettingsViewController.swiftMapReferenceScaleViewController.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
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
//
// Copyright © 2019 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

/// The delegate of a `MapReferenceScaleLayerSelectionViewController`.
protocol MapReferenceScaleLayerSelectionViewControllerDelegate: AnyObject {
    /// Tells the delegate that the given layer was selected.
    ///
    /// - Parameters:
    ///   - controller: The controller sending the message.
    ///   - layer: The layer that was selected.
    func mapReferenceScaleLayerSelectionViewController(_ controller: MapReferenceScaleLayerSelectionViewController, didSelect layer: AGSLayer)
    /// Tells the delegate the the given layer was deselected.
    ///
    /// - Parameters:
    ///   - controller: The controller sending the message.
    ///   - layer: The layer that was deselected.
    func mapReferenceScaleLayerSelectionViewController(_ controller: MapReferenceScaleLayerSelectionViewController, didDeselect layer: AGSLayer)
}

/// A view controller that manages an interface for selecting layers from a
/// list.
class MapReferenceScaleLayerSelectionViewController: UITableViewController {
    /// The layers shown in the table view.
    var layers = [AGSLayer]() {
        didSet {
            guard isViewLoaded else { return }
            tableView.reloadData()
        }
    }
    /// The delegate of the view controller.
    weak var delegate: MapReferenceScaleLayerSelectionViewControllerDelegate?

    /// The index paths of the selected layers.
    private var indexPathsForSelectedRows = Set<IndexPath>()

    /// Selects the given layer in the list.
    ///
    /// - Parameter layer: A layer.
    func selectLayer(_ layer: AGSLayer) {
        guard let row = layers.firstIndex(of: layer) else { return }
        let indexPath = IndexPath(row: row, section: 0)
        indexPathsForSelectedRows.insert(indexPath)
    }

    /// Returns the appropriate accessory type for the cell at the given index
    /// path.
    ///
    /// - Parameter indexPath: An index path.
    /// - Returns: An accessory type. If the corresponding layer is selected,
    /// the type is `checkmark`. Otherwise the type is `none`.
    private func accessoryTypeForCell(at indexPath: IndexPath) -> UITableViewCell.AccessoryType {
        return indexPathsForSelectedRows.contains(indexPath) ? .checkmark : .none
    }
}

extension MapReferenceScaleLayerSelectionViewController /* UITableViewDataSource */ {
    override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return layers.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "LayerCell", for: indexPath)
        cell.textLabel?.text = layers[indexPath.row].name
        cell.accessoryType = accessoryTypeForCell(at: indexPath)
        return cell
    }
}

extension MapReferenceScaleLayerSelectionViewController /* UITableViewDelegate */ {
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        let layer = layers[indexPath.row]
        let cell = tableView.cellForRow(at: indexPath)
        if indexPathsForSelectedRows.contains(indexPath) {
            indexPathsForSelectedRows.remove(indexPath)
            cell?.accessoryType = accessoryTypeForCell(at: indexPath)
            delegate?.mapReferenceScaleLayerSelectionViewController(self, didDeselect: layer)
        } else {
            indexPathsForSelectedRows.insert(indexPath)
            cell?.accessoryType = accessoryTypeForCell(at: indexPath)
            delegate?.mapReferenceScaleLayerSelectionViewController(self, didSelect: layer)
        }
    }
}

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