Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for Qt

Display subtype feature layer

Sample Viewer View Sample on GitHub

Displays a composite layer of all the subtype values in a feature class.

Use case

This is useful for controlling labeling, visibility and symbology of a given subtype as though they are distinct layers on the map.

How to use the sample

The sample loads with the sublayer visible on the map. Toggle its visibility with the "Show sublayer" checkbox. Change the sublayer's renderer with the radio buttons, using "Show original renderer" or "Show alternative renderer", and set its minimum scale using the "Set sublayer minimum scale" button. This will set the sublayer's minimum scale to that of the current map scale. Zoom in and out to see the sublayer become visible based on its new scale range.

How it works

  1. Create a SubtypeFeatureLayer from a ServiceFeatureTable that defines a subtype, and add it to the Map.
  2. Get a SubtypeSublayer from the subtype feature using its name.
  3. Enable the sublayer's labels and define them with LabelDefinitions.
  4. Set the visibility status by setting this sublayer's visible property.
  5. Change the sublayer's symbology with SubtypeSublayer.renderer.
  6. Update the sublayer's minimum scale value with SubtypeSublayer.minScale.

Relevant API

  • LabelDefinition
  • ServiceFeatureTable
  • SubtypeFeatureLayer
  • SubtypeSublayer

About the data

The feature service layer in this sample represents an electric network in Naperville, Illinois, which contains a utility network with asset classification for different devices.

Tags

asset group, feature layer, labeling, sublayer, subtype, symbology, utility network, visible scale range

Sample Code

import QtQuick 2.6
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import QtQuick.Shapes 1.12
import Esri.ArcGISRuntime 100.9

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

    readonly property var labelJson: { "labelExpression": "[nominalvoltage]", "labelPlacement": "esriServerPointLabelPlacementAboveRight", "useCodedValues": true, "symbol": { "angle": 0, "backgroundColor": [ 0, 0, 0, 0 ], "borderLineColor": [ 0, 0, 0, 0 ], "borderLineSize": 0, "color": [ 0, 0, 255, 255 ], "font": { "decoration": "none", "size": 10.5, "style": "normal", "weight": "normal" }, "haloColor": [ 255, 255, 255, 255 ], "haloSize": 2, "horizontalAlignment": "center", "kerning": false, "type": "esriTS", "verticalAlignment": "middle", "xoffset": 0, "yoffset": 0 } }
    property var subtypeSublayer
    property var originalRenderer
    property double mapScale: mapView ? Math.round(mapView.mapScale) : 0
    property double sublayerMinScale


    MapView {
        id: mapView
        anchors.fill: parent

        Map {
            BasemapStreetsNightVector {}

            // create the feature layer
            SubtypeFeatureLayer  {
                id: subtypeFeatureLayer

                // feature table
                ServiceFeatureTable {
                    id: featureTable
                    url: "https://sampleserver7.arcgisonline.com/arcgis/rest/services/UtilityNetwork/NapervilleElectric/FeatureServer/100"
                }

                onLoadStatusChanged: {
                    if (loadStatus != Enums.LoadStatusLoaded)
                        return;

                    // get the Street Light sublayer and define its labels
                    subtypeSublayer = subtypeFeatureLayer.sublayerWithSubtypeName("Street Light");
                    const labelDefinition = ArcGISRuntimeEnvironment.createObject("LabelDefinition", { json : labelJson});

                    if (!labelDefinition || !subtypeSublayer)
                      return;

                    subtypeSublayer.labelDefinitions.append(labelDefinition);
                    subtypeSublayer.labelsEnabled = true;

                    // get the original renderer of the sublayer
                    originalRenderer = subtypeSublayer.renderer;

                    // set a default minimum scale
                    subtypeSublayer.minScale = 3000.0;
                    sublayerMinScale = subtypeSublayer.minScale;
                }

                onErrorChanged: print("%1 - %2 - %3 - %4".arg(error.code, error.domain, error.message, error.additionalMessage));
            }

            ViewpointExtent {
                extent: Envelope {
                    xMin: -9812691.11079696
                    yMin: 5128687.20710657
                    xMax: -9812377.9447607
                    yMax: 5128865.36767282
                }
            }
        }

        SimpleRenderer {
            id: alternativeRenderer
            SimpleMarkerSymbol {
                style: Enums.SimpleMarkerSymbolStyleDiamond
                color: "magenta"
                size: 20
            }
        }

        Rectangle {
            id: controlsBox
            anchors {
                left: parent.left
                top: parent.top
                margins: 3
            }
            width: childrenRect.width
            height: childrenRect.height
            color: "lightgrey"
            opacity: 0.8
            radius: 5

            // catch mouse signals from propagating to parent
            MouseArea {
                anchors.fill: parent
                onClicked: mouse.accepted = true
                onWheel: wheel.accepted = true
            }

            ColumnLayout {
                id: controlItemsLayout

                CheckBox {
                    text: qsTr("Show sublayer")
                    Layout.margins: 2
                    Layout.alignment: Qt.AlignLeft
                    checked: true
                    enabled: subtypeFeatureLayer.loadStatus === Enums.LoadStatusLoaded ? true : false
                    onCheckedChanged: subtypeSublayer ? subtypeSublayer.visible = !subtypeSublayer.visible : null
                }

                RadioButton {
                    text: qsTr("Show original renderer")
                    Layout.margins: 2
                    Layout.alignment: Qt.AlignLeft
                    checked: true
                    enabled: subtypeFeatureLayer.loadStatus === Enums.LoadStatusLoaded ? true : false
                    onCheckedChanged: {
                        if (checked && subtypeSublayer)
                            subtypeSublayer.renderer = originalRenderer;
                    }
                }

                RadioButton {
                    text: qsTr("Show alternative renderer")
                    Layout.margins: 2
                    Layout.alignment: Qt.AlignLeft
                    enabled: subtypeFeatureLayer.loadStatus === Enums.LoadStatusLoaded ? true : false
                    onCheckedChanged: {
                        if (checked && subtypeSublayer)
                            subtypeSublayer.renderer = alternativeRenderer;
                    }
                }

                Shape {
                    id: pageBreak
                    height: 2
                    ShapePath {
                        strokeWidth: 1
                        strokeColor: "black"
                        strokeStyle: ShapePath.SolidLine
                        startX: 2; startY: 0
                        PathLine { x: controlItemsLayout.width - 2 ; y: 0 }
                    }
                }

                Text {
                    text: qsTr("Current map scale: 1:%1".arg(mapScale))
                    Layout.margins: 2
                    Layout.alignment: Qt.AlignLeft
                }

                Text {
                    text: subtypeSublayer ? qsTr("Sublayer min scale: 1:%1".arg(subtypeSublayer.minScale)) : qsTr("Sublayer min scale:")
                    Layout.margins: 2
                    Layout.alignment: Qt.AlignLeft
                }

                Button {
                    text: qsTr("Set sublayer minimum scale")
                    Layout.margins: 2
                    Layout.alignment: Qt.AlignLeft
                    enabled: subtypeFeatureLayer.loadStatus === Enums.LoadStatusLoaded ? true : false
                    onClicked: subtypeSublayer ? subtypeSublayer.minScale = mapScale : null
                }
            }
        }

        BusyIndicator {
            id: busy
            anchors.centerIn: parent
            visible: subtypeFeatureLayer.loadStatus !== Enums.LoadStatusLoaded ? true : false
        }
    }
}