From c2c7ef8e8906ea3748c0dd4761b91ff72d2826e4 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Fri, 13 Sep 2024 14:17:44 +0100 Subject: [PATCH] Show one input route at a time for debugging snapping --- web/src/UploadRouteMode.svelte | 80 +++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/web/src/UploadRouteMode.svelte b/web/src/UploadRouteMode.svelte index 4bf1464..cc98b3e 100644 --- a/web/src/UploadRouteMode.svelte +++ b/web/src/UploadRouteMode.svelte @@ -4,6 +4,7 @@ import type { FeatureCollection } from "geojson"; import { backend, + map, travelMode, bufferMins, showRouteBuffer, @@ -15,13 +16,37 @@ import BufferLayer from "./BufferLayer.svelte"; import { SequentialLegend } from "svelte-utils"; import { colorScale } from "./colors"; + import { onMount, onDestroy } from "svelte"; + let allInput: FeatureCollection | null = null; let input: FeatureCollection | null = null; let output: FeatureCollection | null = null; let totalPopulationInBuffer = 0; let showInput = true; let showOutput = true; + let showOneInput = false; + let oneFeatureId: number | null = null; + + $: if (showOneInput) { + if (oneFeatureId == null) { + oneFeatureId = 0; + } + } else { + oneFeatureId = null; + } + $: if (allInput) { + if (showOneInput && oneFeatureId != null) { + input = { + type: "FeatureCollection", + features: [allInput.features[oneFeatureId]], + }; + } else { + input = allInput; + } + } else { + input = null; + } let fileInput: HTMLInputElement; async function loadFile(e: Event) { @@ -30,7 +55,8 @@ await fileInput.files![0].text(), ) as FeatureCollection; gj.features = gj.features.filter((f) => f.geometry.type == "LineString"); - input = gj; + allInput = gj; + showOneInput = false; } catch (err) { window.alert(`Couldn't snap routes from file: ${err}`); } @@ -66,8 +92,35 @@ $: limits = Array.from(Array(6).keys()).map( (i) => (($bufferMins * 60) / (6 - 1)) * i, ); + + onMount(() => { + $map?.keyboard.disable(); + }); + onDestroy(() => { + $map?.keyboard.enable(); + }); + + function onKeyDown(e: KeyboardEvent) { + if (oneFeatureId == null || allInput == null) { + return; + } + if (e.key == "ArrowLeft") { + e.stopPropagation(); + if (oneFeatureId > 0) { + oneFeatureId--; + } + } + if (e.key == "ArrowRight") { + e.stopPropagation(); + if (oneFeatureId != allInput.features.length - 1) { + oneFeatureId++; + } + } + } + +
@@ -81,6 +134,26 @@ + {#if input} + + + {#if oneFeatureId != null} +
+ + {oneFeatureId + 1} / {allInput.features.length} + +
+ {/if} + {/if} +