forked from Esri/arcgis-appstudio-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyApp.qml
496 lines (418 loc) · 19 KB
/
MyApp.qml
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
/* Copyright 2021 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.
*
*/
// You can run your app in Qt Creator by pressing Alt+Shift+R.
// Alternatively, you can run apps through UI using Tools > External > AppStudio > Run.
// AppStudio users frequently use the Ctrl+A and Ctrl+I commands to
// automatically indent the entirety of the .qml file.
import QtQuick 2.6
import QtQuick.Layouts 1.12
import QtQuick.Controls 2.12
import QtQuick.Controls.Material 2.1
import ArcGIS.AppFramework 1.0
import Esri.ArcGISRuntime 100.11
import "controls" as Controls
App {
id: app
width: 414
height: 736
function units(value) {
return AppFramework.displayScaleFactor * value
}
property real scaleFactor: AppFramework.displayScaleFactor
property int baseFontSize : app.info.propertyValue("baseFontSize", 15 * scaleFactor) + (isSmallScreen ? 0 : 3)
property bool isSmallScreen: (width || height) < units(400)
property bool junctionSelected: false
property Point clickPoint
property var barriers: []
property var deviceObjIds: []
property var domainNetwork
property var element
property var identifiedFeature
property var lineObjIds: []
property var mediumVoltageTier
property var myTraceResult
property var startingLocations: []
property var terminal
property var terminals: []
property var utilityNetworkSource
readonly property url featureLayerUrl: "https://sampleserver7.arcgisonline.com/server/rest/services/UtilityNetwork/NapervilleElectric/FeatureServer"
Page{
anchors.fill: parent
header: ToolBar{
id:header
width: parent.width
height: 50 * scaleFactor
Material.background: "#8f499c"
Controls.HeaderBar{}
}
contentItem: Rectangle{
id: rootRectangle
anchors.top:header.bottom
MapView {
id: mapView
anchors.fill: parent
Map {
BasemapStreetsNightVector {}
ViewpointExtent {
Envelope {
xMin: -9813547.35557238
yMin: 5129980.36635111
xMax: -9813185.0602376
yMax: 5130215.41254146
spatialReference: Factory.SpatialReference.createWebMercator();
}
}
// Add the layer with electric distribution lines.
FeatureLayer {
id: lineLayer
ServiceFeatureTable {
url: featureLayerUrl + "/3"
Credential {
username: "viewer01"
password: "I68VGU^nMurF"
}
}
UniqueValueRenderer {
fieldNames: ["ASSETGROUP"]
// set for medium voltage
UniqueValue {
label: "Medium Voltage"
values: ["5"]
SimpleLineSymbol {
style: Enums.SimpleLineSymbolStyleSolid
color: "DarkCyan"
width: 3
}
}
// set for low voltage
UniqueValue {
label: "Low Voltage"
values: ["3"]
SimpleLineSymbol {
style: Enums.SimpleLineSymbolStyleDash
color: "DarkCyan"
width: 3
}
}
}
onSelectFeaturesStatusChanged: checkSelectionStatus();
}
// Add the layer with electric devices.
FeatureLayer {
id: deviceLayer
ServiceFeatureTable {
url: featureLayerUrl + "/0"
Credential {
username: "viewer01"
password: "I68VGU^nMurF"
}
}
onSelectFeaturesStatusChanged: checkSelectionStatus();
}
}
GraphicsOverlay {
id: unGraphicsOverlay
}
onMouseClicked: {
const screenX = mouse.x;
const screenY = mouse.y;
const tolerance = 10;
const returnPopups = false;
clickPoint = mouse.mapPoint;
mapView.identifyLayers(screenX, screenY, tolerance, returnPopups);
}
onIdentifyLayersStatusChanged : {
if (identifyLayersStatus !== Enums.TaskStatusCompleted)
return;
const results = mapView.identifyLayersResults;
const result = results[0];
if (!result) {
dialogText.text = qsTr("Could not identify location.")
traceCompletedDialog.open();
return;
}
identifiedFeature = result.geoElements[0];
utilityNetworkSource = utilityNetwork.definition.networkSource(identifiedFeature.featureTable.tableName);
// get domain network
domainNetwork = utilityNetwork.definition.domainNetwork("ElectricDistribution");
const tiers = domainNetwork.tiers;
for (let i = 0; i < tiers.length; i++) {
if (tiers[i].name === "Medium Voltage Radial")
mediumVoltageTier = tiers[i];
}
if (utilityNetworkSource.sourceType === Enums.UtilityNetworkSourceTypeJunction) {
junctionSelected = true;
const assetGroupFieldName = identifiedFeature.featureTable.subtypeField;
const assetGroupCode = identifiedFeature.attributes.attributeValue(assetGroupFieldName);
let assetGroup;
for (let i = 0; i < utilityNetworkSource.assetGroups.length; i++) {
if (utilityNetworkSource.assetGroups[i].code === assetGroupCode) {
assetGroup = utilityNetworkSource.assetGroups[i];
break;
}
}
const assetTypeCode = identifiedFeature.attributes.attributeValue("assettype");
let assetType;
for (let i = 0; i < assetGroup.assetTypes.length; i++) {
if (assetGroup.assetTypes[i].code === assetTypeCode) {
assetType = assetGroup.assetTypes[i];
break;
}
}
terminals = assetType.terminalConfiguration.terminals;
if (terminals.length > 1) {
multiTerminal.visible = true;
return;
} else if (terminals.length === 1) {
element = utilityNetwork.createElementWithArcGISFeature(identifiedFeature, terminals[0]);
}
} else if (utilityNetworkSource.sourceType === Enums.UtilityNetworkSourceTypeEdge) {
junctionSelected = false;
element = utilityNetwork.createElementWithArcGISFeature(identifiedFeature);
// Compute how far tapped location is along the edge feature.
if (identifiedFeature.geometry.geometryType === Enums.GeometryTypePolyline) {
const line = GeometryEngine.removeZ(identifiedFeature.geometry);
// Set how far the element is along the edge.
element.fractionAlongEdge = GeometryEngine.fractionAlong(line, clickPoint, -1);
}
}
addToParamAndGraphic();
}
}
SimpleMarkerSymbol {
id: startingPointSymbol
style: Enums.SimpleMarkerSymbolStyleCross
color: "lime"
size: 20
}
SimpleMarkerSymbol {
id: barrierPointSymbol
style: Enums.SimpleMarkerSymbolStyleX
color: "Red"
size: 20
}
UtilityNetwork {
id: utilityNetwork
url: featureLayerUrl
Credential {
username: "viewer01"
password: "I68VGU^nMurF"
}
onTraceStatusChanged: {
if (traceStatus !== Enums.TaskStatusCompleted)
return;
if (traceResult.count === 0) {
busy.visible = false;
return;
}
dialogText.text = qsTr("Trace completed.");
traceCompletedDialog.open();
myTraceResult = traceResult.get(0);
const resultElements = myTraceResult.elements;
for (let i = 0; i < resultElements.length; i++) {
if (resultElements[i].networkSource.name === "Electric Distribution Device") {
deviceObjIds.push(resultElements[i].objectId);
} else if (resultElements[i].networkSource.name === "Electric Distribution Line") {
lineObjIds.push(resultElements[i].objectId);
}
}
let deviceParams = ArcGISRuntimeEnvironment.createObject("QueryParameters");
let lineParams = ArcGISRuntimeEnvironment.createObject("QueryParameters");
deviceParams.objectIds = deviceObjIds;
lineParams.objectIds = lineObjIds;
deviceLayer.selectFeaturesWithQuery(deviceParams, Enums.SelectionModeAdd);
lineLayer.selectFeaturesWithQuery(lineParams, Enums.SelectionModeAdd);
}
onErrorChanged: {
dialogText.text = qsTr("%1 - %2".arg(error.message).arg(error.additionalMessage));
traceCompletedDialog.open();
}
onComponentCompleted: {
busy.visible = true;
load();
}
onLoadStatusChanged: {
if (loadStatus === Enums.LoadStatusLoaded)
busy.visible = false;
}
}
UtilityTraceParameters {
id: params
}
Dialog {
id: multiTerminal
modal: true
standardButtons: Dialog.Ok | Dialog.Cancel
x: Math.round(parent.width - width) / 2
y: Math.round(parent.height - height) / 2
ColumnLayout {
Text {
text: qsTr("Select the terminal for this junction.")
Layout.alignment: Qt.AlignHCenter
}
ComboBox {
id: terminalSelection
model: ["High", "Low"]
Layout.alignment: Qt.AlignHCenter
}
}
onAccepted: {
terminal = terminals[terminalSelection.currentIndex];
element = utilityNetwork.createElementWithArcGISFeature(identifiedFeature, terminal);
addToParamAndGraphic();
}
}
Dialog {
id: traceCompletedDialog
modal: true
standardButtons: Dialog.Ok
x: Math.round(parent.width - width) / 2
y: Math.round(parent.height - height) / 2
Text {
id: dialogText
anchors.centerIn: parent
wrapMode: Text.Wrap
}
clip: true
}
BusyIndicator {
id: busy
anchors.centerIn: parent
visible: false
}
Rectangle {
id: backBox
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
}
Column {
GridLayout {
columns: 2
rows: 3
property var centerAlignment: Qt.AlignHCenter | Qt.AlignVCenter
flow: GridLayout.LeftToRight
RadioButton {
id: startingLocBtn
checked: true
text: qsTr("Add starting location(s)")
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
}
RadioButton {
id: barriersBtn
text: qsTr("Add barrier(s)")
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
}
Text {
text: qsTr("Trace Type:")
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
}
ComboBox {
id: traceTypes
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
model: ["Connected", "Subnetwork", "Upstream", "Downstream"]
}
Button {
id: resetBtn
text: qsTr("Reset")
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
enabled: !busy.visible
onClicked: {
params.barriers = null;
barriers = [];
params.startingLocations = null;
startingLocations = [];
deviceObjIds = [];
lineObjIds = [];
mapView.graphicsOverlays.get(0).graphics.clear();
mapView.map.operationalLayers.forEach(function(layer){
layer.clearSelection();
});
}
}
Button {
id: traceBtn
text: qsTr("Trace")
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
enabled: !busy.visible
onClicked: {
busy.visible = true;
switch (traceTypes.currentIndex) {
case 0:
params.traceType = Enums.UtilityTraceTypeConnected;
break;
case 1:
params.traceType = Enums.UtilityTraceTypeSubnetwork;
break;
case 2:
params.traceType = Enums.UtilityTraceTypeUpstream;
break;
case 3:
params.traceType = Enums.UtilityTraceTypeDownstream;
}
// check to see if it exists before assigning it to the parameters.
if (mediumVoltageTier)
params.traceConfiguration = mediumVoltageTier.traceConfiguration;
// Perform a connected trace on the utility network
utilityNetwork.trace(params);
}
}
}
Text {
// Displays fraction along edge
text: junctionSelected ? qsTr("Junction Selected") : qsTr("Fraction along edge: %1".arg(element ? element.fractionAlongEdge.toFixed(6) : 0.0.toFixed(6)))
anchors.horizontalCenter: parent.horizontalCenter
}
}
}
}
}
function addToParamAndGraphic() {
if (startingLocBtn.checked) {
startingLocations.push(element);
params.startingLocations = startingLocations;
} else {
barriers.push(element);
params.barriers = barriers;
}
const graphic = ArcGISRuntimeEnvironment.createObject("Graphic", {
geometry: clickPoint,
symbol: startingLocBtn.checked ? startingPointSymbol : barrierPointSymbol
});
unGraphicsOverlay.graphics.append(graphic);
}
function checkSelectionStatus() {
if (!(lineLayer.selectFeaturesStatus && deviceLayer.selectFeaturesStatus))
return;
busy.visible = false;
}
Controls.DescriptionPage{
id:descPage
visible: false
}
}