-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBasemapColor.html
115 lines (97 loc) · 3.31 KB
/
BasemapColor.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
<!--
Codepen sample: https://codepen.io/kellyhutchins/pen/KKxmNJQ
-->
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<title>
Basemap Theme
</title>
<link rel="stylesheet" href="https://js.arcgis.com/4.26/esri/themes/light/main.css" />
<script src="https://js.arcgis.com/4.26/"></script>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>
<script>
require([
"esri/Map",
"esri/Graphic",
"esri/widgets/BasemapToggle",
"esri/core/reactiveUtils",
"esri/core/promiseUtils",
"esri/views/support/colorUtils",
"esri/views/MapView",
"esri/widgets/Locate",
"esri/symbols/SimpleMarkerSymbol"
], (Map, Graphic, BasemapToggle, reactiveUtils, promiseUtils, colorUtils, MapView, Locate, SimpleMarkerSymbol) => {
let hasLocation = false;
const lightColor = "#7A003C";
const darkColor = "#fff";
const textSymbol = {
type: "text",
color: "#7A003C",
text: "\ue61d", // esri-icon-map-pin
font: {
size: 36,
family: "CalciteWebCoreIcons" // Esri Icon Font
}
}
const map = new Map({
basemap: "gray-vector"
});
const view = new MapView({
center: [-97.63, 38.34],
container: "viewDiv",
map,
zoom: 3
});
const locate = new Locate({
view,
graphic: new Graphic({ symbol: textSymbol })
});
locate.on("locate", () => {
hasLocation = true;
})
view.ui.add(locate, "top-left");
const basemapToggle = new BasemapToggle({
view,
nextBasemap: "dark-gray"
})
view.ui.add(basemapToggle, "bottom-right");
let abortController = null;
const basemapHandle = reactiveUtils.watch(
() => view.map.basemap,
() => onBasemapChange(),
{ initial: true }
);
// Remove watch handle when view is destroyed
view.addHandles(basemapHandle);
async function onBasemapChange() {
abortController?.abort();
const { signal } = (abortController = new AbortController());
await reactiveUtils.whenOnce(() => !view.updating, signal);
// getBackgroundColor is also available
const backgroundTheme = await colorUtils.getBackgroundColorTheme(view);
const color = backgroundTheme === "light" ? lightColor : darkColor;
locate.graphic.symbol.color = color;
if (hasLocation) {
// We already have a graphic. Let's recreate
view.graphics.removeAll();
locate.locate();
}
}
});
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>