Skip to content

Commit

Permalink
Let the user add a fixed image to the map and move/scale/rotate it. No
Browse files Browse the repository at this point in the history
saving or nice controls yet.
  • Loading branch information
dabreegster committed Nov 3, 2023
1 parent 25f8dfb commit 8cedfef
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lib/draw/Toolbox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
Split route
</SecondaryButton>
{/if}
<SecondaryButton on:click={() => mode.set({ mode: "new-image" })}>
New image
</SecondaryButton>
<SecondaryButton on:click={() => mode.set({ mode: "streetview" })}>
<img src={streetViewIcon} alt="StreetView" />
StreetView
Expand Down
17 changes: 17 additions & 0 deletions src/lib/draw/image/ImageLayer.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script lang="ts">
// TODO This should just be part of InterventionLayer? treat it like a
// feature? could even base64 encode the bytes to embed it, at risk of
// blowing up local storage?
import { map } from "stores";
import { Marker } from "svelte-maplibre";
import imgUrl from "../../../../assets/warning.svg?url";
import { opacity, rotate, scale } from "./stores";
let lngLat = $map.getCenter().toArray();
$: style = `transform: rotate(${$rotate}deg); opacity: ${$opacity / 100.0}`;
</script>

<Marker bind:lngLat draggable>
<img src={imgUrl} alt="Georeferenced image" width={$scale * 50} {style} />
</Marker>
29 changes: 29 additions & 0 deletions src/lib/draw/image/ImageMode.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<script lang="ts">
import { SecondaryButton } from "lib/govuk";
import { mode } from "stores";
import { opacity, rotate, scale } from "./stores";
</script>

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

<div>
<label>
Scale
<input type="number" min="0.1" step="0.1" bind:value={$scale} />
</label>
</div>
<div>
<label>
Rotation (degrees)
<input type="number" bind:value={$rotate} />
</label>
</div>

<div>
<label>
<input type="range" min="0" max="100" bind:value={$opacity} />
Opacity
</label>
</div>
7 changes: 7 additions & 0 deletions src/lib/draw/image/stores.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { writable, type Writable } from "svelte/store";

// Use this to share between two components, nested under the sidebar and map

export const scale: Writable<number> = writable(1.0);
export const rotate: Writable<number> = writable(0.0);
export const opacity: Writable<number> = writable(100);
4 changes: 4 additions & 0 deletions src/lib/sidebar/LeftSidebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { onDestroy } from "svelte";
import type { Schema } from "types";
import EditGeometryMode from "../draw/EditGeometryMode.svelte";
import ImageMode from "../draw/image/ImageMode.svelte";
import { PointTool } from "../draw/point/point_tool";
import PointMode from "../draw/point/PointMode.svelte";
import { PolygonTool } from "../draw/polygon/polygon_tool";
Expand Down Expand Up @@ -78,6 +79,9 @@ toolbox, but that gets created and destroyed frequently. -->
to cancel
</li>
</ul>
{:else if $mode.mode == "new-image"}
<h2>New image</h2>
<ImageMode />
{:else if $mode.mode == "streetview"}
<h2>StreetView</h2>
<StreetViewMode />
Expand Down
3 changes: 3 additions & 0 deletions src/pages/SketchSchemes.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
MapLibreMap,
ZoomOutMap,
} from "lib/common";
import ImageLayer from "lib/draw/image/ImageLayer.svelte";
import InterventionLayer from "lib/draw/InterventionLayer.svelte";
import SplitRouteMode from "lib/draw/route/SplitRouteMode.svelte";
import Toolbox from "lib/draw/Toolbox.svelte";
Expand Down Expand Up @@ -115,6 +116,8 @@
<Toolbox {schema} />
{:else if $mode.mode == "split-route"}
<SplitRouteMode />
{:else if $mode.mode == "new-image"}
<ImageLayer />
{/if}
</MapLibreMap>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,5 @@ export type Mode =
| { mode: "new-snapped-polygon" }
| { mode: "new-route" }
| { mode: "split-route" }
| { mode: "new-image" }
| { mode: "streetview" };

0 comments on commit 8cedfef

Please sign in to comment.