Skip to content

Commit

Permalink
Try using line width to show shortcuts. #59
Browse files Browse the repository at this point in the history
It's a start, but leaving disabled
  • Loading branch information
dabreegster committed Jan 5, 2025
1 parent f438760 commit a5ce0b1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
26 changes: 23 additions & 3 deletions web/src/RenderNeighbourhood.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
} from "svelte-maplibre";
import { layerId, roadLineWidth } from "./common";
import OneWayLayer from "./OneWayLayer.svelte";
import { roadStyle } from "./stores";
import { roadStyle, thickRoadsForShortcuts } from "./stores";
import type { RenderNeighbourhoodOutput } from "./wasm";
export let gj: RenderNeighbourhoodOutput;
Expand Down Expand Up @@ -45,6 +45,26 @@
);
}
function lineWidth(
thickRoadsForShortcuts: boolean,
maxShortcuts: number,
extraWidth: number,
): ExpressionSpecification {
if (!thickRoadsForShortcuts || maxShortcuts <= 2) {
return roadLineWidth(extraWidth);
}
// TODO It'd still be nice to depend on zoom here
return [
"interpolate",
["linear"],
["get", "shortcuts"],
0,
5 + extraWidth,
maxShortcuts,
25 + extraWidth,
];
}
function invertBoundary(gj: RenderNeighbourhoodOutput): Feature<Polygon> {
// @ts-expect-error TS can't figure out that we're narrowing the case here
let boundary: Feature<Polygon> = gj.features.find(
Expand Down Expand Up @@ -112,7 +132,7 @@
{...layerId("interior-roads-outlines")}
filter={["==", ["get", "kind"], "interior_road"]}
paint={{
"line-width": roadLineWidth(2),
"line-width": lineWidth($thickRoadsForShortcuts, gj.maxShortcuts, 0),
"line-color": "black",
}}
/>
Expand All @@ -121,7 +141,7 @@
{...layerId("interior-roads")}
filter={["==", ["get", "kind"], "interior_road"]}
paint={{
"line-width": roadLineWidth(0),
"line-width": lineWidth($thickRoadsForShortcuts, gj.maxShortcuts, 0),
"line-color": roadLineColor($roadStyle, gj.maxShortcuts),
"line-opacity": hoverStateFilter(1.0, 0.5),
}}
Expand Down
7 changes: 6 additions & 1 deletion web/src/Settings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Modal } from "svelte-utils";
import icon from "../assets/settings.svg?url";
import { BasemapPicker } from "./common";
import { roadStyle } from "./stores";
import { roadStyle, thickRoadsForShortcuts } from "./stores";
let show = false;
</script>
Expand All @@ -25,6 +25,11 @@
</select>
</label>

<label>
<input type="checkbox" bind:checked={$thickRoadsForShortcuts} />
Road thickness depends on shortcuts
</label>

<center><button on:click={() => (show = false)}>Confirm</button></center>
</Modal>
{/if}
1 change: 1 addition & 0 deletions web/src/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export let filterType: Writable<string> = writable("walk_cycle_only");
export let animateShortcuts = writable(false);
export let editPerimeterRoads = writable(false);
export let roadStyle: Writable<"shortcuts" | "cells"> = writable("shortcuts");
export let thickRoadsForShortcuts = writable(false);

export function autosave() {
let key = get(projectName);
Expand Down

0 comments on commit a5ce0b1

Please sign in to comment.