-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
90 lines (76 loc) · 2.07 KB
/
script.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
require([
"esri/views/MapView",
"esri/WebMap",
"esri/widgets/Expand",
"esri/widgets/Legend",
"esri/widgets/Compass",
"esri/widgets/BasemapGallery"
], function(MapView, WebMap, Expand, Legend, Compass, BasemapGallery) {
const webmap = new WebMap({
portalItem: {
id: "245d299f83de4bc1b43fe18ae23dbabf"
}
})
const view = new MapView({
map: webmap,
container: "viewDiv"
})
const compass = new Compass({
view: view
})
view.ui.add(compass, "top-left")
const basemaps = new BasemapGallery({
view: view,
container: document.createElement("div")
})
const basemapsExpand = new Expand({
view: view,
content: basemaps,
expandTooltip: "Basemap Gallery",
group: "widgets"
})
view.ui.add(basemapsExpand, "top-left")
const legend = new Legend({
view: view,
container: document.createElement("div")
})
const legendExpand = new Expand({
view: view,
content: legend,
expandTooltip: "Legend",
group: "widgets"
})
view.ui.add(legendExpand, "bottom-left")
const selectExpand = new Expand({
view: view,
content: document.getElementById("scenario-container"),
expanded: true,
expandTooltip: "Scenarios",
group: "widgets"
})
view.ui.add(selectExpand, "bottom-right")
const mapScenarioInputs = document.querySelectorAll("input[type=radio][name='map-scenario']")
mapScenarioInputs.forEach(radio => radio.addEventListener("change", () => {
view.map.layers.map(function(lyr){
console.log(lyr.title);
lyr.visible = false;
});
let checkedLayerName = getCheckedRadioValue(mapScenarioInputs)
// console.log(view.map.layers)
let checkedLayer = webmap.allLayers.find(function(layer) {
return layer.title === checkedLayerName;
});
console.log(checkedLayer.title)
checkedLayer.visible = true
console.log(checkedLayer.visible)
}))
})
function getCheckedRadioValue(selectors) {
let checkedName;
selectors.forEach(selector => {
if (selector.checked) {
checkedName = selector.value
}
})
return checkedName
}