-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesriWaterTest.html
209 lines (188 loc) · 5.57 KB
/
esriWaterTest.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<html>
<head>
<meta charset="utf-8" />
<title>
Realistic water visualization in 3D | Sample | ArcGIS API for JavaScript
4.23
</title>
<link
rel="stylesheet"
href="https://js.arcgis.com/4.23/esri/themes/light/main.css"
/>
<script src="https://js.arcgis.com/4.23/"></script>
<script>
require([
"esri/WebScene",
"esri/views/SceneView",
"esri/layers/FeatureLayer",
"esri/widgets/Slider"
], (WebScene, SceneView, FeatureLayer, Slider) => {
/***********************************
* Load webscene and create a SceneView
***********************************/
const webscene = new WebScene({
portalItem: {
id: "8ede93ea9d8d48bc8cdcbea775936a13"
}
});
const view = new SceneView({
container: "viewDiv",
map: webscene,
qualityProfile: "high"
});
webscene.when(() => {
// set this property to display trees, buildings and other
// 3D objects reflected in the water.
view.environment.lighting.waterReflectionEnabled = true;
});
/***********************************
* Add polygon layer with water body
***********************************/
const waterLayer = new FeatureLayer({
url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Water_bodies/FeatureServer",
elevationInfo: {
mode: "absolute-height",
offset: 15
},
renderer: {
type: "simple",
symbol: {
type: "polygon-3d",
symbolLayers: [
{
type: "water",
waveDirection: 260,
color: "#25427c",
waveStrength: "moderate",
waterbodySize: "medium"
}
]
}
}
});
webscene.add(waterLayer);
view.ui.add("menu", "top-right");
const slider = new Slider({
container: "waveSlider",
min: 0,
max: 360,
visibleElements: {
labels: true
},
precision: 0,
values: [260]
});
slider.on("thumb-drag", (event) => {
const value = parseInt(event.value);
const renderer = waterLayer.renderer.clone();
renderer.symbol.symbolLayers.getItemAt(0).waveDirection = value;
waterLayer.renderer = renderer;
});
const waveStrengthRadio =
document.getElementsByName("waveStrengthRadio");
for (let i = 0; i < waveStrengthRadio.length; i++) {
const element = waveStrengthRadio[i];
element.addEventListener("change", (event) => {
const renderer = waterLayer.renderer.clone();
renderer.symbol.symbolLayers.getItemAt(0).waveStrength =
event.target.value;
waterLayer.renderer = renderer;
});
}
function setWaterColor(color) {
const renderer = waterLayer.renderer.clone();
renderer.symbol.symbolLayers.getItemAt(0).color = color;
waterLayer.renderer = renderer;
}
document.getElementById("navy").addEventListener("click", () => {
setWaterColor("#25427c");
});
document.getElementById("green").addEventListener("click", () => {
setWaterColor("#039962");
});
document.getElementById("turqoise").addEventListener("click", () => {
setWaterColor("#a2f9f5");
});
document
.getElementById("reflection")
.addEventListener("click", (event) => {
view.environment.lighting.waterReflectionEnabled =
event.target.checked;
});
});
</script>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
#menu {
padding: 1em;
}
#waveSlider {
height: 50px;
margin-top: 2em;
}
.color-btn {
border: 1px solid rgb(173, 172, 172);
width: 40px;
height: 20px;
cursor: pointer;
}
#navy {
background-color: #25427c;
}
#green {
background-color: #039962;
}
#turqoise {
background-color: #a2f9f5;
}
</style>
</head>
<body>
<div id="viewDiv"></div>
<div id="menu" class="esri-widget">
<h4>Wave direction</h4>
<div id="waveSlider"></div>
<h4>Wave strength</h4>
<input
type="radio"
name="waveStrengthRadio"
value="calm"
id="calm"
/><label for="calm">Calm</label><br />
<input
type="radio"
name="waveStrengthRadio"
value="rippled"
id="rippled"
/><label for="rippled">Rippled</label><br />
<input
type="radio"
name="waveStrengthRadio"
value="slight"
id="slight"
/><label for="slight">Slight</label><br />
<input
type="radio"
name="waveStrengthRadio"
value="moderate"
id="moderate"
checked
/><label for="moderate">Moderate</label><br />
<h4>Dominant color</h4>
<button id="navy" class="color-btn"></button>
<button id="green" class="color-btn"></button>
<button id="turqoise" class="color-btn"></button>
<br />
<input type="checkbox" id="reflection" checked /><label for="reflection"
>Water reflections</label
>
</div>
</body>
</html>