Skip to content

Commit

Permalink
Stop redrawing the network layer constantly. #13
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Aug 9, 2024
1 parent 447718c commit 94744ab
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 18 deletions.
13 changes: 6 additions & 7 deletions web/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import DebugMode from "./DebugMode.svelte";
import RouteMode from "./RouteMode.svelte";
import ScoreMode from "./ScoreMode.svelte";
import NetworkLayer from "./NetworkLayer.svelte";
import {
map as mapStore,
mode,
Expand Down Expand Up @@ -144,15 +145,13 @@
<GeoJSON data={JSON.parse($model.getInvertedBoundary())}>
<FillLayer paint={{ "fill-color": "black", "fill-opacity": 0.3 }} />
</GeoJSON>

<NetworkLayer show={$mode.kind != "debug"} {showSeverances} {opacity} />

{#if $mode.kind == "route"}
<RouteMode
{showSeverances}
{opacity}
route_a={$mode.route_a}
route_b={$mode.route_b}
/>
<RouteMode route_a={$mode.route_a} route_b={$mode.route_b} />
{:else if $mode.kind == "score"}
<ScoreMode {showSeverances} {opacity} />
<ScoreMode />
{:else if $mode.kind == "debug"}
<DebugMode {showSeverances} {opacity} />
{/if}
Expand Down
2 changes: 2 additions & 0 deletions web/src/DebugMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import { model } from "./stores";
import NavBar from "./NavBar.svelte";
// TODO Could try to reuse NetworkLayer and add in the interactivity
export let showSeverances: boolean;
export let opacity: number;
</script>
Expand Down
4 changes: 4 additions & 0 deletions web/src/NetworkLayer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { constructMatchExpression } from "svelte-utils/map";
import { model } from "./stores";
export let show: boolean;
// TODO Use filter expressions?
export let showSeverances: boolean;
export let opacity: number;
Expand All @@ -14,6 +15,9 @@
<LineLayer
id="network"
beforeId="Road labels"
layout={{
visibility: show ? "visible" : "none",
}}
paint={{
"line-width": 5,
"line-color": constructMatchExpression(
Expand Down
5 changes: 0 additions & 5 deletions web/src/RouteMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
import type { MapMouseEvent } from "maplibre-gl";
import { MapEvents, GeoJSON, LineLayer, Marker } from "svelte-maplibre";
import Directions from "./Directions.svelte";
import NetworkLayer from "./NetworkLayer.svelte";
import { SplitComponent } from "svelte-utils/top_bar_layout";
import { model, type RouteGJ } from "./stores";
import NavBar from "./NavBar.svelte";
export let route_a: [number, number];
export let route_b: [number, number];
export let showSeverances: boolean;
export let opacity: number;
// TODO or empty
let route_gj: RouteGJ | null = null;
Expand Down Expand Up @@ -57,8 +54,6 @@
<div slot="map">
<MapEvents on:contextmenu={onRightClick} />

<NetworkLayer {showSeverances} {opacity} />

<Marker bind:lngLat={route_a} draggable><span class="dot">A</span></Marker>
<Marker bind:lngLat={route_b} draggable><span class="dot">B</span></Marker>
{#if route_gj}
Expand Down
6 changes: 0 additions & 6 deletions web/src/ScoreMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@
type LayerClickInfo,
} from "svelte-maplibre";
import { colorScale, limits } from "./colors";
import NetworkLayer from "./NetworkLayer.svelte";
import { SplitComponent } from "svelte-utils/top_bar_layout";
import { map, model, mode, minScore, maxScore } from "./stores";
import NavBar from "./NavBar.svelte";
export let showSeverances: boolean;
export let opacity: number;
let scoreGj: FeatureCollection<LineString, { score: number }> = JSON.parse(
$model!.makeHeatmap(),
);
Expand Down Expand Up @@ -119,8 +115,6 @@
<div slot="map">
<MapEvents on:click={onClick} />

<NetworkLayer {showSeverances} {opacity} />

<GeoJSON data={scoreGj}>
<LineLayer
id="scores"
Expand Down

0 comments on commit 94744ab

Please sign in to comment.