diff --git a/src/lib/draw/EditMode.svelte b/src/lib/draw/EditMode.svelte index ba16df1..357d823 100644 --- a/src/lib/draw/EditMode.svelte +++ b/src/lib/draw/EditMode.svelte @@ -17,6 +17,7 @@ import AreaControls from "./area/AreaControls.svelte"; import type { AreaProps, RouteProps } from "route-snapper-ts"; import type { Writable } from "svelte/store"; + import { finishCurrentFeature } from "./stores"; export let cfg: Config; export let gjSchemes: Writable>; @@ -60,6 +61,7 @@ }); } controls = "route"; + finishCurrentFeature.set(finishRoute); } else if (feature.geometry.type == "Polygon") { if (feature.properties.waypoints) { // Transform into the correct format @@ -82,14 +84,17 @@ $areaWaypoints = $areaWaypoints; } controls = "area"; + finishCurrentFeature.set(finishArea); } else if (feature.geometry.type == "Point") { $pointPosition = JSON.parse(JSON.stringify(feature.geometry.coordinates)); controls = "point"; + finishCurrentFeature.set(finish); } }); onDestroy(() => { $pointPosition = null; - + finishCurrentFeature.set(() => {}); + $routeTool?.stop(); $routeTool?.clearEventListeners(); diff --git a/src/lib/draw/NewFeatureForm.svelte b/src/lib/draw/NewFeatureForm.svelte index a0a44e7..dda689b 100644 --- a/src/lib/draw/NewFeatureForm.svelte +++ b/src/lib/draw/NewFeatureForm.svelte @@ -2,8 +2,9 @@ import { type Config } from "$lib/config"; import { onDestroy } from "svelte"; import type { Schemes } from "$lib/draw/types"; - import type { Writable } from "svelte/store"; - import { featureProps } from "./stores"; + import { get, type Writable } from "svelte/store"; + import { featureProps, finishCurrentFeature, mode } from "./stores"; + import { DefaultButton, SecondaryButton } from "govuk-svelte"; export let cfg: Config; export let gjSchemes: Writable>; @@ -19,6 +20,22 @@

New intervention

+ { + $finishCurrentFeature(); + }} +> + Finish + + + { + mode.set({ mode: "list" }); + }} +> + Cancel + + ; export let gjSchemes: Writable>; onMount(() => { $waypoints = []; + finishCurrentFeature.set(finish); + }); + + onDestroy(() => { + finishCurrentFeature.set(() => {}); }); function onSuccess(feature: Feature) { diff --git a/src/lib/draw/point/PointMode.svelte b/src/lib/draw/point/PointMode.svelte index bf0a6e4..e9ef59d 100644 --- a/src/lib/draw/point/PointMode.svelte +++ b/src/lib/draw/point/PointMode.svelte @@ -13,6 +13,7 @@ import { map, type Config } from "$lib/config"; import type { FeatureWithID, Schemes } from "$lib/draw/types"; import type { Writable } from "svelte/store"; + import { finishCurrentFeature } from "$lib/draw/stores"; export let cfg: Config; export let gjSchemes: Writable>; @@ -21,9 +22,12 @@ if ($map) { $map.getCanvas().style.cursor = "crosshair"; } + finishCurrentFeature.set(onSuccess); }); + onDestroy(() => { $pointPosition = null; + finishCurrentFeature.set(() => {}); if ($map) { $map.getCanvas().style.cursor = "inherit"; } diff --git a/src/lib/draw/route/RouteMode.svelte b/src/lib/draw/route/RouteMode.svelte index c91a6fc..8235c4b 100644 --- a/src/lib/draw/route/RouteMode.svelte +++ b/src/lib/draw/route/RouteMode.svelte @@ -7,19 +7,24 @@ featureProps, routeTool, } from "$lib/draw/stores"; - import { DefaultButton, SecondaryButton } from "govuk-svelte"; - import { onMount } from "svelte"; + import { onDestroy, onMount } from "svelte"; import RouteControls from "./RouteControls.svelte"; import { type Config } from "$lib/config"; import type { FeatureWithID, Schemes } from "$lib/draw/types"; import type { Writable } from "svelte/store"; import { waypoints } from "./stores"; + import { finishCurrentFeature } from "../stores"; export let cfg: Config; export let gjSchemes: Writable>; onMount(() => { $waypoints = []; + finishCurrentFeature.set(finish); + }); + + onDestroy(() => { + finishCurrentFeature.set(() => {}); }); function onSuccess(feature: Feature) { diff --git a/src/lib/draw/stores.ts b/src/lib/draw/stores.ts index 7a63f34..ebeb96d 100644 --- a/src/lib/draw/stores.ts +++ b/src/lib/draw/stores.ts @@ -31,6 +31,9 @@ export const mode: Writable = writable({ mode: "list" }); // the generic parameter isn't known here. export const featureProps: Writable> = writable({}); +// Used to share the function currently required to finish drawing a feature +export const finishCurrentFeature: Writable = writable(() => {}); + // All feature IDs must: // // - be unique diff --git a/src/lib/sidebar/EditFeatureForm.svelte b/src/lib/sidebar/EditFeatureForm.svelte index a140bd9..75544df 100644 --- a/src/lib/sidebar/EditFeatureForm.svelte +++ b/src/lib/sidebar/EditFeatureForm.svelte @@ -1,6 +1,6 @@