Skip to content

Search symbol style dictionary

View on GitHub

Find symbols within the mil2525d specification that match a keyword.

Image of Search symbol style dictionary sample

Use case

You can use support for military symbology to allow users to report changes in the field using the correct military symbols.

How to use the sample

The sample uses a pre-defined set of search parameters to search the symbol style. Results are shown in a list.

How it works

  1. Create a symbol dictionary with the mil2525d specification by passing the URL to a .stylx file to the SymbolDictionary initializer.
  2. Create SymbolStyleSearchParameters.
  3. Add members to the names, tags, symbolClasses, categories, and keys list fields of the search parameters.
  4. Search for symbols using the parameters with searchSymbols(using:) method.
  5. Get the Symbol from the list of returned SymbolStyleSearchResults.

Relevant API

  • Symbol
  • SymbolDictionary
  • SymbolStyleSearchParameters
  • SymbolStyleSearchResult

Additional information

This sample features the mil2525D specification. ArcGIS Maps SDK supports other military symbology standards, including mil2525C and mil2525B(change 2). See the Military Symbology Styles overview on ArcGIS Solutions for Defense for more information about support for military symbology.

Tags

CIM, defense, look up, MIL-STD-2525B, MIL-STD-2525C, MIL-STD-2525D, mil2525b, mil2525c, mil2525d, military, military symbology, search, symbology

Sample Code

SearchSymbolStyleDictionaryView.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
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
// Copyright 2025 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
//
//   https://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 ArcGIS
import SwiftUI

struct SearchSymbolStyleDictionaryView: View {
    /// The error shown in the error alert.
    @State private var error: Error?
    /// The view model for the sample.
    @State private var model = Model()
    /// The search results from the symbol style search.
    @State private var searchResults: [SymbolStyleSearchResult] = []

    var body: some View {
        List {
            ForEach(searchResults, id: \.key) { result in
                Section("Key: \(result.key)") {
                    Label {
                        Text(result.name)
                            .lineLimit(1)
                            .textSelection(.enabled)
                    } icon: {
                        AsyncSwatch(searchResult: result)
                    }

                    LabeledContent("Category", value: result.category)

                    NavigationLink {
                        List(result.tags, id: \.self) { tag in
                            Text(tag)
                        }
                        .navigationTitle("Tags")
                    } label: {
                        LabeledContent("Tags") {
                            Text("^[\(result.tags.count) tag](inflect: true)")
                        }
                    }

                    LabeledContent("Symbol Class", value: result.symbolClass)
                }
            }
        }
        .task {
            do {
                try await model.dictionarySymbolStyle.load()
                searchResults = try await model.searchSymbolStyles()
            } catch {
                self.error = error
            }
        }
        .errorAlert(presentingError: $error)
    }
}

private extension SearchSymbolStyleDictionaryView {
    /// The view model for the sample.
    class Model {
        /// A MIL-STD-2525D dictionary symbol style from a file.
        let dictionarySymbolStyle = DictionarySymbolStyle(url: .mil2525dStyleFile)
        /// The parameters used to search for symbol styles.
        private let symbolStyleSearchParameters: SymbolStyleSearchParameters = {
            let parameters = SymbolStyleSearchParameters()
            // Sets the search parameters to find specific symbols. You can
            // specify names, tags, symbol classes, categories, and keys.
            parameters.addName("Maritime Points")
            parameters.addTags(["MAIN", "Point"])
            parameters.addSymbolClass("3")
            parameters.addCategory("Point")
            parameters.addKeys([
                "25210100",
                "25210200",
                "25210400",
                "25210500",
                "25210700",
                "25210900"
            ])
            return parameters
        }()

        /// Searches the dictionary symbol style using the baked-in parameters.
        /// - Returns: An array of symbol style search results.
        @MainActor
        func searchSymbolStyles() async throws -> [SymbolStyleSearchResult] {
            try await dictionarySymbolStyle.searchSymbols(using: symbolStyleSearchParameters)
        }
    }

    struct AsyncSwatch: View {
        /// The display scale of the environment.
        @Environment(\.displayScale) private var displayScale

        /// The search result to create a swatch.
        let searchResult: SymbolStyleSearchResult
        /// The result of creating the swatch image.
        @State private var result: Result<UIImage, Error>?

        var body: some View {
            Group {
                switch result {
                case .none:
                    ProgressView()
                case .failure:
                    Image(systemName: "exclamationmark.triangle")
                case .success(let image):
                    Image(uiImage: image)
                }
            }
            .task {
                result = await Result {
                    try await searchResult.symbol.makeSwatch(scale: displayScale)
                }
            }
        }
    }
}

private extension URL {
    /// The URL to the "Joint Military Symbology MIL-STD-2525D" mobile style file.
    static var mil2525dStyleFile: URL {
        Bundle.main.url(forResource: "mil2525d", withExtension: "stylx")!
    }
}

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