-
Notifications
You must be signed in to change notification settings - Fork 1
/
description-region.html
122 lines (107 loc) · 3.9 KB
/
description-region.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
<!-- Codepen: https://codepen.io/geospatialem/pen/YzMPemx -->
<!-- Resources:
1. 2023 Map Description demo: https://github.com/kellyhutchins/DevSummit2023-A11y/blob/main/demos/MapDescription.html
2. Spread syntax (...): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Map Description and Live Regions</title>
<link id="light-style" rel="stylesheet" href="https://js.arcgis.com/4.29/esri/themes/light/main.css" />
<link id="dark-style" rel="stylesheet" href="https://js.arcgis.com/4.29/esri/themes/dark/main.css" disabled/>
<script src="https://js.arcgis.com/4.29/"></script>
<link rel="stylesheet" type="text/css" href="https://js.arcgis.com/calcite-components/2.6.0/calcite.css" />
<script type="module" src="https://js.arcgis.com/calcite-components/2.6.0/calcite.esm.js"></script>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0,0,0,0);
border: 0;
}
</style>
</head>
<body aria-describedby="map-loaded">
<calcite-shell content-behind>
<calcite-navigation slot="header" id="nav">
<calcite-navigation-logo
icon="accessibility"
slot="logo"
heading="Map Description and Live Regions"
description="Esri Developer Summit 2024"
></calcite-navigation-logo>
<calcite-action-pad layout="horizontal" expand-disabled slot="content-end">
<calcite-action id="toggle-mode" text="Toggle mode" icon="brightness"></calcite-action>
</calcite-action-pad>
<calcite-tooltip placement="bottom" reference-element="toggle-mode" slot="content-end">Toggle mode</calcite-tooltip>
</calcite-navigation>
<calcite-panel>
<div id="viewDiv"></div>
<p id="map-loaded" aria-live="polite" class="sr-only"></p>
<p id="map-description" class="sr-only"></p>
</calcite-panel>
</calcite-shell>
</body>
<script>
require([
"esri/views/MapView",
"esri/core/reactiveUtils",
"esri/WebMap"
], (
MapView,
reactiveUtils,
WebMap
) => {
// Mode
let mode = "light";
const toggleModeEl = document.getElementById("toggle-mode");
const darkModeCss = document.getElementById("dark-style");
const lightModeCss = document.getElementById("light-style");
const mapLoadMsg = document.getElementById("map-loaded");
const mapDescription = document.getElementById("map-description");
const map = new WebMap({
portalItem: {
id: "f2e9b762544945f390ca4ac3671cfa72"
}
});
const view = new MapView({
map,
container: "viewDiv"
});
viewWhen();
async function viewWhen() {
await view.when();
mapLoadMsg.innerText = `${map.portalItem.title} map has loaded.`;
mapDescription.innerText = map.portalItem.snippet;
const surfacesEls = [...document.getElementsByClassName("esri-view-surface")]; // Resource: Spread syntax (...)
surfacesEls.forEach((surfaceEl) => surfaceEl.setAttribute("aria-describedby", "map-description"));
}
// Toggle mode
toggleModeEl.addEventListener("click", () => {
mode = mode === "dark" ? "light" : "dark";
const isDarkMode = mode === "dark";
darkModeCss.disabled = !darkModeCss.disabled;
lightModeCss.disabled = !lightModeCss.disabled;
const widgets = [...document.getElementsByClassName("esri-ui")]; // Resource: Spread syntax (...)
widgets.forEach((widget) => widget.classList.toggle("calcite-mode-dark"));
map.basemap = isDarkMode ? "dark-gray" : "gray";
toggleModeEl.icon = isDarkMode ? "moon" : "brightness";
document.body.className = isDarkMode ? "calcite-mode-dark" : undefined;
});
});
</script>
</html>