Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for Qt

Read symbols from a mobile style

Sample Viewer View Sample on GitHub

Open a mobile style (.stylx) and read its contents. Combine several symbols from the style into a single multilayer point symbol, then use it to display graphics in the map view.

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. On startup, read a mobile style file by creating and loading a SymbolStyle.
  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 MultilayerPointSymbol by passing the keys for the selected symbols into SymbolStyle.fetchSymbolWithKeyList.
  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.fetchSymbolWithKeyList
  • 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, multilayer, mobile style, stylx

Sample Code

import QtQuick 2.11
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.3
import Esri.ArcGISRuntime 100.9
import Esri.ArcGISExtras 1.1

Rectangle {
    id: rootRectangle
    clip: true
    width: 800
    height: 600

    readonly property url styleDataPath: System.userHomePath + "/ArcGIS/Runtime/Data/styles/emoji-mobile.stylx"
    property var currentSymbol
    property var currentFace
    property var currentEyes
    property var currentMouth
    property var currentHat

    MapView {
        id: mapView
        anchors.fill: parent

        Map {
            BasemapTopographic {}
        }

        GraphicsOverlay {
            id: graphicsOverlay
        }

        onMouseClicked: {
            const graphic = ArcGISRuntimeEnvironment.createObject("Graphic");
            graphic.geometry = mouse.mapPoint;
            graphic.symbol = currentSymbol;
            graphicsOverlay.graphics.append(graphic);
        }

        Button {
            anchors {
                bottom: mapView.attributionTop
                horizontalCenter: parent.horizontalCenter
                bottomMargin: 10
            }
            text: "Clear Graphics"
            onClicked: graphicsOverlay.graphics.clear();
        }
    }

    SymbolStyle {
        id: symbolStyle
        styleLocation: styleDataPath
        Component.onCompleted: load()

        onLoadStatusChanged: {
            // fetch the default parameters
            if (loadStatus === Enums.LoadStatusLoaded) {
                defaultSearchParameters();
            }
        }

        onDefaultSearchParametersStatusChanged: {
            // search the symbol style with defaults - all symbols will be returned
            if (defaultSearchParametersStatus === Enums.TaskStatusCompleted) {
                searchSymbols(defaultSearchParametersResult);
            }
        }

        onSearchSymbolsStatusChanged: {
            if (searchSymbolsStatus !== Enums.TaskStatusCompleted)
                return;

            // get initial list of symbols
            for (let i = 0; i < searchSymbolsResult.count; i++) {
                const result = searchSymbolsResult.get(i);
                if (result.category === "Face") {
                    currentFace = result;
                    break;
                }
            }

            // fetch a new symbol with the initial symbol layer keys
            updateSymbol();
        }

        onFetchSymbolStatusChanged: {
            if (fetchSymbolStatus !== Enums.TaskStatusCompleted)
                return;

            // set the current symbol
            currentSymbol = fetchSymbolResult;

            // set the color locked preferences per layer
            currentSymbol.symbolLayers.forEach(symbolLyr => symbolLyr.colorLocked = true);

            currentSymbol.symbolLayers.get(0).colorLocked = false;

            // update size
            currentSymbol.size = sizeSlider.value;

            // update color
            currentSymbol.color = colorComboBox.currentText;

            // update swatch
            currentSymbol.swatchImageChanged.connect(()=> {
                symbolImage.source = currentSymbol.swatchImage;
            });

            currentSymbol.createSwatch();
        }
    }

    function updateSymbol() {
        if (!currentFace || !currentEyes || !currentMouth || !currentHat)
            return;

        // fetch the multilayer symbol composed of these 4 symbol layers
        symbolStyle.fetchSymbolWithKeyList([currentFace.key, currentEyes.key, currentMouth.key, currentHat.key]);
    }

    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 {
            dataPath: styleDataPath
            filterKeyword: "Eyes"
            onSelectionCompleted: {
                currentEyes = currentItem;
                updateSymbol();
            }
        }

        Label {
            text: "Mouth"
        }

        SymbolComboBox {
            dataPath: styleDataPath
            filterKeyword: "Mouth"
            onSelectionCompleted: {
                currentMouth = currentItem;
                updateSymbol();
            }
        }

        Label {
            text: "Hat"
        }

        SymbolComboBox {
            dataPath: styleDataPath
            filterKeyword: "Hat"
            onSelectionCompleted: {
                currentHat = currentItem;
                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
            sourceSize.width: 40
            sourceSize.height: 40
            fillMode: Image.PreserveAspectFit
            width: 40
            height: 40
        }
    }
}
import QtQuick 2.11
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.3
import Esri.ArcGISRuntime 100.9

ComboBox {
    id: rootComboBox
    property var style
    property var dataPath
    property var filterKeyword
    property var currentItem
    signal selectionCompleted()

    model: style ? style.searchSymbolsResult : []
    textRole: "name"
    onCurrentTextChanged: {
        currentItem = style.searchSymbolsResult.get(currentIndex);
        selectionCompleted();
    }
    Component.onCompleted: {
        // Create a SymbolStyle and only fetch the filtered symbols
        style = ArcGISRuntimeEnvironment.createObject("SymbolStyle", {
                                                          styleLocation: dataPath
                                                      });

        const params = ArcGISRuntimeEnvironment.createObject("SymbolStyleSearchParameters", {categories: [filterKeyword]});
        style.searchSymbols(params);
    }
    delegate: Item {
        id: cboDelegate
        height: 30
        width: parent.width

        RowLayout {
            Image {
                id: img
                source: symbolUrl
                Layout.preferredWidth: 20
                Layout.preferredHeight: 20
            }
            Label {
                text: name
                Layout.preferredWidth: cboDelegate.width - img.width
                elide: Text.ElideRight
            }
        }

        MouseArea {
            anchors.fill: parent
            onClicked: {
                rootComboBox.currentIndex = index;
                rootComboBox.popup.close();
            }
        }
    }
}