This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
360 lines (283 loc) · 10.9 KB
/
app.js
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
// TODO point cloud renderers: https://developers.arcgis.com/javascript/latest/sample-code/layers-pointcloud/
// TODO võrkmudelile luua oma lokaator
// TODO calcite slider sketchile
// TODO hiljem proovida ka vajalike kihtide koosseis säilitada
// TODO seda peaks ilmselt tegema hard codega esialgse seisuga ja siis listide võrdlemine
// TODO los arendus
// TODO kui määrata id title asemel (töökindlam), määrata vb ka kuskil failis? ja jagada läbi selle?
// TODO fronti nupud jäävad jagamisele muutmata, kuidagi peab lahendama, et topelt muutus ei tuleks
// TODO kuidagi läbi tekkinud bugi (otsides basemap mis pole allLayers all tekkis olukord, kus visibility muutus ja jäi nahk kihiks), proovida taasluua nupp, mis kasutaks ära seda käitumist
// TODO uurida mis state on ja kuidas seda kasutada, et teha tühi basemap võimalus kasutajale, ilmselt peab basemaps ka eraldi parameetrina välja tooma
// TODO ilmselt peab muutma activeBasemap hübriidiks vms
// Esri imports
import Conversion from "@arcgis/core/widgets/CoordinateConversion/support/Conversion.js";
// Local imports
import {
setupGraphicsLayer,
setupInternalLayer,
setupWMSLayer,
getGeologyLayers,
setupGroupLayer,
taimkateWorkaround,
getVisibleLayers,
compareVisibleLayers,
setNoBasemap,
} from "./modules/layers.js";
import { setupWebScene, setupWebView } from "./modules/scene.js";
import {
setupLayerListMain,
setupLayerListWMS,
setupBasemapGallery,
loadWMStile,
getLayerInfo,
} from "./modules/layerList";
import { setupCoordinateWidget, setupNewFormat } from "./modules/coordinate.js";
import { setupLoS, getStartPoint } from "./modules/lineOfSight.js";
import {
setupCustomSearchSource,
setupSearchWidget,
} from "./modules/search.js";
import { setupSketch } from "./modules/sketch.js";
import { setupDaylight } from "./modules/daylight.js";
import { setupElevationProfile } from "./modules/elevationProfile.js";
import { setupMeasurement } from "./modules/measurement.js";
import { setupShadowCast } from "./modules/shadowCast.js";
import { setupSlice } from "./modules/slice.js";
import { setupLocate } from "./modules/locate.js";
import {
elevationManipulation,
setupElevationLayer,
} from "./modules/elevation.js";
import {
getUndergroundInfo,
getLayerVisibility,
getElevationVisibility,
getLocation,
copyTextToClipboard,
createURL,
setupViewPoint,
} from "./modules/goToLocation.js";
import { displayWindmills } from "./modules/rotatingWindmill";
/************************************************************
* Init scene (/w layers) and view
************************************************************/
// const mediaQuery = window.matchMedia('(max-width: 768px)');
// initMediaQuery.handleMediaQueryChange(mediaQuery)
// mediaQuery.addEventListener(initMediaQuery.handleMediaQueryChange);
const graphicsLayer = setupGraphicsLayer();
const communicationTower = setupInternalLayer(
"66e382030b224ffa999249a4d1cbbf4f",
"Sidemastid"
);
const ortofotoWMS = setupWMSLayer();
const scene = setupWebScene(
"92d29869db444e28beab584f696b86c3",
graphicsLayer,
ortofotoWMS
);
const geologyScene = setupWebScene("da15a55042b54c31b0208ba98c1647fc");
const geologyView = setupWebView(geologyScene);
const apDTM = setupElevationLayer(
"https://tiles.arcgis.com/tiles/ZYGCYltwz5ExeoGm/arcgis/rest/services/APR_50m_Eesti_tif/ImageServer",
"Aluspõhi 50m"
);
const akDTM = setupElevationLayer(
"https://tiles.arcgis.com/tiles/ZYGCYltwz5ExeoGm/arcgis/rest/services/AKR_50m_2/ImageServer",
"Aluskord 50m"
);
const view = setupWebView(scene);
view.when(() => {
/**************************************
* Geology layer setup
**************************************/
const geologyLayers = getGeologyLayers(geologyView);
const boreholes = geologyLayers.items.find(
// (layer) => layer.title === "Puurkaevud/puuraugud"
(layer) => layer.title === "Andmepunktid"
);
const constructionGeology = geologyLayers.items.find(
(layer) => layer.title === "Ehitusgeoloogia"
);
const geologyWMS = geologyLayers.items.find(
(layer) => layer.title === "Geoloogia WMS"
);
geologyWMS.visible = false;
// Adding other DTM layers layers
view.map.ground.layers.addMany([apDTM, akDTM]);
/**************************************
* Desc info
**************************************/
// TODO kui kakskeelseks teha, siis peaks ilmselt läbi portaali ära kaotama ja tekstid kuhugi lisama
const { description } = scene.portalItem;
const itemDesc = document.querySelector("#item-description");
itemDesc.innerHTML = description;
/**************************************
* Built-in UI components
**************************************/
view.ui.move("zoom", "top-right");
view.ui.move("navigation-toggle", "top-right");
view.ui.move("compass", "top-right");
/**************************************
* Line of Sight analysis custom
**************************************/
getStartPoint(view);
/**************************************
* Reworking taimkate logic
**************************************/
const treeGroupLayer = setupGroupLayer("Taimkate", "exclusive");
taimkateWorkaround(treeGroupLayer, view);
// Add the GroupLayer to view
view.map.add(treeGroupLayer);
/**************************************
* Layerlist from scene
**************************************/
const layerList = setupLayerListMain(view);
getLayerInfo(layerList, view);
/**************************************
* WMS layerlist gallery
**************************************/
const wmsLayerList = setupLayerListWMS(view);
getLayerInfo(wmsLayerList, view);
/**************************************
* Basemap gallery
**************************************/
const basemaps = setupBasemapGallery(view);
loadWMStile(basemaps, view);
setNoBasemap(basemaps, view);
/**************************************
* Geology layer group
**************************************/
// Creating a geology layer group
const geologyGroupLayer = setupGroupLayer("Geoloogia", "independent");
geologyGroupLayer.addMany([boreholes, constructionGeology]);
// Adding a geology layer group to view
view.map.add(geologyGroupLayer);
// Geology WMS
view.map.add(geologyWMS);
// TODO exxaggeration ka tuua üle - aga see veits keerulisem
/**************************************
* Elevation toolbox
**************************************/
elevationManipulation(view);
/**************************************
* Coordinate tool
**************************************/
const ccWidget = setupCoordinateWidget(view);
const newFormat = setupNewFormat();
ccWidget.formats.add(newFormat);
ccWidget.conversions.splice(0, 0, new Conversion({ format: newFormat }));
view.ui.add(ccWidget, "bottom-right");
/**************************************
* Initialize the LineOfSight widget
**************************************/
setupLoS(view);
/**************************************
* Initialize the Search Widget
**************************************/
const customSearchSource = setupCustomSearchSource();
setupSearchWidget(view, customSearchSource);
/**************************************
* Initialize daylight
**************************************/
setupDaylight(view);
/**************************************
* Elevation profile
**************************************/
setupElevationProfile(view);
/**************************************
* Measurement 3D
**************************************/
setupMeasurement(view);
/**************************************
* Slicing
**************************************/
setupSlice(view);
/**************************************
* Locate
**************************************/
const locate = setupLocate(view);
view.ui.add(locate, "top-right");
/**************************************
* Sketching
**************************************/
setupSketch(view, graphicsLayer);
/**************************************
* Rotating windmills
**************************************/
// TODO selle kuvamine võiks olla dummy kihi kaudu (ka renderdamine, sest muidu jookseb app liiga kaua ilmselt)
// displayWindmills(view);
/**************************************
* Reordering layers
**************************************/
// Reordering for on-the-fly layers
view.map.reorder(treeGroupLayer, 6);
view.map.reorder(geologyGroupLayer, 6);
view.map.reorder(geologyWMS, -1);
// Replacing sidemastid location, adding to correct group
const rajatisedGroup = view.map.findLayerById("180fa46104d-layer-35");
rajatisedGroup.add(communicationTower);
/**************************************
* Collecting visible layers before modification and rerendering
**************************************/
const initVisibleLayers = getVisibleLayers(view);
/**************************************
* Calcite CSS/JS
**************************************/
// TODO võiks ka eraldi calcite funktsioonideks kirjutada
const shadowCast = setupShadowCast(view);
let activeWidget;
const handleActionBarClick = ({ target }) => {
if (target.tagName !== "CALCITE-ACTION") {
return;
}
if (activeWidget) {
document.querySelector(`[data-action-id=${activeWidget}]`).active = false;
document.querySelector(`[data-panel-id=${activeWidget}]`).hidden = true;
}
const nextWidget = target.dataset.actionId;
if (nextWidget !== activeWidget) {
document.querySelector(`[data-action-id=${nextWidget}]`).active = true;
document.querySelector(`[data-panel-id=${nextWidget}]`).hidden = false;
activeWidget = nextWidget;
} else {
activeWidget = null;
}
if (nextWidget === "shadowCast") {
shadowCast.visible = !shadowCast.visible;
}
if (nextWidget === "share") {
const visibleLayersCurrently = getVisibleLayers(view);
const [regularLayers, elevationChanged] = compareVisibleLayers(
initVisibleLayers,
visibleLayersCurrently
);
const sharedLocation = createURL(view, regularLayers, elevationChanged);
copyTextToClipboard(sharedLocation);
// Displaying popup
const shareMapAlert = document.getElementById("share-map-alert");
shareMapAlert.open = "true";
}
};
document
.querySelector("calcite-action-bar")
.addEventListener("click", handleActionBarClick);
let actionBarExpanded = false;
document.addEventListener("calciteActionBarToggle", (event) => {
actionBarExpanded = !actionBarExpanded;
view.padding = {
left: actionBarExpanded ? 135 : 49,
};
});
/**************************************
* Parsing URL if sharing is used
**************************************/
// Going to specified location at runtime
const locationArray = getLocation();
getUndergroundInfo(view);
getLayerVisibility(view);
getElevationVisibility(view);
if (locationArray !== null) {
const viewpoint = setupViewPoint(locationArray);
view.goTo(viewpoint, { animate: false });
}
});