aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--content/editor.html3
-rw-r--r--content/logger.html9
-rw-r--r--content/static/main.js78
3 files changed, 56 insertions, 34 deletions
diff --git a/content/editor.html b/content/editor.html
index 1bb4588..467c789 100644
--- a/content/editor.html
+++ b/content/editor.html
@@ -19,6 +19,7 @@
19 <button id="shape-kind-unburned" type="button">Shape Unburned</button> 19 <button id="shape-kind-unburned" type="button">Shape Unburned</button>
20 <button id="shape-kind-burned" type="button">Shape Burned</button> 20 <button id="shape-kind-burned" type="button">Shape Burned</button>
21 <button id="shapes-update" type="button">Update Shapes</button> 21 <button id="shapes-update" type="button">Update Shapes</button>
22 <input type="range" min="1" max="50" value="15" class="slider" id="shape-vertex-radius">
22 </div> 23 </div>
23 <div id="map"></div> 24 <div id="map"></div>
24 </div> 25 </div>
@@ -66,7 +67,7 @@
66</style> 67</style>
67 68
68<script> 69<script>
69 window.addEventListener("load", () => page_shape__main()) 70 window.addEventListener("load", () => page_editor__main())
70</script> 71</script>
71 72
72</html> 73</html>
diff --git a/content/logger.html b/content/logger.html
index 4c0700a..e187699 100644
--- a/content/logger.html
+++ b/content/logger.html
@@ -35,6 +35,12 @@
35 <td>Heading</td> 35 <td>Heading</td>
36 <td id="value-heading"></td> 36 <td id="value-heading"></td>
37 </tr> 37 </tr>
38 <tr>
39 <td>Vibrate</td>
40 <td>
41 <input id="input-vibrate" type="checkbox" name="vibrate" value="false">
42 </td>
43 </tr>
38 </tbody> 44 </tbody>
39 </table> 45 </table>
40 <div class="grid"> 46 <div class="grid">
@@ -119,6 +125,9 @@
119 } 125 }
120 126
121 logger_state.inprogress = true; 127 logger_state.inprogress = true;
128 if (document.getElementById("input-vibrate").checked) {
129 navigator.vibrate(200);
130 }
122 log_post(); 131 log_post();
123 update_ui(); 132 update_ui();
124 } 133 }
diff --git a/content/static/main.js b/content/static/main.js
index 216cbea..960e291 100644
--- a/content/static/main.js
+++ b/content/static/main.js
@@ -170,41 +170,41 @@ function lib_shape_create_from_descriptor(desc) {
170 }; 170 };
171} 171}
172 172
173function page_shape__on_shape_create(state) { 173function page_editor__on_shape_create(state) {
174 const shape = lib_shape_create_empty(); 174 const shape = lib_shape_create_empty();
175 state.shapes.push(shape); 175 state.shapes.push(shape);
176 page_shape__ui_shape_select(state, shape); 176 page_editor__ui_shape_select(state, shape);
177} 177}
178 178
179function page_shape__on_shape_delete(state) { 179function page_editor__on_shape_delete(state) {
180 if (state.selected_shape == null) 180 if (state.selected_shape == null)
181 return; 181 return;
182 page_shape__ui_shape_remove(state, state.selected_shape); 182 page_editor__ui_shape_remove(state, state.selected_shape);
183 state.shapes.splice(state.shapes.indexOf(state.selected_shape), 1); 183 state.shapes.splice(state.shapes.indexOf(state.selected_shape), 1);
184 state.selected_shape = null; 184 state.selected_shape = null;
185} 185}
186 186
187function page_shape__on_shape_delete_vertex(state) { 187function page_editor__on_shape_delete_vertex(state) {
188 if (state.delete_selected_vertex_fn == null) 188 if (state.delete_selected_vertex_fn == null)
189 return; 189 return;
190 state.delete_selected_vertex_fn(); 190 state.delete_selected_vertex_fn();
191} 191}
192 192
193function page_shape__on_shape_kind_unburned(state) { 193function page_editor__on_shape_kind_unburned(state) {
194 if (state.selected_shape == null) 194 if (state.selected_shape == null)
195 return; 195 return;
196 state.selected_shape.kind = SHAPE_KIND_UNBURNED; 196 state.selected_shape.kind = SHAPE_KIND_UNBURNED;
197 page_shape__ui_shape_add(state, state.selected_shape); 197 page_editor__ui_shape_add(state, state.selected_shape);
198} 198}
199 199
200function page_shape__on_shape_kind_burned(state) { 200function page_editor__on_shape_kind_burned(state) {
201 if (state.selected_shape == null) 201 if (state.selected_shape == null)
202 return; 202 return;
203 state.selected_shape.kind = SHAPE_KIND_BURNED; 203 state.selected_shape.kind = SHAPE_KIND_BURNED;
204 page_shape__ui_shape_add(state, state.selected_shape); 204 page_editor__ui_shape_add(state, state.selected_shape);
205} 205}
206 206
207function page_shape__on_shapes_update(state) { 207function page_editor__on_shapes_update(state) {
208 const shape_descriptors = []; 208 const shape_descriptors = [];
209 for (const shape of state.shapes) { 209 for (const shape of state.shapes) {
210 if (shape.points.length < 3) 210 if (shape.points.length < 3)
@@ -236,7 +236,7 @@ function page_shape__on_shapes_update(state) {
236 }); 236 });
237} 237}
238 238
239function page_shape__on_map_click(state, ev) { 239function page_editor__on_map_click(state, ev) {
240 console.log("clicked on map"); 240 console.log("clicked on map");
241 if (state.selected_shape == null) 241 if (state.selected_shape == null)
242 return; 242 return;
@@ -245,21 +245,23 @@ function page_shape__on_map_click(state, ev) {
245 longitude: ev.latlng.lng, 245 longitude: ev.latlng.lng,
246 }); 246 });
247 state.selected_shape.point_insert_idx += 1; 247 state.selected_shape.point_insert_idx += 1;
248 page_shape__ui_shape_add(state, state.selected_shape); 248 page_editor__ui_shape_add(state, state.selected_shape);
249} 249}
250 250
251function page_shape__setup_handlers(state) { 251function page_editor__setup_handlers(state) {
252 lib_setup_handler_onclick(ELEM_ID_BTN_SHAPE_CREATE, () => page_shape__on_shape_create(state)); 252 lib_setup_handler_onclick(ELEM_ID_BTN_SHAPE_CREATE, () => page_editor__on_shape_create(state));
253 lib_setup_handler_onclick(ELEM_ID_BTN_SHAPE_DELETE, () => page_shape__on_shape_delete(state)); 253 lib_setup_handler_onclick(ELEM_ID_BTN_SHAPE_DELETE, () => page_editor__on_shape_delete(state));
254 lib_setup_handler_onclick(ELEM_ID_BTN_SHAPE_DELETE_VERTEX, () => page_shape__on_shape_delete_vertex(state)); 254 lib_setup_handler_onclick(ELEM_ID_BTN_SHAPE_DELETE_VERTEX, () => page_editor__on_shape_delete_vertex(state));
255 lib_setup_handler_onclick(ELEM_ID_BTN_SHAPE_UNBURNED, () => page_shape__on_shape_kind_unburned(state)); 255 lib_setup_handler_onclick(ELEM_ID_BTN_SHAPE_UNBURNED, () => page_editor__on_shape_kind_unburned(state));
256 lib_setup_handler_onclick(ELEM_ID_BTN_SHAPE_BURNED, () => page_shape__on_shape_kind_burned(state)); 256 lib_setup_handler_onclick(ELEM_ID_BTN_SHAPE_BURNED, () => page_editor__on_shape_kind_burned(state));
257 lib_setup_handler_onclick(ELEM_ID_BTN_SHAPES_UPDATE, () => page_shape__on_shapes_update(state)); 257 lib_setup_handler_onclick(ELEM_ID_BTN_SHAPES_UPDATE, () => page_editor__on_shapes_update(state));
258 258
259 state.map.on('click', (ev) => page_shape__on_map_click(state, ev)); 259 state.map.on('click', (ev) => page_editor__on_map_click(state, ev));
260} 260}
261 261
262function page_shape__ui_shape_remove(state, shape) { 262function page_editor__ui_shape_remove(state, shape) {
263 if (shape == null)
264 return;
263 for (const layer of shape.layers) { 265 for (const layer of shape.layers) {
264 state.map.removeLayer(layer); 266 state.map.removeLayer(layer);
265 layer.remove(); 267 layer.remove();
@@ -267,16 +269,19 @@ function page_shape__ui_shape_remove(state, shape) {
267 shape.layers = []; 269 shape.layers = [];
268} 270}
269 271
270function page_shape__ui_shape_select(state, shape) { 272function page_editor__ui_shape_select(state, shape) {
271 const prev_shape = state.selected_shape; 273 const prev_shape = state.selected_shape;
272 state.selected_shape = shape; 274 state.selected_shape = shape;
273 page_shape__ui_shape_add(state, shape); 275 page_editor__ui_shape_add(state, shape);
274 if (prev_shape != null) 276 if (prev_shape != null)
275 page_shape__ui_shape_add(state, prev_shape); 277 page_editor__ui_shape_add(state, prev_shape);
276} 278}
277 279
278function page_shape__ui_shape_add(state, shape) { 280function page_editor__ui_shape_add(state, shape) {
279 page_shape__ui_shape_remove(state, shape); 281 if (shape == null)
282 return;
283
284 page_editor__ui_shape_remove(state, shape);
280 285
281 const selected = state.selected_shape == shape; 286 const selected = state.selected_shape == shape;
282 const color = lib_shape_color_for_kind(shape.kind); 287 const color = lib_shape_color_for_kind(shape.kind);
@@ -293,18 +298,18 @@ function page_shape__ui_shape_add(state, shape) {
293 const remove_circle = () => { 298 const remove_circle = () => {
294 shape.points.splice(circle_idx, 1); 299 shape.points.splice(circle_idx, 1);
295 shape.point_insert_idx = circle_idx; 300 shape.point_insert_idx = circle_idx;
296 page_shape__ui_shape_add(state, shape); 301 page_editor__ui_shape_add(state, shape);
297 }; 302 };
298 const update_insert_idx = () => { 303 const update_insert_idx = () => {
299 shape.point_insert_idx = circle_idx + 1; 304 shape.point_insert_idx = circle_idx + 1;
300 page_shape__ui_shape_add(state, shape); 305 page_editor__ui_shape_add(state, shape);
301 }; 306 };
302 307
303 if (highlight_point) 308 if (highlight_point)
304 state.delete_selected_vertex_fn = remove_circle; 309 state.delete_selected_vertex_fn = remove_circle;
305 310
306 positions.push(coords); 311 positions.push(coords);
307 const circle = L.circle(coords, { radius: 15, color: circle_color, bubblingMouseEvents: false }) 312 const circle = L.circle(coords, { radius: state.vertex_radius, color: circle_color, bubblingMouseEvents: false })
308 .on('click', (e) => { 313 .on('click', (e) => {
309 if (e.originalEvent.shiftKey) { 314 if (e.originalEvent.shiftKey) {
310 remove_circle(); 315 remove_circle();
@@ -325,7 +330,7 @@ function page_shape__ui_shape_add(state, shape) {
325 330
326 if (positions.length >= 3) { 331 if (positions.length >= 3) {
327 const opacity = state.selected_shape == shape ? 0.2 : 0.04; 332 const opacity = state.selected_shape == shape ? 0.2 : 0.04;
328 const select = () => page_shape__ui_shape_select(state, shape); 333 const select = () => page_editor__ui_shape_select(state, shape);
329 const poly = L.polygon(positions, { color: color, fillOpacity: opacity }) 334 const poly = L.polygon(positions, { color: color, fillOpacity: opacity })
330 .on('click', (ev) => { if (ev.originalEvent.shiftKey) { L.DomEvent.stopPropagation(ev); select(); } }) 335 .on('click', (ev) => { if (ev.originalEvent.shiftKey) { L.DomEvent.stopPropagation(ev); select(); } })
331 .on('dblclick', (ev) => { 336 .on('dblclick', (ev) => {
@@ -337,7 +342,7 @@ function page_shape__ui_shape_add(state, shape) {
337 } 342 }
338} 343}
339 344
340async function page_shape__main() { 345async function page_editor__main() {
341 const map = lib_setup_map(); 346 const map = lib_setup_map();
342 const locations = await lib_fetch_location_logs(); 347 const locations = await lib_fetch_location_logs();
343 const shape_descriptors = await lib_fetch_shape_descriptors(); 348 const shape_descriptors = await lib_fetch_shape_descriptors();
@@ -348,16 +353,23 @@ async function page_shape__main() {
348 shapes: [], 353 shapes: [],
349 selected_shape: null, 354 selected_shape: null,
350 delete_selected_vertex_fn: null, 355 delete_selected_vertex_fn: null,
356 vertex_radius: 15,
351 }; 357 };
352 window.state = state; // to allow access from the console 358 window.state = state; // to allow access from the console
353 359
354 page_shape__setup_handlers(state); 360 page_editor__setup_handlers(state);
355 lib_add_location_logs_to_map(state.map, state.locations); 361 lib_add_location_logs_to_map(state.map, state.locations);
356 362
363 const vertex_radius_slider = document.getElementById("shape-vertex-radius");
364 vertex_radius_slider.addEventListener("change", () => {
365 state.vertex_radius = vertex_radius_slider.value;
366 page_editor__ui_shape_add(state, state.selected_shape);
367 });
368
357 for (const descriptor of shape_descriptors) { 369 for (const descriptor of shape_descriptors) {
358 const shape = lib_shape_create_from_descriptor(descriptor); 370 const shape = lib_shape_create_from_descriptor(descriptor);
359 state.shapes.push(shape); 371 state.shapes.push(shape);
360 page_shape__ui_shape_add(state, shape); 372 page_editor__ui_shape_add(state, shape);
361 } 373 }
362} 374}
363 375