EsriDevEvents
/
building-utility-network-applications-with-arcgis-maps-sdk-for-javascript-2023
Public
generated from EsriDevEvents/ds-2024-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssociations_API.html
executable file
·136 lines (130 loc) · 4.5 KB
/
Associations_API.html
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
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>UN JS API | View Connectivity and Structural Attachment Associations | ArcGIS API for JavaScript 4.23</title>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
#ctrlDiv {
top: 10px;
color: #444;
height: auto;
font-family: arial;
right: 10px;
margin: 5px;
padding: 5px;
position: absolute;
width: 305px;
z-index: 40;
background-color: #fff;
}
</style>
<link rel="stylesheet" href="https://js.arcgis.com/4.23/esri/themes/light/main.css" />
<script src="https://js.arcgis.com/4.23/"></script>
<script>
require([
"dojo/dom",
"dojo/on",
"esri/Basemap",
"esri/Graphic",
"esri/WebMap",
"esri/rest/networks/support/SynthesizeAssociationGeometriesParameters",
"esri/rest/networks/synthesizeAssociationGeometries",
"esri/views/MapView",
], function(
dom,
on,
Basemap,
Graphic,
WebMap,
SynthesizeAssociationGeometriesParameters,
synthesizeAssociationGeometries,
MapView,
) {
console.log("Sign in to access the data in this sample.");
console.log("username: viewer01 password: I68VGU^nMurF");
let utilityNetwork;
// Connect click events to UI buttons
on(dom.byId("btnShowAssociations"), "click", showAssociations);
on(dom.byId("btnRemoveAssociations"), "click", function() {
view.graphics.removeAll()
});
const webMap = new WebMap({
portalItem: {
portal: {
url: "https://sampleserver7.arcgisonline.com/portal"
},
id: "cff20b71fdae4b3393b530b0099e4390"
}
});
webMap.basemap = Basemap.fromId("gray-vector");
const view = new MapView({
map: webMap,
container: "viewDiv"
});
view.when(async 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.
await utilityNetwork.load();
}
});
async function showAssociations() {
view.graphics.removeAll();
// Define parameters required to obtain associations whithin a specific extent.
const associationParameters = new SynthesizeAssociationGeometriesParameters({
returnConnectivityAssociations: true,
returnAttachmentAssociations: true,
extent: view.extent,
outSpatialReference: utilityNetwork.spatialReference,
maxGeometryCount: 500, // Useful to avoid slowing down the operation.
});
// Synthesize associations
synthesizeAssociationGeometries.synthesizeAssociationGeometries(utilityNetwork.networkServiceUrl, associationParameters)
.then(async function(results) {
// Use results.
if (!results.maxGeometryCountExceeded) {
view.graphics.addMany(
results.associations.map(a => {
return new Graphic({
geometry: {
type: "polyline",
paths: a.geometry.paths,
spatialReference: a.geometry.spatialReference,
},
symbol: {
type: "simple-line",
color: (a.associationType === "connectivity") ? [190, 41, 236] : [57, 255, 20], // Connectivity: Purple; Attachment: Green
width: 4,
}
})
})
);
} else {
console.log("The number of associations found exceeded the maximum allowable number. Check your parameters or try querying a smaller area.");
}
})
.catch(function(error) {
console.log(error);
});
}
});
</script>
</head>
<body>
<div id="viewDiv"></div>
<div id="ctrlDiv">
<button id="btnShowAssociations" style="width:150px">Show Associations</button>
<button id="btnRemoveAssociations" style="width:150px">Remove Associations</button>
</div>
</body>
</html>