Read symbols from a mobile style

View inQMLC++
View on GitHub
Sample viewer app

Combine multiple symbols from a mobile style file into a single symbol.

screenshot

Use case

You may choose to display individual elements of a dataset like a water infrastructure network (such as valves, nodes, or endpoints) with the same basic shape, but wish to modify characteristics of elements according to some technical specifications. Multilayer symbols lets you add or remove components or modify the colors to create advanced symbol styles.

How to use the sample

Select a symbol and a color from each of the category lists to create an emoji. A preview of the symbol is updated as selections are made. The size of the symbol can be set using the slider. Click the map to create a point graphic using the customized emoji symbol, and click Clear to clear all graphics from the display.

How it works

  1. Create a new SymbolStyle from a stylx file, and load it.
  2. Get a list of symbols in the style by calling SymbolStyle::searchSymbols.
  3. Display the resulting SymbolStyleSearchResultListModel inside a series of ComboBoxes.
  4. When symbol selections change, create a new multilayer symbol by passing the keys for the selected symbols into SymbolStyle::fetchSymbol.
  5. Iterate through the symbol layers and color lock all symbol layers except the base layer and update the current symbol preview image by calling Symbol::createSwatch.
  6. Create graphics symbolized with the current symbol when the user taps the map view.

Relevant API

  • MultilayerPointSymbol
  • Symbol::createSwatch
  • SymbolLayer
  • SymbolStyle
  • SymbolStyle::searchSymbols
  • SymbolStyle::fetchSymbol
  • SymbolStyleSearchResultListModel
  • SymbolStyleSearchResult
  • SymbolStyleSearchParameters

Offline Data

A mobile style file (created using ArcGIS Pro) provides the symbols used by the sample.

Link Local Location
Emoji mobile style <userhome>/ArcGIS/Runtime/Data/style/emoji-mobile.stylx

About the data

The mobile style file used in this sample was created using ArcGIS Pro, and is hosted on ArcGIS Online. It contains symbol layers that can be combined to create emojis.

Additional information

While each of these symbols can be created from scratch, a more convenient workflow is to author them using ArcGIS Pro and store them in a mobile style file (.stylx). ArcGIS Runtime can read symbols from a mobile style, and you can modify and combine them as needed in your app.

Tags

advanced symbology, mobile style, multilayer, stylx

Sample Code

ReadSymbolsFromMobileStyle.qmlReadSymbolsFromMobileStyle.cppReadSymbolsFromMobileStyle.hSymbolComboBox.qmlSymbolImageProvider.cppSymbolImageProvider.h
                                                                                                                                               
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
// [WriteFile Name=ReadSymbolsFromMobileStyle, Category=DisplayInformation]
// [Legal]
// 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.
// [Legal]

import QtQuick 2.11
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.3
import Esri.Samples 1.0

Item {

    // add a mapView component
    MapView {
        id: view
        anchors.fill: parent

        Button {
            anchors {
                bottom: view.attributionTop
                horizontalCenter: parent.horizontalCenter
                bottomMargin: 10
            }
            text: "Clear Graphics"
            onClicked: model.clearGraphics();
        }
    }

    // Declare the C++ instance which creates the scene etc. and supply the view
    ReadSymbolsFromMobileStyleSample {
        id: model
        mapView: view
    }

    Rectangle {
        anchors {
            fill: optionGrid
            margins: -5
        }
        color: "#efefef"
    }

    GridLayout {
        id: optionGrid
        anchors {
            left: parent.left
            top: parent.top
            margins: 10
        }

        columns: 2

        Label {
            Layout.columnSpan: 2
            Layout.alignment: Qt.AlignCenter
            text: "Change Options to Modify Symbol"
            font.underline: true
        }

        Label {
            text: "Eyes"
        }

        SymbolComboBox {
            id: eyeComboBox
            model: model.eyesResults
            onCurrentTextChanged: updateSymbol()
        }

        Label {
            text: "Mouth"
        }

        SymbolComboBox {
            id: mouthComboBox
            model: model.mouthResults
            onCurrentTextChanged: updateSymbol()
        }

        Label {
            text: "Hat"
        }

        SymbolComboBox {
            id: hatComboBox
            model: model.hatResults
            onCurrentTextChanged: updateSymbol()
        }

        Label {
            text: "Base Color"
        }

        ComboBox {
            id: colorComboBox
            model: ["yellow", "green", "pink"]
            onCurrentTextChanged: updateSymbol()
        }

        Label {
            text: "Size"
        }

        Slider {
            id: sizeSlider
            Layout.preferredWidth: parent.width / 2
            from: 1
            to: 60
            value: 40
            onValueChanged: updateSymbol()
        }

        Label {
            text: "Preview:"
        }

        Image {
            id: symbolImage
            source: model.symbolImageUrl
            sourceSize.width: 40
            sourceSize.height: 40
            fillMode: Image.PreserveAspectFit
            width: 40
            height: 40
        }
    }

    function updateSymbol() {
        model.updateSymbol(hatComboBox.currentIndex, mouthComboBox.currentIndex, eyeComboBox.currentIndex,
                           colorComboBox.currentText, sizeSlider.value);
    }
}

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