Group a collection of layers together and toggle their visibility as a group.
Use case
Group layers communicate to the user that layers are related and can be managed together.
In a land development project, you might group layers according to the phase of development.
How to use the sample
The layers in the map will be displayed in a table of contents. Toggle the checkbox next to a layer's name to change its visibility. Turning a group layer's visibility off will override the visibility of its child layers.
How it works
Create an empty GroupLayer.
Create a new layer and add it to the group layer's layers collection.
Set the group layer's GroupVisibilityMode to change its behavior:
Enums.GroupVisibilityModeIndependent allows each sublayer to change its visibility independently.
Enums.GroupVisibilityModeExclusive allows only one sublayer to be visible at a time.
Enums.GroupVisibilityModeInherited treats the group layer as if it is one merged layer.
Create a ListView and bind the model the the scene's operational layer list model.
Create a delegate for the group layer and and another delegate for all other layers. The group layer delegate will have nested checkboxes.
Check that the layer is a group layer. If true, load the group layer delegate. If false, load the other delegate.
Each delegate will use the name and layerVisible roles exposed on the LayerListModel.
To toggle the visibility of the group, simply change the group layer's visibility property.
Relevant API
GroupLayer
Additional information
The full extent of a group layer may change when child layers are added/removed. Group layers do not have a spatial reference, but the full extent will have the spatial reference of the first child layer.
Tags
group layer, layers
Sample Code
GroupLayers.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
// [WriteFile Name=GroupLayers, 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
import QtQuick.Controls
import Esri.ArcGISRuntime
Rectangle {
id: rootRectangleclip: truewidth: 800height: 600SceneView {
id: sceneViewanchors.fill: parentScene {
id: sceneBasemap {
initStyle: Enums.BasemapStyleArcGISImageryStandard
}
Surface {
// add an arcgis tiled elevation sourceArcGISTiledElevationSource {
url: "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer" }
}
// Layers nested as children are appended to the group layerGroupLayer {
id: glname: "Buildings group"visibilityMode: Enums.GroupVisibilityModeExclusive
ArcGISSceneLayer {
url: "https://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/DevA_BuildingShells/SceneServer" }
ArcGISSceneLayer {
url: "https://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/DevB_BuildingShells/SceneServer" }
}
// Add layers outside group layerArcGISSceneLayer {
url: "https://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/DevA_Trees/SceneServer" }
FeatureLayer {
ServiceFeatureTable {
url: "https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/DevelopmentProjectArea/FeatureServer/0" }
}
FeatureLayer {
ServiceFeatureTable {
url: "https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/DevA_Pathways/FeatureServer/1" }
}
}
Component.onCompleted: {
// Set the focus on SceneView to initially enable keyboard navigation forceActiveFocus();
// create initial viewpoint extentconst env = ArcGISRuntimeEnvironment.createObject("Envelope", {
json: {
"spatialReference": {
"wkid":4326 },
"xmax":-122.67960721754773,
"xmin":-122.68647066116789,
"ymax":45.53584958588318,
"ymin":45.531539857343745 }
});
// set viewpoint sceneView.setViewpoint(ArcGISRuntimeEnvironment.createObject("ViewpointExtent", {
extent: env
}));
}
}
// Create a window to display the layersRectangle {
id: layerVisibilityRectanchors {
fill: layerVisibilityListView
margins: -5 }
color: "lightgrey"border.color: "#4D4D4D"opacity: 0.9radius: 5 }
// Create a list view to display the itemsListView {
id: layerVisibilityListViewanchors {
left: parent.left
top: parent.top
margins: 10 }
width: 250height: childrenRect.height
clip: true// Assign the model to the list model of layersmodel: scene.operationalLayers
// Assign the delegate to the delegate created abovedelegate: Item {
property var type: layerType
height: childrenRect.height
// select the component based on the layer typeLoader {
sourceComponent: layerType === Enums.LayerTypeGroupLayer ?
groupLayerDelegate : layerDelegate
}
// Delegate for GroupLayers - Contains secondary repeater for sublayersComponent {
id: groupLayerDelegateColumn {
CheckBox {
id: parentBoxtext: name
checked: layerVisible
onCheckedChanged: layerVisible = checked
}
Repeater {
property var groupLyr: scene.operationalLayers.get(layerVisibilityListView.currentIndex)
model: groupLyr ? groupLyr.layers : nulldelegate: RadioDelegate {
checked: index === 0text: name
leftPadding: indicator.width
width: layerVisibilityRect.width - leftPadding
onCheckedChanged: layerVisible = checked
}
}
}
}
// Delegate for all other layers - standard CheckboxComponent {
id: layerDelegateCheckBox {
text: name
checked: layerVisible
onCheckedChanged: layerVisible = checked
}
}
}
}
}