Create symbol styles from web styles

View inC++QMLView on GitHubSample viewer app

Create symbol styles from a style file hosted on a portal.

screenshot

Use case

Style files hosted on an ArcGIS Online or Enterprise portal are known as web styles. They can be used to style symbols on a feature layer or graphic overlay. Since styles are published from ArcGIS Pro, you can author and design your own beautiful multilayer vector symbols. These vector symbols look good at any resolution and scale well. Runtime users can now access these styles from their native application, and make use of the vector symbols within them to enhance features and graphics in the map.

How to use the sample

The sample displays a map with a set of symbols that represent the categories of the features within the dataset. Pan and zoom on the map and view the legend to explore the appearance and names of the different symbols from the selected symbol style.

How it works

  1. Create a FeatureLayer and add it to the map.
  2. Create a UniqueValueRenderer and add it to the feature layer.
  3. Create a SymbolStyle from a portal by passing in the web style name and portal URL. * Note: passing null as the portal will default to ArcGIS.com.
  4. Create SearchSymbolParameters and set the keys parameter to the names of the symbols you want to display.
  5. Search for symbols in the SymbolStyle by name using symbolStyle->searchSymbols(symbolStyleSearchParameters).
  6. Call fetchSymbol on each SymbolStyleSearchResult in the returned SymbolStyleSearchResultListModel to generate a symbol for each search key.
  7. Create UniqueValue objects for each symbol with defined values to map the symbol to features on the feature layer.
  8. Add each UniqueValue to the UniqueValueRenderer.

Relevant API

  • FeatureLayer
  • Symbol
  • SymbolStyle
  • UniqueValue
  • UniqueValueRenderer

About the data

The sample uses the 'Esri2DPointSymbolsStyle' Web Style.

The map shows features from the LA County Points of Interest service hosted on ArcGIS Online.

Additional information

2D web styles, dictionary web styles, and 3D web styles can all be hosted on an ArcGIS Online or Enterprise portal.

Tags

renderer, symbol, symbology, web style

Sample Code

CreateSymbolStylesFromWebStyles.qml
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// [WriteFile Name=CreateSymbolStylesFromWebStyles, Category=DisplayInformation]
// [Legal]
// Copyright 2021 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 2.6
import Esri.ArcGISRuntime 100.15

Rectangle {
    id: rootRectangle
    clip: true
    width: 800
    height: 600
    property var legendItems: []

    SymbolStyle {
        id: symbolStyle
        styleName: "Esri2DPointSymbolsStyle"

        SymbolStyleSearchParameters {
            id: symbolStyleSearchParameters
            keys: ["atm", "beach", "campground", "city-hall", "hospital", "library", "park", "place-of-worship", "police-station", "post-office", "school", "trail"]
            keysStrictlyMatch: true
        }

        Component.onCompleted: {
            symbolStyle.searchSymbolsStatusChanged.connect(searchSymbolsHandler);
            symbolStyle.searchSymbols(symbolStyleSearchParameters);
        }

        function searchSymbolsHandler() {
            if (symbolStyle.searchSymbolsStatus !== Enums.TaskStatusCompleted)
                return;

            legendItems = symbolStyle.searchSymbolsResult;
            symbolStyle.searchSymbolsResult.forEach((symbolResult) => {
                                                        symbolResult.fetchSymbolStatusChanged.connect(() => fetchSymbolsHandler(symbolResult));
                                                        symbolResult.fetchSymbol();
                                                    });
        }

        function fetchSymbolsHandler(symbolResult) {
            if (symbolResult.fetchSymbolStatus !== Enums.TaskStatusCompleted)
                return;

            const values = getValuesFromSymbolLabel(symbolResult.key);
            values.forEach((value) => {
                               const uniqueValue = ArcGISRuntimeEnvironment.createObject("UniqueValue", {
                                                                                             label: symbolResult.key,
                                                                                             values: [value],
                                                                                             symbol: symbolResult.fetchSymbolResult
                                                                                         }, webLayer);
                               webLayerUniqueValueRenderer.uniqueValues.append(uniqueValue);
                           });
        }

        function getValuesFromSymbolLabel(symbolLabel) {
            switch (symbolLabel) {
            case "atm": return ["Banking and Finance"];
            case "beach": return ["Beaches and Marinas"];
            case "campground": return ["Campgrounds"];
            case "city-hall": return ["City Halls", "Government Offices"];
            case "hospital": return ["Hospitals and Medical Centers", "Health Screening and Testing", "Health Centers", "Mental Health Centers"];
            case "library": return ["Libraries"];
            case "park": return ["Parks and Gardens"];
            case "place-of-worship": return ["Churches"];
            case "police-station": return ["Sheriff and Police Stations"];
            case "post-office": return ["DHL Locations", "Federal Express Locations"];
            case "school": return ["Public High Schools", "Public Elementary Schools", "Private and Charter Schools"];
            case "trail": return ["Trails"];
            default: return [];
            }
        }
    }

    MapView {
        id: mapView
        anchors.fill: parent

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

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

            // Set the scale at which feature symbols and text will appear at their default size
            referenceScale: 100000

            FeatureLayer {
                id: webLayer
                // Set scale symbols to true when we zoom in so the symbols don't take up the entire view
                scaleSymbols: mapView.mapScale >= 80000

                ServiceFeatureTable {
                    url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/LA_County_Points_of_Interest/FeatureServer/0"
                }

                UniqueValueRenderer {
                    id: webLayerUniqueValueRenderer

                    // The UniqueValueRenderer will affect specific features based on the values of the specified FieldName(s)
                    fieldNames: ["cat2"]
                }
            }

            initialViewpoint: ViewpointCenter {
                center: Point {
                    x: -118.44186
                    y: 34.28301
                    spatialReference: SpatialReference { wkid: 4326 }
                }
                targetScale: 7000
            }
        }
    }

    Rectangle {
        id: legendRectangle
        anchors {
            margins: 10
            left: parent.left
            top: parent.top
        }
        height: 545
        width: 175
        color: "lightgrey"
        opacity: 0.9
        clip: true
        border {
            color: "darkgrey"
            width: 1
        }

        // Catch mouse signals so they don't propagate to the map
        MouseArea {
            anchors.fill: parent
            onClicked: mouse.accepted = true
            onWheel: wheel.accepted = true
        }

        Column {
            anchors {
                fill: parent
                margins: 10
            }
            spacing: 2

            Row {
                spacing: 55

                Text {
                    text: qsTr("Legend")
                    font {
                        pixelSize: 18
                        bold: true
                    }
                }
            }

            // Create a list view to display the Legend
            ListView {
                id: legendListView
                anchors.margins: 10
                width: parent.width * .9
                height: parent.height * .9
                clip: true
                model: legendItems

                // Create delegate to display the name with an image
                delegate: Item {
                    id: legendItem
                    width: 175
                    height: 40
                    clip: true

                    Row {
                        spacing: 5
                        anchors.verticalCenter: parent.verticalCenter

                        Image {
                            anchors.verticalCenter: parent.verticalCenter
                            width: 25
                            height: width
                            source: symbolUrl
                        }

                        Text {
                            id: symbolText
                            anchors.verticalCenter: parent.verticalCenter
                            width: 110
                            text: name
                            wrapMode: Text.Wrap
                            font.pixelSize: 12
                        }
                    }
                }
            }

        }
    }
}

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