-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
305 lines (272 loc) · 11.2 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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>Terrain Viewer</title>
<style>
body { margin: 0; }
</style>
<link rel="stylesheet" href="./bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="./bootstrap/css/bootstrap-icons.min.css" />
<link rel="stylesheet" href="./app.css" />
<script src="./jszip/jszip.min.js"></script>
<script src="./jquery/jquery-3.7.0.min.js"></script>
<script src="./bootstrap/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div id="container">
<canvas id="render_canvas" ></canvas>
<div id="labels"></div>
</div>
<script type="importmap">
{
"imports": {
"three": "./three.module.min.js"
}
}
</script>
<button type="button" class="btn btn btn-primary menu-btn" style="position:absolute; top: 0px; z-index:200" id="menubtn" data-bs-toggle="offcanvas"
data-bs-target="#menu">
Menu
</button>
<div id="debug_info" style="display:none">
<div id="fps" style="position: absolute;
top: 10px;
width: 100%;
text-align: center;
display:block">FPS</div>
<div id="profiler" style="position: absolute;
top: 30px;
width: 100%;
text-align: left;
display:block">Profiler Info</div>
<div id="geolocation" style="position: absolute;
bottom: 0px;
width: 100%;
text-align: left;
display:block;">Location Info</div>
<div id="triangles" style="position: absolute;
top: 10px;
width: 100%;
text-align: right;
display:block;">TRIANGLES</div>
<div id="loadtime" style="position: absolute;
top: 30px;
width: 100%;
text-align: right;
display:block;">Load time</div>
</div>
<div id="gui">
<div class="compass"></div>
<div id="gps" class="gps_off"></div>
<div id="gps_loc" class="gps_loc"></div>
<div id="gps_info" class="gps_info">
<div id="gps_info_lat">LAT</div>
<div id="gps_info_lon">LON</div>
<div id="gps_info_accuracy">ACC</div>
<div id="terrain_elevation">ELEV</div>
</div>
<div id="search_container" style="display: none;">
<div class="inpup-group">
<div class="input-group mb-3">
<input id="search" type="search" class="form-control" placeholder="search...">
<span id="search_btn" class="input-group-text bi-search"></span>
</div>
</div>
<div id="search_results"></div>
</div>
</div>
<div class="offcanvas offcanvas-start" data-bs-scroll="true" data-bs-backdrop="false" tabindex="-1" id="menu"
aria-labelledby="menu-label" aria-controls="menu">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="menu-label">Menu</h5>
<button type="button" id="close_menu_btn" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<div>
<input type="file" accept=".zip" id="project_browser" style="display:none"/>
<button type="button" id="project_browser_btn" class="btn btn-primary">Open Project</button>
<button type="button" id="project_browser_btn_loading" class="btn btn-primary" disabled style="display:none">
<span class="spinner-border spinner-border-sm" aria-hidden="true"></span>
<span role="status">Loading...</span>
</button>
<div id="project_details"></div>
</div>
<hr />
<div>
<input type="file" accept=".kml,.kmz" id="kml_browser" style="display:none"/>
<button type="button" id="kml_browser_btn" class="btn btn-primary">Open KML</button>
<button type="button" id="kml_browser_btn_loading" class="btn btn-primary" disabled style="display:none">
<span class="spinner-border spinner-border-sm" aria-hidden="true"></span>
<span role="status">Loading...</span>
</button>
<div id="kml_details"></div>
</div>
<div style="position: absolute; bottom: 10px">
<button type="button" id="debug_toggle_btn" class="btn btn-info">Show debug info</button>
</div>
</div>
</div>
</body>
<script>
const registerServiceWorker = async () => {
if ('serviceWorker' in navigator) {
try {
const registration = await navigator.serviceWorker.register(
'sw.js',
{
scope: './',
}
);
if (registration.installing) {
console.log('Service worker installing');
} else if (registration.waiting) {
console.log('Service worker installed');
} else if (registration.active) {
console.log('Service worker active');
}
registration.addEventListener('updatefound', (e) => {
console.info("update found");
if (confirm("A new version of this application was found. Please close the page and open it to use the newest version. (NOTE: Reloading the page will not be enough. It has to be closed and opened again.)"))
{
//location.reload();
}
})
} catch (error) {
console.error(`Registration failed with ${error}`);
}
}
};
registerServiceWorker();
</script>
<script type="module">
import {App} from './app.js';
let gps_status = false;
let debug_status = false;
let proj_fileurl = null;
let kml_fileurl = null;
let search_timeout = null;
let app = new App();
app.initialise(document.getElementById('render_canvas'));
$('#project_browser_btn').on('click', show_project_browser);
$('#project_browser').on('change', project_file_selected);
$('#kml_browser_btn').on('click', show_kml_browser);
$('#kml_browser').on('change', kml_file_selected);
$('#debug_toggle_btn').on('click', toggle_debug);
$('#label1').on('click', () => console.log('clicked on label1'));
$('#gps').on('click', () => app.switch_gps_state());
$('#search').on('keydown', wait_to_do_search);
$('#search').on('focusout', search_lost_focus);
$('#search').on('focusin', search_gained_focus);
app.add_event_listener('loaded_project', (e) => {
$('#project_browser_btn').show();
$('#project_browser_btn_loading').hide();
// $('#close_menu_btn').click();
$('#project_details').html('Name: ' + e.project_name + '<br/>Desc: ' + e.description + '<br/>Zone: ' + e.zone + '<br/>Terrain Tiles: ' + e.terrains.length);
$('#search_container').hide();
$('#kml_details').html('');
})
function show_project_browser()
{
$('#project_browser').click();
}
async function project_file_selected()
{
let el = $('#project_browser').get(0);
if (!el.files.length) return;
let file = el.files[0];
if (proj_fileurl) URL.revokeObjectURL(proj_fileurl); // remove existing reference
proj_fileurl = URL.createObjectURL(file);
app.load_project(proj_fileurl);
el.value = ''; // allows for reloading of same project file (change event does not fire if the same file is selected)
$('#project_browser_btn').hide();
$('#project_browser_btn_loading').show();
}
function show_kml_browser()
{
$('#kml_browser').click();
}
async function kml_file_selected()
{
let el = $('#kml_browser').get(0);
if (!el.files.length) return;
let file = el.files[0];
if (kml_fileurl) URL.revokeObjectURL(kml_fileurl); // remove existing reference
kml_fileurl = URL.createObjectURL(file);
$('#kml_browser_btn').hide();
$('#kml_browser_btn_loading').show();
let kml = await app.load_kml(kml_fileurl);
$('#kml_browser_btn').show();
$('#kml_browser_btn_loading').hide();
$('#kml_details').html('Name: ' + kml.name + '<br>Locations: ' + kml.locations_cnt)
// $('#close_menu_btn').click();
$('#search_container').show();
}
function wait_to_do_search()
{
window.clearTimeout(search_timeout);
search_timeout = window.setTimeout(do_search, 250);
}
function do_search()
{
let text = $('#search').val();
if (text === '')
{
$('#search_results').html('');
return;
}
let matches = app.search_locations(text);
$('#search_results').html('');
let html = '<ul class="list-group">';
for (let match of matches)
{
html += '<li class="list-group-item">' + match.label_text + '</li>';
}
if (matches.length == 0)
{
html += '<li class="list-group-item">No results</li>';
}
$('#search_results').html(html);
$('#search_results li').on('click', selected_marker);
$('#search_results').show();
}
function search_lost_focus()
{
//
let hide_search_timeout = window.setTimeout(() => {$('#search_results').hide();}, 250);
}
function search_gained_focus()
{
// If there are existing search results then show them.
$('#search_results').show();
}
function toggle_search()
{
$('#search').toggle();
}
function selected_marker(el)
{
let loc = app.find_location_by_name(el.target.textContent)
app.focus_camera_on_location(loc.mesh.position.clone());
console.log(el.target.textContent, loc);
//app.request_render();
//$('#search_results').html('');
}
function toggle_debug()
{
if (!debug_status)
{
debug_status = true;
$(this).text('Hide debug info');
$('#debug_info').show();
}
else
{
debug_status = false;
$(this).text('Show debug info');
$('#debug_info').hide();
}
}
</script>
</html>