Graphics overlay (dictionary renderer)

View inC++QMLView on GitHubSample viewer app

This sample demonstrates applying a dictionary renderer to graphics, in order to display military symbology without the need for a feature table.

screenshot

Use case

Use a dictionary renderer on a graphics overlay to display more transient data, such as military messages coming through a local tactical network.

How to use the sample

Run the sample and view the military symbols on the map.

How it works

  1. Create a new GraphicsOverlay.
  2. Create a new DictionaryRenderer and set it to the graphics overlay.
  3. Create a new DictionarySymbolStyle.
  4. Parse through the XML and create a Graphic for each element:

i. Use the _wkid key to get the geometry's spatial reference. ii. Use the _control_points key to get the geometry's shape. iii. Create a geometry using the shape and spatial reference from above. iv. Create a Graphic for each attribute, utilizing its defined geometry. v. Add the graphic to the graphics overlay.

Relevant API

  • DictionaryRenderer
  • DictionarySymbolStyle
  • GraphicsOverlay

Offline data

To set up the sample's offline data, see the Use offline data in the samples section of the Qt Samples repository overview.

Link Local Location
Mil2525d Stylx File <userhome>/ArcGIS/Runtime/Data/styles/arcade_style/mil2525d.stylx
MIL-STD-2525D XML Message File <userhome>/ArcGIS/Runtime/Data/xml/arcade_style/Mil2525DMessages.xml

About the data

The sample opens to a view of the county Wiltshire, United Kingdom. It displays military symbols illustrating a simulated combat situation in the area.

Tags

defense, military, situational awareness, tactical, visualization

Sample Code

GODictionaryRenderer.qmlGODictionaryRenderer.qmlXmlParser.cppXmlParser.h
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// [WriteFile Name=GODictionaryRenderer, Category=DisplayInformation]
// [Legal]
// 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.
// [Legal]

import QtQuick
import QtQuick.Controls
import Esri.ArcGISRuntime
import Esri.ArcGISExtras
import Esri.samples

Rectangle {
    width: 800
    height: 600

    readonly property url dataPath: {
        Qt.platform.os === "ios" ?
                    System.writableLocationUrl(System.StandardPathsDocumentsLocation) + "/ArcGIS/Runtime/Data" :
                    System.writableLocationUrl(System.StandardPathsHomeLocation) + "/ArcGIS/Runtime/Data"
    }
    property bool graphicsLoaded: false


    // Create MapView that a GraphicsOverlay
    // for the military symbols.
    MapView {
        id: mapView
        anchors.fill: parent

        Map {
            id: map
            Basemap {
                initStyle: Enums.BasemapStyleArcGISTopographic
            }
        }

        Component.onCompleted: {
            // Set the focus on MapView to initially enable keyboard navigation
            forceActiveFocus();

            // Read the XML file and create a graphic from each entry
            xmlParser.parseXmlFileAsync(dataPath + "/xml/arcade_style/Mil2525DMessages.xml");
        }

        // The GraphicsOverlay does not have a valid extent until it has been added
        // to a MapView with a valid SpatialReference
        onSpatialReferenceChanged: {
            setViewpointGeometryAndPadding( graphicsOverlay.extent, 20 );
        }

        //! [Apply Dictionary Renderer Graphics Overlay QML]
        GraphicsOverlay {
            id: graphicsOverlay

            DictionaryRenderer {
                id: dictionaryRenderer
                dictionarySymbolStyle: Factory.DictionarySymbolStyle.createFromFile(dataPath + "/styles/arcade_style/mil2525d.stylx")

                Component.onCompleted: {
                    dictionarySymbolStyle.loadStatusChanged.connect(() => {
                                                                        if (dictionarySymbolStyle.loadStatus === Enums.LoadStatusLoaded) {
                                                                            const dictionarySymbolStyleConfigurations = dictionarySymbolStyle.configurations;
                                                                            for (let i = 0; i < dictionarySymbolStyleConfigurations.length; i++) {
                                                                                if (dictionarySymbolStyleConfigurations[i].name === "model") {
                                                                                    dictionarySymbolStyleConfigurations[i].value = "ORDERED ANCHOR POINTS";
                                                                                }
                                                                            }
                                                                        }
                                                                    });
                }
            }
        }
        //! [Apply Dictionary Renderer Graphics Overlay QML]
    }

    ProgressBar {
        id: progressBar_loading
        anchors {
            horizontalCenter: parent.horizontalCenter
            bottom: parent.bottom
            margins: 5
        }
        indeterminate: true
        visible: !graphicsLoaded
    }

    XmlParser {
        id: xmlParser

        onXmlParseComplete: (parsedXml) => {
                                parsedXml.forEach(element => {createGraphicFromElement(element)});
                                graphicsLoaded = true;
                            }
    }

    function createGraphicFromElement(element) {
        let wkid = element._wkid;
        if (!wkid) {
            // If _wkid was absent, use WGS 1984 (4326) by default.
            wkid = 4326;
        }
        const pointStrings = element._control_points.split(";");
        const sr = ArcGISRuntimeEnvironment.createObject("SpatialReference", { wkid: wkid });
        let geom;
        if (pointStrings.length === 1) {
            // It's a point
            const pointBuilder = ArcGISRuntimeEnvironment.createObject("PointBuilder");
            pointBuilder.spatialReference = sr;
            const coords = pointStrings[0].split(",");
            pointBuilder.setXY(coords[0], coords[1]);
            geom = pointBuilder.geometry;
        } else {
            const builder = ArcGISRuntimeEnvironment.createObject("MultipointBuilder");
            builder.spatialReference = sr;

            for (let ptIndex = 0; ptIndex < pointStrings.length; ptIndex++) {
                const coords = pointStrings[ptIndex].split(",");
                builder.points.addPointXY(coords[0], coords[1]);
            }
            geom = builder.geometry;
        }
        if (geom) {
            const graphic = ArcGISRuntimeEnvironment.createObject("Graphic", { geometry: geom });
            graphic.attributes.attributesJson = {
                "identity": element.identity,
                "symbolset": element.symbolset,
                "symbolentity": element.symbolentity,
                "echelon": element.echelon,
                "specialentitysubtype": element.specialentitysubtype,
                "indicator": element.indicator,
                "modifier2": element.modifier2,
                "uniquedesignation": element.uniquedesignation,
                "additionalinformation": element.additionalinformation
            };
            graphicsOverlay.graphics.append(graphic);
        }
    }
}

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