-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidate_API.html
More file actions
executable file
·236 lines (226 loc) · 7.62 KB
/
Copy pathValidate_API.html
File metadata and controls
executable file
·236 lines (226 loc) · 7.62 KB
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>UN JS API | Validate Network Topology | ArcGIS API for JavaScript 4.25</title>
<link rel="stylesheet" href="https://js.arcgis.com/4.25/esri/themes/light/main.css" />
<script src="https://js.arcgis.com/4.25/"></script>
<style media="screen">
#myDiv {
top: 20px;
color: #444;
right: 20px;
position: absolute;
z-index: 40;
background-color: #fff;
padding: 5px;
display: flex;
flex-direction: column;
gap: 5px;
width: 250px;
}
#myLabelTitle {
padding: 10px;
}
#myLabelStatus {
font-size: small;
}
html,
body,
#viewDiv {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
</style>
<script>
require([
"esri/Graphic",
"esri/WebMap",
"esri/layers/FeatureLayer",
"esri/views/MapView",
"esri/widgets/Legend",
], function(
Graphic,
WebMap,
FeatureLayer,
MapView,
Legend,
) {
console.log("Sign in to access the data in this sample.");
console.log("username: editor01 password: S7#i2LWmYH75");
let utilityNetwork;
let dirtyAreasFeatureLayer;
let electricDistributionLineFeatureLayer;
let myVersion = "editor01.testVNT";
const webMap = new WebMap({
portalItem: {
// autocasts as new PortalItem()
id: "471eb0bf37074b1fbb972b1da70fb310", // webmap id
},
});
webMap.load().then(function() {
// Check if webMap contains utility networks.
if (webMap.utilityNetworks.length > 0) {
// Assigns the utility network at index 0 to utilityNetwork.
utilityNetwork = webMap.utilityNetworks.getItemAt(0);
// Triggers the loading of the UtilityNetwork instance.
utilityNetwork.load().then(function() {
// Add dirty areas layer.
let dirtyAreasLayerExists = false;
let dirtyAreasFeatureLayer = new FeatureLayer({
url: utilityNetwork.networkSystemLayers.dirtyAreasLayerUrl
});
// Avoid adding the layer more than once.
webMap.layers.items.forEach((i) => {
if (i.parsedUrl !== null) {
if (i.parsedUrl.path === utilityNetwork.networkSystemLayers.dirtyAreasLayerUrl) {
dirtyAreasLayerExists = true;
}
}
});
if (!dirtyAreasLayerExists) {
let renderer = {
type: "simple", // autocasts as new SimpleRenderer()
symbol: {
type: "simple-fill", // autocasts as new SimpleFillSymbol()
style: "forward-diagonal",
color: [128, 128, 255, 0.5],
outline: { // autocasts as new SimpleLineSymbol()
width: 2.5,
color: [128, 128, 255, 1]
}
}
};
dirtyAreasFeatureLayer.renderer = renderer;
webMap.add(dirtyAreasFeatureLayer);
// Change the Feature Layer to a version with dirty areas (only for the purpose of this sample)
dirtyAreasFeatureLayer.gdbVersion = myVersion;
}
// Used for adding features -> creating dirty areas.
electricDistributionLineFeatureLayer = new FeatureLayer({
url: "https://sampleserver7.arcgisonline.com/server/rest/services/UtilityNetwork/NapervilleElectricV5/FeatureServer/3"
});
electricDistributionLineFeatureLayer.gdbVersion = myVersion;
myLabelStatus.innerHTML = "Ready.";
setTimeout(() => {
myLabelStatus.innerHTML = "";
}, 3500);
});
}
});
const view = new MapView({
map: webMap,
container: "viewDiv",
center: [-88.1500107, 41.7837140],
zoom: 15,
});
view.when(() => {
const legend = new Legend({
view: view,
});
// Add widget to the bottom left corner of the view
view.ui.add(legend, "bottom-left");
btnAddFeatures.addEventListener('click', () => {
addFeatures();
});
btnValidateCurrentExtent.addEventListener('click', () => {
vntCurrentExtent();
});
myLabelStatus.innerHTML = "Loading resources...";
});
function addFeatures() {
const options = {
returnServiceEditsOption: "original-and-current-features",
returnEditMoment: true
};
let connectorFeature = new Graphic({
geometry: {
type: "polyline", // autocasts as new Polyline()
spatialReference: utilityNetwork.spatialReference,
paths: [
[
[1032252.6046055965, 1862709.8517080322, 0, null],
[1032890.4763613455, 1863725.239769116, 0, null]
]
]
},
attributes: {
assetgroup: 2,
assettype: 0,
associationstatus: 0,
isconnected: 2,
fromdeviceterminal: 0,
todeviceterminal: 0
}
});
let busbarFeature = new Graphic({
geometry: {
type: "polyline", // autocasts as new Polyline()
spatialReference: utilityNetwork.spatialReference,
paths: [
[
[1032859.7428270131, 1869630.506173782, 0, null],
[1033852.6988463439, 1868253.6066966132, 0, null],
[1036527.06095168, 1868240.3675498665, 0, null]
]
]
},
attributes: {
assetgroup: 1,
assettype: 0,
associationstatus: 0,
isconnected: 2,
fromdeviceterminal: 0,
todeviceterminal: 0
}
});
let edits = {
addFeatures: [connectorFeature, busbarFeature]
};
electricDistributionLineFeatureLayer.applyEdits(edits, options).then((editsResult) => {
myLabelStatus.innerHTML = "New features were successfully added.";
setTimeout(() => {
myLabelStatus.innerHTML = "";
}, 3500);
});
}
function vntCurrentExtent() {
myLabelStatus.innerHTML = "Executing.";
utilityNetwork
.validateNetworkTopology({
validateArea: view.extent,
gdbVersion: myVersion,
})
.then((resolvedVal) => {
myLabelStatus.innerHTML = "Validate Succesful.";
setTimeout(() => {
myLabelStatus.innerHTML = "";
}, 3500);
})
.catch((error) => {
myLabelStatus.innerHTML = "Status: " + error.message;
setTimeout(() => {
myLabelStatus.innerHTML = "";
}, 3500);
});
}
});
</script>
</head>
<body>
<div id="myDiv">
<div>
<label id="myLabelTitle">Validate Network Topology</label>
</div>
<button id="btnAddFeatures">Add Features</button>
<button id="btnValidateCurrentExtent">Validate Current Extent</button>
<div>
<label id="myLabelStatus"></label>
</div>
</div>
<div id="viewDiv"></div>
</body>
</html>