Skip to content

Commit

Permalink
Move streetview highlighting into config
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Jul 8, 2024
1 parent e38d3e6 commit 17821bf
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 63 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@ TODO: Document all of these
- upgrade packages
- consider renaming "intervention" and "scheme"
- coverage polygons in InterventionLayer
- can we totally remove mapStyle from this library and let streetview tool use a config hook instead?
- baselayer switcher at bottom of sidebar

## Developer guide

This is a fairly standard Sveltekit project. `src/lib` is the library meant for use by others, and `src/routes` is a demo site using it. `npm i`, then `npm run dev` to develop locally.
5 changes: 2 additions & 3 deletions src/lib/common/StreetViewTool.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<script lang="ts">
import { CollapsibleCard, Radio, SecondaryButton } from "govuk-svelte";
import { getRoadLayerNames } from "$lib/maplibre";
import type { MapMouseEvent } from "maplibre-gl";
import { map } from "$lib/config";
import { userSettings } from "$lib/draw/stores";
import { mapStyle } from "$lib/config";
import { onDestroy } from "svelte";
import cameraCursorUrl from "$lib/assets/camera_cursor.svg?url";
import StreetViewHelp from "./StreetViewHelp.svelte";
import { cfg } from "$lib/config";
export let enabled: boolean;
export let showControls = true;
Expand All @@ -21,7 +20,7 @@
$map.on("click", onClick);
$map.getCanvas().style.cursor = `url(${cameraCursorUrl}), auto`;
for (let layer of getRoadLayerNames($map, $mapStyle)) {
for (let layer of cfg.getStreetViewRoadLayerNames($map)) {
defaultLineColorPerLayer.push([
layer,
$map.getPaintProperty(layer, "line-color"),
Expand Down
5 changes: 4 additions & 1 deletion src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { SvelteComponent, type ComponentType } from "svelte";
import type { Map } from "maplibre-gl";

export let map: Writable<Map | null> = writable(null);
export const mapStyle: Writable<string> = writable("dataviz");

// The draw code should be agnostic to the feature properties that differ by
// schema. Start centralizing the logic here, so it's easy for other users to
Expand Down Expand Up @@ -65,4 +64,8 @@ export let cfg = {

// Required for the geocoder in the route mote to work
maptilerApiKey: "",

// When the StreetView tool is activated, line layers with these IDs will be
// highlighted. This depends on the basemap.
getStreetViewRoadLayerNames: (map: Map) => [],
};
57 changes: 0 additions & 57 deletions src/lib/maplibre/highlight_roads.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/lib/maplibre/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export { getRoadLayerNames } from "./highlight_roads";
export { layerId } from "./zorder";

// Helpers for https://maplibre.org/maplibre-gl-js-docs/style-spec/
Expand Down
2 changes: 2 additions & 0 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
cfg.editFeatureForm = ExampleFeatureForm;
cfg.editSchemeForm = ExampleSchemeForm;
cfg.maptilerApiKey = apiKey;
// Just one from the dataviz basemap, as an example
cfg.getStreetViewRoadLayerNames = (map) => ["Road network"];
</script>

<div style="display: flex; height: 100vh">
Expand Down

0 comments on commit 17821bf

Please sign in to comment.