forked from tentone/geo-three
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
290 lines (251 loc) · 9.96 KB
/
index.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
body {
color: #FFFFFF;
}
input {
background-color: #FFFFFF88;
position: absolute;
width: 200px;
height: 25px;
}
select {
background-color: #FFFFFF88;
width: 200px;
height: 25px;
}
</style>
</head>
<body>
<!-- GUI -->
<canvas id="canvas" style="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;"></canvas>
<select id="mode" style="position: absolute; top: 20px; right: 20px;"></select>
<select id="providerColor" style="position: absolute; top: 50px; right: 20px;"></select>
<select id="providerHeight" style="position: absolute; top: 80px; right: 20px;"></select>
<select id="lod" style="position: absolute; top: 110px; right: 20px;"></select>
<!-- API KEys -->
<input id="mapbox_api"
value="pk.eyJ1IjoibGlnYW9mZW5nMDkwMSIsImEiOiJjazJ4MGM4a24wbDhwM2xsenNjcGFwNmxmIn0.NHeyO2E3JokHL5zktvWo6A"
placeholder="Mapbox API KEY" style="top: 140px; right: 20px;"></input>
<input id="heremaps_id" placeholder="HERE Maps ID" style="top: 170px; right: 20px; "></input>
<input id="heremaps_code" placeholder="HERE Maps Code" style="top: 200px; right: 20px;"></input>
<input id="bing_api" placeholder="Bing API KEY" style="top: 230px; right: 20px;"></input>
<input id="maptiler_api" placeholder="MapTiler API KEY" style="top: 260px; right: 20px;"></input>
<input id="openmap_tiles_server" placeholder="OpenMap Tiles URL" style="top: 290px; right: 20px;"></input>
<!-- Code -->
<script type="text/javascript" src="https://threejs.org/build/three.min.js"></script>
<script type="text/javascript" src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
<script type="text/javascript" src="https://threejs.org/examples/js/objects/Sky.js"></script>
<script type="text/javascript" src="./build/geo-three.js"></script>
<script type="text/javascript">
var canvas = document.getElementById("canvas");
var renderer = new THREE.WebGLRenderer({
canvas: canvas,
antialias: true
});
var scene = new THREE.Scene();
scene.background = new THREE.Color(0.4, 0.4, 0.4);
var sky = createSky();
scene.add(sky);
var providers = createProviders();
function createProviders() {
var DEV_MAPBOX_API_KEY = document.getElementById("mapbox_api").value;
var DEV_HEREMAPS_APP_ID = document.getElementById("heremaps_id").value;;
var DEV_HEREMAPS_APP_CODE = document.getElementById("heremaps_code").value;
var DEV_BING_API_KEY = document.getElementById("bing_api").value;
var DEV_MAPTILER_API_KEY = document.getElementById("maptiler_api").value;
var OPEN_MAP_TILES_SERVER_MAP = document.getElementById("openmap_tiles_server").value;
return [
["Vector OpenSteet Maps", new Geo.OpenStreetMapsProvider(),],
["Vector OpenTile Maps", new Geo.OpenMapTilesProvider(OPEN_MAP_TILES_SERVER_MAP)],
["Vector Map Box", new Geo.MapBoxProvider(DEV_MAPBOX_API_KEY, "mapbox/streets-v10", Geo.MapBoxProvider.STYLE)],
["Vector Here Maps", new Geo.HereMapsProvider(DEV_HEREMAPS_APP_ID, DEV_HEREMAPS_APP_CODE, "base", "normal.day")],
["Vector Here Maps Night", new Geo.HereMapsProvider(DEV_HEREMAPS_APP_ID, DEV_HEREMAPS_APP_CODE, "base", "normal.night")],
["Vector Here Maps Terrain", new Geo.HereMapsProvider(DEV_HEREMAPS_APP_ID, DEV_HEREMAPS_APP_CODE, "aerial", "terrain.day")],
["Vector Bing Maps", new Geo.BingMapsProvider(DEV_BING_API_KEY, Geo.BingMapsProvider.ROAD)],
["Vector Map Tiler Basic", new Geo.MapTilerProvider(DEV_MAPTILER_API_KEY, "maps", "basic", "png")],
["Vector Map Tiler Outdoor", new Geo.MapTilerProvider(DEV_MAPTILER_API_KEY, "maps", "outdoor", "png")],
["Satellite Map Box", new Geo.MapBoxProvider(DEV_MAPBOX_API_KEY, "mapbox.satellite", Geo.MapBoxProvider.MAP_ID, "jpg70", false)],
["Satellite Map Box Labels", new Geo.MapBoxProvider(DEV_MAPBOX_API_KEY, "mapbox/satellite-streets-v10", Geo.MapBoxProvider.STYLE, "jpg70")],
["Satellite Here Maps", new Geo.HereMapsProvider(DEV_HEREMAPS_APP_ID, DEV_HEREMAPS_APP_CODE, "aerial", "satellite.day", "jpg")],
["Satellite Bing Maps", new Geo.BingMapsProvider(DEV_BING_API_KEY, Geo.BingMapsProvider.AERIAL)],
["Satellite Maps Tiler Labels", new Geo.MapTilerProvider(DEV_MAPTILER_API_KEY, "maps", "hybrid", "jpg")],
["Satellite Maps Tiler", new Geo.MapTilerProvider(DEV_MAPTILER_API_KEY, "tiles", "satellite", "jpg")],
["Height Map Box", new Geo.MapBoxProvider(DEV_MAPBOX_API_KEY, "mapbox.terrain-rgb", Geo.MapBoxProvider.MAP_ID, "pngraw")],
["Height Map Tiler", new Geo.MapTilerProvider(DEV_MAPTILER_API_KEY, "tiles", "terrain-rgb", "png")],
["Debug Height Map Box", new Geo.HeightDebugProvider(new Geo.MapBoxProvider(DEV_MAPBOX_API_KEY, "mapbox.terrain-rgb", Geo.MapBoxProvider.MAP_ID, "pngraw"))],
["Debug", new Geo.DebugProvider()]
];
}
var modes = [
["Planar", Geo.MapView.PLANAR],
["Height", Geo.MapView.HEIGHT],
// ["Martini", Geo.MapView.MARTINI],
["Height Shader", Geo.MapView.HEIGHT_SHADER],
["Spherical", Geo.MapView.SPHERICAL]
];
var lods = [
["Raycast", Geo.LODRaycast],
["Frustum", Geo.LODFrustum],
["Radial", Geo.LODRadial]
];
var ids = ["mapbox_api", "heremaps_id", "heremaps_code", "bing_api", "maptiler_api", "openmap_tiles_server"];
for(var i = 0; i < ids.length; i++) {
var box = document.getElementById(ids[i]);
box.onchange = function(event)
{
providers = createProviders();
scene.remove(map);
map = new Geo.MapView(modes[mode.selectedIndex][0], providers[providerColor.selectedIndex][0], providers[providerHeight.selectedIndex][1]);
scene.add(map);
};
}
var lod = document.getElementById("lod");
lod.onchange = function(event)
{
if(map !== undefined)
{
map.lod = new lods[lod.selectedIndex][1]();
console.log(map.lod);
}
};
for(var i = 0; i < lods.length; i++)
{
var option = document.createElement("option");
option.innerHTML = lods[i][0];
lod.appendChild(option);
}
var mode = document.getElementById("mode");
mode.onchange = function(event)
{
if(map !== undefined)
{
scene.remove(map);
console.log(modes[mode.selectedIndex][0], providers[providerColor.selectedIndex][0], providers[providerHeight.selectedIndex][1]);
map = new Geo.MapView(modes[mode.selectedIndex][1], providers[providerColor.selectedIndex][1], providers[providerHeight.selectedIndex][1]);
scene.add(map);
}
};
for(var i = 0; i < modes.length; i++)
{
var option = document.createElement("option");
option.innerHTML = modes[i][0];
mode.appendChild(option);
}
var providerColor = document.getElementById("providerColor");
providerColor.onchange = function(event)
{
if(map !== undefined)
{
map.setProvider(providers[event.target.selectedIndex][1]);
}
};
for(var i = 0; i < providers.length; i++)
{
var option = document.createElement("option");
option.innerHTML = providers[i][0];
providerColor.appendChild(option);
}
var providerHeight = document.getElementById("providerHeight");
providerHeight.onchange = function(event)
{
if(map !== undefined)
{
map.setHeightProvider(providers[event.target.selectedIndex][1]);
}
};
for(var i = 0; i < providers.length; i++)
{
var option = document.createElement("option");
option.innerHTML = providers[i][0];
providerHeight.appendChild(option);
}
mode.selectedIndex = 1;
providerColor.selectedIndex = 12;
providerHeight.selectedIndex = 15;
lod.selectedIndex = 1;
var map = new Geo.MapView(modes[mode.selectedIndex][1], providers[providerColor.selectedIndex][1], providers[providerHeight.selectedIndex][1]);
scene.add(map);
map.updateMatrixWorld(true);
var camera = new THREE.PerspectiveCamera(80, 1, 1e2, 1e12);
// var test = new THREE.Mesh(new Geo.MapNodeGeometry(1e6, 1e6, 8.0, 8.0, true, 2e5), new THREE.MeshPhongMaterial({wireframe: false, color: 0xFFFFFF}));
// test.position.set(0, 1e6);
// scene.add(test);
var controls = new THREE.MapControls(camera, canvas);
controls.minDistance = 1e1;
controls.zoomSpeed = 2.0;
var coords = Geo.UnitsUtils.datumsToSpherical(40.940119, -8.535589);
controls.target.set(coords.x, 0, -coords.y);
camera.position.set(0, 500000, 0);
scene.add(new THREE.AmbientLight(0x777777));
var directional = new THREE.DirectionalLight(0x888888);
directional.position.set(100, 10000, 700);
scene.add(directional);
document.body.onresize = function()
{
var width = window.innerWidth;
var height = window.innerHeight;
renderer.setSize(width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
document.body.onresize();
let shouldUpdate = true;
map.onNodeReady = () => {
// console.log("onNodeReady");
shouldUpdate = true;
};
map.onNodeCreated = () => {
// console.log("onNodeCreated");
shouldUpdate = true;
}
map.onNodeSubdivided = () => {
// console.log("onNodeSubdivided");
shouldUpdate = true;
}
function animate()
{
requestAnimationFrame(animate);
controls.update();
//if (shouldUpdate) {
shouldUpdate = false;
map.update(camera);
//}
renderer.render(scene, camera);
}
animate();
function createSky()
{
// Add Sky
var sky = new THREE.Sky();
sky.scale.setScalar(1e8);
// GUI
var effectController = {
turbidity: 0,
rayleigh: 0.5,
mieCoefficient: 0.005,
mieDirectionalG: 0.7,
inclination: 0.48,
azimuth: 0.25,
exposure: 0.5
};
const uniforms = sky.material.uniforms;
uniforms["turbidity"].value = effectController.turbidity;
uniforms["rayleigh"].value = effectController.rayleigh;
uniforms["mieCoefficient"].value = effectController.mieCoefficient;
uniforms["mieDirectionalG"].value = effectController.mieDirectionalG;
var theta = Math.PI * (effectController.inclination - 0.5);
var phi = 2 * Math.PI * (effectController.azimuth - 0.5);
var sun = new THREE.Vector3();
sun.x = Math.cos(phi);
sun.y = Math.sin(phi) * Math.sin(theta);
sun.z = Math.sin(phi) * Math.cos(theta);
uniforms["sunPosition"].value.copy(sun);
return sky;
}
</script>
</body>
</html>