-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start a coverage mode to show gaps around some amenity. #5
- Loading branch information
1 parent
d64bb5e
commit 5ee3903
Showing
7 changed files
with
231 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<script lang="ts"> | ||
import { PickProfile, NavBar } from "./common"; | ||
import { colorScale } from "./colors"; | ||
import type { FeatureCollection } from "geojson"; | ||
import { SymbolLayer, GeoJSON, FillLayer, LineLayer } from "svelte-maplibre"; | ||
import { SplitComponent } from "svelte-utils/top_bar_layout"; | ||
import { | ||
backend, | ||
profile, | ||
type Profile, | ||
startTime, | ||
coverageMins, | ||
} from "./stores"; | ||
import { SequentialLegend, notNull } from "svelte-utils"; | ||
import { Popup, makeColorRamp, isLine, isPolygon } from "svelte-utils/map"; | ||
let fromAmenity = "bicycle_parking"; | ||
// TODO Generalize; show source amenity | ||
let showParking = true; | ||
let style = "Roads"; | ||
let isochroneGj: FeatureCollection | null = null; | ||
let err = ""; | ||
async function updateIsochrone( | ||
_x: string, | ||
_y: Profile, | ||
_z: string, | ||
_t: string, | ||
_im: number, | ||
) { | ||
try { | ||
isochroneGj = await $backend!.isochroneFromAmenity({ | ||
fromAmenity, | ||
profile: $profile, | ||
style, | ||
startTime: $startTime, | ||
maxSeconds: 60 * $coverageMins, | ||
}); | ||
err = ""; | ||
} catch (err: any) { | ||
isochroneGj = null; | ||
err = err.toString(); | ||
} | ||
} | ||
$: updateIsochrone(fromAmenity, $profile, style, $startTime, $coverageMins); | ||
$: limits = Array.from(Array(6).keys()).map( | ||
(i) => (($coverageMins * 60) / (6 - 1)) * i, | ||
); | ||
</script> | ||
|
||
<SplitComponent> | ||
<div slot="top"> | ||
<NavBar /> | ||
</div> | ||
|
||
<div slot="sidebar"> | ||
<h2>Coverage mode</h2> | ||
|
||
<label> | ||
<input type="checkbox" bind:checked={showParking} /> | ||
Show parking | ||
</label> | ||
|
||
<PickProfile bind:profile={$profile} /> | ||
|
||
<label> | ||
Start time (PT only) | ||
<input | ||
type="time" | ||
bind:value={$startTime} | ||
disabled={$profile != "transit"} | ||
/> | ||
</label> | ||
|
||
<label | ||
>Draw: | ||
<select bind:value={style}> | ||
<option value="Roads">Roads</option> | ||
<option value="Grid">Grid</option> | ||
<option value="Contours">Contours</option> | ||
</select> | ||
</label> | ||
|
||
<label | ||
>Minutes away | ||
<input type="number" bind:value={$coverageMins} min="1" max="30" /> | ||
</label> | ||
<SequentialLegend {colorScale} limits={limits.map((l) => l / 60)} /> | ||
{#if err} | ||
<p>{err}</p> | ||
{/if} | ||
</div> | ||
|
||
<div slot="map"> | ||
{#if isochroneGj} | ||
<GeoJSON data={isochroneGj} generateId> | ||
<LineLayer | ||
id="isochrone" | ||
filter={isLine} | ||
paint={{ | ||
"line-width": 2, | ||
"line-color": makeColorRamp( | ||
["get", "cost_seconds"], | ||
limits, | ||
colorScale, | ||
), | ||
"line-opacity": 0.5, | ||
}} | ||
eventsIfTopMost | ||
> | ||
<Popup openOn="hover" let:props> | ||
{(props.cost_seconds / 60).toFixed(1)} minutes away | ||
</Popup> | ||
</LineLayer> | ||
|
||
<FillLayer | ||
id="isochrone-contours" | ||
filter={isPolygon} | ||
paint={{ | ||
"fill-color": makeColorRamp( | ||
["get", "min_seconds"], | ||
limits, | ||
colorScale, | ||
), | ||
"fill-opacity": 0.5, | ||
}} | ||
/> | ||
</GeoJSON> | ||
|
||
{#await notNull($backend).renderAmenities() then data} | ||
<GeoJSON {data}> | ||
<SymbolLayer | ||
filter={["==", ["get", "amenity_kind"], "bicycle_parking"]} | ||
layout={{ | ||
"icon-image": "cycle_parking", | ||
"icon-size": 1.0, | ||
"icon-allow-overlap": true, | ||
visibility: showParking ? "visible" : "none", | ||
}} | ||
/> | ||
</GeoJSON> | ||
{/await} | ||
{/if} | ||
</div> | ||
</SplitComponent> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters