Skip to content

Commit

Permalink
Refactor the zoom-dependent line width helper
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Jan 5, 2025
1 parent 727fcc9 commit 12e698b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 43 deletions.
46 changes: 3 additions & 43 deletions web/src/RenderNeighbourhood.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
hoverStateFilter,
LineLayer,
} from "svelte-maplibre";
import { layerId } from "./common";
import { layerId, roadLineWidth } from "./common";
import OneWayLayer from "./OneWayLayer.svelte";
import { roadStyle } from "./stores";
import type { RenderNeighbourhoodOutput } from "./wasm";
Expand Down Expand Up @@ -70,14 +70,6 @@
},
};
}
// Add some thickness
let outline = 2.0;
// TODO Refactor helpers for zoom interpolation. The values below are adapted
// from the Minor road layer in
// https://api.maptiler.com/maps/streets-v2/style.json, treating all
// interior roads as the secondary class.
</script>

<GeoJSON data={gj} generateId>
Expand Down Expand Up @@ -120,23 +112,7 @@
{...layerId("interior-roads-outlines")}
filter={["==", ["get", "kind"], "interior_road"]}
paint={{
"line-width": [
"interpolate",
["linear"],
["zoom"],
5,
0.5 + outline,
10,
1 + outline,
12,
1.5 + outline,
14,
4 + outline,
16,
7 + outline,
20,
24 + outline,
],
"line-width": roadLineWidth(2),
"line-color": "black",
}}
/>
Expand All @@ -145,23 +121,7 @@
{...layerId("interior-roads")}
filter={["==", ["get", "kind"], "interior_road"]}
paint={{
"line-width": [
"interpolate",
["linear"],
["zoom"],
5,
0.5,
10,
1,
12,
1.5,
14,
4,
16,
7,
20,
24,
],
"line-width": roadLineWidth(0),
"line-color": roadLineColor($roadStyle, gj.maxShortcuts),
"line-opacity": hoverStateFilter(1.0, 0.5),
}}
Expand Down
24 changes: 24 additions & 0 deletions web/src/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { ExpressionSpecification } from "maplibre-gl";

export { default as BasemapPicker } from "./BasemapPicker.svelte";
export { default as DisableInteractiveLayers } from "./DisableInteractiveLayers.svelte";
export { default as DotMarker } from "./DotMarker.svelte";
Expand All @@ -10,3 +12,25 @@ export { layerId } from "./zorder";
export function gjPosition(pt: number[]): [number, number] {
return pt as [number, number];
}

// Zoom-dependant line width, adapted from from the Minor road layer (secondary
// road class) from https://api.maptiler.com/maps/streets-v2/style.json.
export function roadLineWidth(extraWidth: number): ExpressionSpecification {
return [
"interpolate",
["linear"],
["zoom"],
5,
0.5 + extraWidth,
10,
1 + extraWidth,
12,
1.5 + extraWidth,
14,
4 + extraWidth,
16,
7 + extraWidth,
20,
24 + extraWidth,
];
}

0 comments on commit 12e698b

Please sign in to comment.