Display subtype feature layer

View inQMLC++
View on GitHub
Sample viewer app

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

screenshot

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 using this sublayer's setVisible property.
  5. Change the sublayer's symbology with SubtypeSublayer::setRenderer().
  6. Update the sublayer's minimum scale value with SubtypeSublayer::setMinScale().

Relevant API

  • LabelDefinition
  • ServiceFeatureTable
  • SimpleLabelExpression
  • SubtypeFeatureLayer
  • SubtypeSublayer
  • TextSymbol

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.

Additional information

Credentials:

  • Username: viewer01
  • Password: I68VGU^nMurF

Tags

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

Sample Code

DisplaySubtypeFeatureLayer.qmlDisplaySubtypeFeatureLayer.cppDisplaySubtypeFeatureLayer.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
// [WriteFile Name=DisplaySubtypeFeatureLayer, Category=Layers]
// [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.6
import QtQuick.Controls 2.2
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import QtQuick.Shapes 1.12
import Esri.Samples 1.0

Item {

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

        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: !busy.visible
                    onCheckedChanged: model.switchSublayerVisibility();
                }

                RadioButton {
                    text: qsTr("Show original renderer")
                    Layout.margins: 2
                    Layout.alignment: Qt.AlignLeft
                    checked: true
                    enabled: !busy.visible
                    onCheckedChanged: {
                        if (checked)
                            model.setOringalRenderer();
                    }
                }

                RadioButton {
                    text: qsTr("Show alternative renderer")
                    Layout.margins: 2
                    Layout.alignment: Qt.AlignLeft
                    enabled: !busy.visible
                    onCheckedChanged: {
                        if (checked)
                            model.setAlternativeRenderer();
                    }
                }

                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(Math.round(model.mapScale)))
                    Layout.margins: 2
                    Layout.alignment: Qt.AlignLeft
                }

                Text {
                    text: qsTr("Sublayer min scale: %1".arg(model.sublayerMinScale > 0.0 ? Math.round(model.sublayerMinScale) : "not set"))
                    Layout.margins: 2
                    Layout.alignment: Qt.AlignLeft
                }

                Button {
                    text: qsTr("Set sublayer minimum scale")
                    Layout.margins: 2
                    Layout.alignment: Qt.AlignLeft
                    enabled: !busy.visible
                    onClicked: model.setSublayerMinScale();
                }
            }
        }

        BusyIndicator {
            id: busy
            anchors.centerIn: parent
            visible: model.busy
        }
    }

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

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