Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add controls to feature form #11

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/lib/draw/EditMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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<F, S>;
export let gjSchemes: Writable<Schemes<F, S>>;
Expand Down Expand Up @@ -60,6 +61,7 @@
});
}
controls = "route";
finishCurrentFeature.set(finishRoute);
} else if (feature.geometry.type == "Polygon") {
if (feature.properties.waypoints) {
// Transform into the correct format
Expand All @@ -82,13 +84,16 @@
$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();
Expand Down
21 changes: 19 additions & 2 deletions src/lib/draw/NewFeatureForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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<F, S>;
export let gjSchemes: Writable<Schemes<F, S>>;
Expand All @@ -19,6 +20,22 @@

<h2>New intervention</h2>

<DefaultButton
on:click={() => {
$finishCurrentFeature();
}}
>
Finish
</DefaultButton>

<SecondaryButton
on:click={() => {
mode.set({ mode: "list" });
}}
>
Cancel
</SecondaryButton>

<svelte:component
this={cfg.editFeatureForm}
{cfg}
Expand Down
8 changes: 7 additions & 1 deletion src/lib/draw/area/AreaMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@
routeTool,
} from "$lib/draw/stores";
import { DefaultButton, SecondaryButton } from "govuk-svelte";
import { onMount } from "svelte";
import { onDestroy, onMount } from "svelte";
import AreaControls from "./AreaControls.svelte";
import { type Config } from "$lib/config";
import type { FeatureWithID, Schemes } from "$lib/draw/types";
import type { Writable } from "svelte/store";
import { waypoints, calculateArea } from "./stores";
import { finishCurrentFeature } from "$lib/draw/stores";

export let cfg: Config<F, S>;
export let gjSchemes: Writable<Schemes<F, S>>;

onMount(() => {
$waypoints = [];
finishCurrentFeature.set(finish);
});

onDestroy(() => {
finishCurrentFeature.set(() => {});
});

function onSuccess(feature: Feature<LineString | Polygon>) {
Expand Down
4 changes: 4 additions & 0 deletions src/lib/draw/point/PointMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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<F, S>;
export let gjSchemes: Writable<Schemes<F, S>>;
Expand All @@ -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";
}
Expand Down
9 changes: 7 additions & 2 deletions src/lib/draw/route/RouteMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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<F, S>;
export let gjSchemes: Writable<Schemes<F, S>>;

onMount(() => {
$waypoints = [];
finishCurrentFeature.set(finish);
});

onDestroy(() => {
finishCurrentFeature.set(() => {});
});

function onSuccess(feature: Feature<LineString | Polygon>) {
Expand Down
3 changes: 3 additions & 0 deletions src/lib/draw/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export const mode: Writable<Mode> = writable({ mode: "list" });
// the generic parameter isn't known here.
export const featureProps: Writable<FeatureProps<any>> = writable({});

// Used to share the function currently required to finish drawing a feature
export const finishCurrentFeature: Writable<Function> = writable(() => {});

// All feature IDs must:
//
// - be unique
Expand Down
30 changes: 28 additions & 2 deletions src/lib/sidebar/EditFeatureForm.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
<script lang="ts" generics="F, S">
import { deleteIntervention, mode, featureProps } from "$lib/draw/stores";
import { ErrorMessage, WarningButton } from "govuk-svelte";
import {
deleteIntervention,
mode,
featureProps,
finishCurrentFeature,
} from "$lib/draw/stores";
import {
ErrorMessage,
DefaultButton,
SecondaryButton,
WarningButton,
} from "govuk-svelte";
import { type Config } from "$lib/config";
import type { FeatureWithID, Schemes } from "$lib/draw/types";
import type { Writable } from "svelte/store";
Expand Down Expand Up @@ -32,6 +42,22 @@

<h2>Editing {cfg.interventionName(feature)}</h2>

<DefaultButton
on:click={() => {
$finishCurrentFeature();
}}
>
Finish
</DefaultButton>

<SecondaryButton
on:click={() => {
mode.set({ mode: "list" });
}}
>
Cancel
</SecondaryButton>

<WarningButton on:click={() => deleteIntervention(gjSchemes, id)}>
Delete
</WarningButton>
Expand Down