1
- const toggleModeEl = document . getElementById ( "toggle-mode" ) ;
2
- const mapEl = document . querySelector ( "arcgis-map" ) ;
3
- const darkModeCss = document . getElementById ( "jsapi-mode-dark" ) ;
4
- const lightModeCss = document . getElementById ( "jsapi-mode-light" ) ;
5
- const liveRegion = document . getElementById ( "liveRegion" ) ;
6
- const searchEl = document . getElementById ( "search-el" ) ;
7
- const expandEl = document . getElementById ( "expand-el" ) ;
8
-
9
- let mode = "light" ;
10
-
11
- toggleModeEl . addEventListener ( "click" , handleModeChange ) ;
12
-
13
-
14
- function handleModeChange ( ) {
15
- mode = mode === "dark" ? "light" : "dark" ;
16
- const isDarkMode = mode === "dark" ;
17
- darkModeCss . disabled = ! isDarkMode ;
18
- lightModeCss . disabled = isDarkMode ;
19
- toggleModeEl . icon = isDarkMode ? "moon" : "brightness" ;
20
- document . body . className = isDarkMode ? "calcite-mode-dark" : "" ;
21
- mapEl . basemap = isDarkMode ? "dark-grey" : "grey" ;
22
-
23
- document . querySelectorAll ( `.calcite-mode-${ isDarkMode ? "light" : "dark" } ` ) . forEach ( node =>
24
- node . classList . replace ( `calcite-mode-${ isDarkMode ? "light" : "dark" } ` , `calcite-mode-${ mode } ` )
25
- ) ;
26
- }
1
+ require ( [ "esri/Basemap" ] , ( Basemap ) => {
2
+
3
+ const mapEl = document . getElementById ( "mapEl" ) ;
4
+
5
+ // High contrast basemap (dark)
6
+ const highContrastDarkBasemap = new Basemap ( {
7
+ portalItem : {
8
+ id : "3e23478909194c54992eaaee78b5f754" // Dark
9
+ } ,
10
+ title : "High contrast dark theme" ,
11
+ id : "high-contrast-dark"
12
+ } ) ;
13
+
14
+ // High contrast basemap (light)
15
+ const highContrastLightBasemap = new Basemap ( {
16
+ portalItem : {
17
+ id : "084291b0ecad4588b8c8853898d72445" // Light
18
+ } ,
19
+ title : "High contrast (light theme)" ,
20
+ id : "high-contrast-light"
21
+ } ) ;
22
+
23
+ // Mode
24
+ let mode = "light" ;
25
+ const toggleModeEl = document . getElementById ( "toggle-mode" ) ;
26
+ const darkModeCss = document . getElementById ( "jsapi-mode-dark" ) ;
27
+ const lightModeCss = document . getElementById ( "jsapi-mode-light" ) ;
28
+
29
+ toggleModeEl . addEventListener ( "click" , handleModeChange ) ;
30
+
31
+ function handleModeChange ( ) {
32
+ mode = mode === "dark" ? "light" : "dark" ;
33
+ const isDarkMode = mode === "dark" ;
34
+ darkModeCss . disabled = ! isDarkMode ;
35
+ lightModeCss . disabled = isDarkMode ;
36
+ toggleModeEl . icon = isDarkMode ? "moon" : "brightness" ;
37
+ document . body . className = isDarkMode ? "calcite-mode-dark" : "" ;
38
+
39
+ // If high contrast is enabled, display a high contrast basemap
40
+ // Else display a gray basemap
41
+ if ( contrastMedia . matches ) {
42
+ mapEl . basemap = isDarkMode ? highContrastDarkBasemap : highContrastLightBasemap ;
43
+ } else {
44
+ mapEl . basemap = isDarkMode ? "dark-gray-vector" : "gray-vector" ;
45
+ }
46
+
47
+ document . querySelectorAll ( `.calcite-mode-${ isDarkMode ? "light" : "dark" } ` ) . forEach ( node =>
48
+ node . classList . replace ( `calcite-mode-${ isDarkMode ? "light" : "dark" } ` , `calcite-mode-${ mode } ` )
49
+ ) ;
50
+ }
51
+
52
+ // High contrast support with basemap and layer effects
53
+ const contrastMedia = matchMedia ( "(forced-colors: active)" ) ;
54
+ function checkContrastMedia ( ) {
55
+ try {
56
+ if ( mode == "dark" ) {
57
+ mapEl . basemap = contrastMedia . matches ? highContrastDarkBasemap : "dark-gray-vector" ;
58
+ //mapEl.basemap = "dark-gray-vector";
59
+ contrastMedia . matches ? mapEl . map . layers . _items [ 2 ] . effect = "bloom(1.5, 0.5px, 0.1)" : mapEl . map . layers . _items [ 2 ] . effect = "bloom(0, 0px, 0)" ;
60
+ } else {
61
+ mapEl . basemap = contrastMedia . matches ? highContrastLightBasemap : "gray-vector" ;
62
+ //mapEl.basemap = "gray-vector";
63
+ contrastMedia . matches ? mapEl . map . layers . _items [ 2 ] . effect = "drop-shadow(3px, 1px, 3px)" : mapEl . map . layers . _items [ 2 ] . effect = "drop-shadow(0px, 0px, 0px)" ;
64
+ }
65
+ } catch ( err ) { }
66
+ }
67
+
68
+ // Event listeners on map load and high contrast media query
69
+ mapEl . addEventListener ( "arcgisViewChange" , checkContrastMedia ) ;
70
+ contrastMedia . addListener ( checkContrastMedia ) ;
71
+
72
+ } ) ;
0 commit comments