The view status includes information on the loading state of layers and whether layers are visible at a given scale. You might change how a layer is displayed in a layer list to communicate whether it is being viewed in the map. For example, you could show a loading spinner next to its name when the view status is Loading, grey out the name when NotVisible or OutOfScale, show the name normally when Active, or with a warning or error icon when the status is Warning or Error.
How to use the sample
Tap the Load layer button to add a feature layer to the map. The current view status of the layer will display on the map. Zoom in and out of the map and note the layer disappears when the map is scaled outside of its min and max scale range. Control the layer's visibility with the Hide layer button. If you disconnect your device from the network and pan around the map, a warning will display. Reconnect to the network to remove the warning. The layer's current view status will update accordingly as you carry out these actions.
How it works
Create a Map with some operational layers.
Set the map on a MapView.
Connect to the layerViewStateChanged signal from the map view.
Display the LayerViewStatus flag for the FeatureLayer.
The following are members of the LayerViewStatus enum:
Enums.LayerViewStatusActive: The layer in the view is active.
Enums.LayerViewStatusNotVisible: The layer in the view is not visible.
Enums.LayerViewStatusOutOfScale: The layer in the view is out of scale. A status of Enums.LayerViewStatusOutOfScale indicates that the view is zoomed outside of the scale range of the layer. If the view is zoomed too far in (e.g. to a street level), it is beyond the max scale defined for the layer. If the view has zoomed too far out (e.g. to global scale), it is beyond the min scale defined for the layer.
Enums.LayerViewStatusLoading: The layer in the view is loading. Once loading has completed, the layer will be available for display in the view. If there was a problem loading the layer, the status will be set to ERROR.
Enums.LayerViewStatusError: The layer in the view has an unrecoverable error. When the status is Enums.LayerViewStatusError, the layer cannot be rendered in the view. For example, it may have failed to load, be an unsupported layer type, or contain invalid data.
Enums.LayerViewStatusWarning: The layer in the view has a non-breaking problem with its display, such as incomplete information (eg. by requesting more features than the max feature count of a service) or a network request failure.
If your device supports airplane mode, you can toggle this on and pan around the map to see layers display the WARNING status when they cannot online fetch data. Toggle airplane mode back off to see the warning disappear.
Tags
layer, load, map, status, view, visibility
Sample Code
DisplayLayerViewDrawState.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// [WriteFile Name=DisplayLayerViewDrawState, Category=Maps]// [Legal]// Copyright 2020 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 QtQuick.Layouts
import Esri.ArcGISRuntime
import Esri.ArcGISRuntime.Toolkit
Rectangle {
id: rootRectangleclip: truewidth: 800height: 600 readonly property string portalItemId: "b8f4033069f141729ffb298b7418b653"property var statusStringList: []
property var warningMessage: ""MapView {
id: mapViewanchors.fill: parentComponent.onCompleted: {
// Set the focus on MapView to initially enable keyboard navigation forceActiveFocus();
}
Map {
Basemap {
initStyle: Enums.BasemapStyleArcGISTopographic
}
}
FeatureLayer {
id: featureLayerserviceLayerIdAsInt: 0minScale: 400000000maxScale: 400000000 / 10visible: loadLayerButton.text === qsTr("Hide Layer") ? true : falsePortalItem {
id: portalItemitemId: portalItemId
}
// once loaded set the viewpointonLoadStatusChanged: {
if (loadStatus !== Enums.LoadStatusLoaded)
return;
mapView.map.operationalLayers.append(featureLayer);
mapView.setViewpointCenter(viewPoint);
mapView.setViewpointScale(40000000.0);
}
}
Dialog {
id: warningDialoganchors.centerIn: parentstandardButtons: Dialog.Ok
visible: warningMessage !== "" ? true : falseText {
id: warningTexttext: warningMessage;
}
}
onLayerViewStateChanged: (layer, layerViewState) => {
// only update list if the layer is the feature layer.if (layer.name !== featureLayer.name)
return;
// clear list for new view state(s). statusStringList = [];
if (layerViewState.statusFlags & Enums.LayerViewStatusActive) {
statusStringList.push("Active");
}
if (layerViewState.statusFlags & Enums.LayerViewStatusError) {
statusStringList.push("Error");
}
if (layerViewState.statusFlags & Enums.LayerViewStatusLoading) {
statusStringList.push("Loading");
}
if (layerViewState.statusFlags & Enums.LayerViewStatusNotVisible) {
statusStringList.push("NotVisible");
}
if (layerViewState.statusFlags & Enums.LayerViewStatusOutOfScale) {
statusStringList.push("OutOfScale");
}
if (layerViewState.statusFlags & Enums.LayerViewStatusWarning) {
statusStringList.push("Warning");
warningMessage = qsTr("Warning message: %1".arg(layerViewState.loadError.message));
}
layerViewStatusRepeater.model = statusStringList;
}
Rectangle {
id: controlRectanchors {
bottom: loadLayerButton.top
horizontalCenter: parent.horizontalCenter
margins: 5 }
width: childrenRect.width
height: childrenRect.height
color: "#1976D2"radius: 3MouseArea {
width: controlLayout.childrenRect.width
height: controlLayout.childrenRect.height
onClicked: mouse => mouse.accepted = true;
onWheel: wheel => wheel.accepted = true;
}
ColumnLayout{
id: controlLayoutText {
id: textHeadertext: qsTr("Current view status:")
color: "white"Layout.alignment: Qt.AlignHCenter
}
Column {
id: columnLayout.alignment: Qt.AlignHCenter
Repeater {
id: layerViewStatusRepeaterItem {
width: childrenRect.width
height: childrenRect.height
Text {
text: modelData
color: "white" }
}
}
}
}
}
Button {
id: loadLayerButtonanchors {
bottom: mapView.attributionTop
horizontalCenter: parent.horizontalCenter
margins: 5 }
text: qsTr("Load Layer")
enabled: featureLayer.loadStatus !== Enums.LoadStatusLoading ? true : falseclip: trueonClicked: {
if (text === qsTr("Load Layer")) {
// load a feature layer from a portal item featureLayer.load();
text = qsTr("Hide Layer");
}
elseif (text === qsTr("Hide Layer"))
text = qsTr("Show Layer");
elseif (text === qsTr("Show Layer"))
text = qsTr("Hide Layer");
}
}
}
Point {
id: viewPointx: -11000000y: 4500000spatialReference: Factory.SpatialReference.createWebMercator();
}
}