Skip to content

Commit

Permalink
Add a layer with bus stops and frequency. #463
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Feb 8, 2024
1 parent 4a9b9d4 commit 344cf12
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib/browse/LayerControls.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import RoadSpeedsLayerControl from "./layers/lines/RoadSpeeds.svelte";
import RoadWidthsLayerControl from "./layers/lines/RoadWidths.svelte";
import TramsLayerControl from "./layers/lines/Trams.svelte";
import BusStopsLayerControl from "./layers/points/BusStops.svelte";
import CriticalIssuesLayerControl from "./layers/points/CriticalIssues.svelte";
import CrossingsLayerControl from "./layers/points/Crossings.svelte";
import CycleParkingLayerControl from "./layers/points/CycleParking.svelte";
Expand Down Expand Up @@ -84,6 +85,7 @@
<CollapsibleCard label="Public transit">
<BusRoutesLayerControl />
<TramsLayerControl />
<BusStopsLayerControl />
</CollapsibleCard>
<CollapsibleCard label="Boundaries">
<CheckboxGroup small>
Expand Down
1 change: 1 addition & 0 deletions src/lib/browse/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const colors = {
cycle_parking: "black",
crossings: "green",
trams: "black",
bus_stop: "black",

// Thanks to https://github.com/cyipt/cyipt-website/issues/23
cycle_paths: {
Expand Down
92 changes: 92 additions & 0 deletions src/lib/browse/layers/points/BusStops.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<script lang="ts">
import {
ExternalLink,
HelpButton,
Popup,
publicResourceBaseUrl,
} from "lib/common";
import { Checkbox } from "lib/govuk";
import { layerId, makeColorRamp } from "lib/maplibre";
import { CircleLayer, VectorTileSource } from "svelte-maplibre";
import { colors } from "../../colors";
import OsOglLicense from "../OsOglLicense.svelte";
import SequentialLegend from "../SequentialLegend.svelte";
let name = "bus_stops";
let colorScale = colors.sequential_low_to_high;
let limits = [0, 3, 10, 20, 30, 100];
let show = false;
</script>

<Checkbox id={name} bind:checked={show}>
Bus stops
<span slot="right">
<HelpButton>
<p>
Data from the <ExternalLink href="https://data.bus-data.dft.gov.uk">
Bus Open Data Service
</ExternalLink>, as of 7 February 2024. To calculate frequency, every
scheduled arrival time per stop is considered, grouped by day of the
week. The total daily count is just the number of scheduled arrivals for
a day. The peak hour frequency is the highest number of buses in any one
hour window. That window might not lined up perfectly on the hour -- a
peak hour might occur from 8:25 to 9:25,for example.
</p>
<p>
There are known limitations with this layer, so please use caution when
using these numbers. Some stops may not be shown at all. Frequency could
be over- or under-counted, due to exceptions to the regular daily
schedule of a service.
</p>
<OsOglLicense />
</HelpButton>
</span>
</Checkbox>
{#if show}
<p>Peak hourly frequency:</p>
<SequentialLegend {colorScale} {limits} />
{/if}

<VectorTileSource
url={`pmtiles://${publicResourceBaseUrl()}/v1/${name}.pmtiles`}
>
<CircleLayer
{...layerId(name)}
sourceLayer={name}
paint={{
"circle-color": makeColorRamp(["get", "peak"], limits, colorScale),
"circle-radius": [
"interpolate",
["linear"],
["zoom"],
1,
2,
8,
3,
13,
10,
],
}}
layout={{
visibility: show ? "visible" : "none",
}}
manageHoverState
eventsIfTopMost
>
<Popup let:props>
<p>
Stop name: <b>{props.stop_name}</b>
</p>
<p>
Peak frequency: <b>{props.peak}</b>
buses per hour (for the busiest hour of any day)
</p>
<p>
Total buses per day: <b>{props.total}</b>
(for the busiest day of the week)
</p>
</Popup>
</CircleLayer>
</VectorTileSource>
1 change: 1 addition & 0 deletions src/lib/maplibre/zorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const layerZorder = [
"crossings",
"vehicle_counts",
"stats19",
"bus_stops",

// Polygons are bigger than lines, which're bigger than points. When geometry
// overlaps, put the smaller thing on top
Expand Down

0 comments on commit 344cf12

Please sign in to comment.