mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-11-30 09:34:29 +00:00
Compare commits
16
Commits
3f8e2a0c56
...
tauri
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d878fb0e1 | ||
|
|
972510bfbc | ||
|
|
46563ef283 | ||
|
|
c778766293 | ||
|
|
fbd8775528 | ||
|
|
b3fe640575 | ||
|
|
c3ace59527 | ||
|
|
50348e7c5c | ||
|
|
c3ce577e6d | ||
|
|
957f0c35ec | ||
|
|
fbfdc1933c | ||
|
|
6956c19410 | ||
|
|
f5a2db0565 | ||
|
|
39454f0b83 | ||
|
|
68eacc76d1 | ||
|
|
603b73b99d |
No files matched your search
@@ -0,0 +1,67 @@
|
||||
name: Deploy to Cloudflare Pages
|
||||
on:
|
||||
push:
|
||||
branches: 'dev'
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: cloudflare-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
deployments: write
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v5
|
||||
|
||||
- name: Install Node.js
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: 24
|
||||
cache: npm
|
||||
cache-dependency-path: website/package-lock.json
|
||||
|
||||
- name: Install Rust
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
targets: wasm32-unknown-unknown
|
||||
|
||||
- name: Install wasm-pack
|
||||
uses: taiki-e/install-action@v2
|
||||
with:
|
||||
tool: wasm-pack
|
||||
|
||||
- name: Test gpx-rs
|
||||
run: cargo test
|
||||
|
||||
- name: Build wasm
|
||||
run: wasm-pack build --target bundler
|
||||
working-directory: wasm
|
||||
|
||||
- name: Install dependencies for website
|
||||
run: npm install --prefix website
|
||||
|
||||
- name: Test website
|
||||
run: npm test --prefix website
|
||||
|
||||
- name: Create env file
|
||||
run: echo PUBLIC_MAPTILER_KEY=${{ secrets.PUBLIC_MAPTILER_KEY }} >> website/.env
|
||||
|
||||
- name: Build website
|
||||
env:
|
||||
BASE_PATH: ''
|
||||
run: npm run build --prefix website
|
||||
|
||||
- name: Deploy to Cloudflare Pages
|
||||
uses: cloudflare/wrangler-action@v3
|
||||
with:
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
command: pages deploy website/build --project-name=${{ vars.CLOUDFLARE_PROJECT_NAME || 'gpxstudio' }} --branch=${{ github.ref_name }}
|
||||
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -0,0 +1,505 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://www.topografix.com/GPX/1/1"
|
||||
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd
|
||||
http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd
|
||||
http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd
|
||||
http://www.topografix.com/GPX/gpx_style/0/2 http://www.topografix.com/GPX/gpx_style/0/2/gpx_style.xsd"
|
||||
xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1"
|
||||
xmlns:gpxpx="http://www.garmin.com/xmlschemas/PowerExtension/v1"
|
||||
xmlns:gpx_style="http://www.topografix.com/GPX/gpx_style/0/2" version="1.1"
|
||||
creator="https://gpx.studio">
|
||||
<metadata>
|
||||
<name>with_power</name>
|
||||
<author>
|
||||
<name>gpx.studio</name>
|
||||
<link href="https://gpx.studio"></link>
|
||||
</author>
|
||||
</metadata>
|
||||
<trk>
|
||||
<name>with_power</name>
|
||||
<type>Cycling</type>
|
||||
<trkseg>
|
||||
<trkpt lat="50.790867" lon="4.404968">
|
||||
<ele>109.0</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.790714" lon="4.405036">
|
||||
<ele>110.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.790336" lon="4.405259">
|
||||
<ele>110.3</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.790165" lon="4.405331">
|
||||
<ele>110.0</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.790008" lon="4.405359">
|
||||
<ele>110.3</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.789818" lon="4.405359">
|
||||
<ele>109.3</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.789409" lon="4.40534">
|
||||
<ele>107.0</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.789105" lon="4.405411">
|
||||
<ele>106.0</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.788799" lon="4.405527">
|
||||
<ele>108.5</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.788645" lon="4.405606">
|
||||
<ele>109.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.7885" lon="4.405711">
|
||||
<ele>110.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.78822" lon="4.405959">
|
||||
<ele>112.0</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.787956" lon="4.406092">
|
||||
<ele>112.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.787814" lon="4.406143">
|
||||
<ele>113.5</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.787674" lon="4.406177">
|
||||
<ele>114.3</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.787451" lon="4.406199">
|
||||
<ele>115.3</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.787297" lon="4.406177">
|
||||
<ele>114.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.78716" lon="4.406098">
|
||||
<ele>114.3</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.787045" lon="4.405984">
|
||||
<ele>114.3</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.786683" lon="4.405653">
|
||||
<ele>114.5</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.786538" lon="4.405543">
|
||||
<ele>115.0</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.78635" lon="4.405441">
|
||||
<ele>115.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.786275" lon="4.40542">
|
||||
<ele>115.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.786182" lon="4.405435">
|
||||
<ele>116.0</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.786121" lon="4.405475">
|
||||
<ele>115.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.786042" lon="4.405558">
|
||||
<ele>115.5</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.785821" lon="4.405925">
|
||||
<ele>114.5</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.785672" lon="4.406119">
|
||||
<ele>112.5</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.785516" lon="4.406256">
|
||||
<ele>110.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.785384" lon="4.406364">
|
||||
<ele>109.0</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.785126" lon="4.406475">
|
||||
<ele>106.3</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.784697" lon="4.406537">
|
||||
<ele>104.3</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.784591" lon="4.40657">
|
||||
<ele>104.0</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.784507" lon="4.406612">
|
||||
<ele>103.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.784435" lon="4.40669">
|
||||
<ele>103.3</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.784209" lon="4.407148">
|
||||
<ele>103.5</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.784162" lon="4.407257">
|
||||
<ele>103.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.784077" lon="4.407372">
|
||||
<ele>104.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.784006" lon="4.407435">
|
||||
<ele>105.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.783924" lon="4.407471">
|
||||
<ele>106.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.783837" lon="4.407486">
|
||||
<ele>107.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.783771" lon="4.407472">
|
||||
<ele>108.5</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.783697" lon="4.407428">
|
||||
<ele>109.3</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.783626" lon="4.407363">
|
||||
<ele>110.0</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.783548" lon="4.407274">
|
||||
<ele>110.5</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.783458" lon="4.407134">
|
||||
<ele>110.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.783123" lon="4.406435">
|
||||
<ele>111.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.782982" lon="4.406168">
|
||||
<ele>112.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.782871" lon="4.406044">
|
||||
<ele>113.3</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.78279" lon="4.406021">
|
||||
<ele>113.5</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.782714" lon="4.406018">
|
||||
<ele>113.5</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.782607" lon="4.406047">
|
||||
<ele>113.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.782405" lon="4.406194">
|
||||
<ele>114.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.782175" lon="4.406413">
|
||||
<ele>115.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.781749" lon="4.407018">
|
||||
<ele>118.5</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.781654" lon="4.407316">
|
||||
<ele>119.5</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.781563" lon="4.407764">
|
||||
<ele>121.3</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.781487" lon="4.407984">
|
||||
<ele>122.0</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.781422" lon="4.408216">
|
||||
<ele>122.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.781395" lon="4.408508">
|
||||
<ele>123.5</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.781399" lon="4.409114">
|
||||
<ele>126.3</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.781367" lon="4.409428">
|
||||
<ele>128.0</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.781286" lon="4.409607">
|
||||
<ele>129.0</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.78116" lon="4.409789">
|
||||
<ele>130.0</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.780804" lon="4.409993">
|
||||
<ele>130.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.780389" lon="4.410334">
|
||||
<ele>131.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.780232" lon="4.410563">
|
||||
<ele>132.3</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.780094" lon="4.410827">
|
||||
<ele>132.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.779723" lon="4.411582">
|
||||
<ele>135.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.779591" lon="4.411791">
|
||||
<ele>135.5</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.779125" lon="4.412435">
|
||||
<ele>132.5</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.778676" lon="4.412979">
|
||||
<ele>134.0</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.778194" lon="4.413466">
|
||||
<ele>136.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.777427" lon="4.414302">
|
||||
<ele>137.5</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.777165" lon="4.414736">
|
||||
<ele>137.3</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.776927" lon="4.415201">
|
||||
<ele>137.5</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.776778" lon="4.415613">
|
||||
<ele>137.3</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.776553" lon="4.416425">
|
||||
<ele>134.8</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.776326" lon="4.417304">
|
||||
<ele>132.3</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="50.776129" lon="4.418383">
|
||||
<ele>129.5</ele>
|
||||
<extensions>
|
||||
<gpxpx:PowerInWatts>210</gpxpx:PowerInWatts>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
</trkseg>
|
||||
</trk>
|
||||
</gpx>
|
||||
@@ -1222,6 +1222,19 @@ mod tests {
|
||||
assert!(trkpt.power.is_some_and(|p| p == 200));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_trackpoint_power_3() {
|
||||
let gpx = parse_data("with_power_3");
|
||||
|
||||
assert_eq!(gpx.trk.len(), 1);
|
||||
let trk = &gpx.trk[0];
|
||||
assert_eq!(trk.trkseg.len(), 1);
|
||||
let trkseg = &trk.trkseg[0];
|
||||
assert!(!trkseg.is_empty());
|
||||
let trkpt = &trkseg[0];
|
||||
assert!(trkpt.power.is_some_and(|p| p == 200));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_trackpoint_atemp() {
|
||||
let gpx = parse_data("with_temp");
|
||||
|
||||
@@ -402,9 +402,10 @@ fn write_point(
|
||||
Ok(())
|
||||
})?;
|
||||
}
|
||||
// `PowerInWatts` is itself the root element of Garmin's power extension, without a
|
||||
// wrapper
|
||||
if let Some(power) = power {
|
||||
w.create_element("gpxpx:PowerExtension")
|
||||
.write_inner_content(|w| number(w, "gpxpx:PowerInWatts", power))?;
|
||||
number(w, "gpxpx:PowerInWatts", power)?;
|
||||
}
|
||||
if !path.is_empty() {
|
||||
w.create_element("gpxx:RoutePointExtension")
|
||||
@@ -511,6 +512,7 @@ mod tests {
|
||||
"with_temp",
|
||||
"with_power_1",
|
||||
"with_power_2",
|
||||
"with_power_3",
|
||||
"with_surface",
|
||||
"with_highway",
|
||||
"with_style",
|
||||
@@ -578,6 +580,16 @@ mod tests {
|
||||
assert_eq!(again.trk[0].info.name.as_deref(), Some("a <b> & c"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_power_is_written_without_a_wrapper() {
|
||||
let (file, categories) = read("with_power_2");
|
||||
let text: String = written_text(&file, &categories, ExportOptions::ALL)
|
||||
.split_whitespace()
|
||||
.collect();
|
||||
assert!(text.contains("<extensions><gpxpx:PowerInWatts>200</gpxpx:PowerInWatts>"));
|
||||
assert!(!text.contains("<gpxpx:PowerExtension>"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_exportable_data() {
|
||||
let (file, _) = read("with_time");
|
||||
|
||||
@@ -9,10 +9,12 @@ use crate::{Apply, CommandError, FileId, Route, Selection, State, Track};
|
||||
/// after the routes;
|
||||
/// - a track becomes one route per segment, as a route has a single segment, and goes away. A
|
||||
/// selected segment becomes a route and leaves its track, which stays even if it has no segment
|
||||
/// left. The routes have the information of their track, and go after the other routes.
|
||||
/// left. The routes have the information of their track, and go after the other routes;
|
||||
/// - a file with routes only has all of them converted to tracks, and a file with tracks only
|
||||
/// has all of them converted to routes. The files with both, or neither, stay as they are.
|
||||
///
|
||||
/// The segments keep their ids, the new routes and tracks are selected. There is nothing to do
|
||||
/// for the other selections, or for tracks without segments.
|
||||
/// The segments keep their ids, the new routes and tracks are selected (the files stay selected).
|
||||
/// There is nothing to do for the other selections, or for tracks without segments.
|
||||
#[derive(Debug)]
|
||||
pub struct Convert;
|
||||
|
||||
@@ -31,14 +33,7 @@ impl Apply for Convert {
|
||||
.into_iter()
|
||||
.partition::<Vec<_>, _>(|rte| rte_ids.contains(&rte.id));
|
||||
file.rte = kept;
|
||||
let tracks: Vec<Track> = converted
|
||||
.into_iter()
|
||||
.map(|rte| Track {
|
||||
id: Default::default(),
|
||||
info: rte.info,
|
||||
trkseg: vec![rte.seg],
|
||||
})
|
||||
.collect();
|
||||
let tracks = to_tracks(converted);
|
||||
let trk_ids: HashSet<_> = tracks.iter().map(|trk| trk.id).collect();
|
||||
file.trk.splice(0..0, tracks);
|
||||
Selection::Track {
|
||||
@@ -57,14 +52,7 @@ impl Apply for Convert {
|
||||
.into_iter()
|
||||
.partition::<Vec<_>, _>(|trk| trk_ids.contains(&trk.id));
|
||||
file.trk = kept;
|
||||
let routes = converted.into_iter().flat_map(|trk| {
|
||||
trk.trkseg.into_iter().map(move |seg| Route {
|
||||
id: Default::default(),
|
||||
info: trk.info.clone(),
|
||||
seg,
|
||||
})
|
||||
});
|
||||
add_routes(&mut file.rte, *file_id, routes)
|
||||
add_routes(&mut file.rte, *file_id, to_routes(converted))
|
||||
}
|
||||
Selection::TrackSegment {
|
||||
file_id,
|
||||
@@ -94,10 +82,34 @@ impl Apply for Convert {
|
||||
});
|
||||
add_routes(&mut file.rte, *file_id, routes)
|
||||
}
|
||||
Selection::Empty
|
||||
| Selection::File { .. }
|
||||
| Selection::Waypoints { .. }
|
||||
| Selection::Waypoint { .. } => return Err(CommandError::NothingToDo),
|
||||
Selection::File { file_ids } => {
|
||||
let mut converted = false;
|
||||
for file_id in file_ids {
|
||||
let Some(file) = state.files.get_mut(file_id) else {
|
||||
continue;
|
||||
};
|
||||
if !file.rte.is_empty() && file.trk.is_empty() {
|
||||
let file = Rc::make_mut(file);
|
||||
file.trk = to_tracks(std::mem::take(&mut file.rte));
|
||||
} else if file.rte.is_empty()
|
||||
&& file.trk.iter().any(|trk| !trk.trkseg.is_empty())
|
||||
{
|
||||
let file = Rc::make_mut(file);
|
||||
file.rte = to_routes(std::mem::take(&mut file.trk)).collect();
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
converted = true;
|
||||
}
|
||||
return if converted {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(CommandError::NothingToDo)
|
||||
};
|
||||
}
|
||||
Selection::Empty | Selection::Waypoints { .. } | Selection::Waypoint { .. } => {
|
||||
return Err(CommandError::NothingToDo);
|
||||
}
|
||||
};
|
||||
let empty = match &next {
|
||||
Selection::Route { rte_ids, .. } => rte_ids.is_empty(),
|
||||
@@ -113,6 +125,29 @@ impl Apply for Convert {
|
||||
}
|
||||
}
|
||||
|
||||
/// The tracks of the routes, each with the segment of its route.
|
||||
fn to_tracks(routes: Vec<Route>) -> Vec<Track> {
|
||||
routes
|
||||
.into_iter()
|
||||
.map(|rte| Track {
|
||||
id: Default::default(),
|
||||
info: rte.info,
|
||||
trkseg: vec![rte.seg],
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The routes of the tracks, one per segment, each with the information of its track.
|
||||
fn to_routes(tracks: Vec<Track>) -> impl Iterator<Item = Route> {
|
||||
tracks.into_iter().flat_map(|trk| {
|
||||
trk.trkseg.into_iter().map(move |seg| Route {
|
||||
id: Default::default(),
|
||||
info: trk.info.clone(),
|
||||
seg,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/// Adds the routes after the other routes, and gives the selection of them.
|
||||
fn add_routes(
|
||||
rte: &mut Vec<Route>,
|
||||
|
||||
@@ -682,3 +682,43 @@ fn test_convert_segments_to_routes_keeps_their_track() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_convert_a_file_with_routes_or_tracks_only() {
|
||||
let (mut fx, id) = fixture();
|
||||
let before = file(&fx, id).clone();
|
||||
let only_tracks = File {
|
||||
trk: before.trk.clone(),
|
||||
..File::default()
|
||||
};
|
||||
let only_tracks_id = only_tracks.id;
|
||||
fx.files.insert(only_tracks_id, Rc::new(only_tracks));
|
||||
fx.order.0.push(only_tracks_id);
|
||||
|
||||
// the file with both stays as it is, the other gets one route per segment
|
||||
fx.selection = Selection::File {
|
||||
file_ids: [id, only_tracks_id].into(),
|
||||
};
|
||||
Convert.apply(&mut fx.state()).unwrap();
|
||||
assert_eq!(lengths(file(&fx, id)), lengths(&before));
|
||||
let routes = file(&fx, only_tracks_id);
|
||||
assert_eq!((routes.rte.len(), routes.trk.len()), (4, 0));
|
||||
assert_eq!(routes.rte[0].seg.id, before.trk[0].trkseg[0].id);
|
||||
assert_eq!(routes.rte[0].info, before.trk[0].info);
|
||||
|
||||
// and back: one track per route
|
||||
fx.selection = Selection::File {
|
||||
file_ids: [only_tracks_id].into(),
|
||||
};
|
||||
Convert.apply(&mut fx.state()).unwrap();
|
||||
let tracks = file(&fx, only_tracks_id);
|
||||
assert_eq!((tracks.rte.len(), tracks.trk.len()), (0, 4));
|
||||
assert_eq!(tracks.trk[0].trkseg[0].id, before.trk[0].trkseg[0].id);
|
||||
|
||||
// nothing to do for a file with both
|
||||
fx.selection = whole(id);
|
||||
assert_eq!(
|
||||
Convert.apply(&mut fx.state()),
|
||||
Err(CommandError::NothingToDo)
|
||||
);
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
/build
|
||||
/.svelte-kit
|
||||
/package
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
|
||||
# Ignore files for PNPM, NPM and YARN
|
||||
pnpm-lock.yaml
|
||||
package-lock.json
|
||||
yarn.lock
|
||||
@@ -1,31 +0,0 @@
|
||||
/** @type { import("eslint").Linter.Config } */
|
||||
module.exports = {
|
||||
root: true,
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:svelte/recommended',
|
||||
'prettier',
|
||||
],
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: ['@typescript-eslint'],
|
||||
parserOptions: {
|
||||
sourceType: 'module',
|
||||
ecmaVersion: 2020,
|
||||
extraFileExtensions: ['.svelte'],
|
||||
},
|
||||
env: {
|
||||
browser: true,
|
||||
es2017: true,
|
||||
node: true,
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: ['*.svelte'],
|
||||
parser: 'svelte-eslint-parser',
|
||||
parserOptions: {
|
||||
parser: '@typescript-eslint/parser',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
import js from '@eslint/js';
|
||||
import ts from '@typescript-eslint/eslint-plugin';
|
||||
import tsParser from '@typescript-eslint/parser';
|
||||
import svelte from 'eslint-plugin-svelte';
|
||||
import prettier from 'eslint-config-prettier';
|
||||
import globals from 'globals';
|
||||
|
||||
/** @type {import('eslint').Linter.Config[]} */
|
||||
export default [
|
||||
{
|
||||
ignores: ['build/', '.svelte-kit/', 'package/'],
|
||||
},
|
||||
js.configs.recommended,
|
||||
...ts.configs['flat/recommended'],
|
||||
...svelte.configs['flat/recommended'],
|
||||
prettier,
|
||||
...svelte.configs['flat/prettier'],
|
||||
{
|
||||
languageOptions: {
|
||||
globals: { ...globals.browser, ...globals.node },
|
||||
},
|
||||
},
|
||||
{
|
||||
rules: {
|
||||
// TypeScript already reports undefined names
|
||||
'no-undef': 'off',
|
||||
'no-empty': ['error', { allowEmptyCatch: true }],
|
||||
'@typescript-eslint/no-unused-vars': [
|
||||
'error',
|
||||
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['**/*.svelte', '**/*.svelte.ts', '**/*.svelte.js'],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
parser: tsParser,
|
||||
extraFileExtensions: ['.svelte'],
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
// $effect dependencies are tracked by reading them
|
||||
'@typescript-eslint/no-unused-expressions': 'off',
|
||||
},
|
||||
},
|
||||
];
|
||||
Generated
+6
-2
@@ -20,7 +20,7 @@
|
||||
"mapillary-js": "^4.1.2",
|
||||
"maplibre-gl": "^6.15.0",
|
||||
"sanitize-html": "^2.17.0",
|
||||
"sortablejs": "^1.15.6"
|
||||
"sortablejs": "^1.15.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@fontsource-variable/inter": "^5.2.8",
|
||||
@@ -39,7 +39,7 @@
|
||||
"@types/mapbox__tilebelt": "^1.0.4",
|
||||
"@types/node": "^22.15.30",
|
||||
"@types/sanitize-html": "^2.16.0",
|
||||
"@types/sortablejs": "^1.15.8",
|
||||
"@types/sortablejs": "^1.15.9",
|
||||
"@typescript-eslint/eslint-plugin": "^8.33.1",
|
||||
"@typescript-eslint/parser": "^8.33.1",
|
||||
"bits-ui": "^2.17.2",
|
||||
@@ -2762,6 +2762,8 @@
|
||||
},
|
||||
"node_modules/@types/sortablejs": {
|
||||
"version": "1.15.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/sortablejs/-/sortablejs-1.15.9.tgz",
|
||||
"integrity": "sha512-7HP+rZGE2p886PKV9c9OJzLBI6BBJu1O7lJGYnPyG3fS4/duUCcngkNCjsLwIMV+WMqANe3tt4irrXHSIe68OQ==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
@@ -5599,6 +5601,8 @@
|
||||
},
|
||||
"node_modules/sortablejs": {
|
||||
"version": "1.15.7",
|
||||
"resolved": "https://registry.npmjs.org/sortablejs/-/sortablejs-1.15.7.tgz",
|
||||
"integrity": "sha512-Kk8wLQPlS+yi1ZEf48a4+fzHa4yxjC30M/Sr2AnQu+f/MPwvvX9XjZ6OWejiz8crBsLwSq8GHqaxaET7u6ux0A==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/source-map-js": {
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
"@types/mapbox__tilebelt": "^1.0.4",
|
||||
"@types/node": "^22.15.30",
|
||||
"@types/sanitize-html": "^2.16.0",
|
||||
"@types/sortablejs": "^1.15.8",
|
||||
"@types/sortablejs": "^1.15.9",
|
||||
"@typescript-eslint/eslint-plugin": "^8.33.1",
|
||||
"@typescript-eslint/parser": "^8.33.1",
|
||||
"bits-ui": "^2.17.2",
|
||||
@@ -80,6 +80,6 @@
|
||||
"mapillary-js": "^4.1.2",
|
||||
"maplibre-gl": "^6.15.0",
|
||||
"sanitize-html": "^2.17.0",
|
||||
"sortablejs": "^1.15.6"
|
||||
"sortablejs": "^1.15.7"
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
@import 'tailwindcss';
|
||||
@import 'tw-animate-css';
|
||||
@import "shadcn-svelte/tailwind.css";
|
||||
@import "@fontsource-variable/inter";
|
||||
@import 'shadcn-svelte/tailwind.css';
|
||||
@import '@fontsource-variable/inter';
|
||||
|
||||
@custom-variant dark (&:is(.dark *));
|
||||
|
||||
|
||||
Vendored
+5
@@ -8,6 +8,11 @@ declare global {
|
||||
// interface PageState {}
|
||||
// interface Platform {}
|
||||
}
|
||||
|
||||
interface Window {
|
||||
/** The map, for extensions (set once it has loaded). */
|
||||
_map?: import('maplibre-gl').Map;
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
@@ -1,4 +1,4 @@
|
||||
import { base } from '$app/paths';
|
||||
import { asset, resolve as resolvePath } from '$app/paths';
|
||||
import { languages } from '$lib/i18n/languages';
|
||||
import { getURLForLanguage } from '$lib/utils';
|
||||
|
||||
@@ -37,16 +37,16 @@ export async function handle({ event, resolve }) {
|
||||
<meta property="og:description" content="${description}" />
|
||||
<meta name="twitter:title" content="gpx.studio — ${title}" />
|
||||
<meta name="twitter:description" content="${description}" />
|
||||
<meta property="og:image" content="https://gpx.studio${base}/og_logo.png" />
|
||||
<meta property="og:image" content="https://gpx.studio${asset('/og_logo.png')}" />
|
||||
<meta property="og:url" content="https://gpx.studio/" />
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:site_name" content="gpx.studio" />
|
||||
<meta name="twitter:card" content="summary_large_image" />
|
||||
<meta name="twitter:image" content="https://gpx.studio${base}/og_logo.png" />
|
||||
<meta name="twitter:image" content="https://gpx.studio${asset('/og_logo.png')}" />
|
||||
<meta name="twitter:url" content="https://gpx.studio/" />
|
||||
<meta name="twitter:site" content="@gpxstudio" />
|
||||
<meta name="twitter:creator" content="@gpxstudio" />
|
||||
<link rel="alternate" hreflang="x-default" href="https://gpx.studio${getURLForLanguage('en', path)}" />`;
|
||||
<link rel="alternate" hreflang="x-default" href="https://gpx.studio${resolvePath(getURLForLanguage('en', path))}" />`;
|
||||
|
||||
// the manifests are made for the website, not for the desktop app (`npm run build:desktop`)
|
||||
if (process.env.BUILD_TARGET !== 'desktop') {
|
||||
@@ -56,7 +56,7 @@ export async function handle({ event, resolve }) {
|
||||
|
||||
if (page !== '404') {
|
||||
for (let lang of Object.keys(languages)) {
|
||||
headTag += ` <link rel="alternate" hreflang="${lang}" href="https://gpx.studio${getURLForLanguage(lang, path)}" />
|
||||
headTag += ` <link rel="alternate" hreflang="${lang}" href="https://gpx.studio${resolvePath(getURLForLanguage(lang, path))}" />
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<link rel="preconnect" href="https://21XLD94PE3-dsn.algolia.net" crossorigin />
|
||||
<link rel="preconnect" href="https://21XLD94PE3-dsn.algolia.net" crossorigin="anonymous" />
|
||||
</svelte:head>
|
||||
|
||||
<div id="docsearch" class={props.class ?? ''}></div>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<Tooltip.Root>
|
||||
<Tooltip.Trigger>
|
||||
{#snippet child({ props })}
|
||||
<Button {...props} {variant} class="bg-inherit {className}" {onclick}>
|
||||
<Button {...props} {variant} {disabled} class="bg-inherit {className}" {onclick}>
|
||||
{@render children()}
|
||||
</Button>
|
||||
{/snippet}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { resolve } from '$app/paths';
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
import LanguageSelect from '$lib/components/LanguageSelect.svelte';
|
||||
import ModeSwitch from '$lib/components/ModeSwitch.svelte';
|
||||
@@ -31,7 +32,7 @@
|
||||
<Button
|
||||
variant="link"
|
||||
class="h-6 px-0 has-[>svg]:px-0 text-muted-foreground"
|
||||
href={getURLForLanguage(i18n.lang, '/')}
|
||||
href={resolve(getURLForLanguage(i18n.lang, '/'))}
|
||||
>
|
||||
<House size="16" />
|
||||
{i18n._('homepage.home')}
|
||||
@@ -40,7 +41,7 @@
|
||||
data-sveltekit-reload
|
||||
variant="link"
|
||||
class="h-6 px-0 has-[>svg]:px-0 text-muted-foreground"
|
||||
href={getURLForLanguage(i18n.lang, '/app')}
|
||||
href={resolve(getURLForLanguage(i18n.lang, '/app'))}
|
||||
>
|
||||
<Map size="16" />
|
||||
{i18n._('homepage.app')}
|
||||
@@ -48,7 +49,7 @@
|
||||
<Button
|
||||
variant="link"
|
||||
class="h-6 px-0 has-[>svg]:px-0 text-muted-foreground"
|
||||
href={getURLForLanguage(i18n.lang, '/help')}
|
||||
href={resolve(getURLForLanguage(i18n.lang, '/help'))}
|
||||
>
|
||||
<BookOpenText size="16" />
|
||||
{i18n._('menu.help')}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { CircleQuestionMark } from '@lucide/svelte';
|
||||
import { i18n } from '$lib/i18n/i18n.svelte';
|
||||
import type { Snippet } from 'svelte';
|
||||
import { resolve } from '$app/paths';
|
||||
|
||||
let {
|
||||
link,
|
||||
@@ -19,7 +20,7 @@
|
||||
<div>
|
||||
{@render children()}
|
||||
{#if link}
|
||||
<a href={link} target="_blank" class="text-[13px] text-link hover:underline">
|
||||
<a href={resolve(link)} target="_blank" class="text-[13px] text-link hover:underline">
|
||||
{i18n._('menu.more')}
|
||||
</a>
|
||||
{/if}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { resolve } from '$app/paths';
|
||||
import { page } from '$app/state';
|
||||
import * as Select from '$lib/components/ui/select';
|
||||
import { languages } from '$lib/i18n/languages';
|
||||
@@ -15,13 +16,13 @@
|
||||
</span>
|
||||
</Select.Trigger>
|
||||
<Select.Content>
|
||||
{#each Object.entries(languages) as [lang, label]}
|
||||
{#each Object.entries(languages) as [lang, label] (lang)}
|
||||
{#if page.url.pathname.includes('404')}
|
||||
<a href={getURLForLanguage(lang, '/')}>
|
||||
<a href={resolve(getURLForLanguage(lang, '/'))}>
|
||||
<Select.Item value={lang}>{label}</Select.Item>
|
||||
</a>
|
||||
{:else}
|
||||
<a href={getURLForLanguage(lang, page.url.pathname)}>
|
||||
<a href={resolve(getURLForLanguage(lang, page.url.pathname))}>
|
||||
<Select.Item value={lang}>{label}</Select.Item>
|
||||
</a>
|
||||
{/if}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { mode } from 'mode-watcher';
|
||||
import { base } from '$app/paths';
|
||||
import { asset } from '$app/paths';
|
||||
|
||||
let {
|
||||
iconOnly = false,
|
||||
@@ -9,13 +9,13 @@
|
||||
}: {
|
||||
iconOnly?: boolean;
|
||||
company?: 'gpx.studio' | 'github' | 'crowdin' | 'facebook' | 'reddit';
|
||||
[key: string]: any;
|
||||
[key: string]: unknown;
|
||||
} = $props();
|
||||
</script>
|
||||
|
||||
{#if company === 'gpx.studio'}
|
||||
<img
|
||||
src="{base}/{iconOnly ? 'icon' : 'logo'}{mode.current === 'dark' ? '-dark' : ''}.svg"
|
||||
src={asset(`/${iconOnly ? 'icon' : 'logo'}${mode.current === 'dark' ? '-dark' : ''}.svg`)}
|
||||
alt="Logo of gpx.studio."
|
||||
{...others}
|
||||
/>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { resolve } from '$app/paths';
|
||||
import * as Menubar from '$lib/components/ui/menubar/index.js';
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
import Logo from '$lib/components/Logo.svelte';
|
||||
@@ -78,7 +79,7 @@
|
||||
} from '$lib/actions/file-actions';
|
||||
import UnsavedDialog from '$lib/components/file-list/UnsavedDialog.svelte';
|
||||
import { engine } from '$lib/engine';
|
||||
import { allHidden } from '$lib/engine/all-hidden';
|
||||
import { allHidden, selectedFilesConversion } from '$lib/engine/selection-stores';
|
||||
import { selectedFileIds, selectionSize } from '$lib/engine/selection-helpers';
|
||||
import { boundsManager } from '$lib/state/bounds';
|
||||
import { onMount } from 'svelte';
|
||||
@@ -148,7 +149,7 @@
|
||||
<div
|
||||
class="w-fit flex flex-row items-center justify-center p-1 bg-background rounded-b-md md:rounded-md pointer-events-auto shadow-md"
|
||||
>
|
||||
<a href={getURLForLanguage(i18n.lang, '/')} target="_blank" class="shrink-0">
|
||||
<a href={resolve(getURLForLanguage(i18n.lang, '/'))} target="_blank" class="shrink-0">
|
||||
<Logo class="h-5 mt-0.5 mx-2 md:hidden" iconOnly={true} width="16" />
|
||||
<Logo class="h-5 mt-0.5 mx-2 hidden md:block" width="96" />
|
||||
</a>
|
||||
@@ -293,19 +294,6 @@
|
||||
<PaintBucket size="16" />
|
||||
{i18n._('menu.style.button')}
|
||||
</Menubar.Item>
|
||||
<Menubar.Item
|
||||
onclick={() => engine.setSelectionHidden(!$allHidden)}
|
||||
disabled={selectionCount == 0}
|
||||
>
|
||||
{#if $allHidden}
|
||||
<Eye size="16" />
|
||||
{i18n._('menu.unhide')}
|
||||
{:else}
|
||||
<EyeOff size="16" />
|
||||
{i18n._('menu.hide')}
|
||||
{/if}
|
||||
<Shortcut key="H" ctrl={true} />
|
||||
</Menubar.Item>
|
||||
{#if $treeFileView}
|
||||
{#if $selection.type === 'file'}
|
||||
<Menubar.Separator />
|
||||
@@ -347,24 +335,25 @@
|
||||
</Menubar.Item>
|
||||
{/if}
|
||||
{/if}
|
||||
{#if $selectedFilesConversion}
|
||||
{#if !$treeFileView}
|
||||
<Menubar.Separator />
|
||||
{/if}
|
||||
<Menubar.Item onclick={() => engine.convert()}>
|
||||
<ArrowRightLeft size="16" />
|
||||
{i18n._(
|
||||
$selectedFilesConversion === 'route'
|
||||
? 'menu.convert_to_routes'
|
||||
: 'menu.convert_to_tracks'
|
||||
)}
|
||||
</Menubar.Item>
|
||||
{/if}
|
||||
<Menubar.Separator />
|
||||
<Menubar.Item onclick={() => engine.selectAll()} disabled={noFiles}>
|
||||
<FileStack size="16" />
|
||||
{i18n._('menu.select_all')}
|
||||
<Shortcut key="A" ctrl={true} />
|
||||
</Menubar.Item>
|
||||
<Menubar.Item
|
||||
onclick={() => {
|
||||
if (selectionCount > 0) {
|
||||
boundsManager.centerMapOnSelection();
|
||||
}
|
||||
}}
|
||||
disabled={selectionCount == 0}
|
||||
>
|
||||
<Maximize size="16" />
|
||||
{i18n._('menu.center')}
|
||||
<Shortcut key="⏎" ctrl={true} />
|
||||
</Menubar.Item>
|
||||
{#if $treeFileView}
|
||||
<Menubar.Separator />
|
||||
<Menubar.Item onclick={() => engine.copy()} disabled={selectionCount === 0}>
|
||||
@@ -429,6 +418,34 @@
|
||||
/>
|
||||
</Menubar.CheckboxItem>
|
||||
<Menubar.Separator />
|
||||
<Menubar.Item
|
||||
inset
|
||||
onclick={() => engine.setSelectionHidden(!$allHidden)}
|
||||
disabled={selectionCount == 0}
|
||||
>
|
||||
{#if $allHidden}
|
||||
<Eye size="16" />
|
||||
{i18n._('menu.unhide')}
|
||||
{:else}
|
||||
<EyeOff size="16" />
|
||||
{i18n._('menu.hide')}
|
||||
{/if}
|
||||
<Shortcut key="H" ctrl={true} />
|
||||
</Menubar.Item>
|
||||
<Menubar.Item
|
||||
inset
|
||||
onclick={() => {
|
||||
if (selectionCount > 0) {
|
||||
boundsManager.centerMapOnSelection();
|
||||
}
|
||||
}}
|
||||
disabled={selectionCount == 0}
|
||||
>
|
||||
<Maximize size="16" />
|
||||
{i18n._('menu.center')}
|
||||
<Shortcut key="⏎" ctrl={true} />
|
||||
</Menubar.Item>
|
||||
<Menubar.Separator />
|
||||
<Menubar.Item inset onclick={() => map.toggle3D()}>
|
||||
<Box size="16" />
|
||||
{i18n._('menu.toggle_3d')}
|
||||
@@ -510,8 +527,8 @@
|
||||
</Menubar.SubTrigger>
|
||||
<Menubar.SubContent>
|
||||
<Menubar.RadioGroup value={i18n.lang}>
|
||||
{#each Object.entries(languages) as [lang, label]}
|
||||
<a href={getURLForLanguage(lang, '/app')}>
|
||||
{#each Object.entries(languages) as [lang, label] (lang)}
|
||||
<a href={resolve(getURLForLanguage(lang, '/app'))}>
|
||||
<Menubar.RadioItem value={lang}>{label}</Menubar.RadioItem>
|
||||
</a>
|
||||
{/each}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { resolve } from '$app/paths';
|
||||
import Logo from '$lib/components/Logo.svelte';
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
import { BookOpenText, House, Map } from '@lucide/svelte';
|
||||
@@ -9,7 +10,7 @@
|
||||
<nav class="sticky top-0 w-full px-12 py-2 bg-background z-50 flex flex-col items-center border-b">
|
||||
<div class="w-full max-w-5xl flex flex-row items-center gap-4 sm:gap-8">
|
||||
<a
|
||||
href={getURLForLanguage(i18n.lang, '/')}
|
||||
href={resolve(getURLForLanguage(i18n.lang, '/'))}
|
||||
class="shrink-0 translate-y-0.25 justify-self-start"
|
||||
>
|
||||
<Logo class="h-8 xs:hidden" iconOnly={true} width="26" />
|
||||
@@ -18,7 +19,7 @@
|
||||
<Button
|
||||
variant="link"
|
||||
class="text-base px-0 has-[>svg]:px-0 ml-auto"
|
||||
href={getURLForLanguage(i18n.lang, '/')}
|
||||
href={resolve(getURLForLanguage(i18n.lang, '/'))}
|
||||
>
|
||||
<House size="18" />
|
||||
{i18n._('homepage.home')}
|
||||
@@ -27,7 +28,7 @@
|
||||
data-sveltekit-reload
|
||||
variant="link"
|
||||
class="text-base px-0 has-[>svg]:px-0"
|
||||
href={getURLForLanguage(i18n.lang, '/app')}
|
||||
href={resolve(getURLForLanguage(i18n.lang, '/app'))}
|
||||
>
|
||||
<Map size="18" />
|
||||
{i18n._('homepage.app')}
|
||||
@@ -35,7 +36,7 @@
|
||||
<Button
|
||||
variant="link"
|
||||
class="text-base px-0 has-[>svg]:px-0"
|
||||
href={getURLForLanguage(i18n.lang, '/help')}
|
||||
href={resolve(getURLForLanguage(i18n.lang, '/help'))}
|
||||
>
|
||||
<BookOpenText size="18" />
|
||||
{i18n._('menu.help')}
|
||||
|
||||
@@ -39,7 +39,7 @@ export function getPreviousGuide(currentGuide: string): string | undefined {
|
||||
return `${previousGuide}/${guides[previousGuide][guides[previousGuide].length - 1]}`;
|
||||
}
|
||||
} else {
|
||||
if (guides.hasOwnProperty(subguides[0])) {
|
||||
if (Object.hasOwn(guides, subguides[0])) {
|
||||
const subguideIndex = guides[subguides[0]].indexOf(subguides[1]);
|
||||
if (subguideIndex > 0) {
|
||||
return `${subguides[0]}/${guides[subguides[0]][subguideIndex - 1]}`;
|
||||
@@ -56,7 +56,7 @@ export function getNextGuide(currentGuide: string): string | undefined {
|
||||
const subguides = currentGuide.split('/');
|
||||
|
||||
if (subguides.length === 1) {
|
||||
if (guides.hasOwnProperty(currentGuide)) {
|
||||
if (Object.hasOwn(guides, currentGuide)) {
|
||||
if (guides[currentGuide].length === 0) {
|
||||
const keys = Object.keys(guides);
|
||||
const index = keys.indexOf(currentGuide);
|
||||
@@ -68,7 +68,7 @@ export function getNextGuide(currentGuide: string): string | undefined {
|
||||
return undefined;
|
||||
}
|
||||
} else {
|
||||
if (guides.hasOwnProperty(subguides[0])) {
|
||||
if (Object.hasOwn(guides, subguides[0])) {
|
||||
const subguideIndex = guides[subguides[0]].indexOf(subguides[1]);
|
||||
if (subguideIndex < guides[subguides[0]].length - 1) {
|
||||
return `${subguides[0]}/${guides[subguides[0]][subguideIndex + 1]}`;
|
||||
|
||||
@@ -148,7 +148,7 @@ export class ElevationProfile {
|
||||
}
|
||||
|
||||
initialize() {
|
||||
let options: ChartOptions<'line'> = {
|
||||
const options: ChartOptions<'line'> = {
|
||||
animation: false,
|
||||
parsing: false,
|
||||
maintainAspectRatio: false,
|
||||
@@ -178,6 +178,7 @@ export class ElevationProfile {
|
||||
tension: 0.4,
|
||||
borderWidth: 2,
|
||||
cubicInterpolationMode: 'monotone',
|
||||
spanGaps: true,
|
||||
},
|
||||
},
|
||||
interaction: {
|
||||
@@ -199,7 +200,7 @@ export class ElevationProfile {
|
||||
return '';
|
||||
},
|
||||
label: (context: TooltipItem<'line'>) => {
|
||||
let point = context.raw as ElevationProfilePoint;
|
||||
const point = context.raw as ElevationProfilePoint;
|
||||
if (context.datasetIndex === 0) {
|
||||
this._hoveredPoint.set(
|
||||
this._dragging
|
||||
@@ -223,16 +224,18 @@ export class ElevationProfile {
|
||||
}
|
||||
},
|
||||
afterBody: (contexts: TooltipItem<'line'>[]) => {
|
||||
let context = contexts.filter((context) => context.datasetIndex === 0);
|
||||
const context = contexts.filter(
|
||||
(context) => context.datasetIndex === 0
|
||||
);
|
||||
if (context.length === 0) return;
|
||||
let point = context[0].raw as ElevationProfilePoint;
|
||||
const point = context[0].raw as ElevationProfilePoint;
|
||||
// the rest of the data is there once it is read (see `hover`)
|
||||
const hovered = this._hovered;
|
||||
const details =
|
||||
hovered?.index === point.index ? hovered.point : undefined;
|
||||
const elevationFill = get(this._elevationFill);
|
||||
|
||||
let labels = [
|
||||
const labels = [
|
||||
` ${i18n._('quantities.distance')}: ${getDistanceWithUnits(point.x, false)}`,
|
||||
];
|
||||
|
||||
@@ -250,10 +253,10 @@ export class ElevationProfile {
|
||||
}
|
||||
labels.push(` ${i18n._('quantities.slope')}: ${slope}`);
|
||||
}
|
||||
let surface = details.surface ?? 'unknown';
|
||||
let highway = details.highway ?? 'unknown';
|
||||
let sacScale = details.sacScale;
|
||||
let mtbScale = details.mtbScale;
|
||||
const surface = details.surface ?? 'unknown';
|
||||
const highway = details.highway ?? 'unknown';
|
||||
const sacScale = details.sacScale;
|
||||
const mtbScale = details.mtbScale;
|
||||
|
||||
if (elevationFill === 'surface') {
|
||||
labels.push(
|
||||
@@ -305,7 +308,7 @@ export class ElevationProfile {
|
||||
enabled: true,
|
||||
},
|
||||
mode: 'x',
|
||||
onZoomStart: ({ chart, event }: { chart: Chart; event: any }) => {
|
||||
onZoomStart: ({ event }: { event: any }) => {
|
||||
if (!this._chart) {
|
||||
return false;
|
||||
}
|
||||
@@ -335,7 +338,7 @@ export class ElevationProfile {
|
||||
},
|
||||
};
|
||||
|
||||
let datasets: string[] = ['speed', 'hr', 'cad', 'atemp', 'power'];
|
||||
const datasets: string[] = ['speed', 'hr', 'cad', 'atemp', 'power'];
|
||||
datasets.forEach((id) => {
|
||||
options.scales![`y${id}`] = {
|
||||
type: 'linear',
|
||||
@@ -343,7 +346,8 @@ export class ElevationProfile {
|
||||
grid: {
|
||||
display: false,
|
||||
},
|
||||
reverse: () => id === 'speed' && get(velocityUnits) === 'pace',
|
||||
// the pace axis is reversed: set with the data, which the units change
|
||||
reverse: false,
|
||||
display: false,
|
||||
};
|
||||
});
|
||||
@@ -559,6 +563,8 @@ export class ElevationProfile {
|
||||
global.totalDistance,
|
||||
units.distance
|
||||
);
|
||||
// a faster pace is a lower value, it goes up like a higher speed
|
||||
this._chart.options.scales!.yspeed!.reverse = units.velocity === 'pace';
|
||||
|
||||
this.setVisibility();
|
||||
this.setFill();
|
||||
@@ -580,11 +586,11 @@ export class ElevationProfile {
|
||||
}
|
||||
|
||||
const additionalDatasets = get(this._additionalDatasets);
|
||||
let includeSpeed = additionalDatasets.includes('speed');
|
||||
let includeHeartRate = additionalDatasets.includes('hr');
|
||||
let includeCadence = additionalDatasets.includes('cad');
|
||||
let includeTemperature = additionalDatasets.includes('atemp');
|
||||
let includePower = additionalDatasets.includes('power');
|
||||
const includeSpeed = additionalDatasets.includes('speed');
|
||||
const includeHeartRate = additionalDatasets.includes('hr');
|
||||
const includeCadence = additionalDatasets.includes('cad');
|
||||
const includeTemperature = additionalDatasets.includes('atemp');
|
||||
const includePower = additionalDatasets.includes('power');
|
||||
if (this._chart.data.datasets.length == 6) {
|
||||
this._chart.data.datasets[1].hidden = !includeSpeed;
|
||||
this._chart.data.datasets[2].hidden = !includeHeartRate;
|
||||
@@ -639,21 +645,21 @@ export class ElevationProfile {
|
||||
|
||||
const slicedStatistics = get(this._slicedStatistics);
|
||||
if (slicedStatistics) {
|
||||
let startIndex = slicedStatistics.start;
|
||||
let endIndex = slicedStatistics.end;
|
||||
const startIndex = slicedStatistics.start;
|
||||
const endIndex = slicedStatistics.end;
|
||||
|
||||
// Draw selection rectangle
|
||||
let selectionContext = this._overlay.getContext('2d');
|
||||
const selectionContext = this._overlay.getContext('2d');
|
||||
if (selectionContext) {
|
||||
selectionContext.fillStyle = mode.current === 'dark' ? 'white' : 'black';
|
||||
selectionContext.globalAlpha = mode.current === 'dark' ? 0.2 : 0.1;
|
||||
selectionContext.clearRect(0, 0, this._overlay.width, this._overlay.height);
|
||||
|
||||
const statistics = get(this._statistics);
|
||||
let startPixel = this._chart.scales.x.getPixelForValue(
|
||||
const startPixel = this._chart.scales.x.getPixelForValue(
|
||||
getConvertedDistance(statistics.totalDistance[startIndex] ?? 0)
|
||||
);
|
||||
let endPixel = this._chart.scales.x.getPixelForValue(
|
||||
const endPixel = this._chart.scales.x.getPixelForValue(
|
||||
getConvertedDistance(statistics.totalDistance[endIndex] ?? 0)
|
||||
);
|
||||
|
||||
@@ -665,7 +671,7 @@ export class ElevationProfile {
|
||||
);
|
||||
}
|
||||
} else if (this._overlay) {
|
||||
let selectionContext = this._overlay.getContext('2d');
|
||||
const selectionContext = this._overlay.getContext('2d');
|
||||
if (selectionContext) {
|
||||
selectionContext.clearRect(0, 0, this._overlay.width, this._overlay.height);
|
||||
}
|
||||
|
||||
@@ -25,9 +25,10 @@
|
||||
import { PUBLIC_MAPTILER_KEY } from '$env/static/public';
|
||||
import Embedding from './Embedding.svelte';
|
||||
import { onDestroy } from 'svelte';
|
||||
import { base } from '$app/paths';
|
||||
import { resolve } from '$app/paths';
|
||||
import { map } from '$lib/components/map/map';
|
||||
import { mode } from 'mode-watcher';
|
||||
import { getURLForLanguage } from '$lib/utils';
|
||||
|
||||
let options = $state(
|
||||
getMergedEmbeddingOptions(
|
||||
@@ -114,7 +115,7 @@
|
||||
{i18n._(`layers.label.${options.basemap}`)}
|
||||
</Select.Trigger>
|
||||
<Select.Content class="max-h-60 overflow-y-scroll">
|
||||
{#each allowedEmbeddingBasemaps as basemap}
|
||||
{#each allowedEmbeddingBasemaps as basemap (basemap)}
|
||||
<Select.Item value={basemap}
|
||||
>{i18n._(`layers.label.${basemap}`)}</Select.Item
|
||||
>
|
||||
@@ -321,7 +322,7 @@
|
||||
<pre
|
||||
class="bg-primary text-primary-foreground p-3 rounded-md whitespace-normal break-all">
|
||||
<code class="language-html">
|
||||
{`<iframe src="https://gpx.studio${base}/embed?options=${encodeURIComponent(JSON.stringify(getCleanedEmbeddingOptions(iframeOptions)))}${hash}" width="100%" height="600px" frameborder="0" style="outline: none;"/>`}
|
||||
{`<iframe src="https://gpx.studio${resolve(getURLForLanguage(i18n.lang, '/embed'))}?options=${encodeURIComponent(JSON.stringify(getCleanedEmbeddingOptions(iframeOptions)))}${hash}" width="100%" height="600px" frameborder="0" style="outline: none;"/>`}
|
||||
</code>
|
||||
</pre>
|
||||
</fieldset>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { resolve } from '$app/paths';
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
import Logo from '$lib/components/Logo.svelte';
|
||||
import { getURLForLanguage } from '$lib/utils';
|
||||
@@ -16,7 +17,7 @@
|
||||
<Button
|
||||
variant="ghost"
|
||||
class="absolute top-0 flex-wrap h-fit bg-background font-semibold rounded-md py-1 px-2 gap-1.5 xs:text-base mt-2.5 ml-2.5 mr-12"
|
||||
href="{getURLForLanguage(i18n.lang, '/app')}?{files.length > 0
|
||||
href="{resolve(getURLForLanguage(i18n.lang, '/app'))}?{files.length > 0
|
||||
? `files=${encodeURIComponent(JSON.stringify(files))}`
|
||||
: ''}{files.length > 0 && ids.length > 0 ? '&' : ''}{ids.length > 0
|
||||
? `ids=${encodeURIComponent(JSON.stringify(ids))}`
|
||||
|
||||
@@ -109,7 +109,7 @@ export function getURLForGoogleDriveFile(fileId: string): string {
|
||||
}
|
||||
|
||||
export function convertOldEmbeddingOptions(options: URLSearchParams): any {
|
||||
let newOptions: any = {
|
||||
const newOptions: any = {
|
||||
key: PUBLIC_MAPTILER_KEY,
|
||||
files: [],
|
||||
ids: [],
|
||||
@@ -128,7 +128,7 @@ export function convertOldEmbeddingOptions(options: URLSearchParams): any {
|
||||
}
|
||||
}
|
||||
if (options.has('source')) {
|
||||
let basemap = options.get('source')!;
|
||||
const basemap = options.get('source')!;
|
||||
if (basemap === 'satellite') {
|
||||
newOptions.basemap = 'libertySatellite';
|
||||
} else if (basemap === 'otm') {
|
||||
|
||||
@@ -132,7 +132,6 @@
|
||||
<div class="flex flex-col h-full">
|
||||
<div class="px-2 py-1 text-sm font-semibold shrink-0">{i18n._('menu.explorer')}</div>
|
||||
<ScrollArea class="grow min-h-0">
|
||||
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
||||
<div
|
||||
bind:this={container}
|
||||
data-explorer
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
import { editStyle } from '$lib/components/file-list/style/utils.svelte';
|
||||
import { getSymbolKey, symbols } from '$lib/data/symbols';
|
||||
import { engine, type FileState } from '$lib/engine';
|
||||
import { allHidden } from '$lib/engine/all-hidden';
|
||||
import { allHidden, selectedFilesConversion } from '$lib/engine/selection-stores';
|
||||
import { normalizeColor } from '$lib/engine/file-colors';
|
||||
import { isHidden } from '$lib/engine/file-visibility';
|
||||
import {
|
||||
@@ -121,7 +121,6 @@
|
||||
let isCut = $derived($clipboard?.cut === true && isInClipboard($clipboard, node));
|
||||
</script>
|
||||
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<ContextMenu.Root
|
||||
onOpenChange={(open) => {
|
||||
@@ -259,18 +258,8 @@
|
||||
<PaintBucket size="16" />
|
||||
{i18n._('menu.style.button')}
|
||||
</ContextMenu.Item>
|
||||
{/if}
|
||||
<ContextMenu.Item onclick={() => engine.setSelectionHidden(!$allHidden)}>
|
||||
{#if $allHidden}
|
||||
<Eye size="16" />
|
||||
{i18n._('menu.unhide')}
|
||||
{:else}
|
||||
<EyeOff size="16" />
|
||||
{i18n._('menu.hide')}
|
||||
{/if}
|
||||
<Shortcut key="H" ctrl={true} />
|
||||
</ContextMenu.Item>
|
||||
<ContextMenu.Separator />
|
||||
{/if}
|
||||
{#if orientation === 'vertical'}
|
||||
{#if node.type === 'file'}
|
||||
<ContextMenu.Item disabled={!singleSelection} onclick={() => engine.newTrack()}>
|
||||
@@ -281,7 +270,6 @@
|
||||
<Plus size="16" />
|
||||
{i18n._('menu.new_route')}
|
||||
</ContextMenu.Item>
|
||||
<ContextMenu.Separator />
|
||||
{:else if node.type === 'track'}
|
||||
<ContextMenu.Item
|
||||
disabled={!singleSelection}
|
||||
@@ -301,18 +289,44 @@
|
||||
<ContextMenu.Separator />
|
||||
{/if}
|
||||
{/if}
|
||||
{#if node.type === 'file'}
|
||||
{#if $selectedFilesConversion}
|
||||
<ContextMenu.Item onclick={() => engine.convert()}>
|
||||
<ArrowRightLeft size="16" />
|
||||
{i18n._(
|
||||
$selectedFilesConversion === 'route'
|
||||
? 'menu.convert_to_routes'
|
||||
: 'menu.convert_to_tracks'
|
||||
)}
|
||||
</ContextMenu.Item>
|
||||
{/if}
|
||||
{#if orientation === 'vertical' || $selectedFilesConversion}
|
||||
<ContextMenu.Separator />
|
||||
{/if}
|
||||
{/if}
|
||||
<ContextMenu.Item onclick={() => engine.setSelectionHidden(!$allHidden)}>
|
||||
{#if $allHidden}
|
||||
<Eye size="16" />
|
||||
{i18n._('menu.unhide')}
|
||||
{:else}
|
||||
<EyeOff size="16" />
|
||||
{i18n._('menu.hide')}
|
||||
{/if}
|
||||
<Shortcut key="H" ctrl={true} />
|
||||
</ContextMenu.Item>
|
||||
<ContextMenu.Item onclick={() => boundsManager.centerMapOnSelection()}>
|
||||
<Maximize size="16" />
|
||||
{i18n._('menu.center')}
|
||||
<Shortcut key="⏎" ctrl={true} />
|
||||
</ContextMenu.Item>
|
||||
{#if level !== 'waypoints'}
|
||||
<ContextMenu.Separator />
|
||||
<ContextMenu.Item onclick={() => engine.selectAll()}>
|
||||
<FileStack size="16" />
|
||||
{i18n._('menu.select_all')}
|
||||
<Shortcut key="A" ctrl={true} />
|
||||
</ContextMenu.Item>
|
||||
{/if}
|
||||
<ContextMenu.Item onclick={() => boundsManager.centerMapOnSelection()}>
|
||||
<Maximize size="16" />
|
||||
{i18n._('menu.center')}
|
||||
<Shortcut key="⏎" ctrl={true} />
|
||||
</ContextMenu.Item>
|
||||
<ContextMenu.Separator />
|
||||
<ContextMenu.Item onclick={() => engine.duplicate()}>
|
||||
<Copy size="16" />
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
</AlertDialog.Description>
|
||||
</AlertDialog.Header>
|
||||
<ul class="list-disc pl-6 text-sm max-h-40 overflow-y-auto">
|
||||
{#each prompt.names as name}
|
||||
{#each prompt.names as name, i (i)}
|
||||
<li>{name}</li>
|
||||
{/each}
|
||||
</ul>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { isMac } from '$lib/utils';
|
||||
import Sortable, { type Direction } from 'sortablejs/Sortable';
|
||||
import Sortable from './sortable';
|
||||
import type { Direction } from 'sortablejs';
|
||||
import { get, writable } from 'svelte/store';
|
||||
import { tick } from 'svelte';
|
||||
import { engine, type MoveTarget, type Selection } from '$lib/engine';
|
||||
@@ -78,9 +79,13 @@ export class SortableFileList {
|
||||
setTimeout(() => this.updateToSelection(e), 50),
|
||||
onDeselect: (e: Sortable.SortableEvent) =>
|
||||
setTimeout(() => this.updateToSelection(e), 50),
|
||||
onStart: (e: Sortable.SortableEvent) => {
|
||||
// all the nodes, not only the elements: the comments are the anchors of the Svelte blocks
|
||||
onChoose: () => {
|
||||
// all the nodes, not only the elements: the comments are the anchors of the Svelte
|
||||
// blocks. Taken before the drag starts, when MultiDrag removes the other selected
|
||||
// elements from the list.
|
||||
this._snapshot = Array.from(container.childNodes);
|
||||
},
|
||||
onStart: (e: Sortable.SortableEvent) => {
|
||||
dragging.set(sortableLevel);
|
||||
// the files that are dragged (or whose elements are) are open for good
|
||||
engine.keepPreview(this.draggedFiles(e));
|
||||
@@ -241,9 +246,9 @@ export class SortableFileList {
|
||||
return;
|
||||
}
|
||||
const selection_ = get(engine.selection);
|
||||
for (let id of changed) {
|
||||
let element = this._elements[id];
|
||||
let node = this.childNode(id);
|
||||
for (const id of changed) {
|
||||
const element = this._elements[id];
|
||||
const node = this.childNode(id);
|
||||
if (element && node) {
|
||||
if (isSelected(selection_, node)) {
|
||||
Sortable.utils.select(element);
|
||||
@@ -258,7 +263,7 @@ export class SortableFileList {
|
||||
}
|
||||
}
|
||||
|
||||
updateToSelection(e: Sortable.SortableEvent) {
|
||||
updateToSelection(e: Sortable.SortableEvent & { originalEvent?: MouseEvent }) {
|
||||
if (!this._sortable) return;
|
||||
if (this._updatingSelection || this._applying) return;
|
||||
this._updatingSelection = true;
|
||||
@@ -344,7 +349,7 @@ export class SortableFileList {
|
||||
const files = get(engine.files);
|
||||
this._container.childNodes.forEach((element) => {
|
||||
if (element instanceof HTMLElement) {
|
||||
let attr = element.getAttribute('data-id');
|
||||
const attr = element.getAttribute('data-id');
|
||||
if (attr) {
|
||||
if (this._sortableLevel === 'file' && !files.has(attr)) {
|
||||
this.forget(element);
|
||||
@@ -392,12 +397,12 @@ export class SortableFileList {
|
||||
}
|
||||
|
||||
getChangedIds() {
|
||||
let changed: string[] = [];
|
||||
const changed: string[] = [];
|
||||
const selection_ = get(engine.selection);
|
||||
Object.entries(this._elements).forEach(([id, element]) => {
|
||||
const node = this.childNode(id);
|
||||
let inSelection = node !== undefined && isSelected(selection_, node);
|
||||
let isSelectedInList = element.classList.contains('sortable-selected');
|
||||
const inSelection = node !== undefined && isSelected(selection_, node);
|
||||
const isSelectedInList = element.classList.contains('sortable-selected');
|
||||
if (inSelection !== isSelectedInList) {
|
||||
changed.push(id);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import Sortable, { MultiDrag } from 'sortablejs';
|
||||
|
||||
// The ESM build leaves out the MultiDrag plugin. Mounting it twice throws, so it is done here
|
||||
// rather than in a module that hot reloading runs again.
|
||||
Sortable.mount(new MultiDrag());
|
||||
|
||||
export default Sortable;
|
||||
@@ -48,7 +48,7 @@
|
||||
<Card.Title class="text-md">
|
||||
{@const link = waypoint.item.links?.[0]}
|
||||
{#if link?.href}
|
||||
<a href={link.href} target="_blank">
|
||||
<a href={link.href} target="_blank" rel="external">
|
||||
{waypoint.item.name ?? link.href}
|
||||
<ExternalLink size="12" class="inline-block mb-1.5" />
|
||||
</a>
|
||||
@@ -77,9 +77,11 @@
|
||||
</div>
|
||||
<ScrollArea class="flex flex-col max-h-[30dvh]">
|
||||
{#if waypoint.item.desc}
|
||||
<!-- eslint-disable-next-line svelte/no-at-html-tags -- sanitized -->
|
||||
<span class="whitespace-pre-wrap">{@html sanitize(waypoint.item.desc)}</span>
|
||||
{/if}
|
||||
{#if waypoint.item.cmt && waypoint.item.cmt !== waypoint.item.desc}
|
||||
<!-- eslint-disable-next-line svelte/no-at-html-tags -- sanitized -->
|
||||
<span class="whitespace-pre-wrap">{@html sanitize(waypoint.item.cmt)}</span>
|
||||
{/if}
|
||||
</ScrollArea>
|
||||
|
||||
@@ -3,7 +3,7 @@ import { engine } from '$lib/engine';
|
||||
import { getConvertedDistanceToKilometers } from '$lib/units/units';
|
||||
import { get } from 'svelte/store';
|
||||
import { map } from '$lib/components/map/map';
|
||||
import { allHidden } from '$lib/engine/all-hidden';
|
||||
import { allHidden } from '$lib/engine/selection-stores';
|
||||
import type { GeoJSONSource } from 'maplibre-gl';
|
||||
import { ANCHOR_LAYER_KEY } from '$lib/components/map/style';
|
||||
|
||||
@@ -35,7 +35,8 @@ export class DistanceMarkers {
|
||||
|
||||
try {
|
||||
if (get(distanceMarkers) && !get(allHidden)) {
|
||||
let distanceSource: GeoJSONSource | undefined = map_.getSource('distance-markers');
|
||||
const distanceSource: GeoJSONSource | undefined =
|
||||
map_.getSource('distance-markers');
|
||||
if (distanceSource) {
|
||||
distanceSource.setData(this.getDistanceMarkersGeoJSON());
|
||||
} else {
|
||||
@@ -90,7 +91,7 @@ export class DistanceMarkers {
|
||||
map_.removeLayer('distance-markers');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
} catch {
|
||||
// No reliable way to check if the map is ready to add sources and layers
|
||||
return;
|
||||
}
|
||||
@@ -104,12 +105,12 @@ export class DistanceMarkers {
|
||||
// the distance from the start of the selection, and the position, of each trackpoint
|
||||
const { length, totalDistance, lng, lat } = get(engine.statistics);
|
||||
|
||||
let features: GeoJSON.Feature[] = [];
|
||||
const features: GeoJSON.Feature[] = [];
|
||||
let currentTargetDistance = 1;
|
||||
for (let i = 0; i < length; i++) {
|
||||
if (totalDistance[i] >= getConvertedDistanceToKilometers(currentTargetDistance)) {
|
||||
let distance = currentTargetDistance.toFixed(0);
|
||||
let level = levels.find((level) => currentTargetDistance % level === 0) || 1;
|
||||
const distance = currentTargetDistance.toFixed(0);
|
||||
const level = levels.find((level) => currentTargetDistance % level === 0) || 1;
|
||||
features.push({
|
||||
type: 'Feature',
|
||||
geometry: {
|
||||
|
||||
@@ -23,7 +23,7 @@ import { mapCursor, MapCursorState } from '$lib/state/map-cursor';
|
||||
import { ANCHOR_LAYER_KEY } from '$lib/components/map/style';
|
||||
|
||||
export function getSvgForSymbol(symbol?: string | undefined, layerColor?: string | undefined) {
|
||||
let symbolSvg = symbol ? symbols[symbol]?.iconSvg : undefined;
|
||||
const symbolSvg = symbol ? symbols[symbol]?.iconSvg : undefined;
|
||||
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||
${
|
||||
layerColor
|
||||
@@ -63,12 +63,12 @@ export class GPXLayer {
|
||||
currentWaypointData: GeoJSON.FeatureCollection | null = null;
|
||||
draggedWaypointIndex: number | null = null;
|
||||
draggingStartingPosition: Point = new Point(0, 0);
|
||||
unsubscribe: Function[] = [];
|
||||
unsubscribe: (() => void)[] = [];
|
||||
|
||||
updateBinded: () => void = this.update.bind(this);
|
||||
layerOnMouseEnterBinded: (e: any) => void = this.layerOnMouseEnter.bind(this);
|
||||
layerOnMouseEnterBinded: (e: MapLayerMouseEvent) => void = this.layerOnMouseEnter.bind(this);
|
||||
layerOnMouseLeaveBinded: () => void = this.layerOnMouseLeave.bind(this);
|
||||
layerOnMouseMoveBinded: (e: any) => void = this.layerOnMouseMove.bind(this);
|
||||
layerOnMouseMoveBinded: (e: MapLayerMouseEvent) => void = this.layerOnMouseMove.bind(this);
|
||||
layerOnClickBinded: (e: MapLayerMouseEvent) => void = this.layerOnClick.bind(this);
|
||||
layerOnContextMenuBinded: (e: MapLayerMouseEvent) => void = this.layerOnContextMenu.bind(this);
|
||||
waypointLayerOnMouseEnterBinded: (e: MapLayerMouseEvent) => void =
|
||||
@@ -101,7 +101,7 @@ export class GPXLayer {
|
||||
this.unsubscribe.push(
|
||||
engine.selection.subscribe(($selection) => {
|
||||
this.selectionState = $selection;
|
||||
let newSelected = hasSelectionWithin($selection, this.fileNode());
|
||||
const newSelected = hasSelectionWithin($selection, this.fileNode());
|
||||
if (this.selected || newSelected) {
|
||||
this.selected = newSelected;
|
||||
this.update();
|
||||
@@ -146,7 +146,7 @@ export class GPXLayer {
|
||||
this.loadIcons();
|
||||
|
||||
try {
|
||||
let source = _map.getSource(this.fileId) as GeoJSONSource | undefined;
|
||||
const source = _map.getSource(this.fileId) as GeoJSONSource | undefined;
|
||||
if (source) {
|
||||
source.setData(this.getGeoJSON());
|
||||
} else {
|
||||
@@ -234,7 +234,7 @@ export class GPXLayer {
|
||||
}
|
||||
}
|
||||
|
||||
let waypointSource = _map.getSource(this.fileId + '-waypoints') as
|
||||
const waypointSource = _map.getSource(this.fileId + '-waypoints') as
|
||||
| GeoJSONSource
|
||||
| undefined;
|
||||
this.currentWaypointData = this.getWaypointsGeoJSON();
|
||||
@@ -301,7 +301,7 @@ export class GPXLayer {
|
||||
['in', ['get', 'waypointIndex'], ['literal', visibleWaypoints]],
|
||||
{ validate: false }
|
||||
);
|
||||
} catch (e) {
|
||||
} catch {
|
||||
// No reliable way to check if the map is ready to add sources and layers
|
||||
return;
|
||||
}
|
||||
@@ -386,10 +386,10 @@ export class GPXLayer {
|
||||
}
|
||||
}
|
||||
|
||||
layerOnMouseEnter(e: any) {
|
||||
layerOnMouseEnter(e: MapLayerMouseEvent) {
|
||||
if (
|
||||
get(currentTool) === Tool.SCISSORS &&
|
||||
isCovered(this.selectionState, this.segmentNode(e.features[0].properties))
|
||||
isCovered(this.selectionState, this.segmentNode(e.features![0].properties))
|
||||
) {
|
||||
mapCursor.notify(MapCursorState.SCISSORS, true);
|
||||
} else {
|
||||
@@ -402,9 +402,9 @@ export class GPXLayer {
|
||||
mapCursor.notify(MapCursorState.LAYER_HOVER, false);
|
||||
}
|
||||
|
||||
async layerOnMouseMove(e: any) {
|
||||
async layerOnMouseMove(e: MapLayerMouseEvent) {
|
||||
if (e.originalEvent.shiftKey) {
|
||||
const { segmentId } = e.features[0].properties;
|
||||
const { segmentId } = e.features![0].properties;
|
||||
const lngLat = { lng: e.lngLat.lng, lat: e.lngLat.lat };
|
||||
const index = closestPointIndex(await engine.segmentCoordinates(segmentId), lngLat);
|
||||
const trackpoint =
|
||||
@@ -469,7 +469,7 @@ export class GPXLayer {
|
||||
}
|
||||
}
|
||||
|
||||
layerOnContextMenu(e: any) {
|
||||
layerOnContextMenu(e: MapLayerMouseEvent) {
|
||||
if (e.originalEvent.ctrlKey) {
|
||||
this.layerOnClick(e);
|
||||
}
|
||||
@@ -584,7 +584,7 @@ export class GPXLayer {
|
||||
this.currentWaypointData!.features[this.draggedWaypointIndex].geometry as GeoJSON.Point
|
||||
).coordinates = [e.lngLat.lng, e.lngLat.lat];
|
||||
|
||||
let waypointSource = get(map)?.getSource(this.fileId + '-waypoints') as
|
||||
const waypointSource = get(map)?.getSource(this.fileId + '-waypoints') as
|
||||
| GeoJSONSource
|
||||
| undefined;
|
||||
if (waypointSource) {
|
||||
@@ -698,7 +698,7 @@ export class GPXLayer {
|
||||
return;
|
||||
}
|
||||
|
||||
let symbols = new Set<string | undefined>();
|
||||
const symbols = new Set<string | undefined>();
|
||||
get(this.file).waypoints.features.forEach((feature) => {
|
||||
symbols.add(getSymbolKey(feature.properties.sym));
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@ import { currentTool, Tool } from '$lib/components/toolbar/tools';
|
||||
import type { GeoJSONSource } from 'maplibre-gl';
|
||||
import { get } from 'svelte/store';
|
||||
import { map } from '$lib/components/map/map';
|
||||
import { allHidden } from '$lib/engine/all-hidden';
|
||||
import { allHidden } from '$lib/engine/selection-stores';
|
||||
import { ANCHOR_LAYER_KEY } from '$lib/components/map/style';
|
||||
import { loadSVGIcon } from '$lib/utils';
|
||||
import { hoveredPoint, slicedStatistics } from '$lib/state/selection-statistics';
|
||||
@@ -100,7 +100,7 @@ export class StartEndMarkers {
|
||||
});
|
||||
}
|
||||
|
||||
let source = map_.getSource('start-end-markers') as GeoJSONSource | undefined;
|
||||
const source = map_.getSource('start-end-markers') as GeoJSONSource | undefined;
|
||||
if (source) {
|
||||
source.setData(data);
|
||||
} else {
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
Layers2,
|
||||
} from '@lucide/svelte';
|
||||
import { i18n } from '$lib/i18n/i18n.svelte';
|
||||
import { defaultBasemap, type CustomLayer } from '$lib/data/layers';
|
||||
import { defaultBasemap, layerGroup, type CustomLayer } from '$lib/data/layers';
|
||||
import { onMount } from 'svelte';
|
||||
import { remove } from './utils';
|
||||
import { settings } from '$lib/state/settings';
|
||||
@@ -128,15 +128,16 @@
|
||||
],
|
||||
};
|
||||
}
|
||||
addLayer(layerId);
|
||||
|
||||
$customLayers[layerId] = layer;
|
||||
addLayer(layerId);
|
||||
selectedLayerId = undefined;
|
||||
setDataFromSelectedLayer();
|
||||
}
|
||||
|
||||
function getLayerId() {
|
||||
for (let id = 0; ; id++) {
|
||||
if (!$customLayers.hasOwnProperty(`custom-${id}`)) {
|
||||
if (!Object.hasOwn($customLayers, `custom-${id}`)) {
|
||||
return `custom-${id}`;
|
||||
}
|
||||
}
|
||||
@@ -145,7 +146,7 @@
|
||||
function addLayer(layerId: string) {
|
||||
if (layerType === 'basemap') {
|
||||
selectedBasemapTree.update(($tree) => {
|
||||
if (!$tree.basemaps.hasOwnProperty('custom')) {
|
||||
if (!Object.hasOwn($tree.basemaps, 'custom')) {
|
||||
$tree.basemaps['custom'] = {};
|
||||
}
|
||||
$tree.basemaps['custom'][layerId] = true;
|
||||
@@ -161,7 +162,7 @@
|
||||
}
|
||||
} else {
|
||||
selectedOverlayTree.update(($tree) => {
|
||||
if (!$tree.overlays.hasOwnProperty('custom')) {
|
||||
if (!Object.hasOwn($tree.overlays, 'custom')) {
|
||||
$tree.overlays['custom'] = {};
|
||||
}
|
||||
$tree.overlays['custom'][layerId] = true;
|
||||
@@ -169,7 +170,7 @@
|
||||
});
|
||||
|
||||
currentOverlays.update(($overlays) => {
|
||||
if (!$overlays.overlays.hasOwnProperty('custom')) {
|
||||
if (!Object.hasOwn($overlays.overlays, 'custom')) {
|
||||
$overlays.overlays['custom'] = {};
|
||||
}
|
||||
$overlays.overlays['custom'][layerId] = true;
|
||||
@@ -182,8 +183,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
function tryDeleteLayer(node: any, id: string): any {
|
||||
if (node.hasOwnProperty(id)) {
|
||||
function tryDeleteLayer<T>(node: Record<string, T>, id: string): Record<string, T> {
|
||||
if (Object.hasOwn(node, id)) {
|
||||
delete node[id];
|
||||
}
|
||||
return node;
|
||||
@@ -255,13 +256,12 @@
|
||||
onfinalize={(e) => {
|
||||
customBasemapItems = e.detail.items;
|
||||
$customBasemapOrder = customBasemapItems.map((item) => item.id);
|
||||
$selectedBasemapTree.basemaps['custom'] = customBasemapItems.reduce(
|
||||
(acc, item) => {
|
||||
acc[item.id] = true;
|
||||
return acc;
|
||||
},
|
||||
{}
|
||||
selectedBasemapTree.update(($tree) => {
|
||||
layerGroup($tree.basemaps)['custom'] = Object.fromEntries(
|
||||
customBasemapItems.map((item) => [item.id, true])
|
||||
);
|
||||
return $tree;
|
||||
});
|
||||
}}
|
||||
>
|
||||
{#each customBasemapItems as item (item.id)}
|
||||
@@ -315,13 +315,12 @@
|
||||
onfinalize={(e) => {
|
||||
customOverlayItems = e.detail.items;
|
||||
$customOverlayOrder = customOverlayItems.map((item) => item.id);
|
||||
$selectedOverlayTree.overlays['custom'] = customOverlayItems.reduce(
|
||||
(acc, item) => {
|
||||
acc[item.id] = true;
|
||||
return acc;
|
||||
},
|
||||
{}
|
||||
selectedOverlayTree.update(($tree) => {
|
||||
layerGroup($tree.overlays)['custom'] = Object.fromEntries(
|
||||
customOverlayItems.map((item) => [item.id, true])
|
||||
);
|
||||
return $tree;
|
||||
});
|
||||
}}
|
||||
>
|
||||
{#each customOverlayItems as item (item.id)}
|
||||
@@ -365,7 +364,7 @@
|
||||
<Label for="name">{i18n._('menu.metadata.name')}</Label>
|
||||
<Input bind:value={name} id="name" class="h-8" />
|
||||
<Label for="url">{i18n._('layers.custom_layers.urls')}</Label>
|
||||
{#each tileUrls as url, i}
|
||||
{#each tileUrls as _, i (i)}
|
||||
<div class="flex flex-row gap-2">
|
||||
<Input
|
||||
bind:value={tileUrls[i]}
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
|
||||
function setOpacityFromSelection() {
|
||||
if (selectedOverlay) {
|
||||
if ($opacities.hasOwnProperty(selectedOverlay)) {
|
||||
if (Object.hasOwn($opacities, selectedOverlay)) {
|
||||
overlayOpacity = $opacities[selectedOverlay];
|
||||
} else {
|
||||
overlayOpacity = 1;
|
||||
@@ -169,7 +169,7 @@
|
||||
{#if isSelected($selectedOverlayTree, selectedOverlay)}
|
||||
{#if $isLayerFromExtension(selectedOverlay)}
|
||||
{$getLayerName(selectedOverlay)}
|
||||
{:else if $customLayers.hasOwnProperty(selectedOverlay)}
|
||||
{:else if Object.hasOwn($customLayers, selectedOverlay)}
|
||||
{$customLayers[selectedOverlay].name}
|
||||
{:else}
|
||||
{i18n._(`layers.label.${selectedOverlay}`)}
|
||||
@@ -178,7 +178,7 @@
|
||||
{/if}
|
||||
</Select.Trigger>
|
||||
<Select.Content class="h-fit max-h-[40dvh] overflow-y-auto">
|
||||
{#each Object.keys(overlays) as id}
|
||||
{#each Object.keys(overlays) as id (id)}
|
||||
{#if isSelected($selectedOverlayTree, id)}
|
||||
<Select.Item value={id}>
|
||||
{#if $isLayerFromExtension(id)}
|
||||
@@ -189,7 +189,7 @@
|
||||
</Select.Item>
|
||||
{/if}
|
||||
{/each}
|
||||
{#each Object.entries($customLayers) as [id, layer]}
|
||||
{#each Object.entries($customLayers) as [id, layer] (id)}
|
||||
{#if layer.layerType === 'overlay'}
|
||||
<Select.Item value={id}>{layer.name}</Select.Item>
|
||||
{/if}
|
||||
@@ -218,7 +218,7 @@
|
||||
if ($map.getLayer(selectedOverlay)) {
|
||||
$map.removeLayer(selectedOverlay);
|
||||
}
|
||||
} catch (e) {
|
||||
} catch {
|
||||
// No reliable way to check if the map is ready to remove sources and layers
|
||||
}
|
||||
}
|
||||
@@ -247,7 +247,7 @@
|
||||
{i18n._(`layers.label.${$terrainSource}`)}
|
||||
</Select.Trigger>
|
||||
<Select.Content class="h-fit max-h-[40dvh] overflow-y-auto">
|
||||
{#each Object.keys(terrainSources) as id}
|
||||
{#each Object.keys(terrainSources) as id (id)}
|
||||
<Select.Item value={id}>
|
||||
{i18n._(`layers.label.${id}`)}
|
||||
</Select.Item>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
selected?: string;
|
||||
onselect?: (value: string) => void;
|
||||
multiple: boolean;
|
||||
checked: LayerTreeType;
|
||||
checked?: LayerTreeType;
|
||||
} = $props();
|
||||
|
||||
const { customLayers } = settings;
|
||||
@@ -31,7 +31,7 @@
|
||||
$effect.pre(() => {
|
||||
if (checked !== undefined) {
|
||||
Object.keys(node).forEach((id) => {
|
||||
if (!checked.hasOwnProperty(id)) {
|
||||
if (!Object.hasOwn(checked, id)) {
|
||||
if (typeof node[id] == 'boolean') {
|
||||
checked[id] = false;
|
||||
} else {
|
||||
@@ -44,7 +44,7 @@
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-[3px]">
|
||||
{#each Object.keys(node) as id}
|
||||
{#each Object.keys(node) as id (id)}
|
||||
{#if typeof node[id] == 'boolean'}
|
||||
{#if node[id]}
|
||||
<div class="flex flex-row items-center gap-2 first:mt-0.5 h-4">
|
||||
@@ -53,7 +53,9 @@
|
||||
id="{name}-{id}"
|
||||
{name}
|
||||
value={id}
|
||||
bind:checked={checked[id]}
|
||||
bind:checked={
|
||||
() => checked[id] === true, (value) => (checked[id] = value)
|
||||
}
|
||||
class="scale-90"
|
||||
aria-label={i18n._(`layers.label.${id}`)}
|
||||
/>
|
||||
@@ -72,7 +74,7 @@
|
||||
/>
|
||||
{/if}
|
||||
<Label for="{name}-{id}" class="flex flex-row items-center gap-1">
|
||||
{#if $customLayers.hasOwnProperty(id)}
|
||||
{#if Object.hasOwn($customLayers, id)}
|
||||
{$customLayers[id].name}
|
||||
{:else if $isLayerFromExtension(id)}
|
||||
{$getLayerName(id)}
|
||||
@@ -90,12 +92,18 @@
|
||||
{#snippet content()}
|
||||
<div class="ml-2">
|
||||
<Self
|
||||
node={node[id]}
|
||||
node={node[id] as LayerTreeType}
|
||||
{name}
|
||||
{selected}
|
||||
{onselect}
|
||||
{multiple}
|
||||
bind:checked={checked[id]}
|
||||
bind:checked={
|
||||
() => {
|
||||
const group = checked[id];
|
||||
return typeof group === 'object' ? group : undefined;
|
||||
},
|
||||
(value) => (checked[id] = value ?? {})
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
{/snippet}
|
||||
|
||||
@@ -79,11 +79,16 @@
|
||||
</div>
|
||||
{/if}
|
||||
<div class="grid grid-cols-[auto_auto] gap-x-3">
|
||||
{#each Object.entries(tags) as [key, value]}
|
||||
{#each Object.entries(tags) as [key, value] (key)}
|
||||
{#if key !== 'name' && !key.includes('image')}
|
||||
<span class="font-mono">{key}</span>
|
||||
{#if key === 'website' || key.startsWith('website:') || key.endsWith(':website') || key === 'contact:facebook' || key === 'contact:instagram' || key === 'contact:twitter'}
|
||||
<a href={value} target="_blank" class="text-link underline">{value}</a>
|
||||
<a
|
||||
href={value}
|
||||
target="_blank"
|
||||
rel="external"
|
||||
class="text-link underline">{value}</a
|
||||
>
|
||||
{:else if key === 'wikipedia' || key.startsWith('wikipedia:') || key.endsWith(':wikipedia')}
|
||||
<a
|
||||
href="https://wikipedia.org/wiki/{value}"
|
||||
|
||||
@@ -9,6 +9,15 @@ import { ExtensionAPI, type CustomOverlay } from './extension-api';
|
||||
import { isSelected } from './utils';
|
||||
|
||||
const original = { set: engine.setSetting, delete: engine.deleteSetting };
|
||||
|
||||
/** The raster source that an overlay added by an extension uses. */
|
||||
function rasterSource(id: string) {
|
||||
const style = overlays[id];
|
||||
assert.ok(typeof style === 'object');
|
||||
const source = style.sources[id];
|
||||
assert.ok(source?.type === 'raster');
|
||||
return source;
|
||||
}
|
||||
const overlayTreeBefore = JSON.stringify(overlayTree);
|
||||
const overlayIdsBefore = Object.keys(overlays).sort();
|
||||
|
||||
@@ -45,10 +54,7 @@ describe('ExtensionAPI', () => {
|
||||
it('adds an overlay as a layer, in the tree of its extension', () => {
|
||||
api.addOrUpdateOverlay(overlay('one'));
|
||||
|
||||
const layer = overlays['extension-one'];
|
||||
assert.ok(layer && typeof layer === 'object');
|
||||
const source = (layer as any).sources['extension-one'];
|
||||
assert.equal(source.type, 'raster');
|
||||
const source = rasterSource('extension-one');
|
||||
assert.deepEqual(source.tiles, ['https://tiles.example.com/one/{z}/{x}/{y}.png']);
|
||||
assert.equal(source.tileSize, 256);
|
||||
assert.equal(source.maxzoom, 22);
|
||||
@@ -69,7 +75,7 @@ describe('ExtensionAPI', () => {
|
||||
tileUrls: ['https://tiles.example.com/512/{z}/{x}/{y}.png'],
|
||||
maxZoom: 15,
|
||||
});
|
||||
const source = (overlays['extension-big'] as any).sources['extension-big'];
|
||||
const source = rasterSource('extension-big');
|
||||
assert.equal(source.tileSize, 512);
|
||||
assert.equal(source.maxzoom, 15);
|
||||
});
|
||||
@@ -100,9 +106,7 @@ describe('ExtensionAPI', () => {
|
||||
tileUrls: ['https://other/{z}'],
|
||||
});
|
||||
assert.equal(get(api.getLayerName)('extension-one'), 'Renamed');
|
||||
assert.deepEqual((overlays['extension-one'] as any).sources['extension-one'].tiles, [
|
||||
'https://other/{z}',
|
||||
]);
|
||||
assert.deepEqual(rasterSource('extension-one').tiles, ['https://other/{z}']);
|
||||
assert.equal(isSelected(get(settings.currentOverlays)!, 'extension-one'), true);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { settings } from '$lib/state/settings';
|
||||
import { derived, get, writable, type Writable } from 'svelte/store';
|
||||
import { isSelected, remove, removeAll } from './utils';
|
||||
import { overlays, overlayTree } from '$lib/data/layers';
|
||||
import { layerGroup, overlays, overlayTree, type LayerTreeType } from '$lib/data/layers';
|
||||
import { browser } from '$app/environment';
|
||||
import { map } from '$lib/components/map/map';
|
||||
|
||||
@@ -19,7 +19,7 @@ export class ExtensionAPI {
|
||||
private _overlays: Writable<Map<string, CustomOverlay>> = writable(new Map());
|
||||
|
||||
init() {
|
||||
if (browser && !window.hasOwnProperty('gpxstudio')) {
|
||||
if (browser && !Object.hasOwn(window, 'gpxstudio')) {
|
||||
Object.defineProperty(window, 'gpxstudio', {
|
||||
value: this,
|
||||
});
|
||||
@@ -84,14 +84,15 @@ export class ExtensionAPI {
|
||||
],
|
||||
};
|
||||
|
||||
if (!overlayTree.overlays.hasOwnProperty(overlay.extensionName)) {
|
||||
overlayTree.overlays[overlay.extensionName] = {};
|
||||
const extensions = layerGroup(overlayTree.overlays);
|
||||
if (!Object.hasOwn(extensions, overlay.extensionName)) {
|
||||
extensions[overlay.extensionName] = {};
|
||||
}
|
||||
|
||||
overlayTree.overlays[overlay.extensionName][overlay.id] = true;
|
||||
layerGroup(extensions[overlay.extensionName])[overlay.id] = true;
|
||||
|
||||
selectedOverlayTree.update((selected) => {
|
||||
if (!selected.overlays.hasOwnProperty(overlay.extensionName)) {
|
||||
if (!Object.hasOwn(selected.overlays, overlay.extensionName)) {
|
||||
selected.overlays[overlay.extensionName] = {};
|
||||
}
|
||||
selected.overlays[overlay.extensionName][overlay.id] = true;
|
||||
@@ -104,13 +105,13 @@ export class ExtensionAPI {
|
||||
show = true;
|
||||
try {
|
||||
get(map)?.removeLayer(overlay.id);
|
||||
} catch (e) {
|
||||
} catch {
|
||||
// No reliable way to check if the map is ready to remove sources and layers
|
||||
}
|
||||
}
|
||||
|
||||
currentOverlays.update((current) => {
|
||||
if (!current.overlays.hasOwnProperty(overlay.extensionName)) {
|
||||
if (!Object.hasOwn(current.overlays, overlay.extensionName)) {
|
||||
current.overlays[overlay.extensionName] = {};
|
||||
}
|
||||
current.overlays[overlay.extensionName][overlay.id] = show;
|
||||
@@ -155,13 +156,13 @@ export class ExtensionAPI {
|
||||
updateOverlaysOrder(ids: string[]) {
|
||||
ids = ids.map((id) => this.getOverlayId(id));
|
||||
selectedOverlayTree.update((selected) => {
|
||||
let isSelected: Record<string, boolean> = {};
|
||||
const isSelected: Record<string, boolean> = {};
|
||||
ids.forEach((id) => {
|
||||
const overlay = get(this._overlays).get(id);
|
||||
if (
|
||||
overlay &&
|
||||
selected.overlays.hasOwnProperty(overlay.extensionName) &&
|
||||
selected.overlays[overlay.extensionName].hasOwnProperty(id)
|
||||
Object.hasOwn(selected.overlays, overlay.extensionName) &&
|
||||
Object.hasOwn(selected.overlays[overlay.extensionName] as LayerTreeType, id)
|
||||
) {
|
||||
isSelected[id] = selected.overlays[overlay.extensionName][id];
|
||||
delete selected.overlays[overlay.extensionName][id];
|
||||
|
||||
@@ -4,7 +4,7 @@ import { get, writable } from 'svelte/store';
|
||||
import { overpassQueryData } from '$lib/data/layers';
|
||||
import { MapPopup } from '$lib/components/map/map-popup';
|
||||
import { settings } from '$lib/state/settings';
|
||||
import type { GeoJSONSource, Map as MapLibreMap } from 'maplibre-gl';
|
||||
import type { GeoJSONSource, MapLayerMouseEvent, Map as MapLibreMap } from 'maplibre-gl';
|
||||
import { ANCHOR_LAYER_KEY } from '$lib/components/map/style';
|
||||
import type { MapLayerEventManager } from '$lib/components/map/map-layer-event-manager';
|
||||
import { loadSVGIcon } from '$lib/utils';
|
||||
@@ -86,7 +86,7 @@ export class OverpassLayer {
|
||||
};
|
||||
|
||||
try {
|
||||
let source = this.map.getSource('overpass') as GeoJSONSource | undefined;
|
||||
const source = this.map.getSource('overpass') as GeoJSONSource | undefined;
|
||||
if (source) {
|
||||
source.setData(d);
|
||||
} else {
|
||||
@@ -115,7 +115,7 @@ export class OverpassLayer {
|
||||
this.layerEventManager.on('mouseenter', 'overpass', this.onHoverBinded);
|
||||
this.layerEventManager.on('click', 'overpass', this.onHoverBinded);
|
||||
}
|
||||
} catch (e) {
|
||||
} catch {
|
||||
// No reliable way to check if the map is ready to add sources and layers
|
||||
}
|
||||
}
|
||||
@@ -135,28 +135,28 @@ export class OverpassLayer {
|
||||
if (this.map.getSource('overpass')) {
|
||||
this.map.removeSource('overpass');
|
||||
}
|
||||
} catch (e) {
|
||||
} catch {
|
||||
// No reliable way to check if the map is ready to remove sources and layers
|
||||
}
|
||||
}
|
||||
|
||||
onHover(e: any) {
|
||||
onHover(e: MapLayerMouseEvent) {
|
||||
this.popup.setItem({
|
||||
kind: 'overpass',
|
||||
item: {
|
||||
...e.features[0].properties,
|
||||
sym: overpassQueryData[e.features[0].properties.query].symbol ?? '',
|
||||
...e.features![0].properties,
|
||||
sym: overpassQueryData[e.features![0].properties.query].symbol ?? '',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
query(bbox: [number, number, number, number]) {
|
||||
let queries = getCurrentQueries();
|
||||
const queries = getCurrentQueries();
|
||||
if (queries.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let tileLimits = mercator.xyz(bbox, this.queryZoom);
|
||||
const tileLimits = mercator.xyz(bbox, this.queryZoom);
|
||||
|
||||
for (let x = tileLimits.minX; x <= tileLimits.maxX; x++) {
|
||||
for (let y = tileLimits.minY; y <= tileLimits.maxY; y++) {
|
||||
@@ -189,8 +189,8 @@ export class OverpassLayer {
|
||||
}
|
||||
|
||||
this.data.update((updatedData) => {
|
||||
for (let element of data.elements) {
|
||||
for (let query of queries) {
|
||||
for (const element of data.elements) {
|
||||
for (const query of queries) {
|
||||
if (belongsToQuery(element, query)) {
|
||||
updatedData.features.push({
|
||||
type: 'Feature',
|
||||
@@ -224,7 +224,7 @@ export class OverpassLayer {
|
||||
}
|
||||
|
||||
loadIcons() {
|
||||
let currentQueries = getCurrentQueries();
|
||||
const currentQueries = getCurrentQueries();
|
||||
currentQueries.forEach((query) => {
|
||||
loadSVGIcon(
|
||||
this.map,
|
||||
@@ -257,7 +257,7 @@ function getQuery(query: string) {
|
||||
}
|
||||
|
||||
function getQueryItem(tags: Record<string, string | string[]>) {
|
||||
let arrayEntry = Object.entries(tags).find((entry): entry is [string, string[]] =>
|
||||
const arrayEntry = Object.entries(tags).find((entry): entry is [string, string[]] =>
|
||||
Array.isArray(entry[1])
|
||||
);
|
||||
if (arrayEntry !== undefined) {
|
||||
@@ -291,12 +291,12 @@ function belongsToQueryItem(element: any, tags: Record<string, string | string[]
|
||||
}
|
||||
|
||||
function getCurrentQueries() {
|
||||
let currentQueries = get(currentOverpassQueries);
|
||||
const currentQueries = get(currentOverpassQueries);
|
||||
if (currentQueries === undefined) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Object.entries(getLayers(currentQueries))
|
||||
.filter(([_, selected]) => selected)
|
||||
.map(([query, _]) => query);
|
||||
.filter(([, selected]) => selected)
|
||||
.map(([query]) => query);
|
||||
}
|
||||
@@ -235,7 +235,7 @@ export class MapLayerEventManager {
|
||||
|
||||
private _filterLayersIntersectingBounds(layerIds: string[], bounds: LngLatBounds): string[] {
|
||||
const files = get(engine.files);
|
||||
let result = layerIds.filter((layerId) => {
|
||||
const result = layerIds.filter((layerId) => {
|
||||
if (!this._map.getLayer(layerId)) return false;
|
||||
const fileId = layerId.replace('-waypoints', '');
|
||||
if (fileId === layerId) {
|
||||
|
||||
@@ -13,7 +13,7 @@ import { MapLayerEventManager } from '$lib/components/map/map-layer-event-manage
|
||||
|
||||
const { treeFileView, elevationProfile, bottomPanelSize, rightPanelSize, distanceUnits } = settings;
|
||||
|
||||
let fitBoundsOptions: maplibregl.MapOptions['fitBoundsOptions'] = {
|
||||
const fitBoundsOptions: maplibregl.MapOptions['fitBoundsOptions'] = {
|
||||
maxZoom: 15,
|
||||
linear: true,
|
||||
easing: () => 1,
|
||||
@@ -75,7 +75,7 @@ export class MapLibreGLMap {
|
||||
})
|
||||
);
|
||||
if (geocoder) {
|
||||
let geocoder = new MaplibreGeocoder(
|
||||
const geocoder = new MaplibreGeocoder(
|
||||
{
|
||||
forwardGeocode: async (config) => {
|
||||
const results: MaplibreGeocoderFeatureResults = {
|
||||
@@ -85,18 +85,26 @@ export class MapLibreGLMap {
|
||||
try {
|
||||
const request = `https://nominatim.openstreetmap.org/search?format=json&q=${config.query}&limit=5&accept-language=${language}`;
|
||||
const response = await fetch(request);
|
||||
const geojson = await response.json();
|
||||
results.features = geojson.map((result: any) => {
|
||||
const places: {
|
||||
lat: string;
|
||||
lon: string;
|
||||
type: string;
|
||||
display_name: string;
|
||||
}[] = await response.json();
|
||||
results.features = places.map((result) => {
|
||||
return {
|
||||
type: 'Feature',
|
||||
geometry: {
|
||||
type: 'Point',
|
||||
coordinates: [result.lon, result.lat],
|
||||
coordinates: [Number(result.lon), Number(result.lat)],
|
||||
},
|
||||
properties: {},
|
||||
text: result.display_name,
|
||||
place_name: result.display_name,
|
||||
place_type: [result.type],
|
||||
};
|
||||
});
|
||||
} catch (e) {}
|
||||
} catch {}
|
||||
return results;
|
||||
},
|
||||
},
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
type MapLayerMouseEvent,
|
||||
type VectorSourceSpecification,
|
||||
} from 'maplibre-gl';
|
||||
import { Viewer, type ViewerBearingEvent } from 'mapillary-js/dist/mapillary.module';
|
||||
import { Viewer, type ViewerBearingEvent } from 'mapillary-js';
|
||||
import 'mapillary-js/dist/mapillary.css';
|
||||
import { mapCursor, MapCursorState } from '$lib/state/map-cursor';
|
||||
import { ANCHOR_LAYER_KEY } from '$lib/components/map/style';
|
||||
@@ -89,7 +89,7 @@ export class MapillaryLayer {
|
||||
this.viewer.on('position', async () => {
|
||||
if (this.active) {
|
||||
popupOpen.value = true;
|
||||
let latLng = await this.viewer.getPosition();
|
||||
const latLng = await this.viewer.getPosition();
|
||||
this.marker.setLngLat(latLng).addTo(this.map);
|
||||
if (!this.map.getBounds()?.contains(latLng)) {
|
||||
this.map.panTo(latLng);
|
||||
|
||||
@@ -87,7 +87,7 @@ export class StyleManager {
|
||||
updateBasemap() {
|
||||
const map_ = get(this._map);
|
||||
if (!map_) return;
|
||||
let basemap = get(currentBasemap);
|
||||
const basemap = get(currentBasemap);
|
||||
this.buildStyle(basemap).then((style) => {
|
||||
if (get(currentBasemap) === basemap) map_.setStyle(style);
|
||||
});
|
||||
@@ -125,7 +125,7 @@ export class StyleManager {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
console.error(e instanceof Error ? e.message : e);
|
||||
}
|
||||
this.merge(style, basemapStyle);
|
||||
style.sky ??= sky;
|
||||
@@ -148,18 +148,18 @@ export class StyleManager {
|
||||
const overlayOpacities = get(opacities);
|
||||
try {
|
||||
const layers = getLayers(get(currentOverlays) ?? {});
|
||||
for (let overlay in layers) {
|
||||
for (const overlay in layers) {
|
||||
if (!layers[overlay]) {
|
||||
if (this._pastOverlays.has(overlay)) {
|
||||
const overlayInfo = custom[overlay]?.value ?? overlays[overlay];
|
||||
try {
|
||||
const overlayStyle = await this.get(overlayInfo);
|
||||
for (let layer of overlayStyle.layers ?? []) {
|
||||
for (const layer of overlayStyle.layers ?? []) {
|
||||
if (map_.getLayer(layer.id)) {
|
||||
map_.removeLayer(layer.id);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
} catch {
|
||||
// Should not happen
|
||||
}
|
||||
this._pastOverlays.delete(overlay);
|
||||
@@ -170,13 +170,13 @@ export class StyleManager {
|
||||
const overlayStyle = await this.get(overlayInfo);
|
||||
const opacity = overlayOpacities[overlay];
|
||||
|
||||
for (let sourceId in overlayStyle.sources) {
|
||||
for (const sourceId in overlayStyle.sources) {
|
||||
if (!map_.getSource(sourceId)) {
|
||||
map_.addSource(sourceId, overlayStyle.sources[sourceId]);
|
||||
}
|
||||
}
|
||||
|
||||
for (let layer of overlayStyle.layers ?? []) {
|
||||
for (const layer of overlayStyle.layers ?? []) {
|
||||
if (!map_.getLayer(layer.id)) {
|
||||
if (opacity !== undefined) {
|
||||
if (layer.type === 'raster') {
|
||||
@@ -196,11 +196,11 @@ export class StyleManager {
|
||||
}
|
||||
this._pastOverlays.add(overlay);
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
console.error(e instanceof Error ? e.message : e);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
updateTerrain() {
|
||||
@@ -223,7 +223,7 @@ export class StyleManager {
|
||||
|
||||
async get(styleInfo: StyleSpecification | string): Promise<StyleSpecification> {
|
||||
if (typeof styleInfo === 'string') {
|
||||
let styleUrl = styleInfo as string;
|
||||
const styleUrl = styleInfo as string;
|
||||
const response = await fetch(styleUrl, { cache: 'force-cache' });
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error fetching style "${styleInfo}": ${response.status}`);
|
||||
@@ -238,7 +238,7 @@ export class StyleManager {
|
||||
merge(style: StyleSpecification, other: StyleSpecification) {
|
||||
style.sources = { ...style.sources, ...other.sources };
|
||||
const units = get(distanceUnits);
|
||||
for (let layer of other.layers ?? []) {
|
||||
for (const layer of other.layers ?? []) {
|
||||
if ('source' in layer) {
|
||||
if (layer.source == 'contours_m' && units === 'imperial') continue;
|
||||
if (layer.source == 'contours_ft' && units !== 'imperial') continue;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
import { getURLForLanguage } from '$lib/utils';
|
||||
import { Trash2 } from '@lucide/svelte';
|
||||
import { map } from '$lib/components/map/map';
|
||||
import type { GeoJSONSource, LngLat } from 'maplibre-gl';
|
||||
import type { GeoJSONSource, LngLat, MapMouseEvent, MapTouchEvent } from 'maplibre-gl';
|
||||
import { engine } from '$lib/engine';
|
||||
import { mapCursor, MapCursorState } from '$lib/state/map-cursor';
|
||||
import { ANCHOR_LAYER_KEY } from '$lib/components/map/style';
|
||||
@@ -81,18 +81,18 @@
|
||||
});
|
||||
|
||||
let mousedown = false;
|
||||
function onMouseDown(e: any) {
|
||||
function onMouseDown(e: MapMouseEvent | MapTouchEvent) {
|
||||
mousedown = true;
|
||||
rectangleCoordinates = [e.lngLat, e.lngLat];
|
||||
}
|
||||
|
||||
function onMouseMove(e: any) {
|
||||
function onMouseMove(e: MapMouseEvent | MapTouchEvent) {
|
||||
if (mousedown) {
|
||||
rectangleCoordinates[1] = e.lngLat;
|
||||
}
|
||||
}
|
||||
|
||||
function onMouseUp(e: any) {
|
||||
function onMouseUp() {
|
||||
mousedown = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import type { Popup } from 'maplibre-gl';
|
||||
import type { MapMouseEvent, Popup } from 'maplibre-gl';
|
||||
import * as Select from '$lib/components/ui/select';
|
||||
import { Switch } from '$lib/components/ui/switch';
|
||||
import { Label } from '$lib/components/ui/label/index.js';
|
||||
@@ -58,7 +58,7 @@
|
||||
// the tool works on files, routes, tracks and segments, not on waypoints
|
||||
let validSelection = $derived(coversSegments($selection));
|
||||
|
||||
function createFileWithPoint(e: any) {
|
||||
function createFileWithPoint(e: MapMouseEvent) {
|
||||
if ($selection.type === 'empty') {
|
||||
// the engine selects the new file, which starts with the trackpoint: one undo step
|
||||
engine.newFile(newFileName(), { lng: e.lngLat.lng, lat: e.lngLat.lat });
|
||||
@@ -130,7 +130,7 @@
|
||||
{i18n._(`toolbar.routing.activities.${$routingProfile}`)}
|
||||
</Select.Trigger>
|
||||
<Select.Content>
|
||||
{#each Object.keys(routingProfiles) as profile}
|
||||
{#each Object.keys(routingProfiles) as profile (profile)}
|
||||
<Select.Item value={profile}
|
||||
>{i18n._(
|
||||
`toolbar.routing.activities.${profile}`
|
||||
|
||||
@@ -74,7 +74,7 @@ export class RoutingControls {
|
||||
listenedFileIds: string[] = [];
|
||||
popup: Popup;
|
||||
popupElement: HTMLElement;
|
||||
unsubscribes: Function[] = [];
|
||||
unsubscribes: (() => void)[] = [];
|
||||
|
||||
updateBinded: () => void = this.update.bind(this);
|
||||
appendAnchorBinded: (e: MapMouseEvent) => void = this.appendAnchor.bind(this);
|
||||
@@ -270,7 +270,7 @@ export class RoutingControls {
|
||||
layerEventManager.on('mousedown', LAYER_ID, this.onMouseDownBinded);
|
||||
layerEventManager.on('touchstart', LAYER_ID, this.onTouchStartBinded);
|
||||
}
|
||||
} catch (e) {
|
||||
} catch {
|
||||
// No reliable way to check if the map is ready to add sources and layers
|
||||
}
|
||||
}
|
||||
@@ -303,7 +303,7 @@ export class RoutingControls {
|
||||
if (map_?.getSource(LAYER_ID)) {
|
||||
map_?.removeSource(LAYER_ID);
|
||||
}
|
||||
} catch (e) {
|
||||
} catch {
|
||||
// No reliable way to check if the map is ready to remove sources and layers
|
||||
}
|
||||
|
||||
@@ -556,8 +556,9 @@ export class RoutingControls {
|
||||
let response;
|
||||
try {
|
||||
response = await route(targets);
|
||||
} catch (e: any) {
|
||||
toast.error(i18n._(e.message, e.message));
|
||||
} catch (e) {
|
||||
const message = e instanceof Error ? e.message : String(e);
|
||||
toast.error(i18n._(message, message));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -802,7 +803,7 @@ export class RoutingControls {
|
||||
this.moveAnchorFeature(this.anchorWithId(this.anchors.length)!, position);
|
||||
}
|
||||
|
||||
temporaryAnchorCloseToOtherAnchor(e: any) {
|
||||
temporaryAnchorCloseToOtherAnchor(e: MapMouseEvent) {
|
||||
const map_ = get(map);
|
||||
if (!map_) {
|
||||
return false;
|
||||
|
||||
@@ -137,7 +137,7 @@ async function getGraphHopperRoute(
|
||||
graphHopperProfile: string,
|
||||
privateRoads: boolean
|
||||
): Promise<RoutedPoints> {
|
||||
let response = await fetch('https://graphhopper.gpx.studio/route', {
|
||||
const response = await fetch('https://graphhopper.gpx.studio/route', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -222,9 +222,9 @@ async function getBRouterRoute(
|
||||
points: Coordinates[],
|
||||
brouterProfile: string
|
||||
): Promise<RoutedPoints> {
|
||||
let url = `https://brouter.de/brouter?lonlats=${points.map((point) => `${point.lng.toFixed(8)},${point.lat.toFixed(8)}`).join('|')}&profile=${brouterProfile}&format=geojson&alternativeidx=0`;
|
||||
const url = `https://brouter.de/brouter?lonlats=${points.map((point) => `${point.lng.toFixed(8)},${point.lat.toFixed(8)}`).join('|')}&profile=${brouterProfile}&format=geojson&alternativeidx=0`;
|
||||
|
||||
let response = await fetch(url);
|
||||
const response = await fetch(url);
|
||||
|
||||
if (!response.ok) {
|
||||
throw brouterError(await response.text());
|
||||
@@ -289,11 +289,10 @@ export function parseBRouterRoute(geojson: any): RoutedPoints {
|
||||
/** The tags of a way, `key=value` separated by spaces, with the `:` of the keys as `_`. */
|
||||
export function getTags(message: string): { [key: string]: string } {
|
||||
const fields = message.split(' ');
|
||||
let tags: { [key: string]: string } = {};
|
||||
const tags: { [key: string]: string } = {};
|
||||
for (let i = 0; i < fields.length; i++) {
|
||||
let [key, value] = fields[i].split('=');
|
||||
key = key.replace(/:/g, '_');
|
||||
tags[key] = value;
|
||||
const [key, value] = fields[i].split('=');
|
||||
tags[key.replace(/:/g, '_')] = value;
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@
|
||||
{i18n._('gpx.' + $splitAs)}
|
||||
</Select.Trigger>
|
||||
<Select.Content>
|
||||
{#each splitTypes as splitType}
|
||||
{#each splitTypes as splitType (splitType)}
|
||||
<Select.Item value={splitType}>{i18n._('gpx.' + splitType)}</Select.Item>
|
||||
{/each}
|
||||
</Select.Content>
|
||||
|
||||
@@ -12,7 +12,7 @@ export const SplitType = {
|
||||
} as const satisfies Record<string, EngineSplitType>;
|
||||
export type SplitType = (typeof SplitType)[keyof typeof SplitType];
|
||||
|
||||
export let splitAs: Writable<SplitType> = writable(SplitType.FILES);
|
||||
export const splitAs: Writable<SplitType> = writable(SplitType.FILES);
|
||||
|
||||
/** The ids of the segments of the routes of the files of the selection. */
|
||||
export function routeSegmentIds(selection: Selection): Set<string> {
|
||||
|
||||
@@ -23,15 +23,15 @@ import {
|
||||
export class SplitControls {
|
||||
map: Map;
|
||||
layerEventManager: MapLayerEventManager;
|
||||
unsubscribes: Function[] = [];
|
||||
unsubscribes: (() => void)[] = [];
|
||||
/** What the tool needs from the engine, while it shows the anchors. */
|
||||
request: StatisticsRequest = engine.requestStatistics();
|
||||
selection: Selection = { type: 'empty' };
|
||||
statistics: SelectionStatistics | undefined = undefined;
|
||||
|
||||
layerOnMouseEnterBinded: (e: any) => void = this.layerOnMouseEnter.bind(this);
|
||||
layerOnMouseEnterBinded: () => void = this.layerOnMouseEnter.bind(this);
|
||||
layerOnMouseLeaveBinded: () => void = this.layerOnMouseLeave.bind(this);
|
||||
layerOnClickBinded: (e: any) => void = this.layerOnClick.bind(this);
|
||||
layerOnClickBinded: (e: MapLayerMouseEvent) => void = this.layerOnClick.bind(this);
|
||||
|
||||
constructor(map: Map, layerEventManager: MapLayerEventManager) {
|
||||
this.map = map;
|
||||
@@ -116,7 +116,7 @@ export class SplitControls {
|
||||
};
|
||||
|
||||
try {
|
||||
let source = this.map.getSource('split-controls') as GeoJSONSource | undefined;
|
||||
const source = this.map.getSource('split-controls') as GeoJSONSource | undefined;
|
||||
if (source) {
|
||||
source.setData(data);
|
||||
} else {
|
||||
@@ -154,7 +154,7 @@ export class SplitControls {
|
||||
);
|
||||
this.layerEventManager.on('click', 'split-controls', this.layerOnClickBinded);
|
||||
}
|
||||
} catch (e) {
|
||||
} catch {
|
||||
// No reliable way to check if the map is ready to add sources and layers
|
||||
}
|
||||
}
|
||||
@@ -172,12 +172,12 @@ export class SplitControls {
|
||||
if (this.map.getSource('split-controls')) {
|
||||
this.map.removeSource('split-controls');
|
||||
}
|
||||
} catch (e) {
|
||||
} catch {
|
||||
// No reliable way to check if the map is ready to remove sources and layers
|
||||
}
|
||||
}
|
||||
|
||||
layerOnMouseEnter(e: any) {
|
||||
layerOnMouseEnter() {
|
||||
mapCursor.notify(MapCursorState.SPLIT_CONTROL, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
import { selectedWaypoint } from './waypoint';
|
||||
import { map } from '$lib/components/map/map';
|
||||
import { mapCursor, MapCursorState } from '$lib/state/map-cursor';
|
||||
import { Marker } from 'maplibre-gl';
|
||||
import { Marker, type MapMouseEvent } from 'maplibre-gl';
|
||||
import { getSvgForSymbol } from '$lib/components/map/gpx-layer/gpx-layer';
|
||||
|
||||
let props: {
|
||||
@@ -108,7 +108,7 @@
|
||||
reset();
|
||||
}
|
||||
|
||||
function setCoordinates(e: any) {
|
||||
function setCoordinates(e: MapMouseEvent) {
|
||||
if (
|
||||
$map?.queryRenderedFeatures(e.point, {
|
||||
layers: $map.getLayersOrder().filter((layerId) => layerId.endsWith('-waypoints')),
|
||||
@@ -117,8 +117,8 @@
|
||||
// Clicked on a waypoint, ignoring
|
||||
return;
|
||||
}
|
||||
latitude = e.lngLat.lat.toFixed(6);
|
||||
longitude = e.lngLat.lng.toFixed(6);
|
||||
latitude = parseFloat(e.lngLat.lat.toFixed(6));
|
||||
longitude = parseFloat(e.lngLat.lng.toFixed(6));
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
@@ -212,7 +212,7 @@
|
||||
</span>
|
||||
</Select.Trigger>
|
||||
<Select.Content class="max-h-60">
|
||||
{#each sortedSymbols as [key, symbol]}
|
||||
{#each sortedSymbols as [key, symbol] (key)}
|
||||
<Select.Item value={symbol.value}>
|
||||
<span>
|
||||
{#if symbol.icon}
|
||||
|
||||
@@ -56,6 +56,8 @@
|
||||
</script>
|
||||
|
||||
{#if href}
|
||||
<!-- the href comes resolved (or external) from the users of the button -->
|
||||
<!-- eslint-disable svelte/no-navigation-without-resolve -->
|
||||
<a
|
||||
bind:this={ref}
|
||||
data-slot="button"
|
||||
@@ -68,6 +70,7 @@
|
||||
>
|
||||
{@render children?.()}
|
||||
</a>
|
||||
<!-- eslint-enable svelte/no-navigation-without-resolve -->
|
||||
{:else}
|
||||
<button
|
||||
bind:this={ref}
|
||||
|
||||
@@ -101,10 +101,7 @@
|
||||
if (typeof hours === 'string') {
|
||||
hours = parseInt(hours);
|
||||
}
|
||||
if (hours >= 0) {
|
||||
} else if (hours < 0) {
|
||||
hours = 0;
|
||||
} else {
|
||||
if (hours < 0) {
|
||||
hours = 0;
|
||||
}
|
||||
onChange();
|
||||
@@ -124,12 +121,9 @@
|
||||
if (typeof minutes === 'string') {
|
||||
minutes = parseInt(minutes);
|
||||
}
|
||||
if (minutes >= 0 && (minutes <= 59 || !showHours)) {
|
||||
} else if (minutes < 0) {
|
||||
minutes = 0;
|
||||
} else if (showHours && minutes > 59) {
|
||||
if (showHours && minutes > 59) {
|
||||
minutes = 59;
|
||||
} else {
|
||||
} else if (minutes < 0) {
|
||||
minutes = 0;
|
||||
}
|
||||
minutes = minutes.toString().padStart(showHours ? 2 : 1, '0');
|
||||
@@ -149,12 +143,9 @@
|
||||
if (typeof seconds === 'string') {
|
||||
seconds = parseInt(seconds);
|
||||
}
|
||||
if (seconds >= 0 && seconds <= 59) {
|
||||
} else if (seconds < 0) {
|
||||
seconds = 0;
|
||||
} else if (seconds > 59) {
|
||||
if (seconds > 59) {
|
||||
seconds = 59;
|
||||
} else {
|
||||
} else if (seconds < 0) {
|
||||
seconds = 0;
|
||||
}
|
||||
seconds = seconds.toString().padStart(2, '0');
|
||||
|
||||
@@ -96,10 +96,10 @@ function createPattern(
|
||||
size: number = 16,
|
||||
lineWidth: number = 4
|
||||
) {
|
||||
let canvas = document.createElement('canvas');
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = size;
|
||||
canvas.height = size;
|
||||
let ctx = canvas.getContext('2d');
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (ctx) {
|
||||
ctx.fillStyle = backgroundColor;
|
||||
ctx.fillRect(0, 0, size, size);
|
||||
@@ -139,11 +139,11 @@ export function getHighwayColor(
|
||||
sacScale: string | undefined,
|
||||
mtbScale: string | undefined
|
||||
) {
|
||||
let backgroundColor = highwayColors[highway] ? highwayColors[highway] : highwayColors.missing;
|
||||
let sacScaleColor = sacScale ? sacScaleColors[sacScale] : undefined;
|
||||
let mtbScaleColor = mtbScale ? mtbScaleColors[mtbScale] : undefined;
|
||||
const backgroundColor = highwayColors[highway] ? highwayColors[highway] : highwayColors.missing;
|
||||
const sacScaleColor = sacScale ? sacScaleColors[sacScale] : undefined;
|
||||
const mtbScaleColor = mtbScale ? mtbScaleColors[mtbScale] : undefined;
|
||||
if (sacScale || mtbScale) {
|
||||
let patternId = `${backgroundColor}-${[sacScale, mtbScale].filter((x) => x).join('-')}`;
|
||||
const patternId = `${backgroundColor}-${[sacScale, mtbScale].filter((x) => x).join('-')}`;
|
||||
if (!patterns[patternId]) {
|
||||
patterns[patternId] = createPattern(backgroundColor, sacScaleColor, mtbScaleColor);
|
||||
}
|
||||
@@ -164,8 +164,8 @@ export function getSlopeColor(slope: number): string {
|
||||
v = 1 / (1 + Math.exp(-6 * v));
|
||||
v = v - 0.5;
|
||||
|
||||
let hue = ((0.5 - v) * 120).toString(10);
|
||||
let lightness = 90 - Math.abs(v) * 70;
|
||||
const hue = ((0.5 - v) * 120).toString(10);
|
||||
const lightness = 90 - Math.abs(v) * 70;
|
||||
|
||||
return `hsl(${hue},70%,${lightness}%)`;
|
||||
}
|
||||
@@ -794,6 +794,14 @@ export const defaultOpacities: { [key: string]: number } = {
|
||||
|
||||
export type LayerTreeType = { [key: string]: LayerTreeType | boolean };
|
||||
|
||||
/** A node of a layer tree that is a group of layers, not a layer (which is selected or not). */
|
||||
export function layerGroup(node: LayerTreeType | boolean | undefined): LayerTreeType {
|
||||
if (typeof node !== 'object') {
|
||||
throw new Error('Not a group of layers');
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
// Hierarchy containing all basemaps
|
||||
export const basemapTree: LayerTreeType = {
|
||||
basemaps: {
|
||||
@@ -1170,6 +1178,25 @@ export type CustomLayer = {
|
||||
value: string | StyleSpecification;
|
||||
};
|
||||
|
||||
/** Whether a saved value is a custom layer, with all that the layers have had from the start. */
|
||||
export function isCustomLayer(value: unknown): value is CustomLayer {
|
||||
if (typeof value !== 'object' || value === null) {
|
||||
return false;
|
||||
}
|
||||
const layer: Partial<Record<keyof CustomLayer, unknown>> = value;
|
||||
return (
|
||||
typeof layer.id === 'string' &&
|
||||
typeof layer.name === 'string' &&
|
||||
Array.isArray(layer.tileUrls) &&
|
||||
layer.tileUrls.every((url) => typeof url === 'string') &&
|
||||
typeof layer.maxZoom === 'number' &&
|
||||
(layer.layerType === 'basemap' || layer.layerType === 'overlay') &&
|
||||
(layer.resourceType === 'raster' || layer.resourceType === 'vector') &&
|
||||
(typeof layer.value === 'string' ||
|
||||
(typeof layer.value === 'object' && layer.value !== null))
|
||||
);
|
||||
}
|
||||
|
||||
type OverpassQueryData = {
|
||||
icon: {
|
||||
svg: string;
|
||||
|
||||
@@ -51,7 +51,7 @@ By right-clicking on a file tab, you can access the same actions as in the [edit
|
||||
|
||||
As mentioned in the [view options section](./menu/view), you can switch to a tree layout for the files list.
|
||||
This layout is ideal for managing a large number of open files, as it organizes them into a vertical list on the right side of the map.
|
||||
In addition, the file tree view enables you to inspect the [tracks, segments, and points of interest](./gpx) contained inside the files through collapsible sections.
|
||||
In addition, the file tree view enables you to inspect the [tracks, segments, routes, and points of interest](./gpx) contained inside the files through collapsible sections.
|
||||
|
||||
You can also apply [edit actions](./menu/edit) and [tools](./toolbar) to internal file items.
|
||||
Furthermore, you can drag and drop the inner items to reorder them, or move them in the hierarchy or even to another file.
|
||||
|
||||
@@ -3,13 +3,15 @@ title: GPX file format
|
||||
---
|
||||
|
||||
<script>
|
||||
import { Waypoints, MapPin } from '@lucide/svelte';
|
||||
import DocsNote from '$lib/components/docs/DocsNote.svelte';
|
||||
import { Waypoints, Route, MapPin } from '@lucide/svelte';
|
||||
</script>
|
||||
|
||||
# { title }
|
||||
|
||||
The <a href="https://www.topografix.com/gpx.asp" target="_blank">GPX file format</a> is an open standard for exchanging GPS data between applications and GPS devices.
|
||||
It essentially consists of a series of GPS points encoding one or multiple GPS traces, and, optionally, some points of interest.
|
||||
These traces can be stored either as tracks or as routes.
|
||||
|
||||
GPX files may also contain metadata, of which the **name** and **description** fields are the most useful for users.
|
||||
|
||||
@@ -27,6 +29,20 @@ Some devices also store additional information such as heart rate, cadence, temp
|
||||
In most cases, GPX files contain a single track with a single segment.
|
||||
However, the hierarchy described above allows for more advanced use cases, such as planning multi-day trips with several variants for each day.
|
||||
|
||||
### <Route size="16" class="inline-block" style="margin-bottom: 2px" /> Routes
|
||||
|
||||
A **route** is a single continuous path made of a sequence of **route points**.
|
||||
These are mandatory checkpoints, which correspond to the anchor points of the [routing tool](./toolbar/routing).
|
||||
The points in between are only a suggested path connecting the route points.
|
||||
Like a track, a route can have a **name**, a **description**, and **appearance properties**.
|
||||
|
||||
<DocsNote>
|
||||
|
||||
Nowadays, most apps and GPS devices work perfectly well with tracks, even for navigation.
|
||||
However, some of them only work with routes: in that case, you can [convert](./menu/edit) your tracks to routes, or [create](./menu/file) a route file from the start.
|
||||
|
||||
</DocsNote>
|
||||
|
||||
### <MapPin size="16" class="inline-block" style="margin-bottom: 2px" /> Points of interest
|
||||
|
||||
**Points of interest** (technically called *waypoints*) represent locations of interest to show either on a GPS device or on a digital map.
|
||||
|
||||
@@ -3,14 +3,14 @@ title: Edit actions
|
||||
---
|
||||
|
||||
<script lang="ts">
|
||||
import { Undo2, Redo2, Info, PaintBucket, EyeOff, FileStack, ClipboardCopy, Scissors, ClipboardPaste, Trash2, Maximize, Plus } from '@lucide/svelte';
|
||||
import { Undo2, Redo2, Info, PaintBucket, ArrowRightLeft, FileStack, ClipboardCopy, Scissors, ClipboardPaste, Trash2, Plus } from '@lucide/svelte';
|
||||
import DocsNote from '$lib/components/docs/DocsNote.svelte';
|
||||
</script>
|
||||
|
||||
# { title }
|
||||
|
||||
Unlike the file actions, the edit actions can potentially modify the content of the currently selected files.
|
||||
Moreover, when the tree layout of the files list is enabled (see [Files and statistics](../files-and-stats)), they can also be applied to [tracks, segments, and points of interest](../gpx).
|
||||
Moreover, when the tree layout of the files list is enabled (see [Files and statistics](../files-and-stats)), they can also be applied to [tracks, segments, routes, and points of interest](../gpx).
|
||||
Therefore, we will refer to the elements that can be modified by these actions as *file items*.
|
||||
Note that except for the undo and redo actions, the edit actions are also accessible through the context menu (right-click) of the file items.
|
||||
|
||||
@@ -27,10 +27,6 @@ Open the information dialog of the currently selected file item, where you can s
|
||||
|
||||
Open the appearance dialog, where you can change the color, opacity, and width of the selected file items on the map.
|
||||
|
||||
### <EyeOff size="16" class="inline-block" style="margin-bottom: 2px" /> Hide/unhide
|
||||
|
||||
Toggle the visibility of the selected file items on the map.
|
||||
|
||||
### <Plus size="16" class="inline-block" style="margin-bottom: 2px" /> New track
|
||||
|
||||
Create a new track in the selected file.
|
||||
@@ -42,6 +38,17 @@ Additionally, the selection must be a single file.
|
||||
|
||||
</DocsNote>
|
||||
|
||||
### <Plus size="16" class="inline-block" style="margin-bottom: 2px" /> New route
|
||||
|
||||
Create a new route in the selected file.
|
||||
|
||||
<DocsNote>
|
||||
|
||||
This action is only available when the tree layout of the files list is enabled.
|
||||
Additionally, the selection must be a single file.
|
||||
|
||||
</DocsNote>
|
||||
|
||||
### <Plus size="16" class="inline-block" style="margin-bottom: 2px" /> New segment
|
||||
|
||||
Create a new segment in the selected track.
|
||||
@@ -53,14 +60,23 @@ Additionally, the selection must be a single track.
|
||||
|
||||
</DocsNote>
|
||||
|
||||
### <ArrowRightLeft size="16" class="inline-block" style="margin-bottom: 2px" /> Convert to route/track
|
||||
|
||||
Convert the selected routes to tracks, or the selected tracks or segments to routes.
|
||||
Since a route has a single segment, a track with multiple segments is converted into one route per segment.
|
||||
|
||||
When the selected files contain only routes, or only tracks, you can also convert all of them at once.
|
||||
|
||||
<DocsNote>
|
||||
|
||||
Except for whole files, this action is only available when the tree layout of the files list is enabled.
|
||||
|
||||
</DocsNote>
|
||||
|
||||
### <FileStack size="16" class="inline-block" style="margin-bottom: 2px" /> Select all
|
||||
|
||||
Add all file items in the current hierarchy level to the selection.
|
||||
|
||||
### <Maximize size="16" class="inline-block" style="margin-bottom: 2px" /> Center
|
||||
|
||||
Center the map on the selected file items.
|
||||
|
||||
### <ClipboardCopy size="16" class="inline-block" style="margin-bottom: 2px" /> Copy
|
||||
|
||||
Copy the selected file items to the clipboard.
|
||||
|
||||
@@ -15,6 +15,10 @@ The file actions menu contains a set of pretty self-explanatory file operations.
|
||||
|
||||
Create a new empty file.
|
||||
|
||||
### <Plus size="16" class="inline-block" style="margin-bottom: 2px" /> New route file
|
||||
|
||||
Create a new file containing an empty [route](../gpx).
|
||||
|
||||
### <FolderOpen size="16" class="inline-block" style="margin-bottom: 2px" /> Open...
|
||||
|
||||
Open files from your computer.
|
||||
|
||||
@@ -3,7 +3,7 @@ title: View options
|
||||
---
|
||||
|
||||
<script lang="ts">
|
||||
import { ChartArea, ListTree, Map, Layers2, Coins, Milestone, Box, Maximize2 } from '@lucide/svelte';
|
||||
import { ChartArea, ListTree, Map, Layers2, Coins, Milestone, EyeOff, Maximize, Box, Maximize2 } from '@lucide/svelte';
|
||||
import DocsNote from '$lib/components/docs/DocsNote.svelte';
|
||||
</script>
|
||||
|
||||
@@ -19,7 +19,7 @@ Hide the elevation profile to make room for the map, or show it to inspect the c
|
||||
|
||||
Toggle the tree layout for the [file list](../files-and-stats).
|
||||
This layout is ideal for managing a large number of open files, as it organizes them into a vertical list on the right side of the map.
|
||||
In addition, the file tree view enables you to inspect the [tracks, segments, and points of interest](../gpx) contained inside the files through collapsible sections.
|
||||
In addition, the file tree view enables you to inspect the [tracks, segments, routes, and points of interest](../gpx) contained inside the files through collapsible sections.
|
||||
|
||||
### <Map size="16" class="inline-block" style="margin-bottom: 2px" /> Switch to previous basemap
|
||||
|
||||
@@ -38,6 +38,14 @@ They are displayed for the current selection, like the [elevation profile](../fi
|
||||
|
||||
Toggle the visibility of direction arrows on the map.
|
||||
|
||||
### <EyeOff size="16" class="inline-block" style="margin-bottom: 2px" /> Hide/unhide
|
||||
|
||||
Toggle the visibility of the selected file items on the map.
|
||||
|
||||
### <Maximize size="16" class="inline-block" style="margin-bottom: 2px" /> Center
|
||||
|
||||
Center the map on the selected file items.
|
||||
|
||||
### <Box size="16" class="inline-block" style="margin-bottom: 2px" /> Toggle 3D
|
||||
|
||||
Enter or exit the 3D map view.
|
||||
|
||||
@@ -16,7 +16,7 @@ This tool allows you to extract [tracks (or segments)](../gpx) from files (or tr
|
||||
<Extract class="text-foreground p-3 border rounded-md shadow-lg" />
|
||||
</div>
|
||||
|
||||
Applying the tool to a file containing multiple tracks will create a new file for each of the tracks it contains.
|
||||
Applying the tool to a file containing multiple [tracks or routes](../gpx) will create a new file for each of the tracks and routes it contains.
|
||||
Similarly, applying the tool to a track containing multiple segments will create (in the same file) a new track for each of the segments it contains.
|
||||
|
||||
<DocsNote>
|
||||
|
||||
@@ -10,11 +10,11 @@ title: Merge
|
||||
|
||||
# <Group size="24" class="inline-block" style="margin-bottom: 5px" /> { title }
|
||||
|
||||
To use this tool, you need to [select](../files-and-stats) multiple files, [tracks, or segments](../gpx).
|
||||
To use this tool, you need to [select](../files-and-stats) multiple files, [tracks, segments or routes](../gpx).
|
||||
|
||||
- If your goal is to create a single continuous trace from your selection, use the **Connect the traces** option and validate.
|
||||
- The second option can be used to create or manage files with multiple [tracks or segments](../gpx).
|
||||
Merging files (or tracks) will result in a single file (or track) containing all tracks (or segments) from the selection.
|
||||
- The second option can be used to create or manage files with multiple [tracks, segments or routes](../gpx).
|
||||
Merging files (or tracks) will result in a single file (or track) containing all tracks and routes (or segments) from the selection.
|
||||
|
||||
<DocsNote>
|
||||
|
||||
|
||||
@@ -27,6 +27,6 @@ To split the selected trace into two parts, click on one of the split markers di
|
||||
To split at a specific point of your choice, hover over the trace on the map.
|
||||
Scissors will appear at the cursor position, showing that you can split the trace at that point.
|
||||
|
||||
You can choose to split the trace into two GPX files, or to keep the split parts in the same file as [tracks or segments](../gpx).
|
||||
You can choose to split the trace into two GPX files, or to keep the split parts in the same file as [tracks, segments or routes](../gpx).
|
||||
|
||||
<DocsImage src="tools/split" alt="Hovering over the selected trace turns your cursor into scissors." />
|
||||
@@ -1,49 +0,0 @@
|
||||
import { readable } from 'svelte/store';
|
||||
import { engine, FileStateCollectionObserver, type FileState, type Selection } from '$lib/engine';
|
||||
import { isSelectionHidden } from '$lib/engine/selection-helpers';
|
||||
|
||||
/**
|
||||
* Whether all the selected elements are hidden. It follows the selection and, through the
|
||||
* observer of the files, the state of every file (hiding, editing).
|
||||
*/
|
||||
export const allHidden = readable(false, (set) => {
|
||||
let selection: Selection = { type: 'empty' };
|
||||
const states = new Map<string, FileState>();
|
||||
const unsubscribes = new Map<string, () => void>();
|
||||
|
||||
const update = () => set(isSelectionHidden(selection, states));
|
||||
|
||||
const unsubscribeSelection = engine.selection.subscribe(($selection) => {
|
||||
selection = $selection;
|
||||
update();
|
||||
});
|
||||
const observer = new FileStateCollectionObserver(
|
||||
(files) => {
|
||||
files.forEach((store, fileId) => {
|
||||
unsubscribes.set(
|
||||
fileId,
|
||||
store.subscribe(($file) => {
|
||||
states.set(fileId, $file);
|
||||
update();
|
||||
})
|
||||
);
|
||||
});
|
||||
},
|
||||
(fileId) => {
|
||||
unsubscribes.get(fileId)?.();
|
||||
unsubscribes.delete(fileId);
|
||||
states.delete(fileId);
|
||||
update();
|
||||
},
|
||||
() => {
|
||||
unsubscribes.forEach((unsubscribe) => unsubscribe());
|
||||
unsubscribes.clear();
|
||||
states.clear();
|
||||
}
|
||||
);
|
||||
|
||||
return () => {
|
||||
unsubscribeSelection();
|
||||
observer.destroy();
|
||||
};
|
||||
});
|
||||
@@ -143,19 +143,25 @@ describe('errors', () => {
|
||||
});
|
||||
|
||||
describe('selection', () => {
|
||||
/** The selected files, when files are selected. */
|
||||
const selectedFiles = () => {
|
||||
const selection = get(engine.selection);
|
||||
return selection.type === 'file' ? selection.fileIds : [];
|
||||
};
|
||||
|
||||
it('adds and toggles files', async () => {
|
||||
await load('simple', 'with_tracks', 'with_waypoint');
|
||||
const [a, b, c] = get(engine.order);
|
||||
await engine.select([a]);
|
||||
await engine.select([b], 'add');
|
||||
assert.deepEqual(new Set((get(engine.selection) as any).fileIds), new Set([a, b]));
|
||||
assert.deepEqual(new Set(selectedFiles()), new Set([a, b]));
|
||||
await engine.select([a], 'toggle');
|
||||
assert.deepEqual((get(engine.selection) as any).fileIds, [b]);
|
||||
assert.deepEqual(selectedFiles(), [b]);
|
||||
await engine.select([]);
|
||||
assert.deepEqual(get(engine.selection), { type: 'empty' });
|
||||
|
||||
assert.equal(await engine.selectAll(), true);
|
||||
assert.deepEqual(new Set((get(engine.selection) as any).fileIds), new Set([a, b, c]));
|
||||
assert.deepEqual(new Set(selectedFiles()), new Set([a, b, c]));
|
||||
});
|
||||
|
||||
it('selects tracks and segments of a file', async () => {
|
||||
|
||||
@@ -374,7 +374,8 @@ class Engine {
|
||||
|
||||
/**
|
||||
* Converts the selected routes to tracks, or the selected tracks or segments to routes (one
|
||||
* per segment), which are selected. Resolves to `false` when there is nothing to convert.
|
||||
* per segment), which are selected. Selected files with routes only (or tracks only) have all
|
||||
* of them converted. Resolves to `false` when there is nothing to convert.
|
||||
*/
|
||||
convert() {
|
||||
return this.run((b) => b.convert());
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { VisibilityState } from '$lib/engine/file-visibility';
|
||||
import {
|
||||
coversSegments,
|
||||
elementId,
|
||||
fileConversion,
|
||||
hasSelectionWithin,
|
||||
isCovered,
|
||||
isInClipboard,
|
||||
@@ -274,4 +275,41 @@ describe('selection helpers', () => {
|
||||
assert.equal(isSelectionHidden(files('F1', 'F2'), states('F1')), false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('fileConversion', () => {
|
||||
const segment = (id: string) => ({ id, rev: id, length: 2 });
|
||||
const structure = (routes: string[], tracks: string[]): { structure: FileStructure } => ({
|
||||
structure: {
|
||||
id: 'F',
|
||||
name: 'file',
|
||||
waypointsRev: 'rev',
|
||||
waypoints: [],
|
||||
routes: routes.map((id) => ({ id, segment: segment(`${id}-S`) })),
|
||||
tracks: tracks.map((id) => ({ id, segments: [segment(`${id}-S`)] })),
|
||||
},
|
||||
});
|
||||
const states = new Map([
|
||||
['routes', structure(['R1', 'R2'], [])],
|
||||
['tracks', structure([], ['T1'])],
|
||||
['both', structure(['R1'], ['T1'])],
|
||||
['none', structure([], [])],
|
||||
]);
|
||||
|
||||
it('converts files with tracks only to routes, and routes only to tracks', () => {
|
||||
assert.equal(fileConversion(files('tracks'), states), 'route');
|
||||
assert.equal(fileConversion(files('routes'), states), 'track');
|
||||
});
|
||||
|
||||
it('does not convert files with both, neither, or a mix of the two', () => {
|
||||
assert.equal(fileConversion(files('both'), states), undefined);
|
||||
assert.equal(fileConversion(files('none'), states), undefined);
|
||||
assert.equal(fileConversion(files('routes', 'tracks'), states), undefined);
|
||||
assert.equal(fileConversion(files('unknown'), states), undefined);
|
||||
});
|
||||
|
||||
it('only converts files', () => {
|
||||
assert.equal(fileConversion(empty, states), undefined);
|
||||
assert.equal(fileConversion(tracks('T1'), states), undefined);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -247,3 +247,34 @@ export function isSelectionHidden(
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* What the selected files convert to: `'route'` when they all have tracks only (with segments),
|
||||
* `'track'` when they all have routes only, `undefined` otherwise (other selections, files with
|
||||
* both or neither, or a mix of the two). `states` holds the files by id.
|
||||
*/
|
||||
export function fileConversion(
|
||||
selection: Selection,
|
||||
states: ReadonlyMap<string, { structure: FileStructure }>
|
||||
): 'route' | 'track' | undefined {
|
||||
if (selection.type !== 'file' || selection.fileIds.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
const targets = new Set(
|
||||
selection.fileIds.map((fileId) => {
|
||||
const structure = states.get(fileId)?.structure;
|
||||
if (structure === undefined) {
|
||||
return undefined;
|
||||
} else if (structure.routes.length > 0 && structure.tracks.length === 0) {
|
||||
return 'track' as const;
|
||||
} else if (
|
||||
structure.routes.length === 0 &&
|
||||
structure.tracks.some((track) => track.segments.length > 0)
|
||||
) {
|
||||
return 'route' as const;
|
||||
}
|
||||
return undefined;
|
||||
})
|
||||
);
|
||||
return targets.size === 1 ? targets.values().next().value : undefined;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import { readable, type Readable } from 'svelte/store';
|
||||
import { engine, FileStateCollectionObserver, type FileState, type Selection } from '$lib/engine';
|
||||
import { fileConversion, isSelectionHidden } from '$lib/engine/selection-helpers';
|
||||
|
||||
/**
|
||||
* A value computed from the selection and the states of the files. It follows the selection and,
|
||||
* through the observer of the files, the state of every file (hiding, editing).
|
||||
*/
|
||||
function fromSelectionAndFiles<T>(
|
||||
initial: T,
|
||||
compute: (selection: Selection, states: ReadonlyMap<string, FileState>) => T
|
||||
): Readable<T> {
|
||||
return readable(initial, (set) => {
|
||||
let selection: Selection = { type: 'empty' };
|
||||
const states = new Map<string, FileState>();
|
||||
const unsubscribes = new Map<string, () => void>();
|
||||
|
||||
const update = () => set(compute(selection, states));
|
||||
|
||||
const unsubscribeSelection = engine.selection.subscribe(($selection) => {
|
||||
selection = $selection;
|
||||
update();
|
||||
});
|
||||
const observer = new FileStateCollectionObserver(
|
||||
(files) => {
|
||||
files.forEach((store, fileId) => {
|
||||
unsubscribes.set(
|
||||
fileId,
|
||||
store.subscribe(($file) => {
|
||||
states.set(fileId, $file);
|
||||
update();
|
||||
})
|
||||
);
|
||||
});
|
||||
},
|
||||
(fileId) => {
|
||||
unsubscribes.get(fileId)?.();
|
||||
unsubscribes.delete(fileId);
|
||||
states.delete(fileId);
|
||||
update();
|
||||
},
|
||||
() => {
|
||||
unsubscribes.forEach((unsubscribe) => unsubscribe());
|
||||
unsubscribes.clear();
|
||||
states.clear();
|
||||
}
|
||||
);
|
||||
|
||||
return () => {
|
||||
unsubscribeSelection();
|
||||
observer.destroy();
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/** Whether all the selected elements are hidden. */
|
||||
export const allHidden = fromSelectionAndFiles(false, isSelectionHidden);
|
||||
|
||||
/** What the selected files convert to, see `fileConversion`. */
|
||||
export const selectedFilesConversion = fromSelectionAndFiles<'route' | 'track' | undefined>(
|
||||
undefined,
|
||||
fileConversion
|
||||
);
|
||||
@@ -1,5 +1,5 @@
|
||||
import { get, writable, type Readable } from 'svelte/store';
|
||||
import { categoryIntervals, type CategoryIntervals } from '$lib/engine/trackpoint-categories';
|
||||
import type { CategoryIntervals } from '$lib/engine/trackpoint-categories';
|
||||
import type { Backend } from './backend';
|
||||
import {
|
||||
EMPTY_SELECTION_STATISTICS,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Readable } from 'svelte/store';
|
||||
import type { Feature, FeatureCollection, LineString, Point } from 'geojson';
|
||||
import type { FeatureCollection, LineString, Point } from 'geojson';
|
||||
import type { Visibility } from '$lib/engine/file-visibility';
|
||||
import type { CategoryIntervals } from '$lib/engine/trackpoint-categories';
|
||||
import type { FileStructure, GlobalStatistics, SelectionPoint } from 'gpx-wasm';
|
||||
|
||||
@@ -19,18 +19,23 @@ function sources(dir: string): string[] {
|
||||
});
|
||||
}
|
||||
|
||||
function has(dictionary: any, key: string): boolean {
|
||||
let value = dictionary;
|
||||
/** The value at a key (`a.b.c`) of a dictionary, `undefined` if there is none. */
|
||||
function valueAt(dictionary: object, key: string): unknown {
|
||||
let value: unknown = dictionary;
|
||||
for (const part of key.split('.')) {
|
||||
if (value === null || typeof value !== 'object' || !(part in value)) {
|
||||
return false;
|
||||
return undefined;
|
||||
}
|
||||
value = value[part];
|
||||
value = (value as Record<string, unknown>)[part];
|
||||
}
|
||||
return typeof value === 'string';
|
||||
return value;
|
||||
}
|
||||
|
||||
function keysOf(dictionary: any, prefix = ''): string[] {
|
||||
function has(dictionary: object, key: string): boolean {
|
||||
return typeof valueAt(dictionary, key) === 'string';
|
||||
}
|
||||
|
||||
function keysOf(dictionary: object, prefix = ''): string[] {
|
||||
return Object.entries(dictionary).flatMap(([key, value]) =>
|
||||
typeof value === 'object' && value !== null
|
||||
? keysOf(value, `${prefix}${key}.`)
|
||||
@@ -60,7 +65,7 @@ describe('translations', () => {
|
||||
|
||||
it('have no empty text in english', () => {
|
||||
const empty = keysOf(english).filter((key) => {
|
||||
const value = key.split('.').reduce((v: any, part) => v[part], english);
|
||||
const value = valueAt(english, key);
|
||||
return typeof value === 'string' && value.trim() === '';
|
||||
});
|
||||
assert.deepEqual(empty, []);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import fs from 'fs';
|
||||
import { languages } from '$lib/i18n/languages';
|
||||
|
||||
function localizeManifest(manifestTemplateData: any, language: string) {
|
||||
function localizeManifest(manifestTemplateData: Record<string, unknown>, language: string) {
|
||||
const localizedManifestFile = `static/${language}.manifest.webmanifest`;
|
||||
const localizedStringsFile = `src/locales/${language}.json`;
|
||||
const localizedStrings = JSON.parse(fs.readFileSync(localizedStringsFile, 'utf8'));
|
||||
|
||||
@@ -19,7 +19,7 @@ export class BoundsManager {
|
||||
this.fitBoundsOnLoad(Array.from(newFiles.keys()));
|
||||
}
|
||||
},
|
||||
(fileId) => {},
|
||||
() => {},
|
||||
() => {}
|
||||
);
|
||||
}
|
||||
@@ -40,7 +40,7 @@ export class BoundsManager {
|
||||
}
|
||||
});
|
||||
},
|
||||
(fileId) => {},
|
||||
() => {},
|
||||
() => {}
|
||||
);
|
||||
}
|
||||
@@ -51,7 +51,7 @@ export class BoundsManager {
|
||||
this._files.delete(fileId);
|
||||
|
||||
if (file.statistics.bounds) {
|
||||
let bounds = new LngLatBounds([
|
||||
const bounds = new LngLatBounds([
|
||||
file.statistics.bounds.west,
|
||||
file.statistics.bounds.south,
|
||||
file.statistics.bounds.east,
|
||||
|
||||
@@ -36,10 +36,10 @@ export class MapCursor {
|
||||
constructor() {
|
||||
this._states = writable(new Set());
|
||||
this._states.subscribe((states) => {
|
||||
let state = Array.from(states.values()).reduce((max, value) => {
|
||||
const state = Array.from(states.values()).reduce((max, value) => {
|
||||
return value > max ? value : max;
|
||||
}, MapCursorState.DEFAULT);
|
||||
let canvas = get(map)?.getCanvas();
|
||||
const canvas = get(map)?.getCanvas();
|
||||
if (canvas) {
|
||||
canvas.style.cursor = cursorStyles[state];
|
||||
}
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { afterEach, beforeEach, describe, it } from 'node:test';
|
||||
import { get } from 'svelte/store';
|
||||
import type { LayerTreeType } from '$lib/data/layers';
|
||||
import { isCustomLayer, type LayerTreeType } from '$lib/data/layers';
|
||||
import {
|
||||
filterLayerTree,
|
||||
getArrayValidator,
|
||||
getLayerTreeValidator,
|
||||
getLayerValidator,
|
||||
getListValidator,
|
||||
getRecordValidator,
|
||||
getValueValidator,
|
||||
isNumber,
|
||||
isString,
|
||||
Setting,
|
||||
SettingInitOnFirstRead,
|
||||
storedValue,
|
||||
@@ -48,7 +52,9 @@ describe('validators', () => {
|
||||
const validate = getValueValidator(['metric', 'imperial'], 'metric');
|
||||
assert.equal(validate('imperial'), 'imperial');
|
||||
assert.equal(validate('nautical'), 'metric');
|
||||
assert.equal(validate(undefined as any), 'metric');
|
||||
assert.equal(validate(undefined), 'metric');
|
||||
assert.equal(validate(null), 'metric');
|
||||
assert.equal(validate(3), 'metric');
|
||||
const optional = getValueValidator<string | undefined>(['slope', undefined], undefined);
|
||||
assert.equal(optional('slope'), 'slope');
|
||||
assert.equal(optional('other'), undefined);
|
||||
@@ -60,6 +66,48 @@ describe('validators', () => {
|
||||
assert.deepEqual(validate([]), []);
|
||||
});
|
||||
|
||||
it('keeps nothing of a saved value that is not a list', () => {
|
||||
const validate = getArrayValidator(['hr', 'cad', 'power']);
|
||||
for (const saved of [null, 'hr', 3, { 0: 'hr' }]) {
|
||||
assert.deepEqual(validate(saved), []);
|
||||
}
|
||||
});
|
||||
|
||||
it('keeps the items of a list that are what it holds', () => {
|
||||
const validate = getListValidator(isString);
|
||||
assert.deepEqual(validate(['a', 3, null, 'b']), ['a', 'b']);
|
||||
assert.deepEqual(validate('a'), []);
|
||||
});
|
||||
|
||||
it('keeps the entries of a record that are what it holds, else takes the fallback', () => {
|
||||
const fallback = { a: 0.5 };
|
||||
const validate = getRecordValidator(isNumber, fallback);
|
||||
assert.deepEqual(validate({ a: 0.4, b: 'x', c: 1 }), { a: 0.4, c: 1 });
|
||||
for (const saved of [null, 3, ['a'], 'a']) {
|
||||
assert.equal(validate(saved), fallback);
|
||||
}
|
||||
});
|
||||
|
||||
it('recognizes a custom layer', () => {
|
||||
const layer = {
|
||||
id: 'custom-0',
|
||||
name: 'Layer',
|
||||
tileUrls: ['https://tiles/{z}/{x}/{y}.png'],
|
||||
maxZoom: 20,
|
||||
layerType: 'basemap',
|
||||
resourceType: 'raster',
|
||||
value: { version: 8, sources: {}, layers: [] },
|
||||
};
|
||||
assert.ok(isCustomLayer(layer));
|
||||
assert.ok(isCustomLayer({ ...layer, resourceType: 'vector', value: 'https://style.json' }));
|
||||
assert.ok(!isCustomLayer({ ...layer, layerType: 'other' }));
|
||||
assert.ok(!isCustomLayer({ ...layer, tileUrls: [3] }));
|
||||
assert.ok(!isCustomLayer({ ...layer, value: null }));
|
||||
const { name: _name, ...nameless } = layer;
|
||||
assert.ok(!isCustomLayer(nameless));
|
||||
assert.ok(!isCustomLayer(null));
|
||||
});
|
||||
|
||||
it('accepts the known layers, and the custom and extension ones', () => {
|
||||
const validate = getLayerValidator({ libertyTopo: 'url', osm: 'url' }, 'libertyTopo');
|
||||
assert.equal(validate('osm'), 'osm');
|
||||
@@ -67,6 +115,9 @@ describe('validators', () => {
|
||||
assert.equal(validate('extension-some-id'), 'extension-some-id');
|
||||
assert.equal(validate('gone'), 'libertyTopo');
|
||||
assert.equal(validate('toString'), 'libertyTopo');
|
||||
for (const saved of [null, 3, ['osm'], { id: 'osm' }]) {
|
||||
assert.equal(validate(saved), 'libertyTopo');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -116,12 +167,33 @@ describe('layer trees', () => {
|
||||
a: false,
|
||||
b: false,
|
||||
});
|
||||
// a branch saved for a layer, and values that are not choices
|
||||
assert.deepEqual(filterLayerTree({ world: { a: { x: true }, b: 'yes' } }, allowed).world, {
|
||||
a: true,
|
||||
b: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('takes the defaults when what was saved is not a tree', () => {
|
||||
for (const saved of [null, true, 'world', 3, ['world']]) {
|
||||
assert.deepEqual(filterLayerTree(saved, allowed), allowed);
|
||||
}
|
||||
assert.deepEqual(
|
||||
filterLayerTree({ world: null, old: null, other: [true] }, allowed),
|
||||
allowed
|
||||
);
|
||||
});
|
||||
|
||||
it('does not share its branches with the allowed tree', () => {
|
||||
const filtered = filterLayerTree({}, allowed);
|
||||
(filtered.world as LayerTreeType).a = false;
|
||||
assert.equal((allowed.world as LayerTreeType).a, true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Setting', () => {
|
||||
it('has its initial value until it is connected', () => {
|
||||
const setting = new Setting('key', 'initial');
|
||||
const setting = new Setting('key', 'initial', getValueValidator(['initial'], 'initial'));
|
||||
assert.equal(get(setting), 'initial');
|
||||
setting.connect({});
|
||||
assert.equal(get(setting), 'initial');
|
||||
@@ -145,6 +217,19 @@ describe('Setting', () => {
|
||||
assert.deepEqual(saved, {});
|
||||
});
|
||||
|
||||
it('takes a saved boolean or number of the type of its initial value', () => {
|
||||
const flag = new Setting('flag', false);
|
||||
flag.connect({ flag: 'true' });
|
||||
assert.equal(get(flag), true);
|
||||
flag.connect({ flag: '"yes"' });
|
||||
assert.equal(get(flag), false);
|
||||
const size = new SettingInitOnFirstRead('size', 170);
|
||||
size.connect({ size: '240' });
|
||||
assert.equal(get(size), 240);
|
||||
size.connect({ size: 'null' });
|
||||
assert.equal(get(size), 170);
|
||||
});
|
||||
|
||||
it('saves what it is set to, when it changes', () => {
|
||||
const setting = new Setting('key', 1);
|
||||
setting.set(2);
|
||||
@@ -160,13 +245,17 @@ describe('Setting', () => {
|
||||
|
||||
it('always saves objects, which may have been changed in place', () => {
|
||||
const value = { a: 1 };
|
||||
const setting = new Setting('key', value);
|
||||
const setting = new Setting('key', value, getRecordValidator(isNumber, value));
|
||||
setting.set(value);
|
||||
assert.deepEqual(saved, { key: '{"a":1}' });
|
||||
});
|
||||
|
||||
it('forgets what it saved when it has no value', () => {
|
||||
const setting = new Setting<string | undefined>('key', 'x');
|
||||
const setting = new Setting<string | undefined>(
|
||||
'key',
|
||||
'x',
|
||||
getValueValidator<string | undefined>(['x', undefined], undefined)
|
||||
);
|
||||
setting.set(undefined);
|
||||
assert.equal(get(setting), undefined);
|
||||
assert.ok('key' in saved);
|
||||
@@ -187,7 +276,11 @@ describe('Setting', () => {
|
||||
|
||||
describe('SettingInitOnFirstRead', () => {
|
||||
it('has no value until it is connected', () => {
|
||||
const setting = new SettingInitOnFirstRead('key', { a: true });
|
||||
const setting = new SettingInitOnFirstRead(
|
||||
'key',
|
||||
{ a: true },
|
||||
getLayerTreeValidator({ a: true })
|
||||
);
|
||||
assert.equal(get(setting), undefined);
|
||||
setting.connect({});
|
||||
assert.deepEqual(get(setting), { a: true });
|
||||
|
||||
@@ -20,7 +20,7 @@ export function useSettingsStorage(newStorage: SettingsStorage | undefined) {
|
||||
}
|
||||
|
||||
/** Reads the saved value of a setting, `undefined` if there is none or if it cannot be read. */
|
||||
export function storedValue(stored: StoredSettings, key: string): { value: any } | undefined {
|
||||
export function storedValue(stored: StoredSettings, key: string): { value: unknown } | undefined {
|
||||
if (!Object.hasOwn(stored, key)) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -41,6 +41,26 @@ function save(key: string, value: unknown) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a saved value one that the setting can hold: what was saved can be anything (an old
|
||||
* format, a value that is not allowed anymore), the validator checks it.
|
||||
*/
|
||||
export type Validator<V> = (value: unknown) => V;
|
||||
|
||||
/**
|
||||
* The validator of a setting: a boolean or a number can do without one, its saved value is then
|
||||
* checked against the type of its initial value. The other settings say what they can hold: a
|
||||
* string is often one of a few, an object has a shape.
|
||||
*/
|
||||
type ValidatorArgument<V> = [V] extends [boolean] | [number]
|
||||
? [validator?: Validator<V>]
|
||||
: [validator: Validator<V>];
|
||||
|
||||
/** Keeps a saved value that has the type of the initial one (a boolean or a number). */
|
||||
function sameTypeAs<V>(initial: V): Validator<V> {
|
||||
return (value) => (typeof value === typeof initial ? (value as V) : initial);
|
||||
}
|
||||
|
||||
/**
|
||||
* A setting: a store whose value is kept when it changes. `S` is what the store holds, which is
|
||||
* `V` or, for a setting that has no value until it is read, `V | undefined`.
|
||||
@@ -48,9 +68,9 @@ function save(key: string, value: unknown) {
|
||||
abstract class SettingBase<V, S extends V | undefined> {
|
||||
protected _key: string;
|
||||
protected _value: Writable<S>;
|
||||
protected _validator?: (value: V) => V;
|
||||
protected _validator: Validator<V>;
|
||||
|
||||
protected constructor(key: string, initial: S, validator?: (value: V) => V) {
|
||||
protected constructor(key: string, initial: S, validator: Validator<V>) {
|
||||
this._key = key;
|
||||
this._value = writable(initial);
|
||||
this._validator = validator;
|
||||
@@ -59,7 +79,7 @@ abstract class SettingBase<V, S extends V | undefined> {
|
||||
/** The saved value, validated, `undefined` if there is none. */
|
||||
protected saved(stored: StoredSettings): { value: V } | undefined {
|
||||
const saved = storedValue(stored, this._key);
|
||||
return saved && { value: this._validator ? this._validator(saved.value) : saved.value };
|
||||
return saved && { value: this._validator(saved.value) };
|
||||
}
|
||||
|
||||
/** Takes the saved value, if there is one. */
|
||||
@@ -83,8 +103,8 @@ abstract class SettingBase<V, S extends V | undefined> {
|
||||
}
|
||||
|
||||
export class Setting<V> extends SettingBase<V, V> {
|
||||
constructor(key: string, initial: V, validator?: (value: V) => V) {
|
||||
super(key, initial, validator);
|
||||
constructor(key: string, initial: V, ...[validator]: ValidatorArgument<V>) {
|
||||
super(key, initial, validator ?? sameTypeAs(initial));
|
||||
}
|
||||
|
||||
connect(stored: StoredSettings) {
|
||||
@@ -99,8 +119,8 @@ export class Setting<V> extends SettingBase<V, V> {
|
||||
export class SettingInitOnFirstRead<V> extends SettingBase<V, V | undefined> {
|
||||
private _initial: V;
|
||||
|
||||
constructor(key: string, initial: V, validator?: (value: V) => V) {
|
||||
super(key, undefined, validator);
|
||||
constructor(key: string, initial: V, ...[validator]: ValidatorArgument<V>) {
|
||||
super(key, undefined, validator ?? sameTypeAs(initial));
|
||||
this._initial = initial;
|
||||
}
|
||||
|
||||
@@ -114,53 +134,90 @@ export class SettingInitOnFirstRead<V> extends SettingBase<V, V | undefined> {
|
||||
}
|
||||
}
|
||||
|
||||
export function getValueValidator<V>(allowed: V[], fallback: V) {
|
||||
const dict = new Set<V>(allowed);
|
||||
return (value: V) => (dict.has(value) ? value : fallback);
|
||||
/** Whether a value is one of the allowed ones. */
|
||||
function oneOf<V>(allowed: V[]) {
|
||||
const dict = new Set<unknown>(allowed);
|
||||
return (value: unknown): value is V => dict.has(value);
|
||||
}
|
||||
|
||||
export function getArrayValidator<V>(allowed: V[]) {
|
||||
const dict = new Set<V>(allowed);
|
||||
return (value: V[]) => value.filter((v) => dict.has(v));
|
||||
export function getValueValidator<V>(allowed: V[], fallback: V): Validator<V> {
|
||||
const isAllowed = oneOf(allowed);
|
||||
return (value) => (isAllowed(value) ? value : fallback);
|
||||
}
|
||||
|
||||
export function getLayerValidator(allowed: Record<string, any>, fallback: string) {
|
||||
return (layer: string) =>
|
||||
allowed.hasOwnProperty(layer) ||
|
||||
export function isString(value: unknown): value is string {
|
||||
return typeof value === 'string';
|
||||
}
|
||||
|
||||
export function isNumber(value: unknown): value is number {
|
||||
return typeof value === 'number';
|
||||
}
|
||||
|
||||
/** Keeps the items of a saved list that are what it holds, in their order; nothing if it is not a list. */
|
||||
export function getListValidator<V>(isItem: (value: unknown) => value is V): Validator<V[]> {
|
||||
return (value) => (Array.isArray(value) ? value.filter(isItem) : []);
|
||||
}
|
||||
|
||||
/** Keeps the allowed values of a list, in their order; nothing if what was saved is not a list. */
|
||||
export function getArrayValidator<V>(allowed: V[]): Validator<V[]> {
|
||||
return getListValidator(oneOf(allowed));
|
||||
}
|
||||
|
||||
/** Keeps the entries of a saved record that are what it holds; `fallback` if it is not a record. */
|
||||
export function getRecordValidator<V>(
|
||||
isEntry: (value: unknown) => value is V,
|
||||
fallback: Record<string, V>
|
||||
): Validator<Record<string, V>> {
|
||||
return (value) =>
|
||||
isRecord(value)
|
||||
? Object.fromEntries(
|
||||
Object.entries(value).filter((entry): entry is [string, V] => isEntry(entry[1]))
|
||||
)
|
||||
: fallback;
|
||||
}
|
||||
|
||||
export function getLayerValidator(
|
||||
allowed: Record<string, unknown>,
|
||||
fallback: string
|
||||
): Validator<string> {
|
||||
return (layer) =>
|
||||
typeof layer === 'string' &&
|
||||
(Object.hasOwn(allowed, layer) ||
|
||||
layer.startsWith('custom-') ||
|
||||
layer.startsWith('extension-')
|
||||
layer.startsWith('extension-'))
|
||||
? layer
|
||||
: fallback;
|
||||
}
|
||||
|
||||
export function filterLayerTree(
|
||||
t: LayerTreeType,
|
||||
allowed: LayerTreeType | undefined
|
||||
): LayerTreeType {
|
||||
/** Whether a value is a record, which can hold the layers of a tree: an object, not null or a list. */
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* The saved tree `t`, with the layers of `allowed`: the choices saved for them are kept, the new
|
||||
* ones have their default, and of the others only the custom and extension layers are kept.
|
||||
*/
|
||||
export function filterLayerTree(t: unknown, allowed: LayerTreeType | undefined): LayerTreeType {
|
||||
const tree = isRecord(t) ? t : {};
|
||||
const filtered: LayerTreeType = {};
|
||||
if (allowed) {
|
||||
Object.entries(allowed).forEach(([key, value]) => {
|
||||
if (Object.hasOwn(t, key)) {
|
||||
const saved = Object.hasOwn(tree, key) ? tree[key] : undefined;
|
||||
if (typeof value === 'boolean') {
|
||||
filtered[key] = t[key];
|
||||
} else if (typeof value === 'object') {
|
||||
filtered[key] = filterLayerTree(
|
||||
typeof t[key] === 'object' ? t[key] : {},
|
||||
value
|
||||
);
|
||||
}
|
||||
filtered[key] = typeof saved === 'boolean' ? saved : value;
|
||||
} else {
|
||||
filtered[key] = value;
|
||||
filtered[key] = filterLayerTree(saved, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
Object.entries(t).forEach(([key, value]) => {
|
||||
Object.entries(tree).forEach(([key, value]) => {
|
||||
if (!Object.hasOwn(filtered, key)) {
|
||||
if (typeof value === 'boolean') {
|
||||
if (key.startsWith('custom-') || key.startsWith('extension-')) {
|
||||
filtered[key] = value;
|
||||
}
|
||||
} else if (typeof value === 'object') {
|
||||
} else if (isRecord(value)) {
|
||||
filtered[key] = filterLayerTree(value, undefined);
|
||||
}
|
||||
}
|
||||
@@ -168,6 +225,6 @@ export function filterLayerTree(
|
||||
return filtered;
|
||||
}
|
||||
|
||||
export function getLayerTreeValidator(allowed: LayerTreeType) {
|
||||
return (value: LayerTreeType) => filterLayerTree(value, allowed);
|
||||
export function getLayerTreeValidator(allowed: LayerTreeType): Validator<LayerTreeType> {
|
||||
return (value) => filterLayerTree(value, allowed);
|
||||
}
|
||||
@@ -8,9 +8,8 @@ import {
|
||||
defaultOverpassQueries,
|
||||
defaultOverpassTree,
|
||||
defaultTerrainSource,
|
||||
isCustomLayer,
|
||||
overpassTree,
|
||||
type CustomLayer,
|
||||
type LayerTreeType,
|
||||
} from '$lib/data/layers';
|
||||
import { browser } from '$app/environment';
|
||||
import type { DistanceUnits, TemperatureUnits, VelocityUnits } from '$lib/units/conversions';
|
||||
@@ -20,7 +19,11 @@ import {
|
||||
getArrayValidator,
|
||||
getLayerTreeValidator,
|
||||
getLayerValidator,
|
||||
getListValidator,
|
||||
getRecordValidator,
|
||||
getValueValidator,
|
||||
isNumber,
|
||||
isString,
|
||||
Setting,
|
||||
SettingInitOnFirstRead,
|
||||
useSettingsStorage,
|
||||
@@ -137,10 +140,14 @@ export const settings = {
|
||||
defaultOverpassTree,
|
||||
getLayerTreeValidator(overpassTree)
|
||||
),
|
||||
opacities: new Setting('opacities', defaultOpacities),
|
||||
customLayers: new Setting<Record<string, CustomLayer>>('customLayers', {}),
|
||||
customBasemapOrder: new Setting<string[]>('customBasemapOrder', []),
|
||||
customOverlayOrder: new Setting<string[]>('customOverlayOrder', []),
|
||||
opacities: new Setting(
|
||||
'opacities',
|
||||
defaultOpacities,
|
||||
getRecordValidator(isNumber, defaultOpacities)
|
||||
),
|
||||
customLayers: new Setting('customLayers', {}, getRecordValidator(isCustomLayer, {})),
|
||||
customBasemapOrder: new Setting('customBasemapOrder', [], getListValidator(isString)),
|
||||
customOverlayOrder: new Setting('customOverlayOrder', [], getListValidator(isString)),
|
||||
terrainSource: new Setting<TerrainSource>(
|
||||
'terrainSource',
|
||||
defaultTerrainSource,
|
||||
@@ -166,16 +173,14 @@ export const settings = {
|
||||
),
|
||||
/** Takes the saved values (see `Engine.openStorage`). */
|
||||
connect(stored: StoredSettings) {
|
||||
for (const key in settings) {
|
||||
const setting = (settings as any)[key];
|
||||
for (const setting of Object.values(settings)) {
|
||||
if (setting instanceof Setting || setting instanceof SettingInitOnFirstRead) {
|
||||
setting.connect(stored);
|
||||
}
|
||||
}
|
||||
},
|
||||
initialize() {
|
||||
for (const key in settings) {
|
||||
const setting = (settings as any)[key];
|
||||
for (const setting of Object.values(settings)) {
|
||||
if (setting instanceof SettingInitOnFirstRead) {
|
||||
setting.initialize();
|
||||
}
|
||||
|
||||
@@ -40,7 +40,11 @@ describe('getURLForLanguage', () => {
|
||||
describe('cn', () => {
|
||||
it('merges class names, the last tailwind class winning', () => {
|
||||
assert.equal(cn('p-2', 'p-4'), 'p-4');
|
||||
assert.equal(cn('text-sm', false && 'hidden', undefined, 'font-bold'), 'text-sm font-bold');
|
||||
const hidden: boolean = false;
|
||||
assert.equal(
|
||||
cn('text-sm', hidden && 'hidden', undefined, 'font-bold'),
|
||||
'text-sm font-bold'
|
||||
);
|
||||
assert.equal(cn(['a', { b: true, c: false }]), 'a b');
|
||||
});
|
||||
});
|
||||
+35
-28
@@ -1,6 +1,6 @@
|
||||
import { clsx, type ClassValue } from 'clsx';
|
||||
import { twMerge } from 'tailwind-merge';
|
||||
import { base } from '$app/paths';
|
||||
import { resolve } from '$app/paths';
|
||||
import { languages } from '$lib/i18n/languages';
|
||||
import type { Coordinates } from '$lib/geo/coordinates';
|
||||
import { LngLatBounds, type Map as MapLibreMap } from 'maplibre-gl';
|
||||
@@ -22,22 +22,22 @@ export function getElevation(
|
||||
ELEVATION_ZOOM: number = 12,
|
||||
tileSize = 512
|
||||
): Promise<number[]> {
|
||||
let coordinates = points;
|
||||
let bbox = new LngLatBounds();
|
||||
const coordinates = points;
|
||||
const bbox = new LngLatBounds();
|
||||
coordinates.forEach((coord) => bbox.extend(coord));
|
||||
|
||||
let tiles = coordinates.map((coord) => pointToTile(coord.lng, coord.lat, ELEVATION_ZOOM));
|
||||
let uniqueTiles = Array.from(new Set(tiles.map((tile) => tile.join(',')))).map((tile) =>
|
||||
const tiles = coordinates.map((coord) => pointToTile(coord.lng, coord.lat, ELEVATION_ZOOM));
|
||||
const uniqueTiles = Array.from(new Set(tiles.map((tile) => tile.join(',')))).map((tile) =>
|
||||
tile.split(',').map((x) => parseInt(x))
|
||||
);
|
||||
let images = new Map<string, ImageData>();
|
||||
const images = new Map<string, ImageData>();
|
||||
|
||||
const getPixelFromImageData = (imageData: ImageData, x: number, y: number): number[] => {
|
||||
const index = (y * imageData.width + x) * 4;
|
||||
return [imageData.data[index], imageData.data[index + 1], imageData.data[index + 2]];
|
||||
};
|
||||
|
||||
let promises = uniqueTiles.map((tile) =>
|
||||
const promises = uniqueTiles.map((tile) =>
|
||||
fetch(`https://tiles.gpx.studio/mapterhorn/${ELEVATION_ZOOM}/${tile[0]}/${tile[1]}.webp`, {
|
||||
cache: 'force-cache',
|
||||
})
|
||||
@@ -71,20 +71,20 @@ export function getElevation(
|
||||
|
||||
return Promise.all(promises).then(() =>
|
||||
coordinates.map((coord, index) => {
|
||||
let tile = tiles[index];
|
||||
let imageData = images.get(tile.join(','));
|
||||
const tile = tiles[index];
|
||||
const imageData = images.get(tile.join(','));
|
||||
|
||||
if (!imageData) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let tf = pointToTileFraction(coord.lng, coord.lat, ELEVATION_ZOOM);
|
||||
let x = tileSize * (tf[0] - tile[0]);
|
||||
let y = tileSize * (tf[1] - tile[1]);
|
||||
let _x = Math.floor(x);
|
||||
let _y = Math.floor(y);
|
||||
let dx = x - _x;
|
||||
let dy = y - _y;
|
||||
const tf = pointToTileFraction(coord.lng, coord.lat, ELEVATION_ZOOM);
|
||||
const x = tileSize * (tf[0] - tile[0]);
|
||||
const y = tileSize * (tf[1] - tile[1]);
|
||||
const _x = Math.floor(x);
|
||||
const _y = Math.floor(y);
|
||||
const dx = x - _x;
|
||||
const dy = y - _y;
|
||||
|
||||
const p00 = getPixelFromImageData(imageData, _x, _y);
|
||||
const p01 = getPixelFromImageData(imageData, _x, _y + (_y + 1 == tileSize ? 0 : 1));
|
||||
@@ -95,10 +95,10 @@ export function getElevation(
|
||||
_y + (_y + 1 == tileSize ? 0 : 1)
|
||||
);
|
||||
|
||||
let ele00 = -32768 + p00[0] * 256 + p00[1] + p00[2] / 256;
|
||||
let ele01 = -32768 + p01[0] * 256 + p01[1] + p01[2] / 256;
|
||||
let ele10 = -32768 + p10[0] * 256 + p10[1] + p10[2] / 256;
|
||||
let ele11 = -32768 + p11[0] * 256 + p11[1] + p11[2] / 256;
|
||||
const ele00 = -32768 + p00[0] * 256 + p00[1] + p00[2] / 256;
|
||||
const ele01 = -32768 + p01[0] * 256 + p01[1] + p01[2] / 256;
|
||||
const ele10 = -32768 + p10[0] * 256 + p10[1] + p10[2] / 256;
|
||||
const ele11 = -32768 + p11[0] * 256 + p11[1] + p11[2] / 256;
|
||||
|
||||
return (
|
||||
ele00 * (1 - dx) * (1 - dy) +
|
||||
@@ -112,7 +112,7 @@ export function getElevation(
|
||||
|
||||
export function loadSVGIcon(map: MapLibreMap, id: string, svg: string, size: number = 100) {
|
||||
if (!map.hasImage(id)) {
|
||||
let icon = new Image(size, size);
|
||||
const icon = new Image(size, size);
|
||||
icon.onload = () => {
|
||||
if (!map.hasImage(id)) {
|
||||
map.addImage(id, icon);
|
||||
@@ -130,11 +130,19 @@ export function isSafari() {
|
||||
return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
||||
}
|
||||
|
||||
/**
|
||||
* The path of a page in another language, without the base path (pass it to `resolve`). `path` is
|
||||
* the path of the page, with or without the base path.
|
||||
*/
|
||||
export function getURLForLanguage(lang: string, path: string): string {
|
||||
let newPath = path.replace(base, '');
|
||||
const base = resolve('/').slice(0, -1);
|
||||
let newPath =
|
||||
base && (path === base || path.startsWith(`${base}/`))
|
||||
? path.slice(base.length) || '/'
|
||||
: path;
|
||||
|
||||
let languageInPath = newPath.split('/')[1];
|
||||
if (!languages.hasOwnProperty(languageInPath)) {
|
||||
if (!Object.hasOwn(languages, languageInPath)) {
|
||||
languageInPath = 'en';
|
||||
}
|
||||
|
||||
@@ -144,17 +152,16 @@ export function getURLForLanguage(lang: string, path: string): string {
|
||||
|
||||
if (languageInPath === 'en') {
|
||||
if (lang === 'en') {
|
||||
return `${base}${newPath}`;
|
||||
return newPath;
|
||||
} else {
|
||||
return `${base}/${lang}${newPath}`;
|
||||
return `/${lang}${newPath}`;
|
||||
}
|
||||
} else {
|
||||
if (lang === 'en') {
|
||||
newPath = newPath.replace(`/${languageInPath}`, '');
|
||||
return newPath === '' ? `${base}/` : `${base}${newPath}`;
|
||||
return newPath === '' ? '/' : newPath;
|
||||
} else {
|
||||
newPath = newPath.replace(`/${languageInPath}`, `/${lang}`);
|
||||
return `${base}${newPath}`;
|
||||
return newPath.replace(`/${languageInPath}`, `/${lang}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,8 @@
|
||||
"new_route": "New route",
|
||||
"convert_to_route": "Convert to route",
|
||||
"convert_to_track": "Convert to track",
|
||||
"convert_to_routes": "Convert to route file",
|
||||
"convert_to_tracks": "Convert to track file",
|
||||
"new_segment": "New segment",
|
||||
"open": "Open...",
|
||||
"open_folder": "Open folder...",
|
||||
|
||||
@@ -15,9 +15,9 @@ export async function load({ params }) {
|
||||
const { language } = params;
|
||||
|
||||
const guideTitles: Record<string, string> = {};
|
||||
for (let guide of Object.keys(guides)) {
|
||||
for (const guide of Object.keys(guides)) {
|
||||
guideTitles[guide] = (await getModule(language, guide)).metadata.title;
|
||||
for (let subguide of guides[guide]) {
|
||||
for (const subguide of guides[guide]) {
|
||||
guideTitles[`${guide}/${subguide}`] = (
|
||||
await getModule(language, `${guide}/${subguide}`)
|
||||
).metadata.title;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
import Footer from '$lib/components/Footer.svelte';
|
||||
import { onMount, type Snippet } from 'svelte';
|
||||
import { convertOldEmbeddingOptions } from '$lib/components/embedding/embedding';
|
||||
import { base } from '$app/paths';
|
||||
import { resolve } from '$app/paths';
|
||||
import { languages } from '$lib/i18n/languages';
|
||||
import { browser } from '$app/environment';
|
||||
import { goto } from '$app/navigation';
|
||||
@@ -31,7 +31,7 @@
|
||||
let folders = page.url.pathname.split('/');
|
||||
let locale =
|
||||
folders.indexOf('l') >= 0 ? (folders[folders.indexOf('l') + 1] ?? 'en') : 'en';
|
||||
window.location.href = `${getURLForLanguage(locale, '/embed')}?options=${encodeURIComponent(JSON.stringify(convertOldEmbeddingOptions(page.url.searchParams)))}`;
|
||||
window.location.href = `${resolve(getURLForLanguage(locale, '/embed'))}?options=${encodeURIComponent(JSON.stringify(convertOldEmbeddingOptions(page.url.searchParams)))}`;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -40,10 +40,10 @@
|
||||
if (page.params.language) {
|
||||
let lang = page.params.language.replace('/', '');
|
||||
if (i18n.lang !== lang) {
|
||||
if (languages.hasOwnProperty(lang)) {
|
||||
if (Object.hasOwn(languages, lang)) {
|
||||
i18n.lang = lang;
|
||||
} else if (browser) {
|
||||
goto(`${base}/404`);
|
||||
goto(resolve('/404'));
|
||||
}
|
||||
}
|
||||
} else if (i18n.lang !== 'en') {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { resolve } from '$app/paths';
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
import Logo from '$lib/components/Logo.svelte';
|
||||
import { getURLForLanguage } from '$lib/utils';
|
||||
@@ -12,7 +13,7 @@
|
||||
<Logo class="h-40 my-3 animate-spin" style="animation-duration: 20000ms" iconOnly={true} />
|
||||
<div class="w-full flex flex-row flex-wrap gap-3 justify-center">
|
||||
<Button
|
||||
href={getURLForLanguage(i18n.lang, '/')}
|
||||
href={resolve(getURLForLanguage(i18n.lang, '/'))}
|
||||
class="text-base w-1/4 min-w-fit rounded-full"
|
||||
>
|
||||
<House size="18" />
|
||||
@@ -20,14 +21,14 @@
|
||||
</Button>
|
||||
<Button
|
||||
data-sveltekit-reload
|
||||
href={getURLForLanguage(i18n.lang, '/app')}
|
||||
href={resolve(getURLForLanguage(i18n.lang, '/app'))}
|
||||
class="text-base w-1/4 min-w-fit rounded-full"
|
||||
>
|
||||
<Map size="18" />
|
||||
{i18n._('homepage.app')}
|
||||
</Button>
|
||||
<Button
|
||||
href={getURLForLanguage(i18n.lang, '/help')}
|
||||
href={resolve(getURLForLanguage(i18n.lang, '/help'))}
|
||||
class="text-base w-1/4 min-w-fit rounded-full"
|
||||
>
|
||||
<BookOpenText size="18" />
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { resolve } from '$app/paths';
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
import ElevationProfile from '$lib/components/elevation-profile/ElevationProfile.svelte';
|
||||
import GPXStatistics from '$lib/components/GPXStatistics.svelte';
|
||||
@@ -58,7 +59,7 @@
|
||||
<div class="w-full flex flex-row xs:justify-center gap-3">
|
||||
<Button
|
||||
data-sveltekit-reload
|
||||
href={getURLForLanguage(i18n.lang, '/app')}
|
||||
href={resolve(getURLForLanguage(i18n.lang, '/app'))}
|
||||
class="w-1/3 min-w-fit"
|
||||
>
|
||||
<Map size="18" />
|
||||
@@ -66,7 +67,7 @@
|
||||
</Button>
|
||||
<Button
|
||||
variant="secondary"
|
||||
href={getURLForLanguage(i18n.lang, '/help')}
|
||||
href={resolve(getURLForLanguage(i18n.lang, '/help'))}
|
||||
class="w-1/3 min-w-fit"
|
||||
>
|
||||
<BookOpenText size="18" />
|
||||
@@ -74,7 +75,10 @@
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<a href={getURLForLanguage(i18n.lang, '/app')} aria-label="Link to the web app.">
|
||||
<a
|
||||
href={resolve(getURLForLanguage(i18n.lang, '/app'))}
|
||||
aria-label="Link to the web app."
|
||||
>
|
||||
<enhanced:img
|
||||
src="/src/lib/assets/img/docs/getting-started/interface.webp"
|
||||
alt="The gpx.studio interface."
|
||||
@@ -145,7 +149,7 @@
|
||||
{elevationFill}
|
||||
/>
|
||||
</div>
|
||||
<GPXStatistics {statistics} {slicedStatistics} orientation={'horizontal'} />
|
||||
<GPXStatistics {statistics} {slicedStatistics} orientation="horizontal" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid md:grid-rows-subgrid md:row-start-3 md:row-end-5 gap-4">
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { resolve } from '$app/paths';
|
||||
import GPXLayers from '$lib/components/map/gpx-layer/GPXLayers.svelte';
|
||||
import ElevationProfile from '$lib/components/elevation-profile/ElevationProfile.svelte';
|
||||
import FileList from '$lib/components/file-list/FileList.svelte';
|
||||
@@ -79,7 +80,9 @@
|
||||
const saved = get(settings.language);
|
||||
if (saved !== undefined && saved !== language) {
|
||||
await goto(
|
||||
`${getURLForLanguage(saved, page.url.pathname)}${page.url.search}${page.url.hash}`,
|
||||
resolve(
|
||||
`${getURLForLanguage(saved, page.url.pathname)}${page.url.search}${page.url.hash}`
|
||||
),
|
||||
{ replaceState: true }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { resolve } from '$app/paths';
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
import AlgoliaDocSearch from '$lib/components/AlgoliaDocSearch.svelte';
|
||||
import { getURLForLanguage } from '$lib/utils';
|
||||
@@ -24,10 +25,10 @@
|
||||
<div class="mb-2">
|
||||
<AlgoliaDocSearch />
|
||||
</div>
|
||||
{#each Object.keys(guides) as guide}
|
||||
{#each Object.keys(guides) as guide (guide)}
|
||||
<Button
|
||||
variant="link"
|
||||
href={getURLForLanguage(i18n.lang, `/help/${guide}`)}
|
||||
href={resolve(getURLForLanguage(i18n.lang, `/help/${guide}`))}
|
||||
class="min-h-5 h-fit p-0 w-fit border-none text-muted-foreground hover:text-foreground hover:no-underline font-normal hover:font-semibold items-start whitespace-normal {page
|
||||
.params.guide === guide
|
||||
? 'font-semibold text-foreground'
|
||||
@@ -35,10 +36,10 @@
|
||||
>
|
||||
{data.guideTitles[guide]}
|
||||
</Button>
|
||||
{#each guides[guide] as subGuide}
|
||||
{#each guides[guide] as subGuide (subGuide)}
|
||||
<Button
|
||||
variant="link"
|
||||
href={getURLForLanguage(i18n.lang, `/help/${guide}/${subGuide}`)}
|
||||
href={resolve(getURLForLanguage(i18n.lang, `/help/${guide}/${subGuide}`))}
|
||||
class="min-h-5 h-fit p-0 w-fit border-none text-muted-foreground hover:text-foreground hover:no-underline font-normal hover:font-semibold items-start whitespace-normal ml-3 {page
|
||||
.params.guide ===
|
||||
guide + '/' + subGuide
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { resolve } from '$app/paths';
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
import { getURLForLanguage } from '$lib/utils';
|
||||
import { i18n } from '$lib/i18n/i18n.svelte';
|
||||
@@ -14,10 +15,10 @@
|
||||
</script>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3">
|
||||
{#each Object.keys(guides) as guide}
|
||||
{#each Object.keys(guides) as guide (guide)}
|
||||
<Button
|
||||
variant="outline"
|
||||
href={getURLForLanguage(i18n.lang, `/help/${guide}`)}
|
||||
href={resolve(getURLForLanguage(i18n.lang, `/help/${guide}`))}
|
||||
class="min-h-36 h-full pt-6 pb-3 px-0"
|
||||
>
|
||||
<div class="flex flex-col w-full">
|
||||
@@ -28,10 +29,12 @@
|
||||
{data.guideTitles[guide]}
|
||||
</div>
|
||||
<div class="flex flex-row justify-center flex-wrap gap-x-6 px-6">
|
||||
{#each guides[guide] as subGuide}
|
||||
{#each guides[guide] as subGuide (subGuide)}
|
||||
<Button
|
||||
variant="link"
|
||||
href={getURLForLanguage(i18n.lang, `/help/${guide}/${subGuide}`)}
|
||||
href={resolve(
|
||||
getURLForLanguage(i18n.lang, `/help/${guide}/${subGuide}`)
|
||||
)}
|
||||
class="min-h-8 h-fit min-w-24 px-0 py-1 text-muted-foreground text-base text-center whitespace-normal"
|
||||
>
|
||||
{#if typeof guideIcons[subGuide] === 'string'}
|
||||
|
||||
@@ -3,14 +3,14 @@ import { guides } from '$lib/components/docs/docs';
|
||||
import type { EntryGenerator } from './$types';
|
||||
|
||||
export const entries: EntryGenerator = () => {
|
||||
let entries = [];
|
||||
for (let lang of Object.keys(languages)) {
|
||||
for (let guide of Object.keys(guides)) {
|
||||
const entries = [];
|
||||
for (const lang of Object.keys(languages)) {
|
||||
for (const guide of Object.keys(guides)) {
|
||||
entries.push({
|
||||
language: lang == 'en' ? '' : lang,
|
||||
guide,
|
||||
});
|
||||
for (let subguide of guides[guide]) {
|
||||
for (const subguide of guides[guide]) {
|
||||
entries.push({
|
||||
language: lang == 'en' ? '' : lang,
|
||||
guide: `${guide}/${subguide}`,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { resolve } from '$app/paths';
|
||||
import { page } from '$app/state';
|
||||
import { getNextGuide, getPreviousGuide } from '$lib/components/docs/docs';
|
||||
import DocsContainer from '$lib/components/docs/DocsContainer.svelte';
|
||||
@@ -6,11 +7,15 @@
|
||||
import { getURLForLanguage } from '$lib/utils';
|
||||
import { ChevronLeft, ChevronRight, PenLine, CornerDownRight } from '@lucide/svelte';
|
||||
import { i18n } from '$lib/i18n/i18n.svelte';
|
||||
import type { Component } from 'svelte';
|
||||
|
||||
let { data }: { data: { guideModule: any; guideTitles: Record<string, string> } } = $props();
|
||||
let {
|
||||
data,
|
||||
}: { data: { guideModule: { default: Component }; guideTitles: Record<string, string> } } =
|
||||
$props();
|
||||
|
||||
let previousGuide = $derived(getPreviousGuide(page.params.guide));
|
||||
let nextGuide = $derived(getNextGuide(page.params.guide));
|
||||
let previousGuide = $derived(getPreviousGuide(page.params.guide ?? ''));
|
||||
let nextGuide = $derived(getNextGuide(page.params.guide ?? ''));
|
||||
</script>
|
||||
|
||||
<div class="markdown flex flex-col gap-3">
|
||||
@@ -22,7 +27,7 @@
|
||||
<Button
|
||||
variant="outline"
|
||||
class="mr-auto"
|
||||
href={getURLForLanguage(i18n.lang, `/help/${previousGuide}`)}
|
||||
href={resolve(getURLForLanguage(i18n.lang, `/help/${previousGuide}`))}
|
||||
>
|
||||
<ChevronLeft size="14" class="mt-0.5" />
|
||||
{data.guideTitles[previousGuide]}
|
||||
@@ -32,7 +37,7 @@
|
||||
<Button
|
||||
variant="outline"
|
||||
class="ml-auto"
|
||||
href={getURLForLanguage(i18n.lang, `/help/${nextGuide}`)}
|
||||
href={resolve(getURLForLanguage(i18n.lang, `/help/${nextGuide}`))}
|
||||
>
|
||||
{data.guideTitles[nextGuide]}
|
||||
<ChevronRight size="14" class="mt-0.5" />
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export const base = '';
|
||||
export const assets = '';
|
||||
export function resolve(path: string) {
|
||||
return path;
|
||||
}
|
||||
export function asset(file: string) {
|
||||
return file;
|
||||
}
|
||||
@@ -47,4 +47,8 @@ export default defineConfig({
|
||||
wasm(),
|
||||
sveltekit(),
|
||||
],
|
||||
ssr: {
|
||||
// their main entry is UMD, which has no named exports in Node: bundle their ESM build instead
|
||||
noExternal: ['mapillary-js', 'sortablejs'],
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user