-
Notifications
You must be signed in to change notification settings - Fork 0
/
nyc-trees-toggle-renderer.html
160 lines (146 loc) · 4.21 KB
/
nyc-trees-toggle-renderer.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
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
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<title>
Scale-dependent heatmap renderer
</title>
<link
rel="stylesheet"
href="https://js.arcgis.com/4.24/esri/themes/light/main.css"
/>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>
<script src="https://js.arcgis.com/4.24/"></script>
<script>
require([
"esri/WebMap",
"esri/layers/FeatureLayer",
"esri/views/MapView",
"esri/widgets/Legend"
], (WebMap, FeatureLayer, MapView, Legend) => {
const heatmapRenderer = {
type: "heatmap",
colorStops: [
{ color: [133, 193, 200, 0], ratio: 0 },
{ color: [133, 193, 200, 0], ratio: 0.01 },
{ color: [133, 193, 200, 255], ratio: 0.01 },
{ color: [133, 193, 200, 255], ratio: 0.01 },
{ color: [144, 161, 190, 255], ratio: 0.0925 },
{ color: [156, 129, 132, 255], ratio: 0.175 },
{ color: [167, 97, 170, 255], ratio: 0.2575 },
{ color: [175, 73, 128, 255], ratio: 0.34 },
{ color: [184, 48, 85, 255], ratio: 0.4225 },
{ color: [192, 24, 42, 255], ratio: 0.505 },
{ color: [200, 0, 0, 255], ratio: 0.5875 },
{ color: [211, 51, 0, 255], ratio: 0.67 },
{ color: [222, 102, 0, 255], ratio: 0.7525 },
{ color: [233, 153, 0, 255], ratio: 0.835 },
{ color: [244, 204, 0, 255], ratio: 0.9175 },
{ color: [255, 255, 0, 255], ratio: 1 }
],
maxDensity: 0.319,
minDensity: 0,
// settings for heatmap apply only to this scale
// so renderer will look consistent without
// dynamically updating on zoom
referenceScale: 36111,
radius: 6,
legendOptions: {
minLabel: "Low tree density",
maxLabel: "High tree density"
}
};
const commonMarkerProps = {
type: "simple-marker",
size: 5,
outline: {
width: 0,
color: "rgba(50,50,50,0.2)"
}
}
const healthRenderer = {
type: "unique-value",
field: "health",
legendOptions: {
title: "Tree health"
},
defaultSymbol: {
...commonMarkerProps,
color: "rgba(128,128,128,1)"
},
defaultLabel: "Unknown",
uniqueValueInfos: [{
value: "Good",
symbol: {
...commonMarkerProps,
color: "rgba(0,140,94,1)"
}
}, {
value: "Fair",
symbol: {
...commonMarkerProps,
color: "rgba(117,222,67,1)"
}
}, {
value: "Poor",
symbol: {
...commonMarkerProps,
color: "rgba(253,127,111,1)"
}
}]
}
const layer = new FeatureLayer({
portalItem: {
id: "a38dd6ef1000447b94bda500084c14c7"
},
popupTemplate: {
title: "<i>{spc_latin}</i>",
content:
"<b>{spc_common}</b> in <b>{health}</b> condition located at {address}, {borough}."
},
renderer: heatmapRenderer,
blendMode: "multiply"
});
const map = new WebMap({
layers: [layer],
basemap: "gray-vector"
});
const view = new MapView({
container: "viewDiv",
center: [-73.95697002727704, 40.626402246806926],
scale: 36111,
rotation: 78,
map,
constraints: {
snapToZoom: false,
minScale: 196253
}
});
view.watch("scale", (scale) => {
layer.renderer = scale <= 9027 ? healthRenderer : heatmapRenderer;
});
view.ui.add(
new Legend({
view
}),
"bottom-left"
);
});
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>