Convert features into graphics to show them with mil2525d symbols.
Use case
A dictionary renderer uses a style file along with a rule engine to display advanced symbology.
This is useful for displaying features using precise military symbology.
How to use the sample
Pan and zoom around the map. Observe the displayed military symbology on the map.
How it works
Create an AGSGeodatabase.
Create and load an AGSDictionarySymbolStyle using the mil2525d.stylx resource.
Load the geodatabase using AGSGeodatabase.load(completion:).
Once the geodatabase is done loading, create an AGSFeatureLayer from each of the geodatabase's AGSGeodatabaseFeatureTables.
After the last AGSFeatureLayer has loaded, set the AGSMapView's viewpoint to the full extent of all the layers using the method AGSMapViewCommon.setViewpointGeometry(_:completion:).
Add the feature layer to the map's operationalLayers.
Create an AGSDictionaryRenderer and attach it to the feature layer.
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
// 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
classFeatureLayerDictionaryRendererViewController: UIViewController{
@IBOutletvar mapView: AGSMapView! {
didSet {
// Initialize the map. mapView.map =AGSMap(basemapStyle: .arcGISTopographic)
// Display symbology using a geodatabase. displayLayersFromGeodatabase()
}
}
funcdisplayLayersFromGeodatabase() {
// Load geodatabase from shared resources.let geodatabaseURL =Bundle.main.url(forResource: "militaryoverlay", withExtension: ".geodatabase")!let generatedGeodatabase =AGSGeodatabase(fileURL: geodatabaseURL)
// Instantiate and load symbol dictionary from shared resources.let styleURL =Bundle.main.url(forResource: "mil2525d", withExtension: "stylx")
let dictionarySymbol =AGSDictionarySymbolStyle(url: styleURL!)
dictionarySymbol.load { [weakself] (error: Error?) iniflet error = error {
self?.presentAlert(error: error)
} else {
return }
}
// Once geodatabase is done loading, create feature layers from each feature table. generatedGeodatabase.load { [weakself] (error: Error?) inguardletself=selfelse { return }
iflet error = error {
self.presentAlert(error: error)
} else {
for featureTable in generatedGeodatabase.geodatabaseFeatureTables {
// Create a feature layer from the feature table.let featureLayer =AGSFeatureLayer(featureTable: featureTable)
// Set the minimum visibility scale. featureLayer.minScale =1000000 featureLayer.load { [weakself] (error: Error?) inguardletself=selfelse { return }
iflet error = error {
self.presentAlert(error: error)
} else {
// Set the viewpoint to the full extent of all layers.self.mapView.setViewpointGeometry(featureLayer.fullExtent!)
}
}
// Add each layer to the map.self.mapView.map?.operationalLayers.add(featureLayer)
// Display features from the layer using mil2525d symbols. featureLayer.renderer =AGSDictionaryRenderer(dictionarySymbolStyle: dictionarySymbol)
}
}
}
}
overridefuncviewDidLoad() {
super.viewDidLoad()
// Add the source code button item to the right of navigation bar. (self.navigationItem.rightBarButtonItem as!SourceCodeBarButtonItem).filenames = ["FeatureLayerDictionaryRendererViewController"]
}
}