-
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.
- Loading branch information
Showing
14 changed files
with
700 additions
and
504 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Empty file.
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,58 @@ | ||
<script lang="ts" context="module"> | ||
export interface TrackProps { | ||
name: string | ||
captureDate: number | ||
filePath: string | ||
fileHash: string | ||
hasImages: boolean | ||
} | ||
</script> | ||
|
||
<script lang="ts"> | ||
import type { FeatureCollection, Feature, LineString } from "geojson" | ||
import TrackExplorerMap from "./TrackExplorerMap.svelte" | ||
import { onMount } from "svelte" | ||
let tracks: FeatureCollection<LineString, TrackProps> = { | ||
type: "FeatureCollection", | ||
features: [], | ||
} | ||
let selectedTrack: Feature<LineString, TrackProps> | null = null | ||
const filters: { [key: string]: any } = { | ||
start: new Date(0), | ||
end: new Date(), | ||
} | ||
async function load() { | ||
const params = new URLSearchParams({ | ||
format: "geojson", | ||
order: "ASC", | ||
}).toString() | ||
const response = await fetch(`/api/tracks?${params}`) | ||
const resp = (await response.json()) as FeatureCollection< | ||
LineString, | ||
TrackProps | ||
> | ||
resp.features = resp.features.filter( | ||
(track) => track.geometry.coordinates.length > 1 | ||
) | ||
resp.features.forEach((track) => { | ||
track.properties.captureDate = new Date( | ||
track.properties.captureDate | ||
).getTime() | ||
}) | ||
tracks = resp | ||
} | ||
onMount(() => { | ||
load() | ||
}) | ||
</script> | ||
|
||
<TrackExplorerMap {tracks} bind:selectedTrack /> |
68 changes: 68 additions & 0 deletions
68
packages/frontend/src/lib/components/TrackExplorerMap.svelte
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,68 @@ | ||
<script lang="ts"> | ||
import type { FeatureCollection, Feature, LineString } from "geojson" | ||
import type { TrackProps } from "./TrackExplorer.svelte" | ||
import { | ||
MapLibre, | ||
Control, | ||
ControlButton, | ||
ControlGroup, | ||
} from "svelte-maplibre" | ||
import TrackSelector from "./TrackSelector.svelte" | ||
import bbox from "@turf/bbox" | ||
import TrackViewer from "./TrackViewer.svelte" | ||
import { FontAwesomeIcon } from "@fortawesome/svelte-fontawesome" | ||
import { faArrowLeft } from "@fortawesome/free-solid-svg-icons" | ||
import { fly } from "svelte/transition" | ||
export let tracks: FeatureCollection<LineString, TrackProps> | ||
export let selectedTrack: Feature<LineString, TrackProps> | null = null | ||
let map: maplibregl.Map | ||
let initialZoom = true | ||
function fitToTrackBounds() { | ||
if (tracks.features.length === 0 && selectedTrack === null) { | ||
return | ||
} | ||
const boundingBox = bbox(selectedTrack ?? tracks) | ||
map.fitBounds(boundingBox as any, { | ||
padding: 100, | ||
duration: initialZoom ? 0 : 1000, | ||
}) | ||
initialZoom = false | ||
} | ||
$: map && (tracks || selectedTrack) && fitToTrackBounds() | ||
</script> | ||
|
||
<MapLibre | ||
bind:map | ||
style="https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json" | ||
class="full-map" | ||
> | ||
{#if selectedTrack === null} | ||
<TrackSelector {tracks} bind:selectedTrack /> | ||
{:else} | ||
<Control position="top-left"> | ||
<div transition:fly={{ x: "-100%" }}> | ||
<ControlGroup> | ||
<ControlButton on:click={() => (selectedTrack = null)}> | ||
<FontAwesomeIcon icon={faArrowLeft} /> | ||
</ControlButton> | ||
</ControlGroup> | ||
</div> | ||
</Control> | ||
|
||
<TrackViewer track={selectedTrack} /> | ||
{/if} | ||
|
||
<slot /> | ||
</MapLibre> | ||
|
||
<style> | ||
:global(.full-map) { | ||
height: 100%; | ||
} | ||
</style> |
44 changes: 44 additions & 0 deletions
44
packages/frontend/src/lib/components/TrackFilterControl.svelte
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,44 @@ | ||
<script lang="ts"> | ||
import DateFilter from "./DateFilter.svelte" | ||
export let filters: { [key: string]: any } = { | ||
start: 0, | ||
end: new Date().getTime(), | ||
} | ||
function loadLastMonth() { | ||
const now = new Date() | ||
filters.start = now.setDate(now.getDate() - 30) | ||
filters.end = new Date().getTime() | ||
} | ||
</script> | ||
|
||
<div class="input-group"> | ||
<label for="from-date">From</label> | ||
<DateFilter id="from-date" bind:value={filters.start} /> | ||
</div> | ||
|
||
<div class="input-group"> | ||
<label for="to-date">To</label> | ||
<DateFilter id="to-date" bind:value={filters.end} /> | ||
</div> | ||
|
||
<div class="input-group"> | ||
<button on:click={loadLastMonth}>Preset: Last 30 Days</button> | ||
</div> | ||
|
||
<style> | ||
.input-group { | ||
display: flex; | ||
flex-direction: column; | ||
margin-bottom: 0.5em; | ||
} | ||
.input-group button { | ||
background-color: revert !important; | ||
} | ||
label { | ||
font-weight: bold; | ||
} | ||
</style> |
Oops, something went wrong.