mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-03-15 17:22:59 +00:00
Compare commits
663 Commits
117c46341b
...
maplibre
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9ca75e2e8 | ||
|
|
091f6a3ed0 | ||
|
|
d6c9fb1025 | ||
|
|
88abd72a41 | ||
|
|
1137e851ce | ||
|
|
b8c1500aad | ||
|
|
bfd0d90abc | ||
|
|
dba01e1826 | ||
|
|
2189c76edd | ||
|
|
6f8c9d66db | ||
|
|
9408ce10c7 | ||
|
|
9895c3c304 | ||
|
|
0ab3b77db8 | ||
|
|
d13e7e7a0a | ||
|
|
e96b544a75 | ||
|
|
375204c379 | ||
|
|
d76c03af4f | ||
|
|
200a6586ba | ||
|
|
f0f1ecb2df | ||
|
|
2eb6ef6f03 | ||
|
|
f7c0805161 | ||
|
|
4e18e3c8a0 | ||
|
|
59f31caf26 | ||
|
|
f24956c58d | ||
|
|
9019317e5c | ||
|
|
2a0227c1de | ||
|
|
f70db42b91 | ||
|
|
9cd87742f0 | ||
|
|
5dcb93ca5d | ||
|
|
256d62b29b | ||
|
|
595ea8e2d3 | ||
|
|
d3e733aa3e | ||
|
|
a011768d2d | ||
|
|
4b45b5d716 | ||
|
|
ebe9681c12 | ||
|
|
51c85e4cd5 | ||
|
|
2e171dfbee | ||
|
|
a6a3917986 | ||
|
|
21f2448213 | ||
|
|
e7a1d0488b | ||
|
|
22b8e0edb4 | ||
|
|
d062a38e8f | ||
|
|
affa59130f | ||
|
|
3c816567bc | ||
|
|
e92e48ffde | ||
|
|
4ce7777b86 | ||
|
|
bc130ad867 | ||
|
|
867b6a6ac7 | ||
|
|
e585fd084c | ||
|
|
b47bb4a771 | ||
|
|
9cff71fed3 | ||
|
|
e76040e416 | ||
|
|
1facf50621 | ||
|
|
57f3cc8bc0 | ||
|
|
1ab3fe1c4a | ||
|
|
10cff632fd | ||
|
|
4105687c0a | ||
|
|
8fe6565527 | ||
|
|
69b018022d | ||
|
|
467cb2e589 | ||
|
|
f13d8c1e22 | ||
|
|
e230d55b82 | ||
|
|
46fcdb4bb2 | ||
|
|
429212ef23 | ||
|
|
4ea0ea6a7a | ||
|
|
2e3ce83605 | ||
|
|
fda908dd0d | ||
|
|
cad77e2b10 | ||
|
|
3542a7c24d | ||
|
|
0d6d161e23 | ||
|
|
89a2e0086b | ||
|
|
cd443faf61 | ||
|
|
bfc56b02a8 | ||
|
|
25bafc6bf1 | ||
|
|
6387580626 | ||
|
|
09b8aa65fc | ||
|
|
6c15193f32 | ||
|
|
4442e29b66 | ||
|
|
b6f96d9f4d | ||
|
|
36b66100f9 | ||
|
|
49d8143cc6 | ||
|
|
fc279fecaf | ||
|
|
bd307daa57 | ||
|
|
7a72f44722 | ||
|
|
8e63fc6946 | ||
|
|
3a65f8dc16 | ||
|
|
d624352a0b | ||
|
|
3fb597a774 | ||
|
|
85e46bc524 | ||
|
|
d3790878b3 | ||
|
|
e648e50f1b | ||
|
|
cb6cede0b6 | ||
|
|
a0157ddc2a | ||
|
|
8f595fbc7b | ||
|
|
2e3b22c5fa | ||
|
|
42b968372b | ||
|
|
415e7b492f | ||
|
|
2ea8e46723 | ||
|
|
977c6c6dde | ||
|
|
1e5db9dc6c | ||
|
|
252dc10e61 | ||
|
|
f9e2315ba1 | ||
|
|
0eca588280 | ||
|
|
33523bbfb9 | ||
|
|
110f23bdf1 | ||
|
|
50a5cb23f5 | ||
|
|
30e72db5ea | ||
|
|
c4c64c8fe8 | ||
|
|
df39350d7d | ||
|
|
5daacd3ed4 | ||
|
|
0f7f64fb2f | ||
|
|
b09a1fdcb7 | ||
|
|
e5d45dee3a | ||
|
|
f3270e19df | ||
|
|
1b9ad41c87 | ||
|
|
8c3365ef24 | ||
|
|
db5cbffb70 | ||
|
|
c6586f0eed | ||
|
|
f40bdc8ed9 | ||
|
|
683ac4e118 | ||
|
|
88c9abb78e | ||
|
|
1729a2f734 | ||
|
|
e5ad8bbb70 | ||
|
|
7f6acbfdbc | ||
|
|
2e070529e0 | ||
|
|
f4b31e5f0a | ||
|
|
f7f093a464 | ||
|
|
95cc340de5 | ||
|
|
51a003c816 | ||
|
|
977152139f | ||
|
|
c6798dbcd5 | ||
|
|
78833df95e | ||
|
|
099d941d2e | ||
|
|
ea58f378a9 | ||
|
|
4060884909 | ||
|
|
d9277c11d2 | ||
|
|
bcbc90820a | ||
|
|
e9caa95673 | ||
|
|
9cd6703b05 | ||
|
|
4233bd7771 | ||
|
|
0e2db441f2 | ||
|
|
571b101ea4 | ||
|
|
0b9dca61ab | ||
|
|
d8fa76d076 | ||
|
|
6116eef513 | ||
|
|
fabe987f2c | ||
|
|
af20880f37 | ||
|
|
44eeab0d4b | ||
|
|
b331900158 | ||
|
|
d74380404c | ||
|
|
3833a9cd6b | ||
|
|
74fdd943c9 | ||
|
|
ad5b772502 | ||
|
|
9bc941aa31 | ||
|
|
705df43047 | ||
|
|
b31e3bb710 | ||
|
|
4082d0a368 | ||
|
|
ce85286cdf | ||
|
|
415cf1a777 | ||
|
|
f249919ec8 | ||
|
|
054c9787d3 | ||
|
|
c1e88e2b5a | ||
|
|
f5efeb16c4 | ||
|
|
59afae7bca | ||
|
|
92c6339064 | ||
|
|
582ae233f2 | ||
|
|
3c3016a211 | ||
|
|
e24e1d9d3c | ||
|
|
85fb564be7 | ||
|
|
18f7db9eee | ||
|
|
ea0770fd11 | ||
|
|
9c28fab3f9 | ||
|
|
bac332a8c4 | ||
|
|
86d2542bd9 | ||
|
|
5f63ec884f | ||
|
|
0f87b33354 | ||
|
|
c7dc99a12f | ||
|
|
05c3c3f8f3 | ||
|
|
2437a43471 | ||
|
|
16cd812ba0 | ||
|
|
c036128720 | ||
|
|
645db15848 | ||
|
|
21e142ffc3 | ||
|
|
23a6b3db72 | ||
|
|
b87d109625 | ||
|
|
651bd295b9 | ||
|
|
01607e92b9 | ||
|
|
f40d54adbb | ||
|
|
60fb387495 | ||
|
|
a7df18723c | ||
|
|
4e39cc937a | ||
|
|
fe513c17ab | ||
|
|
f7fb88ed3d | ||
|
|
b3247c7cbe | ||
|
|
d490dc0a8b | ||
|
|
97e79c23f6 | ||
|
|
7803a29875 | ||
|
|
08093beed1 | ||
|
|
ae46ae89bc | ||
|
|
f7977dca39 | ||
|
|
0b344f3e08 | ||
|
|
6058154eca | ||
|
|
941016f04b | ||
|
|
7a15898087 | ||
|
|
6b4effa90f | ||
|
|
77d56e4a4c | ||
|
|
c4dd622e7b | ||
|
|
9f24535142 | ||
|
|
a45161fcb8 | ||
|
|
4379763a73 | ||
|
|
a25b376dfd | ||
|
|
fb429f6777 | ||
|
|
ae33227c3a | ||
|
|
2fedc61d1e | ||
|
|
6988a36dd1 | ||
|
|
60e1124970 | ||
|
|
a007684006 | ||
|
|
090a709522 | ||
|
|
9e06655214 | ||
|
|
3651825e79 | ||
|
|
dcf3160b58 | ||
|
|
fd014f42cd | ||
|
|
a760f2f7fc | ||
|
|
262c114b7d | ||
|
|
c90bdd83bb | ||
|
|
fdb2d37b12 | ||
|
|
7951837ecf | ||
|
|
d2e112a672 | ||
|
|
90e86077ba | ||
|
|
f69dfcdefe | ||
|
|
5cff7c4e72 | ||
|
|
0eaa833cdf | ||
|
|
db015d925e | ||
|
|
69fd47601e | ||
|
|
17521574f0 | ||
|
|
56650a76ae | ||
|
|
984a98e792 | ||
|
|
49eb0cf202 | ||
|
|
8e24a6b036 | ||
|
|
d07bf6d699 | ||
|
|
877d12c676 | ||
|
|
ca629f625a | ||
|
|
087dd9a4b6 | ||
|
|
d9a967c072 | ||
|
|
6d522c82c3 | ||
|
|
867af98083 | ||
|
|
1be058d831 | ||
|
|
71bc044ae5 | ||
|
|
d660c50ade | ||
|
|
3fd733d903 | ||
|
|
7703b2361d | ||
|
|
68fdb9ebc6 | ||
|
|
b6513343be | ||
|
|
cc95ff1c55 | ||
|
|
c954ee0fde | ||
|
|
1ada5e5d18 | ||
|
|
f5244c3d93 | ||
|
|
1f17776cd4 | ||
|
|
ebd4f36f94 | ||
|
|
dbb9b5f254 | ||
|
|
4301472cb2 | ||
|
|
15e7954321 | ||
|
|
32d1de08e9 | ||
|
|
ea88663dce | ||
|
|
97aecaf890 | ||
|
|
b16688e1b7 | ||
|
|
5ac856251b | ||
|
|
62a9aacd85 | ||
|
|
dff0b55a8c | ||
|
|
3b21c75b13 | ||
|
|
2c7cc4b8e5 | ||
|
|
bcf8c0e35c | ||
|
|
11d2936fca | ||
|
|
5e84429e24 | ||
|
|
48c88b2d7e | ||
|
|
e5185c0b77 | ||
|
|
15773d3aba | ||
|
|
b577837446 | ||
|
|
324e234b2a | ||
|
|
d40fefb0ea | ||
|
|
7e05568549 | ||
|
|
0249a52d1c | ||
|
|
5df1c5b09b | ||
|
|
953ec8fe31 | ||
|
|
6054afebdc | ||
|
|
04f356e119 | ||
|
|
a6ebefbb30 | ||
|
|
9a1edbe1fa | ||
|
|
c46d74be54 | ||
|
|
72e949586a | ||
|
|
68dacad741 | ||
|
|
7e6505ca73 | ||
|
|
362d83f504 | ||
|
|
e4879736b7 | ||
|
|
68fe6628c7 | ||
|
|
f39ef569be | ||
|
|
42c199376a | ||
|
|
cd6b774a8c | ||
|
|
62598f94f8 | ||
|
|
aa3b46141f | ||
|
|
dcaa2aaeab | ||
|
|
e36f5e47da | ||
|
|
578d7b41b4 | ||
|
|
c4f81ce279 | ||
|
|
02a7dbea85 | ||
|
|
0305d3fe36 | ||
|
|
84fd034197 | ||
|
|
61b48e2048 | ||
|
|
c91f85389c | ||
|
|
f3683355a9 | ||
|
|
a86da886f4 | ||
|
|
7bf8d42eb8 | ||
|
|
88533e29b9 | ||
|
|
8299dcc881 | ||
|
|
0d0c250fea | ||
|
|
eb8d86616b | ||
|
|
1edc90810f | ||
|
|
c011d84a35 | ||
|
|
b97f62ac12 | ||
|
|
200a38bdc0 | ||
|
|
e12c53a90e | ||
|
|
7892916f56 | ||
|
|
5d681beab3 | ||
|
|
a54a2affb3 | ||
|
|
120062bb85 | ||
|
|
a0754d2bd7 | ||
|
|
f4b13a84d4 | ||
|
|
1c98e27e4d | ||
|
|
6067e25df8 | ||
|
|
304c50a247 | ||
|
|
274ad8eac2 | ||
|
|
9946a3fc0e | ||
|
|
622d6db968 | ||
|
|
d756ce0656 | ||
|
|
316e776355 | ||
|
|
f861b7ad99 | ||
|
|
01382e98f3 | ||
|
|
3371442bbc | ||
|
|
a81a804364 | ||
|
|
b24cf5c946 | ||
|
|
3d60213644 | ||
|
|
a23822c9df | ||
|
|
9fa69758f1 | ||
|
|
c892d3f134 | ||
|
|
73271501dc | ||
|
|
a62ea520e7 | ||
|
|
a2a0b3c71e | ||
|
|
51bedbe003 | ||
|
|
7062a3e657 | ||
|
|
209d95d5da | ||
|
|
95ee74ab2b | ||
|
|
9f6b268dce | ||
|
|
96e8ebcc10 | ||
|
|
ca261c7037 | ||
|
|
a95fe13b31 | ||
|
|
c3fe76adf9 | ||
|
|
e9b9d51a6e | ||
|
|
aff66205e9 | ||
|
|
aa0c9d65ae | ||
|
|
423bd2122f | ||
|
|
7533910114 | ||
|
|
0d4d377c22 | ||
|
|
3a576b3ea5 | ||
|
|
27f37744a0 | ||
|
|
012ecad0bb | ||
|
|
49b5d5e961 | ||
|
|
01ca48fe96 | ||
|
|
5abe5045b2 | ||
|
|
8c79a577b9 | ||
|
|
5b18f1016f | ||
|
|
bda58312bb | ||
|
|
eff352a003 | ||
|
|
3109d4ff82 | ||
|
|
c44eda3af6 | ||
|
|
33e8c41c6f | ||
|
|
e0b515ba2b | ||
|
|
c6b6ad41fb | ||
|
|
99576238cd | ||
|
|
db712650ef | ||
|
|
d77e7b07eb | ||
|
|
47b35fad3f | ||
|
|
720105ca92 | ||
|
|
ce656068e3 | ||
|
|
e69ba76e7d | ||
|
|
d1bab213a3 | ||
|
|
016a9341ad | ||
|
|
81f407ad5f | ||
|
|
37ff2f6bdb | ||
|
|
13cf1a9551 | ||
|
|
799aaac449 | ||
|
|
fbe430e4cf | ||
|
|
511746620e | ||
|
|
fed5b648f8 | ||
|
|
1f601743f6 | ||
|
|
db3ccf5da7 | ||
|
|
038898d580 | ||
|
|
dafbc6bc51 | ||
|
|
3d8271e7a1 | ||
|
|
e2ade95219 | ||
|
|
604971a576 | ||
|
|
76173103af | ||
|
|
3fcbc60232 | ||
|
|
835bdb39d0 | ||
|
|
200f09c5d2 | ||
|
|
99a008f122 | ||
|
|
9b71e89ba0 | ||
|
|
9955369cfa | ||
|
|
6ef6ffab66 | ||
|
|
0dd46f0f20 | ||
|
|
cce0d85dd4 | ||
|
|
1ed3eae038 | ||
|
|
2854c24197 | ||
|
|
4b90ddda2a | ||
|
|
552c39e583 | ||
|
|
5176e459b5 | ||
|
|
39515d0600 | ||
|
|
5314949394 | ||
|
|
59e5be749c | ||
|
|
da252a0070 | ||
|
|
b6199e430c | ||
|
|
e260a68c26 | ||
|
|
570cb2deaf | ||
|
|
7a36f03fb5 | ||
|
|
6c3058ba97 | ||
|
|
48a1034c12 | ||
|
|
aaddb50ab9 | ||
|
|
a947586cfe | ||
|
|
f3cfa14a59 | ||
|
|
a2c0a77c53 | ||
|
|
c078f9d5cb | ||
|
|
08eab8a157 | ||
|
|
9c36f234bc | ||
|
|
36b81d0e2a | ||
|
|
4432c14377 | ||
|
|
99e6dd5ca3 | ||
|
|
6327a25aec | ||
|
|
40989de7f5 | ||
|
|
58af44e795 | ||
|
|
4910cc05f8 | ||
|
|
164ee24d16 | ||
|
|
0ffda4ab7c | ||
|
|
4694a6271d | ||
|
|
2f50bc747a | ||
|
|
a13f621a81 | ||
|
|
0cc520cc67 | ||
|
|
c9451c3f2d | ||
|
|
8da53ffda2 | ||
|
|
4319761687 | ||
|
|
a1f3227cd9 | ||
|
|
b07f87c920 | ||
|
|
9c8f23eb64 | ||
|
|
36c6c623de | ||
|
|
e334419e24 | ||
|
|
01240c4f2a | ||
|
|
431a9ce827 | ||
|
|
20ab41c3b4 | ||
|
|
3f4ea27be2 | ||
|
|
5bb5b2f8c8 | ||
|
|
e9bb9e27bb | ||
|
|
ee1dd1fae7 | ||
|
|
738530a960 | ||
|
|
16023b0688 | ||
|
|
bce7b5984f | ||
|
|
4e5d7d391a | ||
|
|
0554a85e01 | ||
|
|
2d232b3c4b | ||
|
|
b2a5462372 | ||
|
|
9d61f51270 | ||
|
|
a0eb7d61cc | ||
|
|
9861b319f4 | ||
|
|
b04e0f10b2 | ||
|
|
e6d089b34b | ||
|
|
9df014e986 | ||
|
|
39b8d2e70d | ||
|
|
59710d2e1a | ||
|
|
712dc9bb34 | ||
|
|
5c338d53ae | ||
|
|
ec3eb387e5 | ||
|
|
722cf58486 | ||
|
|
17e5347d55 | ||
|
|
2e828dfde3 | ||
|
|
1b035bcde3 | ||
|
|
30981130c9 | ||
|
|
6db8696a36 | ||
|
|
9c83dcafa7 | ||
|
|
1db9ecafef | ||
|
|
aa624e2c60 | ||
|
|
bde7e3e8aa | ||
|
|
b2b3e1b153 | ||
|
|
76b3d09320 | ||
|
|
899dcddd2e | ||
|
|
9edae7e1b8 | ||
|
|
8d26842aab | ||
|
|
76e654304b | ||
|
|
d73b684999 | ||
|
|
a78bd8d7ca | ||
|
|
2ca53c1004 | ||
|
|
d621516d59 | ||
|
|
ef310cc3cc | ||
|
|
776c867c0b | ||
|
|
8abe0ec333 | ||
|
|
e57ced0ce7 | ||
|
|
32ba679719 | ||
|
|
cac0fefcdb | ||
|
|
498c76dd96 | ||
|
|
7526182304 | ||
|
|
d46bbd9cbf | ||
|
|
e98b537499 | ||
|
|
fc9d8509e5 | ||
|
|
7c6bbb61b5 | ||
|
|
8501ddc87f | ||
|
|
7d9b94525e | ||
|
|
eb02f0eadf | ||
|
|
69a8ba5aec | ||
|
|
fe49b8e618 | ||
|
|
26bf4dde5f | ||
|
|
e9b73050ba | ||
|
|
bacd0ab43f | ||
|
|
e438051371 | ||
|
|
314155593d | ||
|
|
787f819ce0 | ||
|
|
3632a62ea3 | ||
|
|
c7294df007 | ||
|
|
e3ad7fe3c0 | ||
|
|
6213683ddf | ||
|
|
a4ddfc9970 | ||
|
|
7ff271f9b9 | ||
|
|
d75cdd63a9 | ||
|
|
0a7575d1e4 | ||
|
|
ec3022d8ad | ||
|
|
d42103b91b | ||
|
|
00f7d08b04 | ||
|
|
408cc383cb | ||
|
|
5c926d0ac6 | ||
|
|
5cb88782fc | ||
|
|
5eef4e9ece | ||
|
|
04a2124141 | ||
|
|
1b6229b2a1 | ||
|
|
bca6db50a7 | ||
|
|
f3aae26996 | ||
|
|
f3c17a8e0f | ||
|
|
d6b24f8753 | ||
|
|
253db0a303 | ||
|
|
8499e52461 | ||
|
|
d0153179a9 | ||
|
|
264d03727e | ||
|
|
544405d9b9 | ||
|
|
24488a3b67 | ||
|
|
ae78185b29 | ||
|
|
7f682b24ef | ||
|
|
d42a52d8cf | ||
|
|
b85df15890 | ||
|
|
393499f34f | ||
|
|
c656d0f9b5 | ||
|
|
32017a8859 | ||
|
|
d87c5b1140 | ||
|
|
f59f783d3f | ||
|
|
ec298eac61 | ||
|
|
81a25bb4ee | ||
|
|
e99f044e45 | ||
|
|
5ae25a5fd9 | ||
|
|
e9d1cb4907 | ||
|
|
99f8ca2dca | ||
|
|
ddea5d38b5 | ||
|
|
31d2b83550 | ||
|
|
5535e56ed2 | ||
|
|
d740b95dbc | ||
|
|
ae92e9a945 | ||
|
|
29730c3896 | ||
|
|
a5ae8270f0 | ||
|
|
54f5fa6432 | ||
|
|
0260644063 | ||
|
|
267fc03a82 | ||
|
|
bf1537584c | ||
|
|
9ee7825022 | ||
|
|
2be0c42dd1 | ||
|
|
3423c053a2 | ||
|
|
26923cca00 | ||
|
|
36e027659c | ||
|
|
f447dccdb4 | ||
|
|
69eae32851 | ||
|
|
aa2fcfb8cb | ||
|
|
fae5ef2a41 | ||
|
|
7251ca7d2d | ||
|
|
7cdbd919bf | ||
|
|
d450f95602 | ||
|
|
5a65201971 | ||
|
|
d303b8db3e | ||
|
|
06baa33827 | ||
|
|
42743e637e | ||
|
|
9969fd7dec | ||
|
|
fc6d5c2a1d | ||
|
|
f8abb1ca24 | ||
|
|
a5af38ae3d | ||
|
|
aab70951dc | ||
|
|
334cacf93c | ||
|
|
53024012fc | ||
|
|
86a72f77c1 | ||
|
|
bc11a5ad0a | ||
|
|
8f2d217fd4 | ||
|
|
183727cd50 | ||
|
|
676e87591a | ||
|
|
8c05fc4da0 | ||
|
|
2bab06561e | ||
|
|
dfa7e2f5bb | ||
|
|
78bece5616 | ||
|
|
eeea15e373 | ||
|
|
80cd513ab7 | ||
|
|
942ef1615e | ||
|
|
a354698022 | ||
|
|
0cdea488c9 | ||
|
|
4f4291ac47 | ||
|
|
bf0cf03091 | ||
|
|
f7da09f20f | ||
|
|
be1529331c | ||
|
|
301d658a29 | ||
|
|
1cc54e5b2c | ||
|
|
65a7fd21e7 | ||
|
|
856537c0cd | ||
|
|
b2a88e0063 | ||
|
|
85a7068785 | ||
|
|
cbb733d99a | ||
|
|
ce88c94a19 | ||
|
|
16516915d8 | ||
|
|
6addb8da23 | ||
|
|
bc7f664fd8 | ||
|
|
aac17aa33c | ||
|
|
825500e207 | ||
|
|
4d42016c72 | ||
|
|
9d665df602 | ||
|
|
9087f69fb0 | ||
|
|
2a06f6a214 | ||
|
|
78a8428bd0 | ||
|
|
0d235768fa | ||
|
|
af092bbdec | ||
|
|
4961630d62 | ||
|
|
81920b9ab9 | ||
|
|
9e031d3b5b | ||
|
|
7ae3ed6d2a | ||
|
|
05d79f2b51 | ||
|
|
274e591354 | ||
|
|
95fd152b3d | ||
|
|
ffc91ed6d8 | ||
|
|
de0b759875 | ||
|
|
f041dcf944 | ||
|
|
946b9bd9d1 | ||
|
|
db77a69838 | ||
|
|
d10f4d26e2 | ||
|
|
6b62d686ba | ||
|
|
065826e64d | ||
|
|
a3b096343f | ||
|
|
b33be91b06 | ||
|
|
a94a1816c5 | ||
|
|
9a9e7fea07 | ||
|
|
9a03042077 | ||
|
|
704d3b2d6b | ||
|
|
e5c2be238d | ||
|
|
9feea07527 | ||
|
|
b0967d03b8 | ||
|
|
d33fd71f93 | ||
|
|
226b5b2682 | ||
|
|
f8879b0223 | ||
|
|
ada09d96c4 |
10
.github/workflows/deploy.yml
vendored
10
.github/workflows/deploy.yml
vendored
@@ -8,12 +8,12 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: Install Node.js
|
- name: Install Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v6
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 24
|
||||||
cache: npm
|
cache: npm
|
||||||
cache-dependency-path: |
|
cache-dependency-path: |
|
||||||
gpx/package-lock.json
|
gpx/package-lock.json
|
||||||
@@ -31,7 +31,7 @@ jobs:
|
|||||||
- name: Create env file
|
- name: Create env file
|
||||||
run: |
|
run: |
|
||||||
touch website/.env
|
touch website/.env
|
||||||
echo PUBLIC_MAPBOX_TOKEN=${{ secrets.PUBLIC_MAPBOX_TOKEN }} >> website/.env
|
echo PUBLIC_MAPTILER_KEY=${{ secrets.PUBLIC_MAPTILER_KEY }} >> website/.env
|
||||||
cat website/.env
|
cat website/.env
|
||||||
|
|
||||||
- name: Build website
|
- name: Build website
|
||||||
@@ -41,7 +41,7 @@ jobs:
|
|||||||
npm run build --prefix website
|
npm run build --prefix website
|
||||||
|
|
||||||
- name: Upload Artifacts
|
- name: Upload Artifacts
|
||||||
uses: actions/upload-pages-artifact@v3
|
uses: actions/upload-pages-artifact@v4
|
||||||
with:
|
with:
|
||||||
path: 'website/build/'
|
path: 'website/build/'
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
# Ignore files for PNPM, NPM and YARN
|
website/src/lib/components/ui
|
||||||
pnpm-lock.yaml
|
website/src/lib/docs/**/*.mdx
|
||||||
package-lock.json
|
**/*.webmanifest
|
||||||
yarn.lock
|
|
||||||
src/lib/components/ui
|
|
||||||
*.mdx
|
|
||||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2024 gpx.studio
|
Copyright (c) 2026 gpx.studio
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -42,11 +42,11 @@ npm run build
|
|||||||
|
|
||||||
### Running the website
|
### Running the website
|
||||||
|
|
||||||
To be able to load the map, you will need to create your own <a href="https://account.mapbox.com/auth/signup" target="_blank">Mapbox access token</a> and store it in a `.env` file in the `website` directory.
|
To be able to load the map, you will need to create your own <a href="https://cloud.maptiler.com/auth/widget?next=https://cloud.maptiler.com/maps/" target="_blank">MapTiler key</a> and store it in a `.env` file in the `website` directory.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd website
|
cd website
|
||||||
echo PUBLIC_MAPBOX_TOKEN={YOUR_MAPBOX_TOKEN} >> .env
|
echo PUBLIC_MAPTILER_KEY={YOUR_MAPTILER_KEY} >> .env
|
||||||
npm install
|
npm install
|
||||||
npm run dev
|
npm run dev
|
||||||
```
|
```
|
||||||
@@ -69,9 +69,9 @@ This project has been made possible thanks to the following open source projects
|
|||||||
- [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser) — fast GPX file parsing
|
- [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser) — fast GPX file parsing
|
||||||
- [SortableJS](https://github.com/SortableJS/Sortable) — creating a sortable file tree
|
- [SortableJS](https://github.com/SortableJS/Sortable) — creating a sortable file tree
|
||||||
- Mapping:
|
- Mapping:
|
||||||
- [Mapbox GL JS](https://github.com/mapbox/mapbox-gl-js) — beautiful and fast interactive maps
|
- [MapLibre GL JS](https://github.com/maplibre/maplibre-gl-js) — beautiful and fast interactive maps
|
||||||
- [brouter](https://github.com/abrensch/brouter) — routing engine
|
- [brouter](https://github.com/abrensch/brouter) — routing engine
|
||||||
- [OpenStreetMap](https://www.openstreetmap.org) — map data used by Mapbox and brouter
|
- [OpenStreetMap](https://www.openstreetmap.org) — map data used by most of the map layers, and by the routing engine
|
||||||
- Search:
|
- Search:
|
||||||
- [DocSearch](https://github.com/algolia/docsearch) — search engine for the documentation
|
- [DocSearch](https://github.com/algolia/docsearch) — search engine for the documentation
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"postinstall": "npm run build",
|
"postinstall": "npm run build",
|
||||||
"lint": "prettier --check . && eslint .",
|
"lint": "prettier --check . --config ../.prettierrc && eslint .",
|
||||||
"format": "prettier --write ."
|
"format": "prettier --write . --config ../.prettierrc"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
679
gpx/src/gpx.ts
679
gpx/src/gpx.ts
@@ -1,4 +1,5 @@
|
|||||||
import { ramerDouglasPeucker } from './simplify';
|
import { ramerDouglasPeucker } from './simplify';
|
||||||
|
import { GPXStatistics, GPXStatisticsGroup, TrackPointLocalStatistics } from './statistics';
|
||||||
import {
|
import {
|
||||||
Coordinates,
|
Coordinates,
|
||||||
GPXFileAttributes,
|
GPXFileAttributes,
|
||||||
@@ -17,6 +18,9 @@ import {
|
|||||||
import { immerable, isDraft, original, freeze } from 'immer';
|
import { immerable, isDraft, original, freeze } from 'immer';
|
||||||
|
|
||||||
function cloneJSON<T>(obj: T): T {
|
function cloneJSON<T>(obj: T): T {
|
||||||
|
if (obj === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
if (obj === null || typeof obj !== 'object') {
|
if (obj === null || typeof obj !== 'object') {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -33,7 +37,6 @@ export abstract class GPXTreeElement<T extends GPXTreeElement<any>> {
|
|||||||
abstract getNumberOfTrackPoints(): number;
|
abstract getNumberOfTrackPoints(): number;
|
||||||
abstract getStartTimestamp(): Date | undefined;
|
abstract getStartTimestamp(): Date | undefined;
|
||||||
abstract getEndTimestamp(): Date | undefined;
|
abstract getEndTimestamp(): Date | undefined;
|
||||||
abstract getStatistics(): GPXStatistics;
|
|
||||||
abstract getSegments(): TrackSegment[];
|
abstract getSegments(): TrackSegment[];
|
||||||
abstract getTrackPoints(): TrackPoint[];
|
abstract getTrackPoints(): TrackPoint[];
|
||||||
|
|
||||||
@@ -73,14 +76,6 @@ abstract class GPXTreeNode<T extends GPXTreeElement<any>> extends GPXTreeElement
|
|||||||
return this.children[this.children.length - 1].getEndTimestamp();
|
return this.children[this.children.length - 1].getEndTimestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
getStatistics(): GPXStatistics {
|
|
||||||
let statistics = new GPXStatistics();
|
|
||||||
for (let child of this.children) {
|
|
||||||
statistics.mergeWith(child.getStatistics());
|
|
||||||
}
|
|
||||||
return statistics;
|
|
||||||
}
|
|
||||||
|
|
||||||
getSegments(): TrackSegment[] {
|
getSegments(): TrackSegment[] {
|
||||||
return this.children.flatMap((child) => child.getSegments());
|
return this.children.flatMap((child) => child.getSegments());
|
||||||
}
|
}
|
||||||
@@ -145,7 +140,9 @@ export class GPXFile extends GPXTreeNode<Track> {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
this.wpt = gpx.wpt ? gpx.wpt.map((waypoint) => new Waypoint(waypoint)) : [];
|
this.wpt = gpx.wpt
|
||||||
|
? gpx.wpt.map((waypoint, index) => new Waypoint(waypoint, index))
|
||||||
|
: [];
|
||||||
this.trk = gpx.trk ? gpx.trk.map((track) => new Track(track)) : [];
|
this.trk = gpx.trk ? gpx.trk.map((track) => new Track(track)) : [];
|
||||||
if (gpx.rte && gpx.rte.length > 0) {
|
if (gpx.rte && gpx.rte.length > 0) {
|
||||||
this.trk = this.trk.concat(gpx.rte.map((route) => convertRouteToTrack(route)));
|
this.trk = this.trk.concat(gpx.rte.map((route) => convertRouteToTrack(route)));
|
||||||
@@ -183,9 +180,6 @@ export class GPXFile extends GPXTreeNode<Track> {
|
|||||||
segment._data['segmentIndex'] = segmentIndex;
|
segment._data['segmentIndex'] = segmentIndex;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
this.wpt.forEach((waypoint, waypointIndex) => {
|
|
||||||
waypoint._data['index'] = waypointIndex;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get children(): Array<Track> {
|
get children(): Array<Track> {
|
||||||
@@ -206,8 +200,16 @@ export class GPXFile extends GPXTreeNode<Track> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getStatistics(): GPXStatisticsGroup {
|
||||||
|
let statistics = new GPXStatisticsGroup();
|
||||||
|
this.forEachSegment((segment) => {
|
||||||
|
statistics.add(segment.getStatistics());
|
||||||
|
});
|
||||||
|
return statistics;
|
||||||
|
}
|
||||||
|
|
||||||
getStyle(defaultColor?: string): MergedLineStyles {
|
getStyle(defaultColor?: string): MergedLineStyles {
|
||||||
return this.trk
|
const style = this.trk
|
||||||
.map((track) => track.getStyle())
|
.map((track) => track.getStyle())
|
||||||
.reduce(
|
.reduce(
|
||||||
(acc, style) => {
|
(acc, style) => {
|
||||||
@@ -217,8 +219,6 @@ export class GPXFile extends GPXTreeNode<Track> {
|
|||||||
!acc.color.includes(style['gpx_style:color'])
|
!acc.color.includes(style['gpx_style:color'])
|
||||||
) {
|
) {
|
||||||
acc.color.push(style['gpx_style:color']);
|
acc.color.push(style['gpx_style:color']);
|
||||||
} else if (defaultColor && !acc.color.includes(defaultColor)) {
|
|
||||||
acc.color.push(defaultColor);
|
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
style &&
|
style &&
|
||||||
@@ -242,6 +242,10 @@ export class GPXFile extends GPXTreeNode<Track> {
|
|||||||
width: [],
|
width: [],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
if (style.color.length === 0 && defaultColor) {
|
||||||
|
style.color.push(defaultColor);
|
||||||
|
}
|
||||||
|
return style;
|
||||||
}
|
}
|
||||||
|
|
||||||
clone(): GPXFile {
|
clone(): GPXFile {
|
||||||
@@ -804,7 +808,7 @@ export class TrackSegment extends GPXTreeLeaf {
|
|||||||
constructor(segment?: (TrackSegmentType & { _data?: any }) | TrackSegment) {
|
constructor(segment?: (TrackSegmentType & { _data?: any }) | TrackSegment) {
|
||||||
super();
|
super();
|
||||||
if (segment) {
|
if (segment) {
|
||||||
this.trkpt = segment.trkpt.map((point) => new TrackPoint(point));
|
this.trkpt = segment.trkpt.map((point, index) => new TrackPoint(point, index));
|
||||||
if (segment.hasOwnProperty('_data')) {
|
if (segment.hasOwnProperty('_data')) {
|
||||||
this._data = segment._data;
|
this._data = segment._data;
|
||||||
}
|
}
|
||||||
@@ -816,15 +820,12 @@ export class TrackSegment extends GPXTreeLeaf {
|
|||||||
_computeStatistics(): GPXStatistics {
|
_computeStatistics(): GPXStatistics {
|
||||||
let statistics = new GPXStatistics();
|
let statistics = new GPXStatistics();
|
||||||
|
|
||||||
statistics.local.points = this.trkpt.map((point) => point);
|
statistics.global.length = this.trkpt.length;
|
||||||
|
statistics.local.points = this.trkpt.slice(0);
|
||||||
statistics.local.elevation.smoothed = this._computeSmoothedElevation();
|
statistics.local.data = this.trkpt.map(() => new TrackPointLocalStatistics());
|
||||||
statistics.local.slope.at = this._computeSlope();
|
|
||||||
|
|
||||||
const points = this.trkpt;
|
const points = this.trkpt;
|
||||||
for (let i = 0; i < points.length; i++) {
|
for (let i = 0; i < points.length; i++) {
|
||||||
points[i]._data['index'] = i;
|
|
||||||
|
|
||||||
// distance
|
// distance
|
||||||
let dist = 0;
|
let dist = 0;
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
@@ -833,34 +834,18 @@ export class TrackSegment extends GPXTreeLeaf {
|
|||||||
statistics.global.distance.total += dist;
|
statistics.global.distance.total += dist;
|
||||||
}
|
}
|
||||||
|
|
||||||
statistics.local.distance.total.push(statistics.global.distance.total);
|
statistics.local.data[i].distance.total = statistics.global.distance.total;
|
||||||
|
|
||||||
// elevation
|
|
||||||
if (i > 0) {
|
|
||||||
const ele =
|
|
||||||
statistics.local.elevation.smoothed[i] -
|
|
||||||
statistics.local.elevation.smoothed[i - 1];
|
|
||||||
if (ele > 0) {
|
|
||||||
statistics.global.elevation.gain += ele;
|
|
||||||
} else if (ele < 0) {
|
|
||||||
statistics.global.elevation.loss -= ele;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
statistics.local.elevation.gain.push(statistics.global.elevation.gain);
|
|
||||||
statistics.local.elevation.loss.push(statistics.global.elevation.loss);
|
|
||||||
|
|
||||||
// time
|
// time
|
||||||
if (points[i].time === undefined) {
|
if (points[i].time === undefined) {
|
||||||
statistics.local.time.total.push(0);
|
statistics.local.data[i].time.total = 0;
|
||||||
} else {
|
} else {
|
||||||
if (statistics.global.time.start === undefined) {
|
if (statistics.global.time.start === undefined) {
|
||||||
statistics.global.time.start = points[i].time;
|
statistics.global.time.start = points[i].time;
|
||||||
}
|
}
|
||||||
statistics.global.time.end = points[i].time;
|
statistics.global.time.end = points[i].time;
|
||||||
statistics.local.time.total.push(
|
statistics.local.data[i].time.total =
|
||||||
(points[i].time.getTime() - statistics.global.time.start.getTime()) / 1000
|
(points[i].time.getTime() - statistics.global.time.start.getTime()) / 1000;
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// speed
|
// speed
|
||||||
@@ -875,8 +860,8 @@ export class TrackSegment extends GPXTreeLeaf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
statistics.local.distance.moving.push(statistics.global.distance.moving);
|
statistics.local.data[i].distance.moving = statistics.global.distance.moving;
|
||||||
statistics.local.time.moving.push(statistics.global.time.moving);
|
statistics.local.data[i].time.moving = statistics.global.time.moving;
|
||||||
|
|
||||||
// bounds
|
// bounds
|
||||||
statistics.global.bounds.southWest.lat = Math.min(
|
statistics.global.bounds.southWest.lat = Math.min(
|
||||||
@@ -960,8 +945,7 @@ export class TrackSegment extends GPXTreeLeaf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[statistics.local.slope.segment, statistics.local.slope.length] =
|
this._elevationComputation(statistics);
|
||||||
this._computeSlopeSegments(statistics);
|
|
||||||
|
|
||||||
statistics.global.time.total =
|
statistics.global.time.total =
|
||||||
statistics.global.time.start && statistics.global.time.end
|
statistics.global.time.start && statistics.global.time.end
|
||||||
@@ -977,73 +961,115 @@ export class TrackSegment extends GPXTreeLeaf {
|
|||||||
? statistics.global.distance.moving / (statistics.global.time.moving / 3600)
|
? statistics.global.distance.moving / (statistics.global.time.moving / 3600)
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
statistics.local.speed = distanceWindowSmoothingWithDistanceAccumulator(
|
timeWindowSmoothing(
|
||||||
points,
|
points,
|
||||||
200,
|
10000,
|
||||||
(accumulated, start, end) =>
|
(start, end) =>
|
||||||
points[start].time && points[end].time
|
points[start].time && points[end].time
|
||||||
? (3600 * accumulated) /
|
? (3600 *
|
||||||
(points[end].time.getTime() - points[start].time.getTime())
|
(statistics.local.data[end].distance.total -
|
||||||
: undefined
|
statistics.local.data[start].distance.total)) /
|
||||||
|
Math.max(
|
||||||
|
(points[end].time.getTime() - points[start].time.getTime()) / 1000,
|
||||||
|
1
|
||||||
|
)
|
||||||
|
: undefined,
|
||||||
|
(value, index) => {
|
||||||
|
statistics.local.data[index].speed = value;
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return statistics;
|
return statistics;
|
||||||
}
|
}
|
||||||
|
|
||||||
_computeSmoothedElevation(): number[] {
|
_elevationComputation(statistics: GPXStatistics) {
|
||||||
const points = this.trkpt;
|
|
||||||
|
|
||||||
let smoothed = distanceWindowSmoothing(
|
|
||||||
points,
|
|
||||||
100,
|
|
||||||
(index) => points[index].ele ?? 0,
|
|
||||||
(accumulated, start, end) => accumulated / (end - start + 1)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (points.length > 0) {
|
|
||||||
smoothed[0] = points[0].ele ?? 0;
|
|
||||||
smoothed[points.length - 1] = points[points.length - 1].ele ?? 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return smoothed;
|
|
||||||
}
|
|
||||||
|
|
||||||
_computeSlope(): number[] {
|
|
||||||
const points = this.trkpt;
|
|
||||||
|
|
||||||
return distanceWindowSmoothingWithDistanceAccumulator(
|
|
||||||
points,
|
|
||||||
50,
|
|
||||||
(accumulated, start, end) =>
|
|
||||||
(100 * ((points[end].ele ?? 0) - (points[start].ele ?? 0))) /
|
|
||||||
(accumulated > 0 ? accumulated : 1)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
_computeSlopeSegments(statistics: GPXStatistics): [number[], number[]] {
|
|
||||||
let simplified = ramerDouglasPeucker(
|
let simplified = ramerDouglasPeucker(
|
||||||
this.trkpt,
|
this.trkpt,
|
||||||
20,
|
20,
|
||||||
getElevationDistanceFunction(statistics)
|
getElevationDistanceFunction(statistics)
|
||||||
);
|
);
|
||||||
|
|
||||||
let slope = [];
|
for (let i = 0; i < simplified.length - 1; i++) {
|
||||||
let length = [];
|
let start = simplified[i].point._data.index;
|
||||||
|
let end = simplified[i + 1].point._data.index;
|
||||||
|
|
||||||
|
let cumulEle = 0;
|
||||||
|
let currentStart = start;
|
||||||
|
let currentEnd = start;
|
||||||
|
let prevSmoothedEle = 0;
|
||||||
|
distanceWindowSmoothing(
|
||||||
|
start,
|
||||||
|
end + 1,
|
||||||
|
statistics,
|
||||||
|
0.1,
|
||||||
|
(s, e) => {
|
||||||
|
for (let i = currentStart; i < s; i++) {
|
||||||
|
cumulEle -= this.trkpt[i].ele ?? 0;
|
||||||
|
}
|
||||||
|
for (let i = currentEnd; i <= e; i++) {
|
||||||
|
cumulEle += this.trkpt[i].ele ?? 0;
|
||||||
|
}
|
||||||
|
currentStart = s;
|
||||||
|
currentEnd = e + 1;
|
||||||
|
return cumulEle / (e - s + 1);
|
||||||
|
},
|
||||||
|
(smoothedEle, j) => {
|
||||||
|
if (j === start) {
|
||||||
|
smoothedEle = this.trkpt[start].ele ?? 0;
|
||||||
|
prevSmoothedEle = smoothedEle;
|
||||||
|
} else if (j === end) {
|
||||||
|
smoothedEle = this.trkpt[end].ele ?? 0;
|
||||||
|
}
|
||||||
|
const ele = smoothedEle - prevSmoothedEle;
|
||||||
|
if (ele > 0) {
|
||||||
|
statistics.global.elevation.gain += ele;
|
||||||
|
} else if (ele < 0) {
|
||||||
|
statistics.global.elevation.loss -= ele;
|
||||||
|
}
|
||||||
|
prevSmoothedEle = smoothedEle;
|
||||||
|
if (j < end) {
|
||||||
|
statistics.local.data[j].elevation.gain = statistics.global.elevation.gain;
|
||||||
|
statistics.local.data[j].elevation.loss = statistics.global.elevation.loss;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (statistics.global.length > 0) {
|
||||||
|
statistics.local.data[statistics.global.length - 1].elevation.gain =
|
||||||
|
statistics.global.elevation.gain;
|
||||||
|
statistics.local.data[statistics.global.length - 1].elevation.loss =
|
||||||
|
statistics.global.elevation.loss;
|
||||||
|
}
|
||||||
|
|
||||||
for (let i = 0; i < simplified.length - 1; i++) {
|
for (let i = 0; i < simplified.length - 1; i++) {
|
||||||
let start = simplified[i].point._data.index;
|
let start = simplified[i].point._data.index;
|
||||||
let end = simplified[i + 1].point._data.index;
|
let end = simplified[i + 1].point._data.index;
|
||||||
let dist =
|
let dist =
|
||||||
statistics.local.distance.total[end] - statistics.local.distance.total[start];
|
statistics.local.data[end].distance.total -
|
||||||
|
statistics.local.data[start].distance.total;
|
||||||
let ele = (simplified[i + 1].point.ele ?? 0) - (simplified[i].point.ele ?? 0);
|
let ele = (simplified[i + 1].point.ele ?? 0) - (simplified[i].point.ele ?? 0);
|
||||||
|
|
||||||
for (let j = start; j < end + (i + 1 === simplified.length - 1 ? 1 : 0); j++) {
|
for (let j = start; j < end + (i + 1 === simplified.length - 1 ? 1 : 0); j++) {
|
||||||
slope.push((0.1 * ele) / dist);
|
statistics.local.data[j].slope.segment = (0.1 * ele) / dist;
|
||||||
length.push(dist);
|
statistics.local.data[j].slope.length = dist;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return [slope, length];
|
distanceWindowSmoothing(
|
||||||
|
0,
|
||||||
|
this.trkpt.length,
|
||||||
|
statistics,
|
||||||
|
0.05,
|
||||||
|
(start, end) => {
|
||||||
|
const ele = this.trkpt[end].ele - this.trkpt[start].ele || 0;
|
||||||
|
const dist =
|
||||||
|
statistics.local.data[end].distance.total -
|
||||||
|
statistics.local.data[start].distance.total;
|
||||||
|
return dist > 0 ? (0.1 * ele) / dist : 0;
|
||||||
|
},
|
||||||
|
(value, index) => {
|
||||||
|
statistics.local.data[index].slope.at = value;
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getNumberOfTrackPoints(): number {
|
getNumberOfTrackPoints(): number {
|
||||||
@@ -1290,8 +1316,8 @@ export class TrackSegment extends GPXTreeLeaf {
|
|||||||
lastPoint: TrackPoint | undefined
|
lastPoint: TrackPoint | undefined
|
||||||
) {
|
) {
|
||||||
let og = getOriginal(this); // Read as much as possible from the original object because it is faster
|
let og = getOriginal(this); // Read as much as possible from the original object because it is faster
|
||||||
let slope = og._computeSlope();
|
let statistics = og._computeStatistics();
|
||||||
let trkpt = withArtificialTimestamps(og.trkpt, totalTime, lastPoint, startTime, slope);
|
let trkpt = withArtificialTimestamps(og.trkpt, totalTime, lastPoint, startTime, statistics);
|
||||||
this.trkpt = freeze(trkpt); // Pre-freeze the array, faster as well
|
this.trkpt = freeze(trkpt); // Pre-freeze the array, faster as well
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1300,6 +1326,7 @@ export class TrackSegment extends GPXTreeLeaf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const emptyExtensions: Record<string, string> = {};
|
||||||
export class TrackPoint {
|
export class TrackPoint {
|
||||||
[immerable] = true;
|
[immerable] = true;
|
||||||
|
|
||||||
@@ -1310,7 +1337,7 @@ export class TrackPoint {
|
|||||||
|
|
||||||
_data: { [key: string]: any } = {};
|
_data: { [key: string]: any } = {};
|
||||||
|
|
||||||
constructor(point: (TrackPointType & { _data?: any }) | TrackPoint) {
|
constructor(point: (TrackPointType & { _data?: any }) | TrackPoint, index?: number) {
|
||||||
this.attributes = point.attributes;
|
this.attributes = point.attributes;
|
||||||
this.ele = point.ele;
|
this.ele = point.ele;
|
||||||
this.time = point.time;
|
this.time = point.time;
|
||||||
@@ -1318,6 +1345,9 @@ export class TrackPoint {
|
|||||||
if (point.hasOwnProperty('_data')) {
|
if (point.hasOwnProperty('_data')) {
|
||||||
this._data = point._data;
|
this._data = point._data;
|
||||||
}
|
}
|
||||||
|
if (index !== undefined) {
|
||||||
|
this._data.index = index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getCoordinates(): Coordinates {
|
getCoordinates(): Coordinates {
|
||||||
@@ -1391,7 +1421,7 @@ export class TrackPoint {
|
|||||||
this.extensions['gpxtpx:TrackPointExtension'] &&
|
this.extensions['gpxtpx:TrackPointExtension'] &&
|
||||||
this.extensions['gpxtpx:TrackPointExtension']['gpxtpx:Extensions']
|
this.extensions['gpxtpx:TrackPointExtension']['gpxtpx:Extensions']
|
||||||
? this.extensions['gpxtpx:TrackPointExtension']['gpxtpx:Extensions']
|
? this.extensions['gpxtpx:TrackPointExtension']['gpxtpx:Extensions']
|
||||||
: {};
|
: emptyExtensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
toTrackPointType(exclude: string[] = []): TrackPointType {
|
toTrackPointType(exclude: string[] = []): TrackPointType {
|
||||||
@@ -1461,11 +1491,18 @@ export class TrackPoint {
|
|||||||
|
|
||||||
clone(): TrackPoint {
|
clone(): TrackPoint {
|
||||||
return new TrackPoint({
|
return new TrackPoint({
|
||||||
attributes: cloneJSON(this.attributes),
|
attributes: {
|
||||||
|
lat: this.attributes.lat,
|
||||||
|
lon: this.attributes.lon,
|
||||||
|
},
|
||||||
ele: this.ele,
|
ele: this.ele,
|
||||||
time: this.time ? new Date(this.time.getTime()) : undefined,
|
time: this.time ? new Date(this.time.getTime()) : undefined,
|
||||||
extensions: cloneJSON(this.extensions),
|
extensions: this.extensions ? cloneJSON(this.extensions) : undefined,
|
||||||
_data: cloneJSON(this._data),
|
_data: {
|
||||||
|
index: this._data?.index,
|
||||||
|
anchor: this._data?.anchor,
|
||||||
|
zoom: this._data?.zoom,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1484,19 +1521,28 @@ export class Waypoint {
|
|||||||
type?: string;
|
type?: string;
|
||||||
_data: { [key: string]: any } = {};
|
_data: { [key: string]: any } = {};
|
||||||
|
|
||||||
constructor(waypoint: (WaypointType & { _data?: any }) | Waypoint) {
|
constructor(waypoint: (WaypointType & { _data?: any }) | Waypoint, index?: number) {
|
||||||
this.attributes = waypoint.attributes;
|
this.attributes = waypoint.attributes;
|
||||||
this.ele = waypoint.ele;
|
this.ele = waypoint.ele;
|
||||||
this.time = waypoint.time;
|
this.time = waypoint.time;
|
||||||
this.name = waypoint.name;
|
this.name = waypoint.name === '' ? undefined : waypoint.name;
|
||||||
this.cmt = waypoint.cmt;
|
this.cmt = waypoint.cmt === '' ? undefined : waypoint.cmt;
|
||||||
this.desc = waypoint.desc;
|
this.desc = waypoint.desc === '' ? undefined : waypoint.desc;
|
||||||
this.link = waypoint.link;
|
this.link =
|
||||||
this.sym = waypoint.sym;
|
!waypoint.link ||
|
||||||
this.type = waypoint.type;
|
!waypoint.link.attributes ||
|
||||||
|
!waypoint.link.attributes.href ||
|
||||||
|
waypoint.link.attributes.href === ''
|
||||||
|
? undefined
|
||||||
|
: waypoint.link;
|
||||||
|
this.sym = waypoint.sym === '' ? undefined : waypoint.sym;
|
||||||
|
this.type = waypoint.type === '' ? undefined : waypoint.type;
|
||||||
if (waypoint.hasOwnProperty('_data')) {
|
if (waypoint.hasOwnProperty('_data')) {
|
||||||
this._data = waypoint._data;
|
this._data = waypoint._data;
|
||||||
}
|
}
|
||||||
|
if (index !== undefined) {
|
||||||
|
this._data.index = index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getCoordinates(): Coordinates {
|
getCoordinates(): Coordinates {
|
||||||
@@ -1544,7 +1590,10 @@ export class Waypoint {
|
|||||||
|
|
||||||
clone(): Waypoint {
|
clone(): Waypoint {
|
||||||
return new Waypoint({
|
return new Waypoint({
|
||||||
attributes: cloneJSON(this.attributes),
|
attributes: {
|
||||||
|
lat: this.attributes.lat,
|
||||||
|
lon: this.attributes.lon,
|
||||||
|
},
|
||||||
ele: this.ele,
|
ele: this.ele,
|
||||||
time: this.time ? new Date(this.time.getTime()) : undefined,
|
time: this.time ? new Date(this.time.getTime()) : undefined,
|
||||||
name: this.name,
|
name: this.name,
|
||||||
@@ -1593,310 +1642,6 @@ export class Waypoint {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GPXStatistics {
|
|
||||||
global: {
|
|
||||||
distance: {
|
|
||||||
moving: number;
|
|
||||||
total: number;
|
|
||||||
};
|
|
||||||
time: {
|
|
||||||
start: Date | undefined;
|
|
||||||
end: Date | undefined;
|
|
||||||
moving: number;
|
|
||||||
total: number;
|
|
||||||
};
|
|
||||||
speed: {
|
|
||||||
moving: number;
|
|
||||||
total: number;
|
|
||||||
};
|
|
||||||
elevation: {
|
|
||||||
gain: number;
|
|
||||||
loss: number;
|
|
||||||
};
|
|
||||||
bounds: {
|
|
||||||
southWest: Coordinates;
|
|
||||||
northEast: Coordinates;
|
|
||||||
};
|
|
||||||
atemp: {
|
|
||||||
avg: number;
|
|
||||||
count: number;
|
|
||||||
};
|
|
||||||
hr: {
|
|
||||||
avg: number;
|
|
||||||
count: number;
|
|
||||||
};
|
|
||||||
cad: {
|
|
||||||
avg: number;
|
|
||||||
count: number;
|
|
||||||
};
|
|
||||||
power: {
|
|
||||||
avg: number;
|
|
||||||
count: number;
|
|
||||||
};
|
|
||||||
extensions: Record<string, Record<string, number>>;
|
|
||||||
};
|
|
||||||
local: {
|
|
||||||
points: TrackPoint[];
|
|
||||||
distance: {
|
|
||||||
moving: number[];
|
|
||||||
total: number[];
|
|
||||||
};
|
|
||||||
time: {
|
|
||||||
moving: number[];
|
|
||||||
total: number[];
|
|
||||||
};
|
|
||||||
speed: number[];
|
|
||||||
elevation: {
|
|
||||||
smoothed: number[];
|
|
||||||
gain: number[];
|
|
||||||
loss: number[];
|
|
||||||
};
|
|
||||||
slope: {
|
|
||||||
at: number[];
|
|
||||||
segment: number[];
|
|
||||||
length: number[];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this.global = {
|
|
||||||
distance: {
|
|
||||||
moving: 0,
|
|
||||||
total: 0,
|
|
||||||
},
|
|
||||||
time: {
|
|
||||||
start: undefined,
|
|
||||||
end: undefined,
|
|
||||||
moving: 0,
|
|
||||||
total: 0,
|
|
||||||
},
|
|
||||||
speed: {
|
|
||||||
moving: 0,
|
|
||||||
total: 0,
|
|
||||||
},
|
|
||||||
elevation: {
|
|
||||||
gain: 0,
|
|
||||||
loss: 0,
|
|
||||||
},
|
|
||||||
bounds: {
|
|
||||||
southWest: {
|
|
||||||
lat: 90,
|
|
||||||
lon: 180,
|
|
||||||
},
|
|
||||||
northEast: {
|
|
||||||
lat: -90,
|
|
||||||
lon: -180,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
atemp: {
|
|
||||||
avg: 0,
|
|
||||||
count: 0,
|
|
||||||
},
|
|
||||||
hr: {
|
|
||||||
avg: 0,
|
|
||||||
count: 0,
|
|
||||||
},
|
|
||||||
cad: {
|
|
||||||
avg: 0,
|
|
||||||
count: 0,
|
|
||||||
},
|
|
||||||
power: {
|
|
||||||
avg: 0,
|
|
||||||
count: 0,
|
|
||||||
},
|
|
||||||
extensions: {},
|
|
||||||
};
|
|
||||||
this.local = {
|
|
||||||
points: [],
|
|
||||||
distance: {
|
|
||||||
moving: [],
|
|
||||||
total: [],
|
|
||||||
},
|
|
||||||
time: {
|
|
||||||
moving: [],
|
|
||||||
total: [],
|
|
||||||
},
|
|
||||||
speed: [],
|
|
||||||
elevation: {
|
|
||||||
smoothed: [],
|
|
||||||
gain: [],
|
|
||||||
loss: [],
|
|
||||||
},
|
|
||||||
slope: {
|
|
||||||
at: [],
|
|
||||||
segment: [],
|
|
||||||
length: [],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
mergeWith(other: GPXStatistics): void {
|
|
||||||
this.local.points = this.local.points.concat(other.local.points);
|
|
||||||
|
|
||||||
this.local.distance.total = this.local.distance.total.concat(
|
|
||||||
other.local.distance.total.map((distance) => distance + this.global.distance.total)
|
|
||||||
);
|
|
||||||
this.local.distance.moving = this.local.distance.moving.concat(
|
|
||||||
other.local.distance.moving.map((distance) => distance + this.global.distance.moving)
|
|
||||||
);
|
|
||||||
this.local.time.total = this.local.time.total.concat(
|
|
||||||
other.local.time.total.map((time) => time + this.global.time.total)
|
|
||||||
);
|
|
||||||
this.local.time.moving = this.local.time.moving.concat(
|
|
||||||
other.local.time.moving.map((time) => time + this.global.time.moving)
|
|
||||||
);
|
|
||||||
this.local.elevation.gain = this.local.elevation.gain.concat(
|
|
||||||
other.local.elevation.gain.map((gain) => gain + this.global.elevation.gain)
|
|
||||||
);
|
|
||||||
this.local.elevation.loss = this.local.elevation.loss.concat(
|
|
||||||
other.local.elevation.loss.map((loss) => loss + this.global.elevation.loss)
|
|
||||||
);
|
|
||||||
|
|
||||||
this.local.speed = this.local.speed.concat(other.local.speed);
|
|
||||||
this.local.elevation.smoothed = this.local.elevation.smoothed.concat(
|
|
||||||
other.local.elevation.smoothed
|
|
||||||
);
|
|
||||||
this.local.slope.at = this.local.slope.at.concat(other.local.slope.at);
|
|
||||||
this.local.slope.segment = this.local.slope.segment.concat(other.local.slope.segment);
|
|
||||||
this.local.slope.length = this.local.slope.length.concat(other.local.slope.length);
|
|
||||||
|
|
||||||
this.global.distance.total += other.global.distance.total;
|
|
||||||
this.global.distance.moving += other.global.distance.moving;
|
|
||||||
|
|
||||||
this.global.time.start =
|
|
||||||
this.global.time.start !== undefined && other.global.time.start !== undefined
|
|
||||||
? new Date(
|
|
||||||
Math.min(this.global.time.start.getTime(), other.global.time.start.getTime())
|
|
||||||
)
|
|
||||||
: (this.global.time.start ?? other.global.time.start);
|
|
||||||
this.global.time.end =
|
|
||||||
this.global.time.end !== undefined && other.global.time.end !== undefined
|
|
||||||
? new Date(
|
|
||||||
Math.max(this.global.time.end.getTime(), other.global.time.end.getTime())
|
|
||||||
)
|
|
||||||
: (this.global.time.end ?? other.global.time.end);
|
|
||||||
|
|
||||||
this.global.time.total += other.global.time.total;
|
|
||||||
this.global.time.moving += other.global.time.moving;
|
|
||||||
|
|
||||||
this.global.speed.moving =
|
|
||||||
this.global.time.moving > 0
|
|
||||||
? this.global.distance.moving / (this.global.time.moving / 3600)
|
|
||||||
: 0;
|
|
||||||
this.global.speed.total =
|
|
||||||
this.global.time.total > 0
|
|
||||||
? this.global.distance.total / (this.global.time.total / 3600)
|
|
||||||
: 0;
|
|
||||||
|
|
||||||
this.global.elevation.gain += other.global.elevation.gain;
|
|
||||||
this.global.elevation.loss += other.global.elevation.loss;
|
|
||||||
|
|
||||||
this.global.bounds.southWest.lat = Math.min(
|
|
||||||
this.global.bounds.southWest.lat,
|
|
||||||
other.global.bounds.southWest.lat
|
|
||||||
);
|
|
||||||
this.global.bounds.southWest.lon = Math.min(
|
|
||||||
this.global.bounds.southWest.lon,
|
|
||||||
other.global.bounds.southWest.lon
|
|
||||||
);
|
|
||||||
this.global.bounds.northEast.lat = Math.max(
|
|
||||||
this.global.bounds.northEast.lat,
|
|
||||||
other.global.bounds.northEast.lat
|
|
||||||
);
|
|
||||||
this.global.bounds.northEast.lon = Math.max(
|
|
||||||
this.global.bounds.northEast.lon,
|
|
||||||
other.global.bounds.northEast.lon
|
|
||||||
);
|
|
||||||
|
|
||||||
this.global.atemp.avg =
|
|
||||||
(this.global.atemp.count * this.global.atemp.avg +
|
|
||||||
other.global.atemp.count * other.global.atemp.avg) /
|
|
||||||
Math.max(1, this.global.atemp.count + other.global.atemp.count);
|
|
||||||
this.global.atemp.count += other.global.atemp.count;
|
|
||||||
this.global.hr.avg =
|
|
||||||
(this.global.hr.count * this.global.hr.avg +
|
|
||||||
other.global.hr.count * other.global.hr.avg) /
|
|
||||||
Math.max(1, this.global.hr.count + other.global.hr.count);
|
|
||||||
this.global.hr.count += other.global.hr.count;
|
|
||||||
this.global.cad.avg =
|
|
||||||
(this.global.cad.count * this.global.cad.avg +
|
|
||||||
other.global.cad.count * other.global.cad.avg) /
|
|
||||||
Math.max(1, this.global.cad.count + other.global.cad.count);
|
|
||||||
this.global.cad.count += other.global.cad.count;
|
|
||||||
this.global.power.avg =
|
|
||||||
(this.global.power.count * this.global.power.avg +
|
|
||||||
other.global.power.count * other.global.power.avg) /
|
|
||||||
Math.max(1, this.global.power.count + other.global.power.count);
|
|
||||||
this.global.power.count += other.global.power.count;
|
|
||||||
Object.keys(other.global.extensions).forEach((extension) => {
|
|
||||||
if (this.global.extensions[extension] === undefined) {
|
|
||||||
this.global.extensions[extension] = {};
|
|
||||||
}
|
|
||||||
Object.keys(other.global.extensions[extension]).forEach((value) => {
|
|
||||||
if (this.global.extensions[extension][value] === undefined) {
|
|
||||||
this.global.extensions[extension][value] = 0;
|
|
||||||
}
|
|
||||||
this.global.extensions[extension][value] +=
|
|
||||||
other.global.extensions[extension][value];
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
slice(start: number, end: number): GPXStatistics {
|
|
||||||
if (start < 0) {
|
|
||||||
start = 0;
|
|
||||||
} else if (start >= this.local.points.length) {
|
|
||||||
return new GPXStatistics();
|
|
||||||
}
|
|
||||||
if (end < start) {
|
|
||||||
return new GPXStatistics();
|
|
||||||
} else if (end >= this.local.points.length) {
|
|
||||||
end = this.local.points.length - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
let statistics = new GPXStatistics();
|
|
||||||
|
|
||||||
statistics.local.points = this.local.points.slice(start, end + 1);
|
|
||||||
|
|
||||||
statistics.global.distance.total =
|
|
||||||
this.local.distance.total[end] - this.local.distance.total[start];
|
|
||||||
statistics.global.distance.moving =
|
|
||||||
this.local.distance.moving[end] - this.local.distance.moving[start];
|
|
||||||
|
|
||||||
statistics.global.time.start = this.local.points[start].time;
|
|
||||||
statistics.global.time.end = this.local.points[end].time;
|
|
||||||
|
|
||||||
statistics.global.time.total = this.local.time.total[end] - this.local.time.total[start];
|
|
||||||
statistics.global.time.moving = this.local.time.moving[end] - this.local.time.moving[start];
|
|
||||||
|
|
||||||
statistics.global.speed.moving =
|
|
||||||
statistics.global.time.moving > 0
|
|
||||||
? statistics.global.distance.moving / (statistics.global.time.moving / 3600)
|
|
||||||
: 0;
|
|
||||||
statistics.global.speed.total =
|
|
||||||
statistics.global.time.total > 0
|
|
||||||
? statistics.global.distance.total / (statistics.global.time.total / 3600)
|
|
||||||
: 0;
|
|
||||||
|
|
||||||
statistics.global.elevation.gain =
|
|
||||||
this.local.elevation.gain[end] - this.local.elevation.gain[start];
|
|
||||||
statistics.global.elevation.loss =
|
|
||||||
this.local.elevation.loss[end] - this.local.elevation.loss[start];
|
|
||||||
|
|
||||||
statistics.global.bounds.southWest.lat = this.global.bounds.southWest.lat;
|
|
||||||
statistics.global.bounds.southWest.lon = this.global.bounds.southWest.lon;
|
|
||||||
statistics.global.bounds.northEast.lat = this.global.bounds.northEast.lat;
|
|
||||||
statistics.global.bounds.northEast.lon = this.global.bounds.northEast.lon;
|
|
||||||
|
|
||||||
statistics.global.atemp = this.global.atemp;
|
|
||||||
statistics.global.hr = this.global.hr;
|
|
||||||
statistics.global.cad = this.global.cad;
|
|
||||||
statistics.global.power = this.global.power;
|
|
||||||
|
|
||||||
return statistics;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const earthRadius = 6371008.8;
|
const earthRadius = 6371008.8;
|
||||||
export function distance(
|
export function distance(
|
||||||
coord1: TrackPoint | Coordinates,
|
coord1: TrackPoint | Coordinates,
|
||||||
@@ -1911,11 +1656,15 @@ export function distance(
|
|||||||
const rad = Math.PI / 180;
|
const rad = Math.PI / 180;
|
||||||
const lat1 = coord1.lat * rad;
|
const lat1 = coord1.lat * rad;
|
||||||
const lat2 = coord2.lat * rad;
|
const lat2 = coord2.lat * rad;
|
||||||
|
const dLat = lat2 - lat1;
|
||||||
|
const dLon = (coord2.lon - coord1.lon) * rad;
|
||||||
|
|
||||||
|
// Haversine formula - better numerical stability for small distances
|
||||||
const a =
|
const a =
|
||||||
Math.sin(lat1) * Math.sin(lat2) +
|
Math.sin(dLat / 2) * Math.sin(dLat / 2) +
|
||||||
Math.cos(lat1) * Math.cos(lat2) * Math.cos((coord2.lon - coord1.lon) * rad);
|
Math.cos(lat1) * Math.cos(lat2) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
|
||||||
const maxMeters = earthRadius * Math.acos(Math.min(a, 1));
|
const c = 2 * Math.asin(Math.sqrt(Math.min(a, 1)));
|
||||||
return maxMeters;
|
return earthRadius * c;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getElevationDistanceFunction(statistics: GPXStatistics) {
|
export function getElevationDistanceFunction(statistics: GPXStatistics) {
|
||||||
@@ -1926,9 +1675,9 @@ export function getElevationDistanceFunction(statistics: GPXStatistics) {
|
|||||||
if (point1.ele === undefined || point2.ele === undefined || point3.ele === undefined) {
|
if (point1.ele === undefined || point2.ele === undefined || point3.ele === undefined) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
let x1 = statistics.local.distance.total[point1._data.index] * 1000;
|
let x1 = statistics.local.data[point1._data.index].distance.total * 1000;
|
||||||
let x2 = statistics.local.distance.total[point2._data.index] * 1000;
|
let x2 = statistics.local.data[point2._data.index].distance.total * 1000;
|
||||||
let x3 = statistics.local.distance.total[point3._data.index] * 1000;
|
let x3 = statistics.local.data[point3._data.index].distance.total * 1000;
|
||||||
let y1 = point1.ele;
|
let y1 = point1.ele;
|
||||||
let y2 = point2.ele;
|
let y2 = point2.ele;
|
||||||
let y3 = point3.ele;
|
let y3 = point3.ele;
|
||||||
@@ -1942,57 +1691,61 @@ export function getElevationDistanceFunction(statistics: GPXStatistics) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function distanceWindowSmoothing(
|
function windowSmoothing(
|
||||||
points: TrackPoint[],
|
left: number,
|
||||||
distanceWindow: number,
|
right: number,
|
||||||
accumulate: (index: number) => number,
|
distance: (index1: number, index2: number) => number,
|
||||||
compute: (accumulated: number, start: number, end: number) => number,
|
window: number,
|
||||||
remove?: (index: number) => number
|
compute: (start: number, end: number) => number,
|
||||||
): number[] {
|
callback: (value: number, index: number) => void
|
||||||
let result = [];
|
): void {
|
||||||
|
let start = left;
|
||||||
let start = 0,
|
for (var i = left; i < right; i++) {
|
||||||
end = 0,
|
while (start + 1 < i && distance(start, i) > window) {
|
||||||
accumulated = 0;
|
|
||||||
for (var i = 0; i < points.length; i++) {
|
|
||||||
while (
|
|
||||||
start + 1 < i &&
|
|
||||||
distance(points[start].getCoordinates(), points[i].getCoordinates()) > distanceWindow
|
|
||||||
) {
|
|
||||||
if (remove) {
|
|
||||||
accumulated -= remove(start);
|
|
||||||
} else {
|
|
||||||
accumulated -= accumulate(start);
|
|
||||||
}
|
|
||||||
start++;
|
start++;
|
||||||
}
|
}
|
||||||
while (
|
let end = Math.min(i + 2, right);
|
||||||
end < points.length &&
|
while (end < right && distance(i, end) <= window) {
|
||||||
distance(points[i].getCoordinates(), points[end].getCoordinates()) <= distanceWindow
|
|
||||||
) {
|
|
||||||
accumulated += accumulate(end);
|
|
||||||
end++;
|
end++;
|
||||||
}
|
}
|
||||||
result[i] = compute(accumulated, start, end - 1);
|
callback(compute(start, end - 1), i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
function distanceWindowSmoothing(
|
||||||
}
|
left: number,
|
||||||
|
right: number,
|
||||||
function distanceWindowSmoothingWithDistanceAccumulator(
|
statistics: GPXStatistics,
|
||||||
points: TrackPoint[],
|
window: number,
|
||||||
distanceWindow: number,
|
compute: (start: number, end: number) => number,
|
||||||
compute: (accumulated: number, start: number, end: number) => number
|
callback: (value: number, index: number) => void
|
||||||
): number[] {
|
): void {
|
||||||
return distanceWindowSmoothing(
|
windowSmoothing(
|
||||||
points,
|
left,
|
||||||
distanceWindow,
|
right,
|
||||||
(index) =>
|
(index1, index2) =>
|
||||||
index > 0
|
statistics.local.data[index2].distance.total -
|
||||||
? distance(points[index - 1].getCoordinates(), points[index].getCoordinates())
|
statistics.local.data[index1].distance.total,
|
||||||
: 0,
|
window,
|
||||||
compute,
|
compute,
|
||||||
(index) => distance(points[index].getCoordinates(), points[index + 1].getCoordinates())
|
callback
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function timeWindowSmoothing(
|
||||||
|
points: TrackPoint[],
|
||||||
|
window: number,
|
||||||
|
compute: (start: number, end: number) => number,
|
||||||
|
callback: (value: number, index: number) => void
|
||||||
|
): void {
|
||||||
|
windowSmoothing(
|
||||||
|
0,
|
||||||
|
points.length,
|
||||||
|
(index1, index2) =>
|
||||||
|
points[index2].time?.getTime() - points[index1].time?.getTime() || 2 * window,
|
||||||
|
window,
|
||||||
|
compute,
|
||||||
|
callback
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2044,14 +1797,14 @@ function withArtificialTimestamps(
|
|||||||
totalTime: number,
|
totalTime: number,
|
||||||
lastPoint: TrackPoint | undefined,
|
lastPoint: TrackPoint | undefined,
|
||||||
startTime: Date,
|
startTime: Date,
|
||||||
slope: number[]
|
statistics: GPXStatistics
|
||||||
): TrackPoint[] {
|
): TrackPoint[] {
|
||||||
let weight = [];
|
let weight = [];
|
||||||
let totalWeight = 0;
|
let totalWeight = 0;
|
||||||
|
|
||||||
for (let i = 0; i < points.length - 1; i++) {
|
for (let i = 0; i < points.length - 1; i++) {
|
||||||
let dist = distance(points[i].getCoordinates(), points[i + 1].getCoordinates());
|
let dist = distance(points[i].getCoordinates(), points[i + 1].getCoordinates());
|
||||||
let w = dist * (0.5 + 1 / (1 + Math.exp(-0.2 * slope[i])));
|
let w = dist * (0.5 + 1 / (1 + Math.exp(-0.2 * statistics.local.data[i].slope.at)));
|
||||||
weight.push(w);
|
weight.push(w);
|
||||||
totalWeight += w;
|
totalWeight += w;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
export * from './gpx';
|
export * from './gpx';
|
||||||
|
export * from './statistics';
|
||||||
export { Coordinates, LineStyleExtension, WaypointType } from './types';
|
export { Coordinates, LineStyleExtension, WaypointType } from './types';
|
||||||
export { parseGPX, buildGPX } from './io';
|
export { parseGPX, buildGPX } from './io';
|
||||||
export * from './simplify';
|
export * from './simplify';
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ import { Coordinates } from './types';
|
|||||||
|
|
||||||
export type SimplifiedTrackPoint = { point: TrackPoint; distance?: number };
|
export type SimplifiedTrackPoint = { point: TrackPoint; distance?: number };
|
||||||
|
|
||||||
const earthRadius = 6371008.8;
|
|
||||||
|
|
||||||
export function ramerDouglasPeucker(
|
export function ramerDouglasPeucker(
|
||||||
points: TrackPoint[],
|
points: TrackPoint[],
|
||||||
epsilon: number = 50,
|
epsilon: number = 50,
|
||||||
@@ -61,76 +59,56 @@ function ramerDouglasPeuckerRecursive(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function crossarcDistance(
|
export function crossarcDistance(
|
||||||
point1: TrackPoint,
|
point1: TrackPoint | Coordinates,
|
||||||
point2: TrackPoint,
|
point2: TrackPoint | Coordinates,
|
||||||
point3: TrackPoint | Coordinates
|
point3: TrackPoint | Coordinates
|
||||||
): number {
|
): number {
|
||||||
return crossarc(
|
return crossarc(
|
||||||
point1.getCoordinates(),
|
point1 instanceof TrackPoint ? point1.getCoordinates() : point1,
|
||||||
point2.getCoordinates(),
|
point2 instanceof TrackPoint ? point2.getCoordinates() : point2,
|
||||||
point3 instanceof TrackPoint ? point3.getCoordinates() : point3
|
point3 instanceof TrackPoint ? point3.getCoordinates() : point3
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const metersPerLatitudeDegree = 111320;
|
||||||
|
|
||||||
|
function getMetersPerLongitudeDegree(latitude: number): number {
|
||||||
|
return Math.cos((latitude * Math.PI) / 180) * metersPerLatitudeDegree;
|
||||||
|
}
|
||||||
|
|
||||||
function crossarc(coord1: Coordinates, coord2: Coordinates, coord3: Coordinates): number {
|
function crossarc(coord1: Coordinates, coord2: Coordinates, coord3: Coordinates): number {
|
||||||
// Calculates the shortest distance in meters
|
// Calculates the perpendicular distance in meters
|
||||||
// between an arc (defined by p1 and p2) and a third point, p3.
|
// between a line segment (defined by p1 and p2) and a third point, p3.
|
||||||
// Input lat1,lon1,lat2,lon2,lat3,lon3 in degrees.
|
// Uses simple planar geometry (ignores earth curvature).
|
||||||
|
|
||||||
const rad = Math.PI / 180;
|
// Convert to meters using approximate scaling
|
||||||
const lat1 = coord1.lat * rad;
|
const metersPerLongitudeDegree = getMetersPerLongitudeDegree(coord1.lat);
|
||||||
const lat2 = coord2.lat * rad;
|
|
||||||
const lat3 = coord3.lat * rad;
|
|
||||||
|
|
||||||
const lon1 = coord1.lon * rad;
|
const x1 = coord1.lon * metersPerLongitudeDegree;
|
||||||
const lon2 = coord2.lon * rad;
|
const y1 = coord1.lat * metersPerLatitudeDegree;
|
||||||
const lon3 = coord3.lon * rad;
|
const x2 = coord2.lon * metersPerLongitudeDegree;
|
||||||
|
const y2 = coord2.lat * metersPerLatitudeDegree;
|
||||||
|
const x3 = coord3.lon * metersPerLongitudeDegree;
|
||||||
|
const y3 = coord3.lat * metersPerLatitudeDegree;
|
||||||
|
|
||||||
// Prerequisites for the formulas
|
const dx = x2 - x1;
|
||||||
const bear12 = bearing(lat1, lon1, lat2, lon2);
|
const dy = y2 - y1;
|
||||||
const bear13 = bearing(lat1, lon1, lat3, lon3);
|
const segmentLengthSquared = dx * dx + dy * dy;
|
||||||
let dis13 = distance(lat1, lon1, lat3, lon3);
|
|
||||||
|
|
||||||
let diff = Math.abs(bear13 - bear12);
|
if (segmentLengthSquared === 0) {
|
||||||
if (diff > Math.PI) {
|
// p1 and p2 are the same point
|
||||||
diff = 2 * Math.PI - diff;
|
return Math.sqrt((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is relative bearing obtuse?
|
// Project p3 onto the line defined by p1-p2
|
||||||
if (diff > Math.PI / 2) {
|
const t = Math.max(0, Math.min(1, ((x3 - x1) * dx + (y3 - y1) * dy) / segmentLengthSquared));
|
||||||
return dis13;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the cross-track distance.
|
// Find the closest point on the segment
|
||||||
let dxt = Math.asin(Math.sin(dis13 / earthRadius) * Math.sin(bear13 - bear12)) * earthRadius;
|
const projX = x1 + t * dx;
|
||||||
|
const projY = y1 + t * dy;
|
||||||
|
|
||||||
// Is p4 beyond the arc?
|
// Return distance from p3 to the projected point
|
||||||
let dis12 = distance(lat1, lon1, lat2, lon2);
|
return Math.sqrt((x3 - projX) * (x3 - projX) + (y3 - projY) * (y3 - projY));
|
||||||
let dis14 =
|
|
||||||
Math.acos(Math.cos(dis13 / earthRadius) / Math.cos(dxt / earthRadius)) * earthRadius;
|
|
||||||
if (dis14 > dis12) {
|
|
||||||
return distance(lat2, lon2, lat3, lon3);
|
|
||||||
} else {
|
|
||||||
return Math.abs(dxt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function distance(latA: number, lonA: number, latB: number, lonB: number): number {
|
|
||||||
// Finds the distance between two lat / lon points.
|
|
||||||
return (
|
|
||||||
Math.acos(
|
|
||||||
Math.sin(latA) * Math.sin(latB) +
|
|
||||||
Math.cos(latA) * Math.cos(latB) * Math.cos(lonB - lonA)
|
|
||||||
) * earthRadius
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function bearing(latA: number, lonA: number, latB: number, lonB: number): number {
|
|
||||||
// Finds the bearing from one lat / lon point to another.
|
|
||||||
return Math.atan2(
|
|
||||||
Math.sin(lonB - lonA) * Math.cos(latB),
|
|
||||||
Math.cos(latA) * Math.sin(latB) - Math.sin(latA) * Math.cos(latB) * Math.cos(lonB - lonA)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function projectedPoint(
|
export function projectedPoint(
|
||||||
@@ -146,56 +124,39 @@ export function projectedPoint(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function projected(coord1: Coordinates, coord2: Coordinates, coord3: Coordinates): Coordinates {
|
function projected(coord1: Coordinates, coord2: Coordinates, coord3: Coordinates): Coordinates {
|
||||||
// Calculates the point on the line defined by p1 and p2
|
// Calculates the point on the line segment defined by p1 and p2
|
||||||
// that is closest to the third point, p3.
|
// that is closest to the third point, p3.
|
||||||
// Input lat1,lon1,lat2,lon2,lat3,lon3 in degrees.
|
// Uses simple planar geometry (ignores earth curvature).
|
||||||
|
|
||||||
const rad = Math.PI / 180;
|
// Convert to meters using approximate scaling
|
||||||
const lat1 = coord1.lat * rad;
|
const metersPerLongitudeDegree = getMetersPerLongitudeDegree(coord1.lat);
|
||||||
const lat2 = coord2.lat * rad;
|
|
||||||
const lat3 = coord3.lat * rad;
|
|
||||||
|
|
||||||
const lon1 = coord1.lon * rad;
|
const x1 = coord1.lon * metersPerLongitudeDegree;
|
||||||
const lon2 = coord2.lon * rad;
|
const y1 = coord1.lat * metersPerLatitudeDegree;
|
||||||
const lon3 = coord3.lon * rad;
|
const x2 = coord2.lon * metersPerLongitudeDegree;
|
||||||
|
const y2 = coord2.lat * metersPerLatitudeDegree;
|
||||||
|
const x3 = coord3.lon * metersPerLongitudeDegree;
|
||||||
|
const y3 = coord3.lat * metersPerLatitudeDegree;
|
||||||
|
|
||||||
// Prerequisites for the formulas
|
const dx = x2 - x1;
|
||||||
const bear12 = bearing(lat1, lon1, lat2, lon2);
|
const dy = y2 - y1;
|
||||||
const bear13 = bearing(lat1, lon1, lat3, lon3);
|
const segmentLengthSquared = dx * dx + dy * dy;
|
||||||
let dis13 = distance(lat1, lon1, lat3, lon3);
|
|
||||||
|
|
||||||
let diff = Math.abs(bear13 - bear12);
|
if (segmentLengthSquared === 0) {
|
||||||
if (diff > Math.PI) {
|
// p1 and p2 are the same point
|
||||||
diff = 2 * Math.PI - diff;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Is relative bearing obtuse?
|
|
||||||
if (diff > Math.PI / 2) {
|
|
||||||
return coord1;
|
return coord1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the cross-track distance.
|
// Project p3 onto the line defined by p1-p2
|
||||||
let dxt = Math.asin(Math.sin(dis13 / earthRadius) * Math.sin(bear13 - bear12)) * earthRadius;
|
const t = Math.max(0, Math.min(1, ((x3 - x1) * dx + (y3 - y1) * dy) / segmentLengthSquared));
|
||||||
|
|
||||||
// Is p4 beyond the arc?
|
// Find the closest point on the segment
|
||||||
let dis12 = distance(lat1, lon1, lat2, lon2);
|
const projX = x1 + t * dx;
|
||||||
let dis14 =
|
const projY = y1 + t * dy;
|
||||||
Math.acos(Math.cos(dis13 / earthRadius) / Math.cos(dxt / earthRadius)) * earthRadius;
|
|
||||||
if (dis14 > dis12) {
|
|
||||||
return coord2;
|
|
||||||
} else {
|
|
||||||
// Determine the closest point (p4) on the great circle
|
|
||||||
const f = dis14 / earthRadius;
|
|
||||||
const lat4 = Math.asin(
|
|
||||||
Math.sin(lat1) * Math.cos(f) + Math.cos(lat1) * Math.sin(f) * Math.cos(bear12)
|
|
||||||
);
|
|
||||||
const lon4 =
|
|
||||||
lon1 +
|
|
||||||
Math.atan2(
|
|
||||||
Math.sin(bear12) * Math.sin(f) * Math.cos(lat1),
|
|
||||||
Math.cos(f) - Math.sin(lat1) * Math.sin(lat4)
|
|
||||||
);
|
|
||||||
|
|
||||||
return { lat: lat4 / rad, lon: lon4 / rad };
|
// Convert back to degrees
|
||||||
}
|
return {
|
||||||
|
lat: projY / metersPerLatitudeDegree,
|
||||||
|
lon: projX / metersPerLongitudeDegree,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
391
gpx/src/statistics.ts
Normal file
391
gpx/src/statistics.ts
Normal file
@@ -0,0 +1,391 @@
|
|||||||
|
import { TrackPoint } from './gpx';
|
||||||
|
import { Coordinates } from './types';
|
||||||
|
|
||||||
|
export class GPXGlobalStatistics {
|
||||||
|
length: number;
|
||||||
|
distance: {
|
||||||
|
moving: number;
|
||||||
|
total: number;
|
||||||
|
};
|
||||||
|
time: {
|
||||||
|
start: Date | undefined;
|
||||||
|
end: Date | undefined;
|
||||||
|
moving: number;
|
||||||
|
total: number;
|
||||||
|
};
|
||||||
|
speed: {
|
||||||
|
moving: number;
|
||||||
|
total: number;
|
||||||
|
};
|
||||||
|
elevation: {
|
||||||
|
gain: number;
|
||||||
|
loss: number;
|
||||||
|
};
|
||||||
|
bounds: {
|
||||||
|
southWest: Coordinates;
|
||||||
|
northEast: Coordinates;
|
||||||
|
};
|
||||||
|
atemp: {
|
||||||
|
avg: number;
|
||||||
|
count: number;
|
||||||
|
};
|
||||||
|
hr: {
|
||||||
|
avg: number;
|
||||||
|
count: number;
|
||||||
|
};
|
||||||
|
cad: {
|
||||||
|
avg: number;
|
||||||
|
count: number;
|
||||||
|
};
|
||||||
|
power: {
|
||||||
|
avg: number;
|
||||||
|
count: number;
|
||||||
|
};
|
||||||
|
extensions: Record<string, Record<string, number>>;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.length = 0;
|
||||||
|
this.distance = {
|
||||||
|
moving: 0,
|
||||||
|
total: 0,
|
||||||
|
};
|
||||||
|
this.time = {
|
||||||
|
start: undefined,
|
||||||
|
end: undefined,
|
||||||
|
moving: 0,
|
||||||
|
total: 0,
|
||||||
|
};
|
||||||
|
this.speed = {
|
||||||
|
moving: 0,
|
||||||
|
total: 0,
|
||||||
|
};
|
||||||
|
this.elevation = {
|
||||||
|
gain: 0,
|
||||||
|
loss: 0,
|
||||||
|
};
|
||||||
|
this.bounds = {
|
||||||
|
southWest: {
|
||||||
|
lat: 90,
|
||||||
|
lon: 180,
|
||||||
|
},
|
||||||
|
northEast: {
|
||||||
|
lat: -90,
|
||||||
|
lon: -180,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
this.atemp = {
|
||||||
|
avg: 0,
|
||||||
|
count: 0,
|
||||||
|
};
|
||||||
|
this.hr = {
|
||||||
|
avg: 0,
|
||||||
|
count: 0,
|
||||||
|
};
|
||||||
|
this.cad = {
|
||||||
|
avg: 0,
|
||||||
|
count: 0,
|
||||||
|
};
|
||||||
|
this.power = {
|
||||||
|
avg: 0,
|
||||||
|
count: 0,
|
||||||
|
};
|
||||||
|
this.extensions = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
mergeWith(other: GPXGlobalStatistics): void {
|
||||||
|
this.length += other.length;
|
||||||
|
|
||||||
|
this.distance.total += other.distance.total;
|
||||||
|
this.distance.moving += other.distance.moving;
|
||||||
|
|
||||||
|
this.time.start =
|
||||||
|
this.time.start !== undefined && other.time.start !== undefined
|
||||||
|
? new Date(Math.min(this.time.start.getTime(), other.time.start.getTime()))
|
||||||
|
: (this.time.start ?? other.time.start);
|
||||||
|
this.time.end =
|
||||||
|
this.time.end !== undefined && other.time.end !== undefined
|
||||||
|
? new Date(Math.max(this.time.end.getTime(), other.time.end.getTime()))
|
||||||
|
: (this.time.end ?? other.time.end);
|
||||||
|
|
||||||
|
this.time.total += other.time.total;
|
||||||
|
this.time.moving += other.time.moving;
|
||||||
|
|
||||||
|
this.speed.moving =
|
||||||
|
this.time.moving > 0 ? this.distance.moving / (this.time.moving / 3600) : 0;
|
||||||
|
this.speed.total = this.time.total > 0 ? this.distance.total / (this.time.total / 3600) : 0;
|
||||||
|
|
||||||
|
this.elevation.gain += other.elevation.gain;
|
||||||
|
this.elevation.loss += other.elevation.loss;
|
||||||
|
|
||||||
|
this.bounds.southWest.lat = Math.min(this.bounds.southWest.lat, other.bounds.southWest.lat);
|
||||||
|
this.bounds.southWest.lon = Math.min(this.bounds.southWest.lon, other.bounds.southWest.lon);
|
||||||
|
this.bounds.northEast.lat = Math.max(this.bounds.northEast.lat, other.bounds.northEast.lat);
|
||||||
|
this.bounds.northEast.lon = Math.max(this.bounds.northEast.lon, other.bounds.northEast.lon);
|
||||||
|
|
||||||
|
this.atemp.avg =
|
||||||
|
(this.atemp.count * this.atemp.avg + other.atemp.count * other.atemp.avg) /
|
||||||
|
Math.max(1, this.atemp.count + other.atemp.count);
|
||||||
|
this.atemp.count += other.atemp.count;
|
||||||
|
this.hr.avg =
|
||||||
|
(this.hr.count * this.hr.avg + other.hr.count * other.hr.avg) /
|
||||||
|
Math.max(1, this.hr.count + other.hr.count);
|
||||||
|
this.hr.count += other.hr.count;
|
||||||
|
this.cad.avg =
|
||||||
|
(this.cad.count * this.cad.avg + other.cad.count * other.cad.avg) /
|
||||||
|
Math.max(1, this.cad.count + other.cad.count);
|
||||||
|
this.cad.count += other.cad.count;
|
||||||
|
this.power.avg =
|
||||||
|
(this.power.count * this.power.avg + other.power.count * other.power.avg) /
|
||||||
|
Math.max(1, this.power.count + other.power.count);
|
||||||
|
this.power.count += other.power.count;
|
||||||
|
|
||||||
|
Object.keys(other.extensions).forEach((extension) => {
|
||||||
|
if (this.extensions[extension] === undefined) {
|
||||||
|
this.extensions[extension] = {};
|
||||||
|
}
|
||||||
|
Object.keys(other.extensions[extension]).forEach((value) => {
|
||||||
|
if (this.extensions[extension][value] === undefined) {
|
||||||
|
this.extensions[extension][value] = 0;
|
||||||
|
}
|
||||||
|
this.extensions[extension][value] += other.extensions[extension][value];
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TrackPointLocalStatistics {
|
||||||
|
distance: {
|
||||||
|
moving: number;
|
||||||
|
total: number;
|
||||||
|
};
|
||||||
|
time: {
|
||||||
|
moving: number;
|
||||||
|
total: number;
|
||||||
|
};
|
||||||
|
speed: number;
|
||||||
|
elevation: {
|
||||||
|
gain: number;
|
||||||
|
loss: number;
|
||||||
|
};
|
||||||
|
slope: {
|
||||||
|
at: number;
|
||||||
|
segment: number;
|
||||||
|
length: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.distance = {
|
||||||
|
moving: 0,
|
||||||
|
total: 0,
|
||||||
|
};
|
||||||
|
this.time = {
|
||||||
|
moving: 0,
|
||||||
|
total: 0,
|
||||||
|
};
|
||||||
|
this.speed = 0;
|
||||||
|
this.elevation = {
|
||||||
|
gain: 0,
|
||||||
|
loss: 0,
|
||||||
|
};
|
||||||
|
this.slope = {
|
||||||
|
at: 0,
|
||||||
|
segment: 0,
|
||||||
|
length: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class GPXLocalStatistics {
|
||||||
|
points: TrackPoint[];
|
||||||
|
data: TrackPointLocalStatistics[];
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.points = [];
|
||||||
|
this.data = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TrackPointWithLocalStatistics = {
|
||||||
|
trkpt: TrackPoint;
|
||||||
|
} & TrackPointLocalStatistics;
|
||||||
|
|
||||||
|
export class GPXStatistics {
|
||||||
|
global: GPXGlobalStatistics;
|
||||||
|
local: GPXLocalStatistics;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.global = new GPXGlobalStatistics();
|
||||||
|
this.local = new GPXLocalStatistics();
|
||||||
|
}
|
||||||
|
|
||||||
|
sliced(start: number, end: number): GPXGlobalStatistics {
|
||||||
|
if (start < 0) {
|
||||||
|
start = 0;
|
||||||
|
} else if (start >= this.global.length) {
|
||||||
|
return new GPXGlobalStatistics();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (end < start) {
|
||||||
|
return new GPXGlobalStatistics();
|
||||||
|
} else if (end >= this.global.length) {
|
||||||
|
end = this.global.length - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start === 0 && end === this.global.length - 1) {
|
||||||
|
return this.global;
|
||||||
|
}
|
||||||
|
|
||||||
|
let statistics = new GPXGlobalStatistics();
|
||||||
|
|
||||||
|
statistics.length = end - start + 1;
|
||||||
|
|
||||||
|
statistics.distance.total =
|
||||||
|
this.local.data[end].distance.total - this.local.data[start].distance.total;
|
||||||
|
statistics.distance.moving =
|
||||||
|
this.local.data[end].distance.moving - this.local.data[start].distance.moving;
|
||||||
|
|
||||||
|
statistics.time.start = this.local.points[start].time;
|
||||||
|
statistics.time.end = this.local.points[end].time;
|
||||||
|
|
||||||
|
statistics.time.total = this.local.data[end].time.total - this.local.data[start].time.total;
|
||||||
|
statistics.time.moving =
|
||||||
|
this.local.data[end].time.moving - this.local.data[start].time.moving;
|
||||||
|
|
||||||
|
statistics.speed.moving =
|
||||||
|
statistics.time.moving > 0
|
||||||
|
? statistics.distance.moving / (statistics.time.moving / 3600)
|
||||||
|
: 0;
|
||||||
|
statistics.speed.total =
|
||||||
|
statistics.time.total > 0
|
||||||
|
? statistics.distance.total / (statistics.time.total / 3600)
|
||||||
|
: 0;
|
||||||
|
|
||||||
|
statistics.elevation.gain =
|
||||||
|
this.local.data[end].elevation.gain - this.local.data[start].elevation.gain;
|
||||||
|
statistics.elevation.loss =
|
||||||
|
this.local.data[end].elevation.loss - this.local.data[start].elevation.loss;
|
||||||
|
|
||||||
|
statistics.bounds.southWest.lat = this.global.bounds.southWest.lat;
|
||||||
|
statistics.bounds.southWest.lon = this.global.bounds.southWest.lon;
|
||||||
|
statistics.bounds.northEast.lat = this.global.bounds.northEast.lat;
|
||||||
|
statistics.bounds.northEast.lon = this.global.bounds.northEast.lon;
|
||||||
|
|
||||||
|
statistics.atemp = this.global.atemp;
|
||||||
|
statistics.hr = this.global.hr;
|
||||||
|
statistics.cad = this.global.cad;
|
||||||
|
statistics.power = this.global.power;
|
||||||
|
|
||||||
|
return statistics;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class GPXStatisticsGroup {
|
||||||
|
private _statistics: GPXStatistics[];
|
||||||
|
private _cumulative: GPXGlobalStatistics[];
|
||||||
|
private _slice: [number, number] | null = null;
|
||||||
|
global: GPXGlobalStatistics;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this._statistics = [];
|
||||||
|
this._cumulative = [new GPXGlobalStatistics()];
|
||||||
|
this.global = new GPXGlobalStatistics();
|
||||||
|
}
|
||||||
|
|
||||||
|
add(statistics: GPXStatistics | GPXStatisticsGroup): void {
|
||||||
|
if (statistics instanceof GPXStatisticsGroup) {
|
||||||
|
statistics._statistics.forEach((stats) => this._add(stats));
|
||||||
|
} else {
|
||||||
|
this._add(statistics);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_add(statistics: GPXStatistics): void {
|
||||||
|
this._statistics.push(statistics);
|
||||||
|
const cumulative = new GPXGlobalStatistics();
|
||||||
|
cumulative.mergeWith(this._cumulative[this._cumulative.length - 1]);
|
||||||
|
cumulative.mergeWith(statistics.global);
|
||||||
|
this._cumulative.push(cumulative);
|
||||||
|
this.global.mergeWith(statistics.global);
|
||||||
|
}
|
||||||
|
|
||||||
|
sliced(start: number, end: number): GPXGlobalStatistics {
|
||||||
|
let sliced = new GPXGlobalStatistics();
|
||||||
|
for (let i = 0; i < this._statistics.length; i++) {
|
||||||
|
const statistics = this._statistics[i];
|
||||||
|
const cumulative = this._cumulative[i];
|
||||||
|
if (start < cumulative.length + statistics.global.length && end >= cumulative.length) {
|
||||||
|
const localStart = Math.max(0, start - cumulative.length);
|
||||||
|
const localEnd = Math.min(statistics.global.length - 1, end - cumulative.length);
|
||||||
|
sliced.mergeWith(statistics.sliced(localStart, localEnd));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sliced;
|
||||||
|
}
|
||||||
|
|
||||||
|
getTrackPoint(index: number): TrackPointWithLocalStatistics | undefined {
|
||||||
|
if (this._slice !== null) {
|
||||||
|
index += this._slice[0];
|
||||||
|
}
|
||||||
|
for (let i = 0; i < this._statistics.length; i++) {
|
||||||
|
const statistics = this._statistics[i];
|
||||||
|
const cumulative = this._cumulative[i];
|
||||||
|
if (index < cumulative.length + statistics.global.length) {
|
||||||
|
return this._getTrackPoint(cumulative, statistics, index - cumulative.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
_getTrackPoint(
|
||||||
|
cumulative: GPXGlobalStatistics,
|
||||||
|
statistics: GPXStatistics,
|
||||||
|
index: number
|
||||||
|
): TrackPointWithLocalStatistics {
|
||||||
|
const point = statistics.local.points[index];
|
||||||
|
return {
|
||||||
|
trkpt: point,
|
||||||
|
distance: {
|
||||||
|
moving: statistics.local.data[index].distance.moving + cumulative.distance.moving,
|
||||||
|
total: statistics.local.data[index].distance.total + cumulative.distance.total,
|
||||||
|
},
|
||||||
|
time: {
|
||||||
|
moving: statistics.local.data[index].time.moving + cumulative.time.moving,
|
||||||
|
total: statistics.local.data[index].time.total + cumulative.time.total,
|
||||||
|
},
|
||||||
|
speed: statistics.local.data[index].speed,
|
||||||
|
elevation: {
|
||||||
|
gain: statistics.local.data[index].elevation.gain + cumulative.elevation.gain,
|
||||||
|
loss: statistics.local.data[index].elevation.loss + cumulative.elevation.loss,
|
||||||
|
},
|
||||||
|
slope: {
|
||||||
|
at: statistics.local.data[index].slope.at,
|
||||||
|
segment: statistics.local.data[index].slope.segment,
|
||||||
|
length: statistics.local.data[index].slope.length,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
forEachTrackPoint(
|
||||||
|
callback: (
|
||||||
|
point: TrackPoint,
|
||||||
|
distance: number,
|
||||||
|
speed: number,
|
||||||
|
slope: { at: number; segment: number; length: number },
|
||||||
|
index: number
|
||||||
|
) => void
|
||||||
|
): void {
|
||||||
|
for (let i = 0; i < this._statistics.length; i++) {
|
||||||
|
const statistics = this._statistics[i];
|
||||||
|
const cumulative = this._cumulative[i];
|
||||||
|
statistics.local.points.forEach((point, index) =>
|
||||||
|
callback(
|
||||||
|
point,
|
||||||
|
cumulative.distance.total + statistics.local.data[index].distance.total,
|
||||||
|
statistics.local.data[index].speed,
|
||||||
|
statistics.local.data[index].slope,
|
||||||
|
cumulative.length + index
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
6
package-lock.json
generated
6
package-lock.json
generated
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "gpx.studio",
|
|
||||||
"lockfileVersion": 3,
|
|
||||||
"requires": true,
|
|
||||||
"packages": {}
|
|
||||||
}
|
|
||||||
@@ -1 +1 @@
|
|||||||
PUBLIC_MAPBOX_TOKEN=YOUR_MAPBOX_TOKEN
|
PUBLIC_MAPTILER_KEY=YOUR_MAPTILER_KEY
|
||||||
2
website/.gitignore
vendored
2
website/.gitignore
vendored
@@ -8,3 +8,5 @@ node_modules
|
|||||||
!.env.example
|
!.env.example
|
||||||
vite.config.js.timestamp-*
|
vite.config.js.timestamp-*
|
||||||
vite.config.ts.timestamp-*
|
vite.config.ts.timestamp-*
|
||||||
|
static/*.webmanifest
|
||||||
|
!static/en.manifest.webmanifest
|
||||||
1302
website/package-lock.json
generated
1302
website/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -10,8 +10,8 @@
|
|||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||||
"lint": "prettier --check . && eslint .",
|
"lint": "prettier --check . --config ../.prettierrc --ignore-path ../.prettierignore --ignore-path ./.gitignore && eslint .",
|
||||||
"format": "prettier --write ."
|
"format": "prettier --write . --config ../.prettierrc --ignore-path ../.prettierignore --ignore-path ./.gitignore"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@lucide/svelte": "^0.544.0",
|
"@lucide/svelte": "^0.544.0",
|
||||||
@@ -23,15 +23,14 @@
|
|||||||
"@types/eslint": "^9.6.1",
|
"@types/eslint": "^9.6.1",
|
||||||
"@types/events": "^3.0.3",
|
"@types/events": "^3.0.3",
|
||||||
"@types/file-saver": "^2.0.7",
|
"@types/file-saver": "^2.0.7",
|
||||||
|
"@types/mapbox__sphericalmercator": "^1.2.3",
|
||||||
"@types/mapbox__tilebelt": "^1.0.4",
|
"@types/mapbox__tilebelt": "^1.0.4",
|
||||||
"@types/mapbox-gl": "^3.4.1",
|
|
||||||
"@types/node": "^22.15.30",
|
"@types/node": "^22.15.30",
|
||||||
"@types/png.js": "^0.2.3",
|
|
||||||
"@types/sanitize-html": "^2.16.0",
|
"@types/sanitize-html": "^2.16.0",
|
||||||
"@types/sortablejs": "^1.15.8",
|
"@types/sortablejs": "^1.15.8",
|
||||||
"@typescript-eslint/eslint-plugin": "^8.33.1",
|
"@typescript-eslint/eslint-plugin": "^8.33.1",
|
||||||
"@typescript-eslint/parser": "^8.33.1",
|
"@typescript-eslint/parser": "^8.33.1",
|
||||||
"bits-ui": "^2.12.0",
|
"bits-ui": "^2.14.4",
|
||||||
"eslint": "^9.28.0",
|
"eslint": "^9.28.0",
|
||||||
"eslint-config-prettier": "^10.1.5",
|
"eslint-config-prettier": "^10.1.5",
|
||||||
"eslint-plugin-svelte": "^3.9.1",
|
"eslint-plugin-svelte": "^3.9.1",
|
||||||
@@ -46,6 +45,7 @@
|
|||||||
"prettier-plugin-svelte": "^3.4.0",
|
"prettier-plugin-svelte": "^3.4.0",
|
||||||
"svelte": "^5.33.18",
|
"svelte": "^5.33.18",
|
||||||
"svelte-check": "^4.0.0",
|
"svelte-check": "^4.0.0",
|
||||||
|
"svelte-dnd-action": "^0.9.65",
|
||||||
"svelte-sonner": "^1.0.5",
|
"svelte-sonner": "^1.0.5",
|
||||||
"tailwind-variants": "^3.1.1",
|
"tailwind-variants": "^3.1.1",
|
||||||
"tailwindcss": "^4.1.8",
|
"tailwindcss": "^4.1.8",
|
||||||
@@ -61,11 +61,10 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@docsearch/js": "^3.9.0",
|
"@docsearch/js": "^3.9.0",
|
||||||
"@internationalized/date": "^3.8.2",
|
"@internationalized/date": "^3.8.2",
|
||||||
"@mapbox/mapbox-gl-geocoder": "^5.0.3",
|
|
||||||
"@mapbox/sphericalmercator": "^2.0.1",
|
"@mapbox/sphericalmercator": "^2.0.1",
|
||||||
"@mapbox/tilebelt": "^2.0.2",
|
"@mapbox/tilebelt": "^2.0.2",
|
||||||
"@types/mapbox__sphericalmercator": "^1.2.3",
|
"@maplibre/maplibre-gl-geocoder": "^1.9.4",
|
||||||
"chart.js": "^4.4.9",
|
"chart.js": "^4.5.1",
|
||||||
"chartjs-plugin-zoom": "^2.2.0",
|
"chartjs-plugin-zoom": "^2.2.0",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"dexie": "^4.0.11",
|
"dexie": "^4.0.11",
|
||||||
@@ -73,9 +72,8 @@
|
|||||||
"gpx": "file:../gpx",
|
"gpx": "file:../gpx",
|
||||||
"immer": "^10.1.1",
|
"immer": "^10.1.1",
|
||||||
"jszip": "^3.10.1",
|
"jszip": "^3.10.1",
|
||||||
"mapbox-gl": "^3.12.0",
|
|
||||||
"mapillary-js": "^4.1.2",
|
"mapillary-js": "^4.1.2",
|
||||||
"png.js": "^0.2.1",
|
"maplibre-gl": "^5.16.0",
|
||||||
"sanitize-html": "^2.17.0",
|
"sanitize-html": "^2.17.0",
|
||||||
"sortablejs": "^1.15.6",
|
"sortablejs": "^1.15.6",
|
||||||
"tailwind-merge": "^3.3.0"
|
"tailwind-merge": "^3.3.0"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
@import "tailwindcss";
|
@import 'tailwindcss';
|
||||||
@import "tw-animate-css";
|
@import 'tw-animate-css';
|
||||||
|
|
||||||
@custom-variant dark (&:is(.dark *));
|
@custom-variant dark (&:is(.dark *));
|
||||||
|
|
||||||
@@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
--support: rgb(220 15 130);
|
--support: rgb(220 15 130);
|
||||||
--link: rgb(0 110 180);
|
--link: rgb(0 110 180);
|
||||||
|
--selection: hsl(240 4.8% 93%);
|
||||||
|
|
||||||
--radius: 0.5rem;
|
--radius: 0.5rem;
|
||||||
}
|
}
|
||||||
@@ -69,6 +70,7 @@
|
|||||||
|
|
||||||
--support: rgb(255 110 190);
|
--support: rgb(255 110 190);
|
||||||
--link: rgb(80 190 255);
|
--link: rgb(80 190 255);
|
||||||
|
--selection: hsl(240 3.7% 22%);
|
||||||
}
|
}
|
||||||
|
|
||||||
@theme inline {
|
@theme inline {
|
||||||
@@ -109,6 +111,8 @@
|
|||||||
--color-sidebar-ring: var(--sidebar-ring);
|
--color-sidebar-ring: var(--sidebar-ring);
|
||||||
--color-support: var(--support);
|
--color-support: var(--support);
|
||||||
--color-link: var(--link);
|
--color-link: var(--link);
|
||||||
|
|
||||||
|
--breakpoint-xs: 540px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@layer base {
|
@layer base {
|
||||||
|
|||||||
@@ -24,6 +24,14 @@ export async function handle({ event, resolve }) {
|
|||||||
|
|
||||||
let headTag = `<head>
|
let headTag = `<head>
|
||||||
<title>gpx.studio — ${title}</title>
|
<title>gpx.studio — ${title}</title>
|
||||||
|
<script type="application/ld+json">
|
||||||
|
{
|
||||||
|
"@context": "https://schema.org",
|
||||||
|
"@type": "WebSite",
|
||||||
|
"name": "gpx.studio",
|
||||||
|
"url": "https://gpx.studio"
|
||||||
|
}
|
||||||
|
</script>
|
||||||
<meta name="description" content="${description}" />
|
<meta name="description" content="${description}" />
|
||||||
<meta property="og:title" content="gpx.studio — ${title}" />
|
<meta property="og:title" content="gpx.studio — ${title}" />
|
||||||
<meta property="og:description" content="${description}" />
|
<meta property="og:description" content="${description}" />
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sprite": "https://demotiles.maplibre.org/styles/osm-bright-gl-style/sprite",
|
"sprite": "https://demotiles.maplibre.org/styles/osm-bright-gl-style/sprite",
|
||||||
"glyphs": "https://api.maptiler.com/fonts/{fontstack}/{range}.pbf?key={key}",
|
|
||||||
"layers": [
|
"layers": [
|
||||||
{
|
{
|
||||||
"id": "background",
|
"id": "background",
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 3.6 MiB After Width: | Height: | Size: 3.6 MiB |
|
Before Width: | Height: | Size: 1.5 MiB After Width: | Height: | Size: 1.5 MiB |
@@ -22,15 +22,18 @@ import {
|
|||||||
Binoculars,
|
Binoculars,
|
||||||
Toilet,
|
Toilet,
|
||||||
} from 'lucide-static';
|
} from 'lucide-static';
|
||||||
import { type StyleSpecification } from 'mapbox-gl';
|
import { type RasterDEMSourceSpecification, type StyleSpecification } from 'maplibre-gl';
|
||||||
import ignFrTopo from './custom/ign-fr-topo.json';
|
import ignFrTopo from './custom/ign-fr-topo.json';
|
||||||
import ignFrPlan from './custom/ign-fr-plan.json';
|
import ignFrPlan from './custom/ign-fr-plan.json';
|
||||||
import ignFrSatellite from './custom/ign-fr-satellite.json';
|
import ignFrSatellite from './custom/ign-fr-satellite.json';
|
||||||
import bikerouterGravel from './custom/bikerouter-gravel.json';
|
import bikerouterGravel from './custom/bikerouter-gravel.json';
|
||||||
|
|
||||||
|
export const maptilerKeyPlaceHolder = 'MAPTILER_KEY';
|
||||||
|
|
||||||
export const basemaps: { [key: string]: string | StyleSpecification } = {
|
export const basemaps: { [key: string]: string | StyleSpecification } = {
|
||||||
mapboxOutdoors: 'mapbox://styles/mapbox/outdoors-v12',
|
maptilerTopo: `https://api.maptiler.com/maps/topo-v4/style.json?key=${maptilerKeyPlaceHolder}`,
|
||||||
mapboxSatellite: 'mapbox://styles/mapbox/satellite-streets-v12',
|
maptilerOutdoors: `https://api.maptiler.com/maps/outdoor-v4/style.json?key=${maptilerKeyPlaceHolder}`,
|
||||||
|
maptilerSatellite: `https://api.maptiler.com/maps/hybrid-v4/style.json?key=${maptilerKeyPlaceHolder}`,
|
||||||
openStreetMap: {
|
openStreetMap: {
|
||||||
version: 8,
|
version: 8,
|
||||||
sources: {
|
sources: {
|
||||||
@@ -145,18 +148,19 @@ export const basemaps: { [key: string]: string | StyleSpecification } = {
|
|||||||
swisstopoVector: 'https://vectortiles.geo.admin.ch/styles/ch.swisstopo.basemap.vt/style.json',
|
swisstopoVector: 'https://vectortiles.geo.admin.ch/styles/ch.swisstopo.basemap.vt/style.json',
|
||||||
swisstopoSatellite:
|
swisstopoSatellite:
|
||||||
'https://vectortiles.geo.admin.ch/styles/ch.swisstopo.imagerybasemap.vt/style.json',
|
'https://vectortiles.geo.admin.ch/styles/ch.swisstopo.imagerybasemap.vt/style.json',
|
||||||
linz: 'https://basemaps.linz.govt.nz/v1/tiles/topographic/EPSG:3857/style/topographic.json?api=d01fbtg0ar23gctac5m0jgyy2ds',
|
linz: 'https://basemaps.linz.govt.nz/v1/styles/topographic-v2.json?api=d01fbtg0ar23gctac5m0jgyy2ds',
|
||||||
linzTopo: {
|
linzTopo: {
|
||||||
version: 8,
|
version: 8,
|
||||||
sources: {
|
sources: {
|
||||||
linzTopo: {
|
linzTopo: {
|
||||||
type: 'raster',
|
type: 'raster',
|
||||||
tiles: [
|
tiles: [
|
||||||
'https://tiles-cdn.koordinates.com/services;key=39a8b989633a4bef98bc0e065380454a/tiles/v4/layer=50767/EPSG:3857/{z}/{x}/{y}.png',
|
'https://basemaps.linz.govt.nz/v1/tiles/topo-raster/WebMercatorQuad/{z}/{x}/{y}.webp?api=d01fbtg0ar23gctac5m0jgyy2ds',
|
||||||
],
|
],
|
||||||
tileSize: 256,
|
tileSize: 256,
|
||||||
maxzoom: 18,
|
maxzoom: 16,
|
||||||
attribution: '© <a href="https://www.linz.govt.nz/" target="_blank">LINZ</a>',
|
attribution:
|
||||||
|
'© <a href="//www.linz.govt.nz/linz-copyright">LINZ CC BY 4.0</a> © <a href="//www.linz.govt.nz/data/linz-data/linz-basemaps/data-attribution">Imagery Basemap contributors</a>',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
layers: [
|
layers: [
|
||||||
@@ -186,8 +190,8 @@ export const basemaps: { [key: string]: string | StyleSpecification } = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
ignFrPlan: ignFrPlan,
|
ignFrPlan: ignFrPlan as StyleSpecification,
|
||||||
ignFrTopo: ignFrTopo,
|
ignFrTopo: ignFrTopo as StyleSpecification,
|
||||||
ignFrScan25: {
|
ignFrScan25: {
|
||||||
version: 8,
|
version: 8,
|
||||||
sources: {
|
sources: {
|
||||||
@@ -209,7 +213,7 @@ export const basemaps: { [key: string]: string | StyleSpecification } = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
ignFrSatellite: ignFrSatellite,
|
ignFrSatellite: ignFrSatellite as StyleSpecification,
|
||||||
ignEs: {
|
ignEs: {
|
||||||
version: 8,
|
version: 8,
|
||||||
sources: {
|
sources: {
|
||||||
@@ -276,68 +280,6 @@ export const basemaps: { [key: string]: string | StyleSpecification } = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
swedenTopo: {
|
|
||||||
version: 8,
|
|
||||||
sources: {
|
|
||||||
swedenTopoWMTS: {
|
|
||||||
type: 'raster',
|
|
||||||
tiles: [
|
|
||||||
'https://api.lantmateriet.se/open/topowebb-ccby/v1/wmts/token/1d54dd14-a28c-38a9-b6f3-b4ebfcc3c204/1.0.0/topowebb/default/3857/{z}/{y}/{x}.png',
|
|
||||||
],
|
|
||||||
tileSize: 256,
|
|
||||||
maxzoom: 14,
|
|
||||||
attribution:
|
|
||||||
'© <a href="https://www.lantmateriet.se" target="_blank">Lantmäteriet</a>',
|
|
||||||
},
|
|
||||||
swedenTopoWMS: {
|
|
||||||
type: 'raster',
|
|
||||||
tiles: [
|
|
||||||
'https://minkarta.lantmateriet.se/map/topowebb?REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&FORMAT=image%2Fpng&STYLES=&TRANSPARENT=false&LAYERS=topowebbkartan&TILED=true&MAP_RESOLUTION=180&WIDTH=512&HEIGHT=512&SRS=EPSG%3A3857&BBOX={bbox-epsg-3857}',
|
|
||||||
],
|
|
||||||
tileSize: 512,
|
|
||||||
minzoom: 14,
|
|
||||||
maxzoom: 20,
|
|
||||||
attribution:
|
|
||||||
'© <a href="https://www.lantmateriet.se" target="_blank">Lantmäteriet</a>',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
layers: [
|
|
||||||
{
|
|
||||||
id: 'swedenTopoWMTS',
|
|
||||||
type: 'raster',
|
|
||||||
source: 'swedenTopoWMTS',
|
|
||||||
maxzoom: 14,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'swedenTopoWMS',
|
|
||||||
type: 'raster',
|
|
||||||
source: 'swedenTopoWMS',
|
|
||||||
minzoom: 14,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
swedenSatellite: {
|
|
||||||
version: 8,
|
|
||||||
sources: {
|
|
||||||
swedenSatellite: {
|
|
||||||
type: 'raster',
|
|
||||||
tiles: [
|
|
||||||
'https://minkarta.lantmateriet.se/map/ortofoto?REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&FORMAT=image%2Fpng&STYLES=&TRANSPARENT=false&LAYERS=Ortofoto_0.5%2COrtofoto_0.4%2COrtofoto_0.25%2COrtofoto_0.16&TILED=true&MAP_RESOLUTION=180&WIDTH=512&HEIGHT=512&SRS=EPSG%3A3857&BBOX={bbox-epsg-3857}',
|
|
||||||
],
|
|
||||||
tileSize: 512,
|
|
||||||
maxzoom: 22,
|
|
||||||
attribution:
|
|
||||||
'© <a href="https://www.lantmateriet.se" target="_blank">Lantmäteriet</a>',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
layers: [
|
|
||||||
{
|
|
||||||
id: 'swedenSatellite',
|
|
||||||
type: 'raster',
|
|
||||||
source: 'swedenSatellite',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
finlandTopo: {
|
finlandTopo: {
|
||||||
version: 8,
|
version: 8,
|
||||||
sources: {
|
sources: {
|
||||||
@@ -428,7 +370,43 @@ export const overlays: { [key: string]: string | StyleSpecification } = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
bikerouterGravel: bikerouterGravel,
|
bikerouterGravel: bikerouterGravel as StyleSpecification,
|
||||||
|
openRailwayMap: {
|
||||||
|
version: 8,
|
||||||
|
sources: {
|
||||||
|
openRailwayMap: {
|
||||||
|
type: 'raster',
|
||||||
|
tiles: ['https://tiles.openrailwaymap.org/standard/{z}/{x}/{y}.png'],
|
||||||
|
tileSize: 256,
|
||||||
|
maxzoom: 19,
|
||||||
|
attribution:
|
||||||
|
'Data <a href="https://www.openstreetmap.org/copyright">© OpenStreetMap contributors</a>, Style: <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA 2.0</a> <a href="http://www.openrailwaymap.org/">OpenRailwayMap</a>',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
layers: [
|
||||||
|
{
|
||||||
|
id: 'openRailwayMap',
|
||||||
|
type: 'raster',
|
||||||
|
source: 'openRailwayMap',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
mapterhornHillshade: {
|
||||||
|
version: 8,
|
||||||
|
sources: {
|
||||||
|
mapterhornHillshade: {
|
||||||
|
type: 'raster-dem',
|
||||||
|
url: 'https://tiles.mapterhorn.com/tilejson.json',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
layers: [
|
||||||
|
{
|
||||||
|
id: 'mapterhornHillshade',
|
||||||
|
type: 'hillshade',
|
||||||
|
source: 'mapterhornHillshade',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
swisstopoSlope: {
|
swisstopoSlope: {
|
||||||
version: 8,
|
version: 8,
|
||||||
sources: {
|
sources: {
|
||||||
@@ -798,8 +776,9 @@ export type LayerTreeType = { [key: string]: LayerTreeType | boolean };
|
|||||||
export const basemapTree: LayerTreeType = {
|
export const basemapTree: LayerTreeType = {
|
||||||
basemaps: {
|
basemaps: {
|
||||||
world: {
|
world: {
|
||||||
mapboxOutdoors: true,
|
maptilerTopo: true,
|
||||||
mapboxSatellite: true,
|
maptilerOutdoors: true,
|
||||||
|
maptilerSatellite: true,
|
||||||
openStreetMap: true,
|
openStreetMap: true,
|
||||||
openTopoMap: true,
|
openTopoMap: true,
|
||||||
openHikingMap: true,
|
openHikingMap: true,
|
||||||
@@ -833,10 +812,6 @@ export const basemapTree: LayerTreeType = {
|
|||||||
ignEs: true,
|
ignEs: true,
|
||||||
ignEsSatellite: true,
|
ignEsSatellite: true,
|
||||||
},
|
},
|
||||||
sweden: {
|
|
||||||
swedenTopo: true,
|
|
||||||
swedenSatellite: true,
|
|
||||||
},
|
|
||||||
switzerland: {
|
switzerland: {
|
||||||
swisstopoRaster: true,
|
swisstopoRaster: true,
|
||||||
swisstopoVector: true,
|
swisstopoVector: true,
|
||||||
@@ -864,8 +839,10 @@ export const overlayTree: LayerTreeType = {
|
|||||||
waymarkedTrailsHorseRiding: true,
|
waymarkedTrailsHorseRiding: true,
|
||||||
waymarkedTrailsWinter: true,
|
waymarkedTrailsWinter: true,
|
||||||
},
|
},
|
||||||
cyclOSMlite: true,
|
|
||||||
bikerouterGravel: true,
|
bikerouterGravel: true,
|
||||||
|
cyclOSMlite: true,
|
||||||
|
mapterhornHillshade: true,
|
||||||
|
openRailwayMap: true,
|
||||||
},
|
},
|
||||||
countries: {
|
countries: {
|
||||||
france: {
|
france: {
|
||||||
@@ -901,6 +878,7 @@ export const overpassTree: LayerTreeType = {
|
|||||||
shower: true,
|
shower: true,
|
||||||
shelter: true,
|
shelter: true,
|
||||||
barrier: true,
|
barrier: true,
|
||||||
|
cemetery: true,
|
||||||
},
|
},
|
||||||
tourism: {
|
tourism: {
|
||||||
attraction: true,
|
attraction: true,
|
||||||
@@ -933,7 +911,7 @@ export const overpassTree: LayerTreeType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Default basemap used
|
// Default basemap used
|
||||||
export const defaultBasemap = 'mapboxOutdoors';
|
export const defaultBasemap = 'maptilerTopo';
|
||||||
|
|
||||||
// Default overlays used (none)
|
// Default overlays used (none)
|
||||||
export const defaultOverlays: LayerTreeType = {
|
export const defaultOverlays: LayerTreeType = {
|
||||||
@@ -947,8 +925,10 @@ export const defaultOverlays: LayerTreeType = {
|
|||||||
waymarkedTrailsHorseRiding: false,
|
waymarkedTrailsHorseRiding: false,
|
||||||
waymarkedTrailsWinter: false,
|
waymarkedTrailsWinter: false,
|
||||||
},
|
},
|
||||||
cyclOSMlite: false,
|
|
||||||
bikerouterGravel: false,
|
bikerouterGravel: false,
|
||||||
|
cyclOSMlite: false,
|
||||||
|
mapterhornHillshade: false,
|
||||||
|
openRailwayMap: false,
|
||||||
},
|
},
|
||||||
countries: {
|
countries: {
|
||||||
france: {
|
france: {
|
||||||
@@ -984,6 +964,7 @@ export const defaultOverpassQueries: LayerTreeType = {
|
|||||||
shower: false,
|
shower: false,
|
||||||
shelter: false,
|
shelter: false,
|
||||||
barrier: false,
|
barrier: false,
|
||||||
|
cemetery: false,
|
||||||
},
|
},
|
||||||
tourism: {
|
tourism: {
|
||||||
attraction: false,
|
attraction: false,
|
||||||
@@ -1019,8 +1000,9 @@ export const defaultOverpassQueries: LayerTreeType = {
|
|||||||
export const defaultBasemapTree: LayerTreeType = {
|
export const defaultBasemapTree: LayerTreeType = {
|
||||||
basemaps: {
|
basemaps: {
|
||||||
world: {
|
world: {
|
||||||
mapboxOutdoors: true,
|
maptilerTopo: true,
|
||||||
mapboxSatellite: true,
|
maptilerOutdoors: true,
|
||||||
|
maptilerSatellite: true,
|
||||||
openStreetMap: true,
|
openStreetMap: true,
|
||||||
openTopoMap: true,
|
openTopoMap: true,
|
||||||
openHikingMap: true,
|
openHikingMap: true,
|
||||||
@@ -1054,10 +1036,6 @@ export const defaultBasemapTree: LayerTreeType = {
|
|||||||
ignEs: false,
|
ignEs: false,
|
||||||
ignEsSatellite: false,
|
ignEsSatellite: false,
|
||||||
},
|
},
|
||||||
sweden: {
|
|
||||||
swedenTopo: false,
|
|
||||||
swedenSatellite: false,
|
|
||||||
},
|
|
||||||
switzerland: {
|
switzerland: {
|
||||||
swisstopoRaster: false,
|
swisstopoRaster: false,
|
||||||
swisstopoVector: false,
|
swisstopoVector: false,
|
||||||
@@ -1085,8 +1063,10 @@ export const defaultOverlayTree: LayerTreeType = {
|
|||||||
waymarkedTrailsHorseRiding: false,
|
waymarkedTrailsHorseRiding: false,
|
||||||
waymarkedTrailsWinter: false,
|
waymarkedTrailsWinter: false,
|
||||||
},
|
},
|
||||||
cyclOSMlite: false,
|
|
||||||
bikerouterGravel: false,
|
bikerouterGravel: false,
|
||||||
|
cyclOSMlite: false,
|
||||||
|
mapterhornHillshade: false,
|
||||||
|
openRailwayMap: false,
|
||||||
},
|
},
|
||||||
countries: {
|
countries: {
|
||||||
france: {
|
france: {
|
||||||
@@ -1122,6 +1102,7 @@ export const defaultOverpassTree: LayerTreeType = {
|
|||||||
shower: false,
|
shower: false,
|
||||||
shelter: false,
|
shelter: false,
|
||||||
barrier: false,
|
barrier: false,
|
||||||
|
cemetery: false,
|
||||||
},
|
},
|
||||||
tourism: {
|
tourism: {
|
||||||
attraction: false,
|
attraction: false,
|
||||||
@@ -1160,7 +1141,7 @@ export type CustomLayer = {
|
|||||||
maxZoom: number;
|
maxZoom: number;
|
||||||
layerType: 'basemap' | 'overlay';
|
layerType: 'basemap' | 'overlay';
|
||||||
resourceType: 'raster' | 'vector';
|
resourceType: 'raster' | 'vector';
|
||||||
value: string | {};
|
value: string | maplibregl.StyleSpecification;
|
||||||
};
|
};
|
||||||
|
|
||||||
type OverpassQueryData = {
|
type OverpassQueryData = {
|
||||||
@@ -1168,9 +1149,7 @@ type OverpassQueryData = {
|
|||||||
svg: string;
|
svg: string;
|
||||||
color: string;
|
color: string;
|
||||||
};
|
};
|
||||||
tags:
|
tags: Record<string, string | string[]> | Record<string, string | string[]>[];
|
||||||
| Record<string, string | boolean | string[]>
|
|
||||||
| Record<string, string | boolean | string[]>[];
|
|
||||||
symbol?: string;
|
symbol?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1251,6 +1230,20 @@ export const overpassQueryData: Record<string, OverpassQueryData> = {
|
|||||||
},
|
},
|
||||||
symbol: 'Shelter',
|
symbol: 'Shelter',
|
||||||
},
|
},
|
||||||
|
cemetery: {
|
||||||
|
icon: {
|
||||||
|
svg: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 17v-10a6 5 0 1 1 12 0v10"/><path d="M 4 21 a 1 1 0 0 0 1 1 h 14 a 1 1 0 0 0 1-1 v -1 a 2 2 0 0 0-2-2 H6 a 2 2 0 0 0-2 2 z"/></svg>',
|
||||||
|
color: '#000000',
|
||||||
|
},
|
||||||
|
tags: [
|
||||||
|
{
|
||||||
|
landuse: 'cemetery',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amenity: 'grave_yard',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
'fuel-station': {
|
'fuel-station': {
|
||||||
icon: {
|
icon: {
|
||||||
svg: Fuel,
|
svg: Fuel,
|
||||||
@@ -1287,7 +1280,25 @@ export const overpassQueryData: Record<string, OverpassQueryData> = {
|
|||||||
color: '#000000',
|
color: '#000000',
|
||||||
},
|
},
|
||||||
tags: {
|
tags: {
|
||||||
barrier: true,
|
barrier: [
|
||||||
|
'bar',
|
||||||
|
'barrier_board',
|
||||||
|
'block',
|
||||||
|
'chain',
|
||||||
|
'cycle_barrier',
|
||||||
|
'gate',
|
||||||
|
'hampshire_gate',
|
||||||
|
'horse_stile',
|
||||||
|
'kissing_gate',
|
||||||
|
'lift_gate',
|
||||||
|
'motorcycle_barrier',
|
||||||
|
'sliding_beam',
|
||||||
|
'sliding_gate',
|
||||||
|
'stile',
|
||||||
|
'swing_gate',
|
||||||
|
'turnstile',
|
||||||
|
'wicket_gate',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
attraction: {
|
attraction: {
|
||||||
@@ -1447,3 +1458,16 @@ export const overpassQueryData: Record<string, OverpassQueryData> = {
|
|||||||
symbol: 'Anchor',
|
symbol: 'Anchor',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const terrainSources: { [key: string]: RasterDEMSourceSpecification } = {
|
||||||
|
'maptiler-dem': {
|
||||||
|
type: 'raster-dem',
|
||||||
|
url: `https://api.maptiler.com/tiles/terrain-rgb-v2/tiles.json?key=${maptilerKeyPlaceHolder}`,
|
||||||
|
},
|
||||||
|
mapterhorn: {
|
||||||
|
type: 'raster-dem',
|
||||||
|
url: 'https://tiles.mapterhorn.com/tilejson.json',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const defaultTerrainSource = 'maptiler-dem';
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
Landmark,
|
Landmark,
|
||||||
Icon,
|
|
||||||
Shell,
|
Shell,
|
||||||
Bike,
|
Bike,
|
||||||
Building,
|
Building,
|
||||||
@@ -12,7 +11,7 @@ import {
|
|||||||
DoorOpen,
|
DoorOpen,
|
||||||
Trees,
|
Trees,
|
||||||
Fuel,
|
Fuel,
|
||||||
Home,
|
House,
|
||||||
Info,
|
Info,
|
||||||
TreeDeciduous,
|
TreeDeciduous,
|
||||||
CircleParking,
|
CircleParking,
|
||||||
@@ -29,6 +28,7 @@ import {
|
|||||||
TriangleAlert,
|
TriangleAlert,
|
||||||
Anchor,
|
Anchor,
|
||||||
Toilet,
|
Toilet,
|
||||||
|
X,
|
||||||
type IconProps,
|
type IconProps,
|
||||||
} from '@lucide/svelte';
|
} from '@lucide/svelte';
|
||||||
import {
|
import {
|
||||||
@@ -44,7 +44,7 @@ import {
|
|||||||
DoorOpen as DoorOpenSvg,
|
DoorOpen as DoorOpenSvg,
|
||||||
Trees as TreesSvg,
|
Trees as TreesSvg,
|
||||||
Fuel as FuelSvg,
|
Fuel as FuelSvg,
|
||||||
Home as HomeSvg,
|
House as HouseSvg,
|
||||||
Info as InfoSvg,
|
Info as InfoSvg,
|
||||||
TreeDeciduous as TreeDeciduousSvg,
|
TreeDeciduous as TreeDeciduousSvg,
|
||||||
CircleParking as CircleParkingSvg,
|
CircleParking as CircleParkingSvg,
|
||||||
@@ -61,6 +61,7 @@ import {
|
|||||||
TriangleAlert as TriangleAlertSvg,
|
TriangleAlert as TriangleAlertSvg,
|
||||||
Anchor as AnchorSvg,
|
Anchor as AnchorSvg,
|
||||||
Toilet as ToiletSvg,
|
Toilet as ToiletSvg,
|
||||||
|
X as XSvg,
|
||||||
} from 'lucide-static';
|
} from 'lucide-static';
|
||||||
import type { Component } from 'svelte';
|
import type { Component } from 'svelte';
|
||||||
|
|
||||||
@@ -87,7 +88,11 @@ export const symbols: { [key: string]: Symbol } = {
|
|||||||
icon: ShoppingBasket,
|
icon: ShoppingBasket,
|
||||||
iconSvg: ShoppingBasketSvg,
|
iconSvg: ShoppingBasketSvg,
|
||||||
},
|
},
|
||||||
crossing: { value: 'Crossing' },
|
crossing: {
|
||||||
|
value: 'Crossing',
|
||||||
|
icon: X,
|
||||||
|
iconSvg: XSvg,
|
||||||
|
},
|
||||||
department_store: {
|
department_store: {
|
||||||
value: 'Department Store',
|
value: 'Department Store',
|
||||||
icon: ShoppingBasket,
|
icon: ShoppingBasket,
|
||||||
@@ -95,7 +100,7 @@ export const symbols: { [key: string]: Symbol } = {
|
|||||||
},
|
},
|
||||||
drinking_water: { value: 'Drinking Water', icon: Droplet, iconSvg: DropletSvg },
|
drinking_water: { value: 'Drinking Water', icon: Droplet, iconSvg: DropletSvg },
|
||||||
exit: { value: 'Exit', icon: DoorOpen, iconSvg: DoorOpenSvg },
|
exit: { value: 'Exit', icon: DoorOpen, iconSvg: DoorOpenSvg },
|
||||||
lodge: { value: 'Lodge', icon: Home, iconSvg: HomeSvg },
|
lodge: { value: 'Lodge', icon: House, iconSvg: HouseSvg },
|
||||||
lodging: { value: 'Lodging', icon: Bed, iconSvg: BedSvg },
|
lodging: { value: 'Lodging', icon: Bed, iconSvg: BedSvg },
|
||||||
forest: { value: 'Forest', icon: Trees, iconSvg: TreesSvg },
|
forest: { value: 'Forest', icon: Trees, iconSvg: TreesSvg },
|
||||||
gas_station: { value: 'Gas Station', icon: Fuel, iconSvg: FuelSvg },
|
gas_station: { value: 'Gas Station', icon: Fuel, iconSvg: FuelSvg },
|
||||||
@@ -105,7 +110,7 @@ export const symbols: { [key: string]: Symbol } = {
|
|||||||
iconSvg: TrainFrontSvg,
|
iconSvg: TrainFrontSvg,
|
||||||
},
|
},
|
||||||
hotel: { value: 'Hotel', icon: Bed, iconSvg: BedSvg },
|
hotel: { value: 'Hotel', icon: Bed, iconSvg: BedSvg },
|
||||||
house: { value: 'House', icon: Home, iconSvg: HomeSvg },
|
house: { value: 'House', icon: House, iconSvg: HouseSvg },
|
||||||
information: { value: 'Information', icon: Info, iconSvg: InfoSvg },
|
information: { value: 'Information', icon: Info, iconSvg: InfoSvg },
|
||||||
park: { value: 'Park', icon: TreeDeciduous, iconSvg: TreeDeciduousSvg },
|
park: { value: 'Park', icon: TreeDeciduous, iconSvg: TreeDeciduousSvg },
|
||||||
parking_area: { value: 'Parking Area', icon: CircleParking, iconSvg: CircleParkingSvg },
|
parking_area: { value: 'Parking Area', icon: CircleParking, iconSvg: CircleParkingSvg },
|
||||||
|
|||||||
@@ -1,708 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import ButtonWithTooltip from '$lib/components/ButtonWithTooltip.svelte';
|
|
||||||
import * as Popover from '$lib/components/ui/popover/index.js';
|
|
||||||
import * as ToggleGroup from '$lib/components/ui/toggle-group/index.js';
|
|
||||||
import Chart from 'chart.js/auto';
|
|
||||||
import mapboxgl from 'mapbox-gl';
|
|
||||||
import { onDestroy, onMount } from 'svelte';
|
|
||||||
import {
|
|
||||||
BrickWall,
|
|
||||||
TriangleRight,
|
|
||||||
HeartPulse,
|
|
||||||
Orbit,
|
|
||||||
SquareActivity,
|
|
||||||
Thermometer,
|
|
||||||
Zap,
|
|
||||||
Circle,
|
|
||||||
Check,
|
|
||||||
ChartNoAxesColumn,
|
|
||||||
Construction,
|
|
||||||
} from '@lucide/svelte';
|
|
||||||
import { getSlopeColor, getSurfaceColor, getHighwayColor } from '$lib/assets/colors';
|
|
||||||
import {
|
|
||||||
getCadenceWithUnits,
|
|
||||||
getConvertedDistance,
|
|
||||||
getConvertedElevation,
|
|
||||||
getConvertedTemperature,
|
|
||||||
getConvertedVelocity,
|
|
||||||
getDistanceUnits,
|
|
||||||
getDistanceWithUnits,
|
|
||||||
getElevationWithUnits,
|
|
||||||
getHeartRateWithUnits,
|
|
||||||
getPowerWithUnits,
|
|
||||||
getTemperatureWithUnits,
|
|
||||||
getVelocityWithUnits,
|
|
||||||
} from '$lib/units';
|
|
||||||
import type { Readable, Writable } from 'svelte/store';
|
|
||||||
import type { GPXStatistics } from 'gpx';
|
|
||||||
import { mode } from 'mode-watcher';
|
|
||||||
import { settings } from '$lib/logic/settings';
|
|
||||||
import { map } from '$lib/components/map/map';
|
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
|
||||||
|
|
||||||
const { distanceUnits, velocityUnits, temperatureUnits } = settings;
|
|
||||||
|
|
||||||
let {
|
|
||||||
gpxStatistics,
|
|
||||||
slicedGPXStatistics,
|
|
||||||
additionalDatasets = $bindable(),
|
|
||||||
elevationFill = $bindable(),
|
|
||||||
showControls = true,
|
|
||||||
}: {
|
|
||||||
gpxStatistics: Readable<GPXStatistics>;
|
|
||||||
slicedGPXStatistics: Writable<[GPXStatistics, number, number] | undefined>;
|
|
||||||
additionalDatasets: string[];
|
|
||||||
elevationFill: 'slope' | 'surface' | 'highway' | undefined;
|
|
||||||
showControls?: boolean;
|
|
||||||
} = $props();
|
|
||||||
|
|
||||||
let canvas: HTMLCanvasElement;
|
|
||||||
let overlay: HTMLCanvasElement;
|
|
||||||
let chart: Chart;
|
|
||||||
|
|
||||||
Chart.defaults.font.family =
|
|
||||||
'ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"'; // Tailwind CSS font
|
|
||||||
|
|
||||||
let marker: mapboxgl.Marker | null = null;
|
|
||||||
let dragging = false;
|
|
||||||
let panning = false;
|
|
||||||
|
|
||||||
let options = {
|
|
||||||
animation: false,
|
|
||||||
parsing: false,
|
|
||||||
maintainAspectRatio: false,
|
|
||||||
scales: {
|
|
||||||
x: {
|
|
||||||
type: 'linear',
|
|
||||||
ticks: {
|
|
||||||
callback: function (value: number) {
|
|
||||||
return `${value.toFixed(1).replace(/\.0+$/, '')} ${getDistanceUnits()}`;
|
|
||||||
},
|
|
||||||
align: 'inner',
|
|
||||||
maxRotation: 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
y: {
|
|
||||||
type: 'linear',
|
|
||||||
ticks: {
|
|
||||||
callback: function (value: number) {
|
|
||||||
return getElevationWithUnits(value, false);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
datasets: {
|
|
||||||
line: {
|
|
||||||
pointRadius: 0,
|
|
||||||
tension: 0.4,
|
|
||||||
borderWidth: 2,
|
|
||||||
cubicInterpolationMode: 'monotone',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
interaction: {
|
|
||||||
mode: 'nearest',
|
|
||||||
axis: 'x',
|
|
||||||
intersect: false,
|
|
||||||
},
|
|
||||||
plugins: {
|
|
||||||
legend: {
|
|
||||||
display: false,
|
|
||||||
},
|
|
||||||
decimation: {
|
|
||||||
enabled: true,
|
|
||||||
},
|
|
||||||
tooltip: {
|
|
||||||
enabled: () => !dragging && !panning,
|
|
||||||
callbacks: {
|
|
||||||
title: function () {
|
|
||||||
return '';
|
|
||||||
},
|
|
||||||
label: function (context: Chart.TooltipContext) {
|
|
||||||
let point = context.raw;
|
|
||||||
if (context.datasetIndex === 0) {
|
|
||||||
if ($map && marker) {
|
|
||||||
if (dragging) {
|
|
||||||
marker.remove();
|
|
||||||
} else {
|
|
||||||
marker.setLngLat(point.coordinates);
|
|
||||||
marker.addTo($map);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return `${i18n._('quantities.elevation')}: ${getElevationWithUnits(point.y, false)}`;
|
|
||||||
} else if (context.datasetIndex === 1) {
|
|
||||||
return `${$velocityUnits === 'speed' ? i18n._('quantities.speed') : i18n._('quantities.pace')}: ${getVelocityWithUnits(point.y, false)}`;
|
|
||||||
} else if (context.datasetIndex === 2) {
|
|
||||||
return `${i18n._('quantities.heartrate')}: ${getHeartRateWithUnits(point.y)}`;
|
|
||||||
} else if (context.datasetIndex === 3) {
|
|
||||||
return `${i18n._('quantities.cadence')}: ${getCadenceWithUnits(point.y)}`;
|
|
||||||
} else if (context.datasetIndex === 4) {
|
|
||||||
return `${i18n._('quantities.temperature')}: ${getTemperatureWithUnits(point.y, false)}`;
|
|
||||||
} else if (context.datasetIndex === 5) {
|
|
||||||
return `${i18n._('quantities.power')}: ${getPowerWithUnits(point.y)}`;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
afterBody: function (contexts: Chart.TooltipContext[]) {
|
|
||||||
let context = contexts.filter((context) => context.datasetIndex === 0);
|
|
||||||
if (context.length === 0) return;
|
|
||||||
let point = context[0].raw;
|
|
||||||
let slope = {
|
|
||||||
at: point.slope.at.toFixed(1),
|
|
||||||
segment: point.slope.segment.toFixed(1),
|
|
||||||
length: getDistanceWithUnits(point.slope.length),
|
|
||||||
};
|
|
||||||
let surface = point.extensions.surface
|
|
||||||
? point.extensions.surface
|
|
||||||
: 'unknown';
|
|
||||||
let highway = point.extensions.highway
|
|
||||||
? point.extensions.highway
|
|
||||||
: 'unknown';
|
|
||||||
let sacScale = point.extensions.sac_scale;
|
|
||||||
let mtbScale = point.extensions.mtb_scale;
|
|
||||||
|
|
||||||
let labels = [
|
|
||||||
` ${i18n._('quantities.distance')}: ${getDistanceWithUnits(point.x, false)}`,
|
|
||||||
` ${i18n._('quantities.slope')}: ${slope.at} %${elevationFill === 'slope' ? ` (${slope.length} @${slope.segment} %)` : ''}`,
|
|
||||||
];
|
|
||||||
|
|
||||||
if (elevationFill === 'surface') {
|
|
||||||
labels.push(
|
|
||||||
` ${i18n._('quantities.surface')}: ${i18n._(`toolbar.routing.surface.${surface}`)}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (elevationFill === 'highway') {
|
|
||||||
labels.push(
|
|
||||||
` ${i18n._('quantities.highway')}: ${i18n._(`toolbar.routing.highway.${highway}`)}${
|
|
||||||
sacScale
|
|
||||||
? ` (${i18n._(`toolbar.routing.sac_scale.${sacScale}`)})`
|
|
||||||
: ''
|
|
||||||
}`
|
|
||||||
);
|
|
||||||
if (mtbScale) {
|
|
||||||
labels.push(
|
|
||||||
` ${i18n._('toolbar.routing.mtb_scale')}: ${mtbScale}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (point.time) {
|
|
||||||
labels.push(
|
|
||||||
` ${i18n._('quantities.time')}: ${i18n.df.format(point.time)}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return labels;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
zoom: {
|
|
||||||
pan: {
|
|
||||||
enabled: true,
|
|
||||||
mode: 'x',
|
|
||||||
modifierKey: 'shift',
|
|
||||||
onPanStart: function () {
|
|
||||||
// hide tooltip
|
|
||||||
panning = true;
|
|
||||||
$slicedGPXStatistics = undefined;
|
|
||||||
},
|
|
||||||
onPanComplete: function () {
|
|
||||||
panning = false;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
zoom: {
|
|
||||||
wheel: {
|
|
||||||
enabled: true,
|
|
||||||
},
|
|
||||||
mode: 'x',
|
|
||||||
onZoomStart: function ({ chart, event }: { chart: Chart; event: any }) {
|
|
||||||
if (
|
|
||||||
event.deltaY < 0 &&
|
|
||||||
Math.abs(
|
|
||||||
chart.getInitialScaleBounds().x.max /
|
|
||||||
chart.options.plugins.zoom.limits.x.minRange -
|
|
||||||
chart.getZoomLevel()
|
|
||||||
) < 0.01
|
|
||||||
) {
|
|
||||||
// Disable wheel pan if zoomed in to the max, and zooming in
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$slicedGPXStatistics = undefined;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
limits: {
|
|
||||||
x: {
|
|
||||||
min: 'original',
|
|
||||||
max: 'original',
|
|
||||||
minRange: 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
stacked: false,
|
|
||||||
onResize: function () {
|
|
||||||
updateOverlay();
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
let datasets: string[] = ['speed', 'hr', 'cad', 'atemp', 'power'];
|
|
||||||
datasets.forEach((id) => {
|
|
||||||
options.scales[`y${id}`] = {
|
|
||||||
type: 'linear',
|
|
||||||
position: 'right',
|
|
||||||
grid: {
|
|
||||||
display: false,
|
|
||||||
},
|
|
||||||
reverse: () => id === 'speed' && $velocityUnits === 'pace',
|
|
||||||
display: false,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
onMount(async () => {
|
|
||||||
Chart.register((await import('chartjs-plugin-zoom')).default); // dynamic import to avoid SSR and 'window is not defined' error
|
|
||||||
|
|
||||||
chart = new Chart(canvas, {
|
|
||||||
type: 'line',
|
|
||||||
data: {
|
|
||||||
datasets: [],
|
|
||||||
},
|
|
||||||
options,
|
|
||||||
plugins: [
|
|
||||||
{
|
|
||||||
id: 'toggleMarker',
|
|
||||||
events: ['mouseout'],
|
|
||||||
afterEvent: function (chart: Chart, args: { event: Chart.ChartEvent }) {
|
|
||||||
if (args.event.type === 'mouseout') {
|
|
||||||
if ($map && marker) {
|
|
||||||
marker.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
// Map marker to show on hover
|
|
||||||
let element = document.createElement('div');
|
|
||||||
element.className = 'h-4 w-4 rounded-full bg-cyan-500 border-2 border-white';
|
|
||||||
marker = new mapboxgl.Marker({
|
|
||||||
element,
|
|
||||||
});
|
|
||||||
|
|
||||||
let startIndex = 0;
|
|
||||||
let endIndex = 0;
|
|
||||||
function getIndex(evt) {
|
|
||||||
const points = chart.getElementsAtEventForMode(
|
|
||||||
evt,
|
|
||||||
'x',
|
|
||||||
{
|
|
||||||
intersect: false,
|
|
||||||
},
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
if (points.length === 0) {
|
|
||||||
const rect = canvas.getBoundingClientRect();
|
|
||||||
if (evt.x - rect.left <= chart.chartArea.left) {
|
|
||||||
return 0;
|
|
||||||
} else if (evt.x - rect.left >= chart.chartArea.right) {
|
|
||||||
return $gpxStatistics.local.points.length - 1;
|
|
||||||
} else {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let point = points.find((point) => point.element.raw);
|
|
||||||
if (point) {
|
|
||||||
return point.element.raw.index;
|
|
||||||
} else {
|
|
||||||
return points[0].index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let dragStarted = false;
|
|
||||||
function onMouseDown(evt) {
|
|
||||||
if (evt.shiftKey) {
|
|
||||||
// Panning interaction
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
dragStarted = true;
|
|
||||||
canvas.style.cursor = 'col-resize';
|
|
||||||
startIndex = getIndex(evt);
|
|
||||||
}
|
|
||||||
function onMouseMove(evt) {
|
|
||||||
if (dragStarted) {
|
|
||||||
dragging = true;
|
|
||||||
endIndex = getIndex(evt);
|
|
||||||
if (endIndex !== undefined) {
|
|
||||||
if (startIndex === undefined) {
|
|
||||||
startIndex = endIndex;
|
|
||||||
} else if (startIndex !== endIndex) {
|
|
||||||
$slicedGPXStatistics = [
|
|
||||||
$gpxStatistics.slice(
|
|
||||||
Math.min(startIndex, endIndex),
|
|
||||||
Math.max(startIndex, endIndex)
|
|
||||||
),
|
|
||||||
Math.min(startIndex, endIndex),
|
|
||||||
Math.max(startIndex, endIndex),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function onMouseUp(evt) {
|
|
||||||
dragStarted = false;
|
|
||||||
dragging = false;
|
|
||||||
canvas.style.cursor = '';
|
|
||||||
endIndex = getIndex(evt);
|
|
||||||
if (startIndex === endIndex) {
|
|
||||||
$slicedGPXStatistics = undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
canvas.addEventListener('pointerdown', onMouseDown);
|
|
||||||
canvas.addEventListener('pointermove', onMouseMove);
|
|
||||||
canvas.addEventListener('pointerup', onMouseUp);
|
|
||||||
});
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
let data = $gpxStatistics;
|
|
||||||
if (chart && $distanceUnits && $velocityUnits && $temperatureUnits) {
|
|
||||||
// update data
|
|
||||||
chart.data.datasets[0] = {
|
|
||||||
label: i18n._('quantities.elevation'),
|
|
||||||
data: data.local.points.map((point, index) => {
|
|
||||||
return {
|
|
||||||
x: getConvertedDistance(data.local.distance.total[index]),
|
|
||||||
y: point.ele ? getConvertedElevation(point.ele) : 0,
|
|
||||||
time: point.time,
|
|
||||||
slope: {
|
|
||||||
at: data.local.slope.at[index],
|
|
||||||
segment: data.local.slope.segment[index],
|
|
||||||
length: data.local.slope.length[index],
|
|
||||||
},
|
|
||||||
extensions: point.getExtensions(),
|
|
||||||
coordinates: point.getCoordinates(),
|
|
||||||
index: index,
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
normalized: true,
|
|
||||||
fill: 'start',
|
|
||||||
order: 1,
|
|
||||||
};
|
|
||||||
chart.data.datasets[1] = {
|
|
||||||
data: data.local.points.map((point, index) => {
|
|
||||||
return {
|
|
||||||
x: getConvertedDistance(data.local.distance.total[index]),
|
|
||||||
y: getConvertedVelocity(data.local.speed[index]),
|
|
||||||
index: index,
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
normalized: true,
|
|
||||||
yAxisID: 'yspeed',
|
|
||||||
hidden: true,
|
|
||||||
};
|
|
||||||
chart.data.datasets[2] = {
|
|
||||||
data: data.local.points.map((point, index) => {
|
|
||||||
return {
|
|
||||||
x: getConvertedDistance(data.local.distance.total[index]),
|
|
||||||
y: point.getHeartRate(),
|
|
||||||
index: index,
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
normalized: true,
|
|
||||||
yAxisID: 'yhr',
|
|
||||||
hidden: true,
|
|
||||||
};
|
|
||||||
chart.data.datasets[3] = {
|
|
||||||
data: data.local.points.map((point, index) => {
|
|
||||||
return {
|
|
||||||
x: getConvertedDistance(data.local.distance.total[index]),
|
|
||||||
y: point.getCadence(),
|
|
||||||
index: index,
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
normalized: true,
|
|
||||||
yAxisID: 'ycad',
|
|
||||||
hidden: true,
|
|
||||||
};
|
|
||||||
chart.data.datasets[4] = {
|
|
||||||
data: data.local.points.map((point, index) => {
|
|
||||||
return {
|
|
||||||
x: getConvertedDistance(data.local.distance.total[index]),
|
|
||||||
y: getConvertedTemperature(point.getTemperature()),
|
|
||||||
index: index,
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
normalized: true,
|
|
||||||
yAxisID: 'yatemp',
|
|
||||||
hidden: true,
|
|
||||||
};
|
|
||||||
chart.data.datasets[5] = {
|
|
||||||
data: data.local.points.map((point, index) => {
|
|
||||||
return {
|
|
||||||
x: getConvertedDistance(data.local.distance.total[index]),
|
|
||||||
y: point.getPower(),
|
|
||||||
index: index,
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
normalized: true,
|
|
||||||
yAxisID: 'ypower',
|
|
||||||
hidden: true,
|
|
||||||
};
|
|
||||||
chart.options.scales.x['min'] = 0;
|
|
||||||
chart.options.scales.x['max'] = getConvertedDistance(data.global.distance.total);
|
|
||||||
|
|
||||||
chart.update();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function slopeFillCallback(context) {
|
|
||||||
return getSlopeColor(context.p0.raw.slope.segment);
|
|
||||||
}
|
|
||||||
|
|
||||||
function surfaceFillCallback(context) {
|
|
||||||
return getSurfaceColor(context.p0.raw.extensions.surface);
|
|
||||||
}
|
|
||||||
|
|
||||||
function highwayFillCallback(context) {
|
|
||||||
return getHighwayColor(
|
|
||||||
context.p0.raw.extensions.highway,
|
|
||||||
context.p0.raw.extensions.sac_scale,
|
|
||||||
context.p0.raw.extensions.mtb_scale
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
if (elevationFill && chart) {
|
|
||||||
if (elevationFill === 'slope') {
|
|
||||||
chart.data.datasets[0]['segment'] = {
|
|
||||||
backgroundColor: slopeFillCallback,
|
|
||||||
};
|
|
||||||
} else if (elevationFill === 'surface') {
|
|
||||||
chart.data.datasets[0]['segment'] = {
|
|
||||||
backgroundColor: surfaceFillCallback,
|
|
||||||
};
|
|
||||||
} else if (elevationFill === 'highway') {
|
|
||||||
chart.data.datasets[0]['segment'] = {
|
|
||||||
backgroundColor: highwayFillCallback,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
chart.data.datasets[0]['segment'] = {};
|
|
||||||
}
|
|
||||||
chart.update();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
if (additionalDatasets && chart) {
|
|
||||||
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');
|
|
||||||
if (chart.data.datasets.length > 0) {
|
|
||||||
chart.data.datasets[1].hidden = !includeSpeed;
|
|
||||||
chart.data.datasets[2].hidden = !includeHeartRate;
|
|
||||||
chart.data.datasets[3].hidden = !includeCadence;
|
|
||||||
chart.data.datasets[4].hidden = !includeTemperature;
|
|
||||||
chart.data.datasets[5].hidden = !includePower;
|
|
||||||
}
|
|
||||||
chart.update();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function updateOverlay() {
|
|
||||||
if (!canvas) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
overlay.width = canvas.width / window.devicePixelRatio;
|
|
||||||
overlay.height = canvas.height / window.devicePixelRatio;
|
|
||||||
overlay.style.width = `${overlay.width}px`;
|
|
||||||
overlay.style.height = `${overlay.height}px`;
|
|
||||||
|
|
||||||
if ($slicedGPXStatistics) {
|
|
||||||
let startIndex = $slicedGPXStatistics[1];
|
|
||||||
let endIndex = $slicedGPXStatistics[2];
|
|
||||||
|
|
||||||
// Draw selection rectangle
|
|
||||||
let selectionContext = 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, overlay.width, overlay.height);
|
|
||||||
|
|
||||||
let startPixel = chart.scales.x.getPixelForValue(
|
|
||||||
getConvertedDistance($gpxStatistics.local.distance.total[startIndex])
|
|
||||||
);
|
|
||||||
let endPixel = chart.scales.x.getPixelForValue(
|
|
||||||
getConvertedDistance($gpxStatistics.local.distance.total[endIndex])
|
|
||||||
);
|
|
||||||
|
|
||||||
selectionContext.fillRect(
|
|
||||||
startPixel,
|
|
||||||
chart.chartArea.top,
|
|
||||||
endPixel - startPixel,
|
|
||||||
chart.chartArea.height
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else if (overlay) {
|
|
||||||
let selectionContext = overlay.getContext('2d');
|
|
||||||
if (selectionContext) {
|
|
||||||
selectionContext.clearRect(0, 0, overlay.width, overlay.height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
if ($slicedGPXStatistics || mode.current) {
|
|
||||||
updateOverlay();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
onDestroy(() => {
|
|
||||||
if (chart) {
|
|
||||||
chart.destroy();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div class="h-full grow min-w-0 relative py-2">
|
|
||||||
<canvas bind:this={overlay} class="w-full h-full absolute pointer-events-none"></canvas>
|
|
||||||
<canvas bind:this={canvas} class="w-full h-full absolute"></canvas>
|
|
||||||
{#if showControls}
|
|
||||||
<div class="absolute bottom-10 right-1.5">
|
|
||||||
<Popover.Root>
|
|
||||||
<Popover.Trigger>
|
|
||||||
<ButtonWithTooltip
|
|
||||||
label={i18n._('chart.settings')}
|
|
||||||
variant="outline"
|
|
||||||
side="left"
|
|
||||||
class="w-7 h-7 p-0 flex justify-center opacity-70 hover:opacity-100 transition-opacity duration-300 hover:bg-background"
|
|
||||||
>
|
|
||||||
<ChartNoAxesColumn size="18" />
|
|
||||||
</ButtonWithTooltip>
|
|
||||||
</Popover.Trigger>
|
|
||||||
<Popover.Content
|
|
||||||
class="w-fit p-0 flex flex-col divide-y-2 divide-solid divide-gray-500"
|
|
||||||
side="top"
|
|
||||||
align="end"
|
|
||||||
sideOffset={-32}
|
|
||||||
>
|
|
||||||
<ToggleGroup.Root
|
|
||||||
class="flex flex-col items-start gap-0 p-1 w-full border-none"
|
|
||||||
type="single"
|
|
||||||
bind:value={elevationFill}
|
|
||||||
>
|
|
||||||
<ToggleGroup.Item
|
|
||||||
class="p-0 pr-1.5 h-6 w-full gap-1.5 rounded flex justify-start data-[state=on]:bg-background data-[state=on]:hover:bg-accent hover:bg-accent hover:text-foreground"
|
|
||||||
value="slope"
|
|
||||||
>
|
|
||||||
<div class="w-6 flex justify-center items-center">
|
|
||||||
{#if elevationFill === 'slope'}
|
|
||||||
<Circle class="size-1.5 fill-current text-current" />
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
<TriangleRight size="15" />
|
|
||||||
{i18n._('quantities.slope')}
|
|
||||||
</ToggleGroup.Item>
|
|
||||||
<ToggleGroup.Item
|
|
||||||
class="p-0 pr-1.5 h-6 w-full gap-1.5 rounded flex justify-start data-[state=on]:bg-background data-[state=on]:hover:bg-accent hover:bg-accent hover:text-foreground"
|
|
||||||
value="surface"
|
|
||||||
variant="outline"
|
|
||||||
>
|
|
||||||
<div class="w-6 flex justify-center items-center">
|
|
||||||
{#if elevationFill === 'surface'}
|
|
||||||
<Circle class="size-1.5 fill-current text-current" />
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
<BrickWall size="15" />
|
|
||||||
{i18n._('quantities.surface')}
|
|
||||||
</ToggleGroup.Item>
|
|
||||||
<ToggleGroup.Item
|
|
||||||
class="p-0 pr-1.5 h-6 w-full gap-1.5 rounded flex justify-start data-[state=on]:bg-background data-[state=on]:hover:bg-accent hover:bg-accent hover:text-foreground"
|
|
||||||
value="highway"
|
|
||||||
variant="outline"
|
|
||||||
>
|
|
||||||
<div class="w-6 flex justify-center items-center">
|
|
||||||
{#if elevationFill === 'highway'}
|
|
||||||
<Circle class="size-1.5 fill-current text-current" />
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
<Construction size="15" />
|
|
||||||
{i18n._('quantities.highway')}
|
|
||||||
</ToggleGroup.Item>
|
|
||||||
</ToggleGroup.Root>
|
|
||||||
<ToggleGroup.Root
|
|
||||||
class="flex flex-col items-start gap-0 p-1"
|
|
||||||
type="multiple"
|
|
||||||
bind:value={additionalDatasets}
|
|
||||||
>
|
|
||||||
<ToggleGroup.Item
|
|
||||||
class="p-0 pr-1.5 h-6 w-full gap-1.5 rounded flex justify-start data-[state=on]:bg-background data-[state=on]:hover:bg-accent hover:bg-accent hover:text-foreground"
|
|
||||||
value="speed"
|
|
||||||
>
|
|
||||||
<div class="w-6 flex justify-center items-center">
|
|
||||||
{#if additionalDatasets.includes('speed')}
|
|
||||||
<Check size="14" />
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
<Zap size="15" />
|
|
||||||
{$velocityUnits === 'speed'
|
|
||||||
? i18n._('quantities.speed')
|
|
||||||
: i18n._('quantities.pace')}
|
|
||||||
</ToggleGroup.Item>
|
|
||||||
<ToggleGroup.Item
|
|
||||||
class="p-0 pr-1.5 h-6 w-full gap-1.5 rounded flex justify-start data-[state=on]:bg-background data-[state=on]:hover:bg-accent hover:bg-accent hover:text-foreground"
|
|
||||||
value="hr"
|
|
||||||
>
|
|
||||||
<div class="w-6 flex justify-center items-center">
|
|
||||||
{#if additionalDatasets.includes('hr')}
|
|
||||||
<Check size="14" />
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
<HeartPulse size="15" />
|
|
||||||
{i18n._('quantities.heartrate')}
|
|
||||||
</ToggleGroup.Item>
|
|
||||||
<ToggleGroup.Item
|
|
||||||
class="p-0 pr-1.5 h-6 w-full gap-1.5 rounded flex justify-start data-[state=on]:bg-background data-[state=on]:hover:bg-accent hover:bg-accent hover:text-foreground"
|
|
||||||
value="cad"
|
|
||||||
>
|
|
||||||
<div class="w-6 flex justify-center items-center">
|
|
||||||
{#if additionalDatasets.includes('cad')}
|
|
||||||
<Check size="14" />
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
<Orbit size="15" />
|
|
||||||
{i18n._('quantities.cadence')}
|
|
||||||
</ToggleGroup.Item>
|
|
||||||
<ToggleGroup.Item
|
|
||||||
class="p-0 pr-1.5 h-6 w-full gap-1.5 rounded flex justify-start data-[state=on]:bg-background data-[state=on]:hover:bg-accent hover:bg-accent hover:text-foreground"
|
|
||||||
value="atemp"
|
|
||||||
>
|
|
||||||
<div class="w-6 flex justify-center items-center">
|
|
||||||
{#if additionalDatasets.includes('atemp')}
|
|
||||||
<Check size="14" />
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
<Thermometer size="15" />
|
|
||||||
{i18n._('quantities.temperature')}
|
|
||||||
</ToggleGroup.Item>
|
|
||||||
<ToggleGroup.Item
|
|
||||||
class="p-0 pr-1.5 h-6 w-full gap-1.5 rounded flex justify-start data-[state=on]:bg-background data-[state=on]:hover:bg-accent hover:bg-accent hover:text-foreground"
|
|
||||||
value="power"
|
|
||||||
>
|
|
||||||
<div class="w-6 flex justify-center items-center">
|
|
||||||
{#if additionalDatasets.includes('power')}
|
|
||||||
<Check size="14" />
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
<SquareActivity size="15" />
|
|
||||||
{i18n._('quantities.power')}
|
|
||||||
</ToggleGroup.Item>
|
|
||||||
</ToggleGroup.Root>
|
|
||||||
</Popover.Content>
|
|
||||||
</Popover.Root>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import LanguageSelect from '$lib/components/LanguageSelect.svelte';
|
import LanguageSelect from '$lib/components/LanguageSelect.svelte';
|
||||||
import Logo from '$lib/components/Logo.svelte';
|
import Logo from '$lib/components/Logo.svelte';
|
||||||
import { AtSign, BookOpenText, Heart, Home, Map } from '@lucide/svelte';
|
import { AtSign, BookOpenText, Heart, House, Map } from '@lucide/svelte';
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
import { getURLForLanguage } from '$lib/utils';
|
import { getURLForLanguage } from '$lib/utils';
|
||||||
</script>
|
</script>
|
||||||
@@ -14,11 +14,11 @@
|
|||||||
<Logo class="h-8" width="153" />
|
<Logo class="h-8" width="153" />
|
||||||
<Button
|
<Button
|
||||||
variant="link"
|
variant="link"
|
||||||
class="h-6 px-0 text-muted-foreground"
|
class="h-6 px-0 has-[>svg]:px-0 text-muted-foreground"
|
||||||
href="https://github.com/gpxstudio/gpx.studio/blob/main/LICENSE"
|
href="https://github.com/gpxstudio/gpx.studio/blob/main/LICENSE"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
>
|
>
|
||||||
MIT © 2024 gpx.studio
|
MIT © 2026 gpx.studio
|
||||||
</Button>
|
</Button>
|
||||||
<LanguageSelect class="w-40 mt-3" />
|
<LanguageSelect class="w-40 mt-3" />
|
||||||
</div>
|
</div>
|
||||||
@@ -27,15 +27,16 @@
|
|||||||
<span class="font-semibold">{i18n._('homepage.website')}</span>
|
<span class="font-semibold">{i18n._('homepage.website')}</span>
|
||||||
<Button
|
<Button
|
||||||
variant="link"
|
variant="link"
|
||||||
class="h-6 px-0 text-muted-foreground"
|
class="h-6 px-0 has-[>svg]:px-0 text-muted-foreground"
|
||||||
href={getURLForLanguage(i18n.lang, '/')}
|
href={getURLForLanguage(i18n.lang, '/')}
|
||||||
>
|
>
|
||||||
<Home size="16" />
|
<House size="16" />
|
||||||
{i18n._('homepage.home')}
|
{i18n._('homepage.home')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
|
data-sveltekit-reload
|
||||||
variant="link"
|
variant="link"
|
||||||
class="h-6 px-0 text-muted-foreground"
|
class="h-6 px-0 has-[>svg]:px-0 text-muted-foreground"
|
||||||
href={getURLForLanguage(i18n.lang, '/app')}
|
href={getURLForLanguage(i18n.lang, '/app')}
|
||||||
>
|
>
|
||||||
<Map size="16" />
|
<Map size="16" />
|
||||||
@@ -43,7 +44,7 @@
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="link"
|
variant="link"
|
||||||
class="h-6 px-0 text-muted-foreground"
|
class="h-6 px-0 has-[>svg]:px-0 text-muted-foreground"
|
||||||
href={getURLForLanguage(i18n.lang, '/help')}
|
href={getURLForLanguage(i18n.lang, '/help')}
|
||||||
>
|
>
|
||||||
<BookOpenText size="16" />
|
<BookOpenText size="16" />
|
||||||
@@ -54,7 +55,7 @@
|
|||||||
<span class="font-semibold">{i18n._('homepage.contact')}</span>
|
<span class="font-semibold">{i18n._('homepage.contact')}</span>
|
||||||
<Button
|
<Button
|
||||||
variant="link"
|
variant="link"
|
||||||
class="h-6 px-0 text-muted-foreground"
|
class="h-6 px-0 has-[>svg]:px-0 text-muted-foreground"
|
||||||
href="https://www.reddit.com/r/gpxstudio/"
|
href="https://www.reddit.com/r/gpxstudio/"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
>
|
>
|
||||||
@@ -63,7 +64,7 @@
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="link"
|
variant="link"
|
||||||
class="h-6 px-0 text-muted-foreground"
|
class="h-6 px-0 has-[>svg]:px-0 text-muted-foreground"
|
||||||
href="https://facebook.com/gpx.studio"
|
href="https://facebook.com/gpx.studio"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
>
|
>
|
||||||
@@ -72,16 +73,7 @@
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="link"
|
variant="link"
|
||||||
class="h-6 px-0 text-muted-foreground"
|
class="h-6 px-0 has-[>svg]:px-0 text-muted-foreground"
|
||||||
href="https://x.com/gpxstudio"
|
|
||||||
target="_blank"
|
|
||||||
>
|
|
||||||
<Logo company="x" class="h-4 fill-muted-foreground" />
|
|
||||||
{i18n._('homepage.x')}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="link"
|
|
||||||
class="h-6 px-0 text-muted-foreground"
|
|
||||||
href="mailto:hello@gpx.studio"
|
href="mailto:hello@gpx.studio"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
>
|
>
|
||||||
@@ -93,7 +85,7 @@
|
|||||||
<span class="font-semibold">{i18n._('homepage.contribute')}</span>
|
<span class="font-semibold">{i18n._('homepage.contribute')}</span>
|
||||||
<Button
|
<Button
|
||||||
variant="link"
|
variant="link"
|
||||||
class="h-6 px-0 text-muted-foreground"
|
class="h-6 px-0 has-[>svg]:px-0 text-muted-foreground"
|
||||||
href="https://ko-fi.com/gpxstudio"
|
href="https://ko-fi.com/gpxstudio"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
>
|
>
|
||||||
@@ -102,7 +94,7 @@
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="link"
|
variant="link"
|
||||||
class="h-6 px-0 text-muted-foreground"
|
class="h-6 px-0 has-[>svg]:px-0 text-muted-foreground"
|
||||||
href="https://crowdin.com/project/gpxstudio"
|
href="https://crowdin.com/project/gpxstudio"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
>
|
>
|
||||||
@@ -111,7 +103,7 @@
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="link"
|
variant="link"
|
||||||
class="h-6 px-0 text-muted-foreground"
|
class="h-6 px-0 has-[>svg]:px-0 text-muted-foreground"
|
||||||
href="https://github.com/gpxstudio/gpx.studio"
|
href="https://github.com/gpxstudio/gpx.studio"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
import { MoveDownRight, MoveUpRight, Ruler, Timer, Zap } from '@lucide/svelte';
|
import { MoveDownRight, MoveUpRight, Ruler, Timer, Zap } from '@lucide/svelte';
|
||||||
|
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
import type { GPXStatistics } from 'gpx';
|
import type { GPXGlobalStatistics, GPXStatisticsGroup } from 'gpx';
|
||||||
import type { Readable } from 'svelte/store';
|
import type { Readable } from 'svelte/store';
|
||||||
import { settings } from '$lib/logic/settings';
|
import { settings } from '$lib/logic/settings';
|
||||||
|
|
||||||
@@ -18,39 +18,39 @@
|
|||||||
orientation,
|
orientation,
|
||||||
panelSize,
|
panelSize,
|
||||||
}: {
|
}: {
|
||||||
gpxStatistics: Readable<GPXStatistics>;
|
gpxStatistics: Readable<GPXStatisticsGroup>;
|
||||||
slicedGPXStatistics: Readable<[GPXStatistics, number, number] | undefined>;
|
slicedGPXStatistics: Readable<[GPXGlobalStatistics, number, number] | undefined>;
|
||||||
orientation: 'horizontal' | 'vertical';
|
orientation: 'horizontal' | 'vertical';
|
||||||
panelSize: number;
|
panelSize: number;
|
||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
let statistics = $derived(
|
let statistics = $derived(
|
||||||
$slicedGPXStatistics !== undefined ? $slicedGPXStatistics[0] : $gpxStatistics
|
$slicedGPXStatistics !== undefined ? $slicedGPXStatistics[0] : $gpxStatistics.global
|
||||||
);
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Card.Root
|
<Card.Root
|
||||||
class="h-full {orientation === 'vertical'
|
class="h-full {orientation === 'vertical'
|
||||||
? 'min-w-40 sm:min-w-44 text-sm sm:text-base'
|
? 'min-w-40 sm:min-w-44'
|
||||||
: 'w-full'} border-none shadow-none"
|
: 'w-full h-10'} border-none shadow-none p-0 text-sm sm:text-base"
|
||||||
>
|
>
|
||||||
<Card.Content
|
<Card.Content
|
||||||
class="h-full flex {orientation === 'vertical'
|
class="h-full flex {orientation === 'vertical'
|
||||||
? 'flex-col justify-center'
|
? 'flex-col justify-center'
|
||||||
: 'flex-row w-full justify-between'} gap-4 p-0"
|
: 'flex-row w-full justify-evenly'} gap-4 p-0"
|
||||||
>
|
>
|
||||||
<Tooltip label={i18n._('quantities.distance')}>
|
<Tooltip label={i18n._('quantities.distance')}>
|
||||||
<span class="flex flex-row items-center">
|
<span class="flex flex-row items-center">
|
||||||
<Ruler size="16" class="mr-1" />
|
<Ruler size="16" class="mr-1" />
|
||||||
<WithUnits value={statistics.global.distance.total} type="distance" />
|
<WithUnits value={statistics.distance.total} type="distance" />
|
||||||
</span>
|
</span>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Tooltip label={i18n._('quantities.elevation_gain_loss')}>
|
<Tooltip label={i18n._('quantities.elevation_gain_loss')}>
|
||||||
<span class="flex flex-row items-center">
|
<span class="flex flex-row items-center">
|
||||||
<MoveUpRight size="16" class="mr-1" />
|
<MoveUpRight size="16" class="mr-1" />
|
||||||
<WithUnits value={statistics.global.elevation.gain} type="elevation" />
|
<WithUnits value={statistics.elevation.gain} type="elevation" />
|
||||||
<MoveDownRight size="16" class="mx-1" />
|
<MoveDownRight size="16" class="mx-1" />
|
||||||
<WithUnits value={statistics.global.elevation.loss} type="elevation" />
|
<WithUnits value={statistics.elevation.loss} type="elevation" />
|
||||||
</span>
|
</span>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
{#if panelSize > 120 || orientation === 'horizontal'}
|
{#if panelSize > 120 || orientation === 'horizontal'}
|
||||||
@@ -64,13 +64,9 @@
|
|||||||
>
|
>
|
||||||
<span class="flex flex-row items-center">
|
<span class="flex flex-row items-center">
|
||||||
<Zap size="16" class="mr-1" />
|
<Zap size="16" class="mr-1" />
|
||||||
<WithUnits
|
<WithUnits value={statistics.speed.moving} type="speed" showUnits={false} />
|
||||||
value={statistics.global.speed.moving}
|
|
||||||
type="speed"
|
|
||||||
showUnits={false}
|
|
||||||
/>
|
|
||||||
<span class="mx-1">/</span>
|
<span class="mx-1">/</span>
|
||||||
<WithUnits value={statistics.global.speed.total} type="speed" />
|
<WithUnits value={statistics.speed.total} type="speed" />
|
||||||
</span>
|
</span>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -83,9 +79,9 @@
|
|||||||
>
|
>
|
||||||
<span class="flex flex-row items-center">
|
<span class="flex flex-row items-center">
|
||||||
<Timer size="16" class="mr-1" />
|
<Timer size="16" class="mr-1" />
|
||||||
<WithUnits value={statistics.global.time.moving} type="time" />
|
<WithUnits value={statistics.time.moving} type="time" />
|
||||||
<span class="mx-1">/</span>
|
<span class="mx-1">/</span>
|
||||||
<WithUnits value={statistics.global.time.total} type="time" />
|
<WithUnits value={statistics.time.total} type="time" />
|
||||||
</span>
|
</span>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -1,16 +1,23 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { CircleQuestionMark } from '@lucide/svelte';
|
import { CircleQuestionMark } from '@lucide/svelte';
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
|
import type { Snippet } from 'svelte';
|
||||||
|
|
||||||
export let link: string | undefined = undefined;
|
let {
|
||||||
|
link,
|
||||||
|
class: className = '',
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
link: string;
|
||||||
|
class?: string;
|
||||||
|
children: Snippet;
|
||||||
|
} = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div class="text-sm bg-secondary rounded border flex flex-row items-center p-2 {className}">
|
||||||
class="text-sm bg-secondary rounded border flex flex-row items-center p-2 {$$props.class || ''}"
|
|
||||||
>
|
|
||||||
<CircleQuestionMark size="16" class="w-4 mr-2 shrink-0 grow-0" />
|
<CircleQuestionMark size="16" class="w-4 mr-2 shrink-0 grow-0" />
|
||||||
<div>
|
<div>
|
||||||
<slot />
|
{@render children()}
|
||||||
{#if link}
|
{#if link}
|
||||||
<a href={link} target="_blank" class="text-sm text-link hover:underline">
|
<a href={link} target="_blank" class="text-sm text-link hover:underline">
|
||||||
{i18n._('menu.more')}
|
{i18n._('menu.more')}
|
||||||
|
|||||||
@@ -5,12 +5,18 @@
|
|||||||
import { getURLForLanguage } from '$lib/utils';
|
import { getURLForLanguage } from '$lib/utils';
|
||||||
import { Languages } from '@lucide/svelte';
|
import { Languages } from '@lucide/svelte';
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
|
|
||||||
|
let {
|
||||||
|
class: className = '',
|
||||||
|
}: {
|
||||||
|
class?: string;
|
||||||
|
} = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Select.Root type="single" value={i18n.lang}>
|
<Select.Root type="single" value={i18n.lang}>
|
||||||
<Select.Trigger class="w-[180px] {$$props.class ?? ''}" aria-label={i18n._('menu.language')}>
|
<Select.Trigger class="min-w-[180px] {className}" aria-label={i18n._('menu.language')}>
|
||||||
<Languages size="16" />
|
<Languages size="16" />
|
||||||
<span class="ml-2 mr-auto">
|
<span class="mr-auto">
|
||||||
{languages[i18n.lang]}
|
{languages[i18n.lang]}
|
||||||
</span>
|
</span>
|
||||||
</Select.Trigger>
|
</Select.Trigger>
|
||||||
@@ -28,14 +34,3 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</Select.Content>
|
</Select.Content>
|
||||||
</Select.Root>
|
</Select.Root>
|
||||||
|
|
||||||
<!-- hidden links for svelte crawling -->
|
|
||||||
<div class="hidden">
|
|
||||||
{#if !page.url.pathname.includes('404')}
|
|
||||||
{#each Object.entries(languages) as [lang, label]}
|
|
||||||
<a href={getURLForLanguage(lang, page.url.pathname)}>
|
|
||||||
{label}
|
|
||||||
</a>
|
|
||||||
{/each}
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
|
|||||||
@@ -1,29 +1,36 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { base } from '$app/paths';
|
|
||||||
import { mode } from 'mode-watcher';
|
import { mode } from 'mode-watcher';
|
||||||
|
import { base } from '$app/paths';
|
||||||
|
|
||||||
export let iconOnly = false;
|
let {
|
||||||
export let company = 'gpx.studio';
|
iconOnly = false,
|
||||||
|
company = 'gpx.studio',
|
||||||
|
...others
|
||||||
|
}: {
|
||||||
|
iconOnly?: boolean;
|
||||||
|
company?: 'gpx.studio' | 'maptiler' | 'github' | 'crowdin' | 'facebook' | 'reddit';
|
||||||
|
[key: string]: any;
|
||||||
|
} = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if company === 'gpx.studio'}
|
{#if company === 'gpx.studio'}
|
||||||
<img
|
<img
|
||||||
src="{base}/{iconOnly ? 'icon' : 'logo'}{mode.current === 'dark' ? '-dark' : ''}.svg"
|
src="{base}/{iconOnly ? 'icon' : 'logo'}{mode.current === 'dark' ? '-dark' : ''}.svg"
|
||||||
alt="Logo of gpx.studio."
|
alt="Logo of gpx.studio."
|
||||||
{...$$restProps}
|
{...others}
|
||||||
/>
|
/>
|
||||||
{:else if company === 'mapbox'}
|
{:else if company === 'maptiler'}
|
||||||
<img
|
<img
|
||||||
src="{base}/mapbox-logo-{mode.current === 'dark' ? 'white' : 'black'}.svg"
|
src="{base}/maptiler-logo{mode.current === 'dark' ? '-dark' : ''}.svg"
|
||||||
alt="Logo of Mapbox."
|
alt="Logo of Maptiler."
|
||||||
{...$$restProps}
|
{...others}
|
||||||
/>
|
/>
|
||||||
{:else if company === 'github'}
|
{:else if company === 'github'}
|
||||||
<svg
|
<svg
|
||||||
role="img"
|
role="img"
|
||||||
viewBox="0 0 24 24"
|
viewBox="0 0 24 24"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
class="fill-foreground {$$restProps.class ?? ''}"
|
class="fill-foreground {others.class ?? ''}"
|
||||||
><title>GitHub</title><path
|
><title>GitHub</title><path
|
||||||
d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"
|
d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"
|
||||||
/></svg
|
/></svg
|
||||||
@@ -33,7 +40,7 @@
|
|||||||
role="img"
|
role="img"
|
||||||
viewBox="0 0 24 24"
|
viewBox="0 0 24 24"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
class="fill-foreground {$$restProps.class ?? ''}"
|
class="fill-foreground {others.class ?? ''}"
|
||||||
><title>Crowdin</title><path
|
><title>Crowdin</title><path
|
||||||
d="M16.119 17.793a2.619 2.619 0 0 1-1.667-.562c-.546-.436-1.004-1.09-1.018-1.858-.008-.388.414-.388.414-.388l1.018-.008c.332.008.43.47.445.586.128 1.04.717 1.495 1.168 1.702.273.123.204.513-.362.528zm-5.695-5.287L8.5 12.252c-.867-.214-.844-.982-.807-1.247a5.119 5.119 0 0 1 .814-2.125c.545-.804 1.303-1.508 2.29-2.073 1.856-1.074 4.45-1.673 7.31-1.673 2.09 0 4.256.27 4.29.27.197.025.328.213.333.437a.377.377 0 0 1-.355.393l-.92-.01c-2.902 0-4.968.394-6.506 1.248-1.527.837-2.57 2.117-3.287 4.012-.076.163-.335 1.12-1.24 1.022zm2.533 7.823c-1.44 0-2.797-.622-3.825-1.746-.87-.96-1.397-1.931-1.493-3.164-.06-.813.3-1.094.788-1.044l1.988.218c.45.092.75.34.825.854.397 2.736 2.122 3.814 3.15 4.046.18.042.292.157.283.365a.412.412 0 0 1-.322.398c-.458.074-.936.073-1.394.073zm-4.101 2.418a14.216 14.216 0 0 1-2.307-.214c-1.202-.214-2.208-.582-3.072-1.13C1.41 20.095.163 17.786.014 15.048c-.037-.65-.11-1.89 1.427-1.797.638.033 1.653.343 2.368.548.887.247 1.314.933 1.314 1.608 0 3.858 3.494 6.408 5.02 6.408.654 0 .414.701.127.779-.502.136-1.15.153-1.413.153zM3.525 11.419c-.605-.109-1.194-.358-1.768-.5C-.018 10.479.284 8.688.45 8.196c1.617-4.757 6.746-6.35 10.887-6.773 3.898-.4 7.978-.092 11.778.967.31.083 1.269.327.718.891-.35.358-1.7-.016-2.073-.041-2.23-.167-4.434-.192-6.656.15-2.349.357-4.768 1.099-6.71 2.665-.938.758-1.76 1.723-2.313 2.866-.144.3-.256.6-.354.9-.11.327-.47 1.91-2.215 1.6zm9.94.917c.332-1.488 1.81-3.848 6.385-3.686 1.05.033.57.749.052.731-2.586-.09-3.815 1.578-4.457 3.27-.219.546-.68.626-1.271.53-.415-.074-.866-.123-.71-.846Z"
|
d="M16.119 17.793a2.619 2.619 0 0 1-1.667-.562c-.546-.436-1.004-1.09-1.018-1.858-.008-.388.414-.388.414-.388l1.018-.008c.332.008.43.47.445.586.128 1.04.717 1.495 1.168 1.702.273.123.204.513-.362.528zm-5.695-5.287L8.5 12.252c-.867-.214-.844-.982-.807-1.247a5.119 5.119 0 0 1 .814-2.125c.545-.804 1.303-1.508 2.29-2.073 1.856-1.074 4.45-1.673 7.31-1.673 2.09 0 4.256.27 4.29.27.197.025.328.213.333.437a.377.377 0 0 1-.355.393l-.92-.01c-2.902 0-4.968.394-6.506 1.248-1.527.837-2.57 2.117-3.287 4.012-.076.163-.335 1.12-1.24 1.022zm2.533 7.823c-1.44 0-2.797-.622-3.825-1.746-.87-.96-1.397-1.931-1.493-3.164-.06-.813.3-1.094.788-1.044l1.988.218c.45.092.75.34.825.854.397 2.736 2.122 3.814 3.15 4.046.18.042.292.157.283.365a.412.412 0 0 1-.322.398c-.458.074-.936.073-1.394.073zm-4.101 2.418a14.216 14.216 0 0 1-2.307-.214c-1.202-.214-2.208-.582-3.072-1.13C1.41 20.095.163 17.786.014 15.048c-.037-.65-.11-1.89 1.427-1.797.638.033 1.653.343 2.368.548.887.247 1.314.933 1.314 1.608 0 3.858 3.494 6.408 5.02 6.408.654 0 .414.701.127.779-.502.136-1.15.153-1.413.153zM3.525 11.419c-.605-.109-1.194-.358-1.768-.5C-.018 10.479.284 8.688.45 8.196c1.617-4.757 6.746-6.35 10.887-6.773 3.898-.4 7.978-.092 11.778.967.31.083 1.269.327.718.891-.35.358-1.7-.016-2.073-.041-2.23-.167-4.434-.192-6.656.15-2.349.357-4.768 1.099-6.71 2.665-.938.758-1.76 1.723-2.313 2.866-.144.3-.256.6-.354.9-.11.327-.47 1.91-2.215 1.6zm9.94.917c.332-1.488 1.81-3.848 6.385-3.686 1.05.033.57.749.052.731-2.586-.09-3.815 1.578-4.457 3.27-.219.546-.68.626-1.271.53-.415-.074-.866-.123-.71-.846Z"
|
||||||
/></svg
|
/></svg
|
||||||
@@ -43,27 +50,17 @@
|
|||||||
role="img"
|
role="img"
|
||||||
viewBox="0 0 24 24"
|
viewBox="0 0 24 24"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
class="fill-foreground {$$restProps.class ?? ''}"
|
class="fill-foreground {others.class ?? ''}"
|
||||||
><title>Facebook</title><path
|
><title>Facebook</title><path
|
||||||
d="M9.101 23.691v-7.98H6.627v-3.667h2.474v-1.58c0-4.085 1.848-5.978 5.858-5.978.401 0 .955.042 1.468.103a8.68 8.68 0 0 1 1.141.195v3.325a8.623 8.623 0 0 0-.653-.036 26.805 26.805 0 0 0-.733-.009c-.707 0-1.259.096-1.675.309a1.686 1.686 0 0 0-.679.622c-.258.42-.374.995-.374 1.752v1.297h3.919l-.386 2.103-.287 1.564h-3.246v8.245C19.396 23.238 24 18.179 24 12.044c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.628 3.874 10.35 9.101 11.647Z"
|
d="M9.101 23.691v-7.98H6.627v-3.667h2.474v-1.58c0-4.085 1.848-5.978 5.858-5.978.401 0 .955.042 1.468.103a8.68 8.68 0 0 1 1.141.195v3.325a8.623 8.623 0 0 0-.653-.036 26.805 26.805 0 0 0-.733-.009c-.707 0-1.259.096-1.675.309a1.686 1.686 0 0 0-.679.622c-.258.42-.374.995-.374 1.752v1.297h3.919l-.386 2.103-.287 1.564h-3.246v8.245C19.396 23.238 24 18.179 24 12.044c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.628 3.874 10.35 9.101 11.647Z"
|
||||||
/></svg
|
/></svg
|
||||||
>
|
>
|
||||||
{:else if company === 'x'}
|
|
||||||
<svg
|
|
||||||
role="img"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
class="fill-foreground {$$restProps.class ?? ''}"
|
|
||||||
><title>X</title><path
|
|
||||||
d="M18.901 1.153h3.68l-8.04 9.19L24 22.846h-7.406l-5.8-7.584-6.638 7.584H.474l8.6-9.83L0 1.154h7.594l5.243 6.932ZM17.61 20.644h2.039L6.486 3.24H4.298Z"
|
|
||||||
/></svg
|
|
||||||
>
|
|
||||||
{:else if company === 'reddit'}
|
{:else if company === 'reddit'}
|
||||||
<svg
|
<svg
|
||||||
role="img"
|
role="img"
|
||||||
viewBox="0 0 24 24"
|
viewBox="0 0 24 24"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
class="fill-foreground {$$restProps.class ?? ''}"
|
class="fill-foreground {others.class ?? ''}"
|
||||||
><title>Reddit</title><path
|
><title>Reddit</title><path
|
||||||
d="M12 0C5.373 0 0 5.373 0 12c0 3.314 1.343 6.314 3.515 8.485l-2.286 2.286C.775 23.225 1.097 24 1.738 24H12c6.627 0 12-5.373 12-12S18.627 0 12 0Zm4.388 3.199c1.104 0 1.999.895 1.999 1.999 0 1.105-.895 2-1.999 2-.946 0-1.739-.657-1.947-1.539v.002c-1.147.162-2.032 1.15-2.032 2.341v.007c1.776.067 3.4.567 4.686 1.363.473-.363 1.064-.58 1.707-.58 1.547 0 2.802 1.254 2.802 2.802 0 1.117-.655 2.081-1.601 2.531-.088 3.256-3.637 5.876-7.997 5.876-4.361 0-7.905-2.617-7.998-5.87-.954-.447-1.614-1.415-1.614-2.538 0-1.548 1.255-2.802 2.803-2.802.645 0 1.239.218 1.712.585 1.275-.79 2.881-1.291 4.64-1.365v-.01c0-1.663 1.263-3.034 2.88-3.207.188-.911.993-1.595 1.959-1.595Zm-8.085 8.376c-.784 0-1.459.78-1.506 1.797-.047 1.016.64 1.429 1.426 1.429.786 0 1.371-.369 1.418-1.385.047-1.017-.553-1.841-1.338-1.841Zm7.406 0c-.786 0-1.385.824-1.338 1.841.047 1.017.634 1.385 1.418 1.385.785 0 1.473-.413 1.426-1.429-.046-1.017-.721-1.797-1.506-1.797Zm-3.703 4.013c-.974 0-1.907.048-2.77.135-.147.015-.241.168-.183.305.483 1.154 1.622 1.964 2.953 1.964 1.33 0 2.47-.81 2.953-1.964.057-.137-.037-.29-.184-.305-.863-.087-1.795-.135-2.769-.135Z"
|
d="M12 0C5.373 0 0 5.373 0 12c0 3.314 1.343 6.314 3.515 8.485l-2.286 2.286C.775 23.225 1.097 24 1.738 24H12c6.627 0 12-5.373 12-12S18.627 0 12 0Zm4.388 3.199c1.104 0 1.999.895 1.999 1.999 0 1.105-.895 2-1.999 2-.946 0-1.739-.657-1.947-1.539v.002c-1.147.162-2.032 1.15-2.032 2.341v.007c1.776.067 3.4.567 4.686 1.363.473-.363 1.064-.58 1.707-.58 1.547 0 2.802 1.254 2.802 2.802 0 1.117-.655 2.081-1.601 2.531-.088 3.256-3.637 5.876-7.997 5.876-4.361 0-7.905-2.617-7.998-5.87-.954-.447-1.614-1.415-1.614-2.538 0-1.548 1.255-2.802 2.803-2.802.645 0 1.239.218 1.712.585 1.275-.79 2.881-1.291 4.64-1.365v-.01c0-1.663 1.263-3.034 2.88-3.207.188-.911.993-1.595 1.959-1.595Zm-8.085 8.376c-.784 0-1.459.78-1.506 1.797-.047 1.016.64 1.429 1.426 1.429.786 0 1.371-.369 1.418-1.385.047-1.017-.553-1.841-1.338-1.841Zm7.406 0c-.786 0-1.385.824-1.338 1.841.047 1.017.634 1.385 1.418 1.385.785 0 1.473-.413 1.426-1.429-.046-1.017-.721-1.797-1.506-1.797Zm-3.703 4.013c-.974 0-1.907.048-2.77.135-.147.015-.241.168-.183.305.483 1.154 1.622 1.964 2.953 1.964 1.33 0 2.47-.81 2.953-1.964.057-.137-.037-.29-.184-.305-.863-.087-1.795-.135-2.769-.135Z"
|
||||||
/></svg
|
/></svg
|
||||||
|
|||||||
@@ -51,11 +51,7 @@
|
|||||||
import { anySelectedLayer } from '$lib/components/map/layer-control/utils';
|
import { anySelectedLayer } from '$lib/components/map/layer-control/utils';
|
||||||
import { defaultOverlays } from '$lib/assets/layers';
|
import { defaultOverlays } from '$lib/assets/layers';
|
||||||
import LayerControlSettings from '$lib/components/map/layer-control/LayerControlSettings.svelte';
|
import LayerControlSettings from '$lib/components/map/layer-control/LayerControlSettings.svelte';
|
||||||
import {
|
import { ListFileItem, ListTrackItem } from '$lib/components/file-list/file-list';
|
||||||
allowedPastes,
|
|
||||||
ListFileItem,
|
|
||||||
ListTrackItem,
|
|
||||||
} from '$lib/components/file-list/file-list';
|
|
||||||
import Export from '$lib/components/export/Export.svelte';
|
import Export from '$lib/components/export/Export.svelte';
|
||||||
import { mode, setMode } from 'mode-watcher';
|
import { mode, setMode } from 'mode-watcher';
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
@@ -73,6 +69,9 @@
|
|||||||
import { fileActionManager } from '$lib/logic/file-action-manager';
|
import { fileActionManager } from '$lib/logic/file-action-manager';
|
||||||
import { copied, selection } from '$lib/logic/selection';
|
import { copied, selection } from '$lib/logic/selection';
|
||||||
import { allHidden } from '$lib/logic/hidden';
|
import { allHidden } from '$lib/logic/hidden';
|
||||||
|
import { boundsManager } from '$lib/logic/bounds';
|
||||||
|
import { tick } from 'svelte';
|
||||||
|
import { allowedPastes } from '$lib/components/file-list/sortable-file-list';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
distanceUnits,
|
distanceUnits,
|
||||||
@@ -90,6 +89,9 @@
|
|||||||
routing,
|
routing,
|
||||||
} = settings;
|
} = settings;
|
||||||
|
|
||||||
|
const canUndo = fileActionManager.canUndo;
|
||||||
|
const canRedo = fileActionManager.canRedo;
|
||||||
|
|
||||||
function switchBasemaps() {
|
function switchBasemaps() {
|
||||||
[$currentBasemap, $previousBasemap] = [$previousBasemap, $currentBasemap];
|
[$currentBasemap, $previousBasemap] = [$previousBasemap, $currentBasemap];
|
||||||
}
|
}
|
||||||
@@ -142,11 +144,11 @@
|
|||||||
</Menubar.Item>
|
</Menubar.Item>
|
||||||
<Menubar.Separator />
|
<Menubar.Separator />
|
||||||
<Menubar.Item
|
<Menubar.Item
|
||||||
onclick={fileActions.deleteSelectedFiles}
|
onclick={() => tick().then(fileActions.deleteSelectedFiles)}
|
||||||
disabled={$selection.size == 0}
|
disabled={$selection.size == 0}
|
||||||
>
|
>
|
||||||
<FileX size="16" />
|
<FileX size="16" />
|
||||||
{i18n._('menu.close')}
|
{i18n._('menu.delete')}
|
||||||
<Shortcut key="⌫" ctrl={true} />
|
<Shortcut key="⌫" ctrl={true} />
|
||||||
</Menubar.Item>
|
</Menubar.Item>
|
||||||
<Menubar.Item
|
<Menubar.Item
|
||||||
@@ -154,7 +156,7 @@
|
|||||||
disabled={fileStateCollection.size == 0}
|
disabled={fileStateCollection.size == 0}
|
||||||
>
|
>
|
||||||
<FileX size="16" />
|
<FileX size="16" />
|
||||||
{i18n._('menu.close_all')}
|
{i18n._('menu.delete_all')}
|
||||||
<Shortcut key="⌫" ctrl={true} shift={true} />
|
<Shortcut key="⌫" ctrl={true} shift={true} />
|
||||||
</Menubar.Item>
|
</Menubar.Item>
|
||||||
<Menubar.Separator />
|
<Menubar.Separator />
|
||||||
@@ -182,18 +184,12 @@
|
|||||||
<span class="hidden md:block">{i18n._('menu.edit')}</span>
|
<span class="hidden md:block">{i18n._('menu.edit')}</span>
|
||||||
</Menubar.Trigger>
|
</Menubar.Trigger>
|
||||||
<Menubar.Content class="border-none">
|
<Menubar.Content class="border-none">
|
||||||
<Menubar.Item
|
<Menubar.Item onclick={() => fileActionManager.undo()} disabled={!$canUndo}>
|
||||||
onclick={() => fileActionManager.undo()}
|
|
||||||
disabled={!fileActionManager.canUndo}
|
|
||||||
>
|
|
||||||
<Undo2 size="16" />
|
<Undo2 size="16" />
|
||||||
{i18n._('menu.undo')}
|
{i18n._('menu.undo')}
|
||||||
<Shortcut key="Z" ctrl={true} />
|
<Shortcut key="Z" ctrl={true} />
|
||||||
</Menubar.Item>
|
</Menubar.Item>
|
||||||
<Menubar.Item
|
<Menubar.Item onclick={() => fileActionManager.redo()} disabled={!$canRedo}>
|
||||||
onclick={() => fileActionManager.redo()}
|
|
||||||
disabled={!fileActionManager.canRedo}
|
|
||||||
>
|
|
||||||
<Redo2 size="16" />
|
<Redo2 size="16" />
|
||||||
{i18n._('menu.redo')}
|
{i18n._('menu.redo')}
|
||||||
<Shortcut key="Z" ctrl={true} shift={true} />
|
<Shortcut key="Z" ctrl={true} shift={true} />
|
||||||
@@ -281,7 +277,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
<Menubar.Separator />
|
<Menubar.Separator />
|
||||||
<Menubar.Item
|
<Menubar.Item
|
||||||
onclick={selection.selectAll}
|
onclick={() => selection.selectAll()}
|
||||||
disabled={fileStateCollection.size == 0}
|
disabled={fileStateCollection.size == 0}
|
||||||
>
|
>
|
||||||
<FileStack size="16" />
|
<FileStack size="16" />
|
||||||
@@ -291,9 +287,10 @@
|
|||||||
<Menubar.Item
|
<Menubar.Item
|
||||||
onclick={() => {
|
onclick={() => {
|
||||||
if ($selection.size > 0) {
|
if ($selection.size > 0) {
|
||||||
// centerMapOnSelection();
|
boundsManager.centerMapOnSelection();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
disabled={$selection.size == 0}
|
||||||
>
|
>
|
||||||
<Maximize size="16" />
|
<Maximize size="16" />
|
||||||
{i18n._('menu.center')}
|
{i18n._('menu.center')}
|
||||||
@@ -302,7 +299,7 @@
|
|||||||
{#if $treeFileView}
|
{#if $treeFileView}
|
||||||
<Menubar.Separator />
|
<Menubar.Separator />
|
||||||
<Menubar.Item
|
<Menubar.Item
|
||||||
onclick={selection.copySelection}
|
onclick={() => selection.copySelection()}
|
||||||
disabled={$selection.size === 0}
|
disabled={$selection.size === 0}
|
||||||
>
|
>
|
||||||
<ClipboardCopy size="16" />
|
<ClipboardCopy size="16" />
|
||||||
@@ -310,7 +307,7 @@
|
|||||||
<Shortcut key="C" ctrl={true} />
|
<Shortcut key="C" ctrl={true} />
|
||||||
</Menubar.Item>
|
</Menubar.Item>
|
||||||
<Menubar.Item
|
<Menubar.Item
|
||||||
onclick={selection.cutSelection}
|
onclick={() => selection.cutSelection()}
|
||||||
disabled={$selection.size === 0}
|
disabled={$selection.size === 0}
|
||||||
>
|
>
|
||||||
<Scissors size="16" />
|
<Scissors size="16" />
|
||||||
@@ -322,7 +319,7 @@
|
|||||||
$copied.length === 0 ||
|
$copied.length === 0 ||
|
||||||
($selection.size > 0 &&
|
($selection.size > 0 &&
|
||||||
!allowedPastes[$copied[0].level].includes(
|
!allowedPastes[$copied[0].level].includes(
|
||||||
$selection.getSelected().pop()?.level
|
$selection.getSelected().pop()!.level
|
||||||
))}
|
))}
|
||||||
onclick={pasteSelection}
|
onclick={pasteSelection}
|
||||||
>
|
>
|
||||||
@@ -333,7 +330,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
<Menubar.Separator />
|
<Menubar.Separator />
|
||||||
<Menubar.Item
|
<Menubar.Item
|
||||||
onclick={fileActions.deleteSelection}
|
onclick={() => tick().then(fileActions.deleteSelection)}
|
||||||
disabled={$selection.size == 0}
|
disabled={$selection.size == 0}
|
||||||
>
|
>
|
||||||
<Trash2 size="16" />
|
<Trash2 size="16" />
|
||||||
@@ -375,7 +372,7 @@
|
|||||||
/>
|
/>
|
||||||
</Menubar.CheckboxItem>
|
</Menubar.CheckboxItem>
|
||||||
<Menubar.Separator />
|
<Menubar.Separator />
|
||||||
<Menubar.Item inset onclick={map.toggle3D}>
|
<Menubar.Item inset onclick={() => map.toggle3D()}>
|
||||||
<Box size="16" />
|
<Box size="16" />
|
||||||
{i18n._('menu.toggle_3d')}
|
{i18n._('menu.toggle_3d')}
|
||||||
<Shortcut key="{i18n._('menu.ctrl')} {i18n._('menu.drag')}" />
|
<Shortcut key="{i18n._('menu.ctrl')} {i18n._('menu.drag')}" />
|
||||||
@@ -526,7 +523,7 @@
|
|||||||
<HeartHandshake size="18" class="md:hidden" />
|
<HeartHandshake size="18" class="md:hidden" />
|
||||||
<span class="hidden md:flex flex-row items-center">
|
<span class="hidden md:flex flex-row items-center">
|
||||||
{i18n._('menu.donate')}
|
{i18n._('menu.donate')}
|
||||||
<Heart size="16" class="ml-1" fill="rgb(var(--support))" />
|
<Heart size="16" class="ml-1" fill="var(--support)" />
|
||||||
</span>
|
</span>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
@@ -541,6 +538,7 @@
|
|||||||
let targetInput =
|
let targetInput =
|
||||||
e &&
|
e &&
|
||||||
e.target &&
|
e.target &&
|
||||||
|
e.target instanceof HTMLElement &&
|
||||||
(e.target.tagName === 'INPUT' ||
|
(e.target.tagName === 'INPUT' ||
|
||||||
e.target.tagName === 'TEXTAREA' ||
|
e.target.tagName === 'TEXTAREA' ||
|
||||||
e.target.tagName === 'SELECT' ||
|
e.target.tagName === 'SELECT' ||
|
||||||
@@ -629,9 +627,9 @@
|
|||||||
}
|
}
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
} else if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
|
} else if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
|
||||||
// if ($selection.size > 0) {
|
if ($selection.size > 0) {
|
||||||
// centerMapOnSelection();
|
boundsManager.centerMapOnSelection();
|
||||||
// }
|
}
|
||||||
} else if (e.key === 'F1') {
|
} else if (e.key === 'F1') {
|
||||||
switchBasemaps();
|
switchBasemaps();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -654,7 +652,10 @@
|
|||||||
e.key === 'ArrowUp'
|
e.key === 'ArrowUp'
|
||||||
) {
|
) {
|
||||||
if (!targetInput) {
|
if (!targetInput) {
|
||||||
// updateSelectionFromKey(e.key === 'ArrowRight' || e.key === 'ArrowDown', e.shiftKey);
|
selection.updateFromKey(
|
||||||
|
e.key === 'ArrowRight' || e.key === 'ArrowDown',
|
||||||
|
e.shiftKey
|
||||||
|
);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -662,7 +663,7 @@
|
|||||||
on:dragover={(e) => e.preventDefault()}
|
on:dragover={(e) => e.preventDefault()}
|
||||||
on:drop={(e) => {
|
on:drop={(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (e.dataTransfer.files.length > 0) {
|
if (e.dataTransfer && e.dataTransfer.files.length > 0) {
|
||||||
loadFiles(e.dataTransfer.files);
|
loadFiles(e.dataTransfer.files);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -4,21 +4,25 @@
|
|||||||
import { mode, setMode } from 'mode-watcher';
|
import { mode, setMode } from 'mode-watcher';
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
|
|
||||||
export let size = '20';
|
let {
|
||||||
|
class: className = '',
|
||||||
|
}: {
|
||||||
|
class?: string;
|
||||||
|
} = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon"
|
size="icon"
|
||||||
class="h-8 px-1.5 {$$props.class ?? ''}"
|
class={className}
|
||||||
onclick={() => {
|
onclick={() => {
|
||||||
setMode(mode.current === 'light' ? 'dark' : 'light');
|
setMode(mode.current === 'light' ? 'dark' : 'light');
|
||||||
}}
|
}}
|
||||||
aria-label={i18n._('menu.mode')}
|
aria-label={i18n._('menu.mode')}
|
||||||
>
|
>
|
||||||
{#if mode.current === 'light'}
|
{#if mode.current === 'light'}
|
||||||
<Sun {size} />
|
<Sun />
|
||||||
{:else}
|
{:else}
|
||||||
<Moon {size} />
|
<Moon />
|
||||||
{/if}
|
{/if}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import AlgoliaDocSearch from '$lib/components/AlgoliaDocSearch.svelte';
|
import AlgoliaDocSearch from '$lib/components/AlgoliaDocSearch.svelte';
|
||||||
import ModeSwitch from '$lib/components/ModeSwitch.svelte';
|
import ModeSwitch from '$lib/components/ModeSwitch.svelte';
|
||||||
import { BookOpenText, Home, Map } from '@lucide/svelte';
|
import { BookOpenText, House, Map } from '@lucide/svelte';
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
import { getURLForLanguage } from '$lib/utils';
|
import { getURLForLanguage } from '$lib/utils';
|
||||||
</script>
|
</script>
|
||||||
@@ -14,19 +14,32 @@
|
|||||||
<Logo class="h-8 sm:hidden" iconOnly={true} width="26" />
|
<Logo class="h-8 sm:hidden" iconOnly={true} width="26" />
|
||||||
<Logo class="h-8 hidden sm:block" width="153" />
|
<Logo class="h-8 hidden sm:block" width="153" />
|
||||||
</a>
|
</a>
|
||||||
<Button variant="link" class="text-base px-0" href={getURLForLanguage(i18n.lang, '/')}>
|
<Button
|
||||||
<Home size="18" />
|
variant="link"
|
||||||
|
class="text-base px-0 has-[>svg]:px-0"
|
||||||
|
href={getURLForLanguage(i18n.lang, '/')}
|
||||||
|
>
|
||||||
|
<House size="18" />
|
||||||
{i18n._('homepage.home')}
|
{i18n._('homepage.home')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="link" class="text-base px-0" href={getURLForLanguage(i18n.lang, '/app')}>
|
<Button
|
||||||
|
data-sveltekit-reload
|
||||||
|
variant="link"
|
||||||
|
class="text-base px-0 has-[>svg]:px-0"
|
||||||
|
href={getURLForLanguage(i18n.lang, '/app')}
|
||||||
|
>
|
||||||
<Map size="18" />
|
<Map size="18" />
|
||||||
{i18n._('homepage.app')}
|
{i18n._('homepage.app')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="link" class="text-base px-0" href={getURLForLanguage(i18n.lang, '/help')}>
|
<Button
|
||||||
|
variant="link"
|
||||||
|
class="text-base px-0 has-[>svg]:px-0"
|
||||||
|
href={getURLForLanguage(i18n.lang, '/help')}
|
||||||
|
>
|
||||||
<BookOpenText size="18" />
|
<BookOpenText size="18" />
|
||||||
{i18n._('menu.help')}
|
{i18n._('menu.help')}
|
||||||
</Button>
|
</Button>
|
||||||
<AlgoliaDocSearch class="ml-auto" />
|
<AlgoliaDocSearch class="ml-auto" />
|
||||||
<ModeSwitch class="hidden xs:block" />
|
<ModeSwitch class="hidden xs:inline-flex" />
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
@@ -34,9 +34,10 @@
|
|||||||
<Collapsible.Trigger class="w-full">
|
<Collapsible.Trigger class="w-full">
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
class="w-full flex flex-row {side === 'right'
|
size="icon"
|
||||||
|
class="w-full flex flex-row gap-1 {side === 'right'
|
||||||
? 'justify-between'
|
? 'justify-between'
|
||||||
: 'justify-start'} p-0 has-[>svg]:px-0 h-fit {nohover
|
: 'justify-start pl-1'} h-fit {nohover
|
||||||
? 'hover:bg-background'
|
? 'hover:bg-background'
|
||||||
: ''} pointer-events-none"
|
: ''} pointer-events-none"
|
||||||
>
|
>
|
||||||
@@ -60,9 +61,10 @@
|
|||||||
{:else}
|
{:else}
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
class="w-full flex flex-row {side === 'right'
|
size="icon"
|
||||||
|
class="w-full flex flex-row gap-1 {side === 'right'
|
||||||
? 'justify-between'
|
? 'justify-between'
|
||||||
: 'justify-start'} p-0 has-[>svg]:px-0 h-fit {nohover ? 'hover:bg-background' : ''}"
|
: 'justify-start pl-1'} h-fit {nohover ? 'hover:bg-background' : ''}"
|
||||||
>
|
>
|
||||||
{#if side === 'left'}
|
{#if side === 'left'}
|
||||||
<Collapsible.Trigger>
|
<Collapsible.Trigger>
|
||||||
@@ -85,7 +87,6 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<Collapsible.Content>
|
<Collapsible.Content>
|
||||||
{@render props.content()}
|
{@render props.content()}
|
||||||
</Collapsible.Content>
|
</Collapsible.Content>
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import mapboxOutdoorsMap from '$lib/assets/img/home/mapbox-outdoors.png?enhanced';
|
import maptilerTopoMap from '$lib/assets/img/home/maptiler-topo.png?enhanced';
|
||||||
import waymarkedMap from '$lib/assets/img/home/waymarked.png?enhanced';
|
import waymarkedMap from '$lib/assets/img/home/waymarked.png?enhanced';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="relative h-80 aspect-square rounded-2xl shadow-xl overflow-clip">
|
<div class="relative h-80 aspect-square rounded-2xl shadow-xl overflow-clip">
|
||||||
<enhanced:img src={mapboxOutdoorsMap} alt="Mapbox Outdoors map screenshot." class="absolute" />
|
<enhanced:img src={maptilerTopoMap} alt="MapTiler Topo map screenshot." class="absolute" />
|
||||||
<enhanced:img
|
<enhanced:img
|
||||||
src={waymarkedMap}
|
src={waymarkedMap}
|
||||||
alt="Waymarked Trails map screenshot."
|
alt="Waymarked Trails map screenshot."
|
||||||
|
|||||||
@@ -0,0 +1,206 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import ButtonWithTooltip from '$lib/components/ButtonWithTooltip.svelte';
|
||||||
|
import * as Popover from '$lib/components/ui/popover/index.js';
|
||||||
|
import * as ToggleGroup from '$lib/components/ui/toggle-group/index.js';
|
||||||
|
import Separator from '$lib/components/ui/separator/separator.svelte';
|
||||||
|
import { onDestroy, onMount } from 'svelte';
|
||||||
|
import {
|
||||||
|
BrickWall,
|
||||||
|
TriangleRight,
|
||||||
|
HeartPulse,
|
||||||
|
Orbit,
|
||||||
|
SquareActivity,
|
||||||
|
Thermometer,
|
||||||
|
Zap,
|
||||||
|
Circle,
|
||||||
|
Check,
|
||||||
|
ChartNoAxesColumn,
|
||||||
|
Construction,
|
||||||
|
} from '@lucide/svelte';
|
||||||
|
import type { Readable, Writable } from 'svelte/store';
|
||||||
|
import type { Coordinates, GPXGlobalStatistics, GPXStatisticsGroup } from 'gpx';
|
||||||
|
import { settings } from '$lib/logic/settings';
|
||||||
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
|
import { ElevationProfile } from '$lib/components/elevation-profile/elevation-profile';
|
||||||
|
|
||||||
|
const { velocityUnits } = settings;
|
||||||
|
|
||||||
|
let {
|
||||||
|
gpxStatistics,
|
||||||
|
slicedGPXStatistics,
|
||||||
|
hoveredPoint,
|
||||||
|
additionalDatasets,
|
||||||
|
elevationFill,
|
||||||
|
showControls = true,
|
||||||
|
}: {
|
||||||
|
gpxStatistics: Readable<GPXStatisticsGroup>;
|
||||||
|
slicedGPXStatistics: Writable<[GPXGlobalStatistics, number, number] | undefined>;
|
||||||
|
hoveredPoint: Writable<Coordinates | null>;
|
||||||
|
additionalDatasets: Writable<string[]>;
|
||||||
|
elevationFill: Writable<'slope' | 'surface' | 'highway' | undefined>;
|
||||||
|
showControls?: boolean;
|
||||||
|
} = $props();
|
||||||
|
|
||||||
|
let canvas: HTMLCanvasElement;
|
||||||
|
let overlay: HTMLCanvasElement;
|
||||||
|
let elevationProfile: ElevationProfile | null = null;
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
elevationProfile = new ElevationProfile(
|
||||||
|
gpxStatistics,
|
||||||
|
slicedGPXStatistics,
|
||||||
|
hoveredPoint,
|
||||||
|
additionalDatasets,
|
||||||
|
elevationFill,
|
||||||
|
canvas,
|
||||||
|
overlay
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
if (elevationProfile) {
|
||||||
|
elevationProfile.destroy();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="h-full grow min-w-0 min-h-0 relative">
|
||||||
|
<canvas bind:this={overlay} class="w-full h-full absolute pointer-events-none"></canvas>
|
||||||
|
<canvas bind:this={canvas} class="w-full h-full absolute"></canvas>
|
||||||
|
{#if showControls}
|
||||||
|
<div class="absolute bottom-10 right-1.5">
|
||||||
|
<Popover.Root>
|
||||||
|
<Popover.Trigger>
|
||||||
|
<ButtonWithTooltip
|
||||||
|
label={i18n._('chart.settings')}
|
||||||
|
variant="outline"
|
||||||
|
side="left"
|
||||||
|
class="w-7 h-7 p-0 flex justify-center opacity-70 hover:opacity-100 transition-opacity duration-300 hover:bg-background"
|
||||||
|
>
|
||||||
|
<ChartNoAxesColumn size="18" />
|
||||||
|
</ButtonWithTooltip>
|
||||||
|
</Popover.Trigger>
|
||||||
|
<Popover.Content
|
||||||
|
class="w-fit p-0 flex flex-col"
|
||||||
|
side="top"
|
||||||
|
align="end"
|
||||||
|
sideOffset={-32}
|
||||||
|
>
|
||||||
|
<ToggleGroup.Root
|
||||||
|
class="flex flex-col items-start gap-0 p-1 w-full border-none"
|
||||||
|
type="single"
|
||||||
|
bind:value={$elevationFill}
|
||||||
|
>
|
||||||
|
<ToggleGroup.Item
|
||||||
|
class="p-0 pr-1.5 h-6 w-full gap-1.5 rounded flex justify-start data-[state=on]:bg-background data-[state=on]:hover:bg-accent hover:bg-accent hover:text-foreground"
|
||||||
|
value="slope"
|
||||||
|
>
|
||||||
|
<div class="w-6 flex justify-center items-center">
|
||||||
|
{#if $elevationFill === 'slope'}
|
||||||
|
<Circle class="size-1.5 fill-current text-current" />
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<TriangleRight size="15" />
|
||||||
|
{i18n._('quantities.slope')}
|
||||||
|
</ToggleGroup.Item>
|
||||||
|
<ToggleGroup.Item
|
||||||
|
class="p-0 pr-1.5 h-6 w-full gap-1.5 rounded flex justify-start data-[state=on]:bg-background data-[state=on]:hover:bg-accent hover:bg-accent hover:text-foreground"
|
||||||
|
value="surface"
|
||||||
|
variant="outline"
|
||||||
|
>
|
||||||
|
<div class="w-6 flex justify-center items-center">
|
||||||
|
{#if $elevationFill === 'surface'}
|
||||||
|
<Circle class="size-1.5 fill-current text-current" />
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<BrickWall size="15" />
|
||||||
|
{i18n._('quantities.surface')}
|
||||||
|
</ToggleGroup.Item>
|
||||||
|
<ToggleGroup.Item
|
||||||
|
class="p-0 pr-1.5 h-6 w-full gap-1.5 rounded flex justify-start data-[state=on]:bg-background data-[state=on]:hover:bg-accent hover:bg-accent hover:text-foreground"
|
||||||
|
value="highway"
|
||||||
|
variant="outline"
|
||||||
|
>
|
||||||
|
<div class="w-6 flex justify-center items-center">
|
||||||
|
{#if $elevationFill === 'highway'}
|
||||||
|
<Circle class="size-1.5 fill-current text-current" />
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<Construction size="15" />
|
||||||
|
{i18n._('quantities.highway')}
|
||||||
|
</ToggleGroup.Item>
|
||||||
|
</ToggleGroup.Root>
|
||||||
|
<Separator />
|
||||||
|
<ToggleGroup.Root
|
||||||
|
class="flex flex-col items-start gap-0 p-1"
|
||||||
|
type="multiple"
|
||||||
|
bind:value={$additionalDatasets}
|
||||||
|
>
|
||||||
|
<ToggleGroup.Item
|
||||||
|
class="p-0 pr-1.5 h-6 w-full gap-1.5 rounded flex justify-start data-[state=on]:bg-background data-[state=on]:hover:bg-accent hover:bg-accent hover:text-foreground"
|
||||||
|
value="speed"
|
||||||
|
>
|
||||||
|
<div class="w-6 flex justify-center items-center">
|
||||||
|
{#if $additionalDatasets.includes('speed')}
|
||||||
|
<Check size="14" />
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<Zap size="15" />
|
||||||
|
{$velocityUnits === 'speed'
|
||||||
|
? i18n._('quantities.speed')
|
||||||
|
: i18n._('quantities.pace')}
|
||||||
|
</ToggleGroup.Item>
|
||||||
|
<ToggleGroup.Item
|
||||||
|
class="p-0 pr-1.5 h-6 w-full gap-1.5 rounded flex justify-start data-[state=on]:bg-background data-[state=on]:hover:bg-accent hover:bg-accent hover:text-foreground"
|
||||||
|
value="hr"
|
||||||
|
>
|
||||||
|
<div class="w-6 flex justify-center items-center">
|
||||||
|
{#if $additionalDatasets.includes('hr')}
|
||||||
|
<Check size="14" />
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<HeartPulse size="15" />
|
||||||
|
{i18n._('quantities.heartrate')}
|
||||||
|
</ToggleGroup.Item>
|
||||||
|
<ToggleGroup.Item
|
||||||
|
class="p-0 pr-1.5 h-6 w-full gap-1.5 rounded flex justify-start data-[state=on]:bg-background data-[state=on]:hover:bg-accent hover:bg-accent hover:text-foreground"
|
||||||
|
value="cad"
|
||||||
|
>
|
||||||
|
<div class="w-6 flex justify-center items-center">
|
||||||
|
{#if $additionalDatasets.includes('cad')}
|
||||||
|
<Check size="14" />
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<Orbit size="15" />
|
||||||
|
{i18n._('quantities.cadence')}
|
||||||
|
</ToggleGroup.Item>
|
||||||
|
<ToggleGroup.Item
|
||||||
|
class="p-0 pr-1.5 h-6 w-full gap-1.5 rounded flex justify-start data-[state=on]:bg-background data-[state=on]:hover:bg-accent hover:bg-accent hover:text-foreground"
|
||||||
|
value="atemp"
|
||||||
|
>
|
||||||
|
<div class="w-6 flex justify-center items-center">
|
||||||
|
{#if $additionalDatasets.includes('atemp')}
|
||||||
|
<Check size="14" />
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<Thermometer size="15" />
|
||||||
|
{i18n._('quantities.temperature')}
|
||||||
|
</ToggleGroup.Item>
|
||||||
|
<ToggleGroup.Item
|
||||||
|
class="p-0 pr-1.5 h-6 w-full gap-1.5 rounded flex justify-start data-[state=on]:bg-background data-[state=on]:hover:bg-accent hover:bg-accent hover:text-foreground"
|
||||||
|
value="power"
|
||||||
|
>
|
||||||
|
<div class="w-6 flex justify-center items-center">
|
||||||
|
{#if $additionalDatasets.includes('power')}
|
||||||
|
<Check size="14" />
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<SquareActivity size="15" />
|
||||||
|
{i18n._('quantities.power')}
|
||||||
|
</ToggleGroup.Item>
|
||||||
|
</ToggleGroup.Root>
|
||||||
|
</Popover.Content>
|
||||||
|
</Popover.Root>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,628 @@
|
|||||||
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
|
import { settings } from '$lib/logic/settings';
|
||||||
|
import {
|
||||||
|
getCadenceWithUnits,
|
||||||
|
getConvertedDistance,
|
||||||
|
getConvertedElevation,
|
||||||
|
getConvertedTemperature,
|
||||||
|
getConvertedVelocity,
|
||||||
|
getDistanceUnits,
|
||||||
|
getDistanceWithUnits,
|
||||||
|
getElevationWithUnits,
|
||||||
|
getHeartRateWithUnits,
|
||||||
|
getPowerWithUnits,
|
||||||
|
getTemperatureWithUnits,
|
||||||
|
getVelocityWithUnits,
|
||||||
|
} from '$lib/units';
|
||||||
|
import Chart, {
|
||||||
|
type ChartEvent,
|
||||||
|
type ChartOptions,
|
||||||
|
type ScriptableLineSegmentContext,
|
||||||
|
type TooltipItem,
|
||||||
|
} from 'chart.js/auto';
|
||||||
|
import { get, type Readable, type Writable } from 'svelte/store';
|
||||||
|
import type { Coordinates, GPXGlobalStatistics, GPXStatisticsGroup } from 'gpx';
|
||||||
|
import { mode } from 'mode-watcher';
|
||||||
|
import { getHighwayColor, getSlopeColor, getSurfaceColor } from '$lib/assets/colors';
|
||||||
|
|
||||||
|
const { distanceUnits, velocityUnits, temperatureUnits } = settings;
|
||||||
|
|
||||||
|
Chart.defaults.font.family =
|
||||||
|
'ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"'; // Tailwind CSS font
|
||||||
|
|
||||||
|
interface ElevationProfilePoint {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
time?: Date;
|
||||||
|
slope: {
|
||||||
|
at: number;
|
||||||
|
segment: number;
|
||||||
|
length: number;
|
||||||
|
};
|
||||||
|
extensions: Record<string, any>;
|
||||||
|
coordinates: Coordinates;
|
||||||
|
index: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ElevationProfile {
|
||||||
|
private _chart: Chart | null = null;
|
||||||
|
private _canvas: HTMLCanvasElement;
|
||||||
|
private _overlay: HTMLCanvasElement;
|
||||||
|
private _dragging = false;
|
||||||
|
private _panning = false;
|
||||||
|
|
||||||
|
private _gpxStatistics: Readable<GPXStatisticsGroup>;
|
||||||
|
private _slicedGPXStatistics: Writable<[GPXGlobalStatistics, number, number] | undefined>;
|
||||||
|
private _hoveredPoint: Writable<Coordinates | null>;
|
||||||
|
private _additionalDatasets: Readable<string[]>;
|
||||||
|
private _elevationFill: Readable<'slope' | 'surface' | 'highway' | undefined>;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
gpxStatistics: Readable<GPXStatisticsGroup>,
|
||||||
|
slicedGPXStatistics: Writable<[GPXGlobalStatistics, number, number] | undefined>,
|
||||||
|
hoveredPoint: Writable<Coordinates | null>,
|
||||||
|
additionalDatasets: Readable<string[]>,
|
||||||
|
elevationFill: Readable<'slope' | 'surface' | 'highway' | undefined>,
|
||||||
|
canvas: HTMLCanvasElement,
|
||||||
|
overlay: HTMLCanvasElement
|
||||||
|
) {
|
||||||
|
this._gpxStatistics = gpxStatistics;
|
||||||
|
this._slicedGPXStatistics = slicedGPXStatistics;
|
||||||
|
this._hoveredPoint = hoveredPoint;
|
||||||
|
this._additionalDatasets = additionalDatasets;
|
||||||
|
this._elevationFill = elevationFill;
|
||||||
|
this._canvas = canvas;
|
||||||
|
this._overlay = overlay;
|
||||||
|
|
||||||
|
import('chartjs-plugin-zoom').then((module) => {
|
||||||
|
Chart.register(module.default);
|
||||||
|
this.initialize();
|
||||||
|
|
||||||
|
this._gpxStatistics.subscribe(() => {
|
||||||
|
this.updateData();
|
||||||
|
});
|
||||||
|
this._slicedGPXStatistics.subscribe(() => {
|
||||||
|
this.updateOverlay();
|
||||||
|
});
|
||||||
|
distanceUnits.subscribe(() => {
|
||||||
|
this.updateData();
|
||||||
|
});
|
||||||
|
velocityUnits.subscribe(() => {
|
||||||
|
this.updateData();
|
||||||
|
});
|
||||||
|
temperatureUnits.subscribe(() => {
|
||||||
|
this.updateData();
|
||||||
|
});
|
||||||
|
this._additionalDatasets.subscribe(() => {
|
||||||
|
this.updateDataVisibility();
|
||||||
|
});
|
||||||
|
this._elevationFill.subscribe(() => {
|
||||||
|
this.updateFill();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
initialize() {
|
||||||
|
let options: ChartOptions<'line'> = {
|
||||||
|
animation: false,
|
||||||
|
parsing: false,
|
||||||
|
maintainAspectRatio: false,
|
||||||
|
scales: {
|
||||||
|
x: {
|
||||||
|
type: 'linear',
|
||||||
|
ticks: {
|
||||||
|
callback: function (value: number | string) {
|
||||||
|
return `${(value as number).toFixed(1).replace(/\.0+$/, '')} ${getDistanceUnits()}`;
|
||||||
|
},
|
||||||
|
align: 'inner',
|
||||||
|
maxRotation: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
y: {
|
||||||
|
type: 'linear',
|
||||||
|
ticks: {
|
||||||
|
callback: function (value: number | string) {
|
||||||
|
return getElevationWithUnits(value as number, false);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
datasets: {
|
||||||
|
line: {
|
||||||
|
pointRadius: 0,
|
||||||
|
tension: 0.4,
|
||||||
|
borderWidth: 2,
|
||||||
|
cubicInterpolationMode: 'monotone',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
interaction: {
|
||||||
|
mode: 'nearest',
|
||||||
|
axis: 'x',
|
||||||
|
intersect: false,
|
||||||
|
},
|
||||||
|
plugins: {
|
||||||
|
legend: {
|
||||||
|
display: false,
|
||||||
|
},
|
||||||
|
decimation: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
enabled: () => !this._dragging && !this._panning,
|
||||||
|
callbacks: {
|
||||||
|
title: () => {
|
||||||
|
return '';
|
||||||
|
},
|
||||||
|
label: (context: TooltipItem<'line'>) => {
|
||||||
|
let point = context.raw as ElevationProfilePoint;
|
||||||
|
if (context.datasetIndex === 0) {
|
||||||
|
if (this._dragging) {
|
||||||
|
this._hoveredPoint.set(null);
|
||||||
|
} else {
|
||||||
|
this._hoveredPoint.set(point.coordinates);
|
||||||
|
}
|
||||||
|
return `${i18n._('quantities.elevation')}: ${getElevationWithUnits(point.y, false)}`;
|
||||||
|
} else if (context.datasetIndex === 1) {
|
||||||
|
return `${get(velocityUnits) === 'speed' ? i18n._('quantities.speed') : i18n._('quantities.pace')}: ${getVelocityWithUnits(point.y, false)}`;
|
||||||
|
} else if (context.datasetIndex === 2) {
|
||||||
|
return `${i18n._('quantities.heartrate')}: ${getHeartRateWithUnits(point.y)}`;
|
||||||
|
} else if (context.datasetIndex === 3) {
|
||||||
|
return `${i18n._('quantities.cadence')}: ${getCadenceWithUnits(point.y)}`;
|
||||||
|
} else if (context.datasetIndex === 4) {
|
||||||
|
return `${i18n._('quantities.temperature')}: ${getTemperatureWithUnits(point.y, false)}`;
|
||||||
|
} else if (context.datasetIndex === 5) {
|
||||||
|
return `${i18n._('quantities.power')}: ${getPowerWithUnits(point.y)}`;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
afterBody: (contexts: TooltipItem<'line'>[]) => {
|
||||||
|
let context = contexts.filter((context) => context.datasetIndex === 0);
|
||||||
|
if (context.length === 0) return;
|
||||||
|
let point = context[0].raw as ElevationProfilePoint;
|
||||||
|
let slope = {
|
||||||
|
at: point.slope.at.toFixed(1),
|
||||||
|
segment: point.slope.segment.toFixed(1),
|
||||||
|
length: getDistanceWithUnits(point.slope.length),
|
||||||
|
};
|
||||||
|
let surface = point.extensions.surface
|
||||||
|
? point.extensions.surface
|
||||||
|
: 'unknown';
|
||||||
|
let highway = point.extensions.highway
|
||||||
|
? point.extensions.highway
|
||||||
|
: 'unknown';
|
||||||
|
let sacScale = point.extensions.sac_scale;
|
||||||
|
let mtbScale = point.extensions.mtb_scale;
|
||||||
|
|
||||||
|
let labels = [
|
||||||
|
` ${i18n._('quantities.distance')}: ${getDistanceWithUnits(point.x, false)}`,
|
||||||
|
` ${i18n._('quantities.slope')}: ${slope.at} %${get(this._elevationFill) === 'slope' ? ` (${slope.length} @${slope.segment} %)` : ''}`,
|
||||||
|
];
|
||||||
|
|
||||||
|
if (get(this._elevationFill) === 'surface') {
|
||||||
|
labels.push(
|
||||||
|
` ${i18n._('quantities.surface')}: ${i18n._(`toolbar.routing.surface.${surface}`)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (get(this._elevationFill) === 'highway') {
|
||||||
|
labels.push(
|
||||||
|
` ${i18n._('quantities.highway')}: ${i18n._(`toolbar.routing.highway.${highway}`)}${
|
||||||
|
sacScale
|
||||||
|
? ` (${i18n._(`toolbar.routing.sac_scale.${sacScale}`)})`
|
||||||
|
: ''
|
||||||
|
}`
|
||||||
|
);
|
||||||
|
if (mtbScale) {
|
||||||
|
labels.push(
|
||||||
|
` ${i18n._('toolbar.routing.mtb_scale')}: ${mtbScale}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (point.time) {
|
||||||
|
labels.push(
|
||||||
|
` ${i18n._('quantities.time')}: ${i18n.df.format(point.time)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return labels;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
zoom: {
|
||||||
|
pan: {
|
||||||
|
enabled: true,
|
||||||
|
mode: 'x',
|
||||||
|
modifierKey: 'shift',
|
||||||
|
onPanStart: () => {
|
||||||
|
this._panning = true;
|
||||||
|
this._slicedGPXStatistics.set(undefined);
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
onPanComplete: () => {
|
||||||
|
this._panning = false;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
zoom: {
|
||||||
|
wheel: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
mode: 'x',
|
||||||
|
onZoomStart: ({ chart, event }: { chart: Chart; event: any }) => {
|
||||||
|
if (!this._chart) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const maxZoom = this._chart.getInitialScaleBounds()?.x?.max ?? 0;
|
||||||
|
if (
|
||||||
|
event.deltaY < 0 &&
|
||||||
|
Math.abs(maxZoom / this._chart.getZoomLevel()) < 0.01
|
||||||
|
) {
|
||||||
|
// Disable wheel pan if zoomed in to the max, and zooming in
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._slicedGPXStatistics.set(undefined);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
limits: {
|
||||||
|
x: {
|
||||||
|
min: 'original',
|
||||||
|
max: 'original',
|
||||||
|
minRange: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
onResize: () => {
|
||||||
|
this.updateOverlay();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
let datasets: string[] = ['speed', 'hr', 'cad', 'atemp', 'power'];
|
||||||
|
datasets.forEach((id) => {
|
||||||
|
options.scales![`y${id}`] = {
|
||||||
|
type: 'linear',
|
||||||
|
position: 'right',
|
||||||
|
grid: {
|
||||||
|
display: false,
|
||||||
|
},
|
||||||
|
reverse: () => id === 'speed' && get(velocityUnits) === 'pace',
|
||||||
|
display: false,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
this._chart = new Chart(this._canvas, {
|
||||||
|
type: 'line',
|
||||||
|
data: {
|
||||||
|
datasets: [],
|
||||||
|
},
|
||||||
|
options,
|
||||||
|
plugins: [
|
||||||
|
{
|
||||||
|
id: 'toggleMarker',
|
||||||
|
events: ['mouseout'],
|
||||||
|
afterEvent: (chart: Chart, args: { event: ChartEvent }) => {
|
||||||
|
if (args.event.type === 'mouseout') {
|
||||||
|
this._hoveredPoint.set(null);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
let startIndex = 0;
|
||||||
|
let endIndex = 0;
|
||||||
|
const getIndex = (evt: PointerEvent) => {
|
||||||
|
if (!this._chart) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const points = this._chart.getElementsAtEventForMode(
|
||||||
|
evt,
|
||||||
|
'x',
|
||||||
|
{
|
||||||
|
intersect: false,
|
||||||
|
},
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
if (points.length === 0) {
|
||||||
|
const rect = this._canvas.getBoundingClientRect();
|
||||||
|
if (evt.x - rect.left <= this._chart.chartArea.left) {
|
||||||
|
return 0;
|
||||||
|
} else if (evt.x - rect.left >= this._chart.chartArea.right) {
|
||||||
|
return this._chart.data.datasets[0].data.length - 1;
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const point = points.find((point) => (point.element as any).raw);
|
||||||
|
if (point) {
|
||||||
|
return (point.element as any).raw.index;
|
||||||
|
} else {
|
||||||
|
return points[0].index;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let dragStarted = false;
|
||||||
|
const onMouseDown = (evt: PointerEvent) => {
|
||||||
|
if (evt.shiftKey) {
|
||||||
|
// Panning interaction
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dragStarted = true;
|
||||||
|
this._canvas.style.cursor = 'col-resize';
|
||||||
|
startIndex = getIndex(evt);
|
||||||
|
};
|
||||||
|
const onMouseMove = (evt: PointerEvent) => {
|
||||||
|
if (dragStarted) {
|
||||||
|
this._dragging = true;
|
||||||
|
endIndex = getIndex(evt);
|
||||||
|
if (endIndex !== undefined) {
|
||||||
|
if (startIndex === undefined) {
|
||||||
|
startIndex = endIndex;
|
||||||
|
} else if (startIndex !== endIndex) {
|
||||||
|
this._slicedGPXStatistics.set([
|
||||||
|
get(this._gpxStatistics).sliced(
|
||||||
|
Math.min(startIndex, endIndex),
|
||||||
|
Math.max(startIndex, endIndex)
|
||||||
|
),
|
||||||
|
Math.min(startIndex, endIndex),
|
||||||
|
Math.max(startIndex, endIndex),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const onMouseUp = (evt: PointerEvent) => {
|
||||||
|
dragStarted = false;
|
||||||
|
this._dragging = false;
|
||||||
|
this._canvas.style.cursor = '';
|
||||||
|
endIndex = getIndex(evt);
|
||||||
|
if (startIndex === endIndex) {
|
||||||
|
this._slicedGPXStatistics.set(undefined);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this._canvas.addEventListener('pointerdown', onMouseDown);
|
||||||
|
this._canvas.addEventListener('pointermove', onMouseMove);
|
||||||
|
this._canvas.addEventListener('pointerup', onMouseUp);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateData() {
|
||||||
|
if (!this._chart) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = get(this._gpxStatistics);
|
||||||
|
const units = {
|
||||||
|
distance: get(distanceUnits),
|
||||||
|
velocity: get(velocityUnits),
|
||||||
|
temperature: get(temperatureUnits),
|
||||||
|
};
|
||||||
|
|
||||||
|
const datasets: Array<Array<any>> = [[], [], [], [], [], []];
|
||||||
|
data.forEachTrackPoint((trkpt, distance, speed, slope, index) => {
|
||||||
|
datasets[0].push({
|
||||||
|
x: getConvertedDistance(distance, units.distance),
|
||||||
|
y: trkpt.ele ? getConvertedElevation(trkpt.ele, units.distance) : 0,
|
||||||
|
time: trkpt.time,
|
||||||
|
slope: slope,
|
||||||
|
extensions: trkpt.getExtensions(),
|
||||||
|
coordinates: trkpt.getCoordinates(),
|
||||||
|
index: index,
|
||||||
|
});
|
||||||
|
if (data.global.time.total > 0) {
|
||||||
|
datasets[1].push({
|
||||||
|
x: getConvertedDistance(distance, units.distance),
|
||||||
|
y: getConvertedVelocity(speed, units.velocity, units.distance),
|
||||||
|
index: index,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (data.global.hr.count > 0) {
|
||||||
|
datasets[2].push({
|
||||||
|
x: getConvertedDistance(distance, units.distance),
|
||||||
|
y: trkpt.getHeartRate(),
|
||||||
|
index: index,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (data.global.cad.count > 0) {
|
||||||
|
datasets[3].push({
|
||||||
|
x: getConvertedDistance(distance, units.distance),
|
||||||
|
y: trkpt.getCadence(),
|
||||||
|
index: index,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (data.global.atemp.count > 0) {
|
||||||
|
datasets[4].push({
|
||||||
|
x: getConvertedDistance(distance, units.distance),
|
||||||
|
y: getConvertedTemperature(trkpt.getTemperature(), units.temperature),
|
||||||
|
index: index,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (data.global.power.count > 0) {
|
||||||
|
datasets[5].push({
|
||||||
|
x: getConvertedDistance(distance, units.distance),
|
||||||
|
y: trkpt.getPower(),
|
||||||
|
index: index,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this._chart.data.datasets[0] = {
|
||||||
|
label: i18n._('quantities.elevation'),
|
||||||
|
data: datasets[0],
|
||||||
|
normalized: true,
|
||||||
|
fill: 'start',
|
||||||
|
order: 1,
|
||||||
|
segment: {},
|
||||||
|
};
|
||||||
|
this._chart.data.datasets[1] = {
|
||||||
|
data: datasets[1],
|
||||||
|
normalized: true,
|
||||||
|
yAxisID: 'yspeed',
|
||||||
|
};
|
||||||
|
this._chart.data.datasets[2] = {
|
||||||
|
data: datasets[2],
|
||||||
|
normalized: true,
|
||||||
|
yAxisID: 'yhr',
|
||||||
|
};
|
||||||
|
this._chart.data.datasets[3] = {
|
||||||
|
data: datasets[3],
|
||||||
|
normalized: true,
|
||||||
|
yAxisID: 'ycad',
|
||||||
|
};
|
||||||
|
this._chart.data.datasets[4] = {
|
||||||
|
data: datasets[4],
|
||||||
|
normalized: true,
|
||||||
|
yAxisID: 'yatemp',
|
||||||
|
};
|
||||||
|
this._chart.data.datasets[5] = {
|
||||||
|
data: datasets[5],
|
||||||
|
normalized: true,
|
||||||
|
yAxisID: 'ypower',
|
||||||
|
};
|
||||||
|
|
||||||
|
this._chart.options.scales!.x!['min'] = 0;
|
||||||
|
this._chart.options.scales!.x!['max'] = getConvertedDistance(
|
||||||
|
data.global.distance.total,
|
||||||
|
units.distance
|
||||||
|
);
|
||||||
|
|
||||||
|
this.setVisibility();
|
||||||
|
this.setFill();
|
||||||
|
|
||||||
|
this._chart.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateDataVisibility() {
|
||||||
|
if (!this._chart) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.setVisibility();
|
||||||
|
this._chart.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
setVisibility() {
|
||||||
|
if (!this._chart) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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');
|
||||||
|
if (this._chart.data.datasets.length == 6) {
|
||||||
|
this._chart.data.datasets[1].hidden = !includeSpeed;
|
||||||
|
this._chart.data.datasets[2].hidden = !includeHeartRate;
|
||||||
|
this._chart.data.datasets[3].hidden = !includeCadence;
|
||||||
|
this._chart.data.datasets[4].hidden = !includeTemperature;
|
||||||
|
this._chart.data.datasets[5].hidden = !includePower;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateFill() {
|
||||||
|
if (!this._chart) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.setFill();
|
||||||
|
this._chart.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
setFill() {
|
||||||
|
if (!this._chart) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const elevationFill = get(this._elevationFill);
|
||||||
|
const dataset = this._chart.data.datasets[0];
|
||||||
|
let segment: any = {};
|
||||||
|
if (elevationFill === 'slope') {
|
||||||
|
segment = {
|
||||||
|
backgroundColor: this.slopeFillCallback,
|
||||||
|
};
|
||||||
|
} else if (elevationFill === 'surface') {
|
||||||
|
segment = {
|
||||||
|
backgroundColor: this.surfaceFillCallback,
|
||||||
|
};
|
||||||
|
} else if (elevationFill === 'highway') {
|
||||||
|
segment = {
|
||||||
|
backgroundColor: this.highwayFillCallback,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
segment = {};
|
||||||
|
}
|
||||||
|
Object.assign(dataset, { segment });
|
||||||
|
}
|
||||||
|
|
||||||
|
updateOverlay() {
|
||||||
|
if (!this._chart) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._overlay.width = this._canvas.width / window.devicePixelRatio;
|
||||||
|
this._overlay.height = this._canvas.height / window.devicePixelRatio;
|
||||||
|
this._overlay.style.width = `${this._overlay.width}px`;
|
||||||
|
this._overlay.style.height = `${this._overlay.height}px`;
|
||||||
|
|
||||||
|
const slicedGPXStatistics = get(this._slicedGPXStatistics);
|
||||||
|
if (slicedGPXStatistics) {
|
||||||
|
let startIndex = slicedGPXStatistics[1];
|
||||||
|
let endIndex = slicedGPXStatistics[2];
|
||||||
|
|
||||||
|
// Draw selection rectangle
|
||||||
|
let 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 gpxStatistics = get(this._gpxStatistics);
|
||||||
|
let startPixel = this._chart.scales.x.getPixelForValue(
|
||||||
|
getConvertedDistance(
|
||||||
|
gpxStatistics.getTrackPoint(startIndex)?.distance.total ?? 0
|
||||||
|
)
|
||||||
|
);
|
||||||
|
let endPixel = this._chart.scales.x.getPixelForValue(
|
||||||
|
getConvertedDistance(gpxStatistics.getTrackPoint(endIndex)?.distance.total ?? 0)
|
||||||
|
);
|
||||||
|
|
||||||
|
selectionContext.fillRect(
|
||||||
|
startPixel,
|
||||||
|
this._chart.chartArea.top,
|
||||||
|
endPixel - startPixel,
|
||||||
|
this._chart.chartArea.height
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if (this._overlay) {
|
||||||
|
let selectionContext = this._overlay.getContext('2d');
|
||||||
|
if (selectionContext) {
|
||||||
|
selectionContext.clearRect(0, 0, this._overlay.width, this._overlay.height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
slopeFillCallback(context: ScriptableLineSegmentContext & { p0: { raw: any } }) {
|
||||||
|
const point = context.p0.raw as ElevationProfilePoint;
|
||||||
|
return getSlopeColor(point.slope.segment);
|
||||||
|
}
|
||||||
|
|
||||||
|
surfaceFillCallback(context: ScriptableLineSegmentContext & { p0: { raw: any } }) {
|
||||||
|
const point = context.p0.raw as ElevationProfilePoint;
|
||||||
|
return getSurfaceColor(point.extensions.surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
highwayFillCallback(context: ScriptableLineSegmentContext & { p0: { raw: any } }) {
|
||||||
|
const point = context.p0.raw as ElevationProfilePoint;
|
||||||
|
return getHighwayColor(
|
||||||
|
point.extensions.highway,
|
||||||
|
point.extensions.sac_scale,
|
||||||
|
point.extensions.mtb_scale
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
destroy() {
|
||||||
|
if (this._chart) {
|
||||||
|
this._chart.destroy();
|
||||||
|
this._chart = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,43 +1,39 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
// import GPXLayers from '$lib/components/map/gpx-layer/GPXLayers.svelte';
|
import GPXLayers from '$lib/components/map/gpx-layer/GPXLayers.svelte';
|
||||||
// import ElevationProfile from '$lib/components/ElevationProfile.svelte';
|
import ElevationProfile from '$lib/components/elevation-profile/ElevationProfile.svelte';
|
||||||
// import FileList from '$lib/components/file-list/FileList.svelte';
|
import FileList from '$lib/components/file-list/FileList.svelte';
|
||||||
// import GPXStatistics from '$lib/components/GPXStatistics.svelte';
|
import GPXStatistics from '$lib/components/GPXStatistics.svelte';
|
||||||
import Map from '$lib/components/map/Map.svelte';
|
import Map from '$lib/components/map/Map.svelte';
|
||||||
import { map } from '$lib/components/map/map';
|
import LayerControl from '$lib/components/map/layer-control/LayerControl.svelte';
|
||||||
// import LayerControl from '$lib/components/map/layer-control/LayerControl.svelte';
|
|
||||||
import OpenIn from '$lib/components/embedding/OpenIn.svelte';
|
import OpenIn from '$lib/components/embedding/OpenIn.svelte';
|
||||||
import {
|
import { writable } from 'svelte/store';
|
||||||
gpxStatistics,
|
|
||||||
slicedGPXStatistics,
|
|
||||||
embedding,
|
|
||||||
loadFile,
|
|
||||||
updateGPXData,
|
|
||||||
} from '$lib/stores';
|
|
||||||
import { onDestroy, onMount, setContext } from 'svelte';
|
|
||||||
import { readable } from 'svelte/store';
|
|
||||||
import type { GPXFile } from 'gpx';
|
import type { GPXFile } from 'gpx';
|
||||||
import { ListFileItem } from '$lib/components/file-list/file-list';
|
|
||||||
import {
|
import {
|
||||||
allowedEmbeddingBasemaps,
|
allowedEmbeddingBasemaps,
|
||||||
getFilesFromEmbeddingOptions,
|
getFilesFromEmbeddingOptions,
|
||||||
type EmbeddingOptions,
|
type EmbeddingOptions,
|
||||||
} from './Embedding';
|
} from './embedding';
|
||||||
import { mode, setMode } from 'mode-watcher';
|
import { setMode } from 'mode-watcher';
|
||||||
import { browser } from '$app/environment';
|
|
||||||
import { settings } from '$lib/logic/settings';
|
import { settings } from '$lib/logic/settings';
|
||||||
import { fileStateCollection } from '$lib/logic/file-state';
|
import { fileStateCollection } from '$lib/logic/file-state';
|
||||||
|
import { gpxStatistics, hoveredPoint, slicedGPXStatistics } from '$lib/logic/statistics';
|
||||||
|
import { loadFile } from '$lib/logic/file-actions';
|
||||||
|
import { selection } from '$lib/logic/selection';
|
||||||
|
import { untrack } from 'svelte';
|
||||||
|
import { isSelected, toggle } from '$lib/components/map/layer-control/utils';
|
||||||
|
|
||||||
let {
|
let {
|
||||||
useHash = true,
|
useHash = true,
|
||||||
options = $bindable(),
|
options = $bindable(),
|
||||||
hash,
|
hash = $bindable(),
|
||||||
}: { useHash?: boolean; options: EmbeddingOptions; hash: string } = $props();
|
}: { useHash?: boolean; options: EmbeddingOptions; hash: string } = $props();
|
||||||
|
|
||||||
setContext('embedding', true);
|
let additionalDatasets = writable<string[]>([]);
|
||||||
|
let elevationFill = writable<'slope' | 'surface' | 'highway' | undefined>(undefined);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
currentBasemap,
|
currentBasemap,
|
||||||
|
selectedBasemapTree,
|
||||||
distanceUnits,
|
distanceUnits,
|
||||||
velocityUnits,
|
velocityUnits,
|
||||||
temperatureUnits,
|
temperatureUnits,
|
||||||
@@ -46,190 +42,77 @@
|
|||||||
directionMarkers,
|
directionMarkers,
|
||||||
} = settings;
|
} = settings;
|
||||||
|
|
||||||
let prevSettings: {
|
settings.initialize();
|
||||||
distanceMarkers: boolean;
|
|
||||||
directionMarkers: boolean;
|
|
||||||
distanceUnits: 'metric' | 'imperial' | 'nautical';
|
|
||||||
velocityUnits: 'speed' | 'pace';
|
|
||||||
temperatureUnits: 'celsius' | 'fahrenheit';
|
|
||||||
theme: 'light' | 'dark' | 'system';
|
|
||||||
} = {
|
|
||||||
distanceMarkers: false,
|
|
||||||
directionMarkers: false,
|
|
||||||
distanceUnits: 'metric',
|
|
||||||
velocityUnits: 'speed',
|
|
||||||
temperatureUnits: 'celsius',
|
|
||||||
theme: 'system',
|
|
||||||
};
|
|
||||||
|
|
||||||
function applyOptions() {
|
function applyOptions() {
|
||||||
// fileObservers.update(($fileObservers) => {
|
let downloads: Promise<GPXFile | null>[] = getFilesFromEmbeddingOptions(options).map(
|
||||||
// $fileObservers.clear();
|
(url) => {
|
||||||
// return $fileObservers;
|
return fetch(url)
|
||||||
// });
|
.then((response) => response.blob())
|
||||||
// let downloads: Promise<GPXFile | null>[] = [];
|
.then((blob) => new File([blob], url.split('/').pop() ?? url))
|
||||||
// getFilesFromEmbeddingOptions(options).forEach((url) => {
|
.then(loadFile);
|
||||||
// downloads.push(
|
|
||||||
// fetch(url)
|
|
||||||
// .then((response) => response.blob())
|
|
||||||
// .then((blob) => new File([blob], url.split('/').pop() ?? url))
|
|
||||||
// .then(loadFile)
|
|
||||||
// );
|
|
||||||
// });
|
|
||||||
// Promise.all(downloads).then((files) => {
|
|
||||||
// let ids: string[] = [];
|
|
||||||
// let bounds = {
|
|
||||||
// southWest: {
|
|
||||||
// lat: 90,
|
|
||||||
// lon: 180,
|
|
||||||
// },
|
|
||||||
// northEast: {
|
|
||||||
// lat: -90,
|
|
||||||
// lon: -180,
|
|
||||||
// },
|
|
||||||
// };
|
|
||||||
// fileObservers.update(($fileObservers) => {
|
|
||||||
// files.forEach((file, index) => {
|
|
||||||
// if (file === null) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// let id = `gpx-${index}-embed`;
|
|
||||||
// file._data.id = id;
|
|
||||||
// let statistics = new GPXStatisticsTree(file);
|
|
||||||
// $fileObservers.set(
|
|
||||||
// id,
|
|
||||||
// readable({
|
|
||||||
// file,
|
|
||||||
// statistics,
|
|
||||||
// })
|
|
||||||
// );
|
|
||||||
// ids.push(id);
|
|
||||||
// let fileBounds = statistics.getStatisticsFor(new ListFileItem(id)).global
|
|
||||||
// .bounds;
|
|
||||||
// bounds.southWest.lat = Math.min(bounds.southWest.lat, fileBounds.southWest.lat);
|
|
||||||
// bounds.southWest.lon = Math.min(bounds.southWest.lon, fileBounds.southWest.lon);
|
|
||||||
// bounds.northEast.lat = Math.max(bounds.northEast.lat, fileBounds.northEast.lat);
|
|
||||||
// bounds.northEast.lon = Math.max(bounds.northEast.lon, fileBounds.northEast.lon);
|
|
||||||
// });
|
|
||||||
// return $fileObservers;
|
|
||||||
// });
|
|
||||||
// $fileOrder = [...$fileOrder.filter((id) => !id.includes('embed')), ...ids];
|
|
||||||
// selection.update(($selection) => {
|
|
||||||
// $selection.clear();
|
|
||||||
// ids.forEach((id) => {
|
|
||||||
// $selection.toggle(new ListFileItem(id));
|
|
||||||
// });
|
|
||||||
// return $selection;
|
|
||||||
// });
|
|
||||||
// if (hash.length === 0) {
|
|
||||||
// map.subscribe(($map) => {
|
|
||||||
// if ($map) {
|
|
||||||
// $map.fitBounds(
|
|
||||||
// [
|
|
||||||
// bounds.southWest.lon,
|
|
||||||
// bounds.southWest.lat,
|
|
||||||
// bounds.northEast.lon,
|
|
||||||
// bounds.northEast.lat,
|
|
||||||
// ],
|
|
||||||
// {
|
|
||||||
// padding: 80,
|
|
||||||
// linear: true,
|
|
||||||
// easing: () => 1,
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// if (
|
|
||||||
// options.basemap !== $currentBasemap &&
|
|
||||||
// allowedEmbeddingBasemaps.includes(options.basemap)
|
|
||||||
// ) {
|
|
||||||
// $currentBasemap = options.basemap;
|
|
||||||
// }
|
|
||||||
// if (options.distanceMarkers !== $distanceMarkers) {
|
|
||||||
// $distanceMarkers = options.distanceMarkers;
|
|
||||||
// }
|
|
||||||
// if (options.directionMarkers !== $directionMarkers) {
|
|
||||||
// $directionMarkers = options.directionMarkers;
|
|
||||||
// }
|
|
||||||
// if (options.distanceUnits !== $distanceUnits) {
|
|
||||||
// $distanceUnits = options.distanceUnits;
|
|
||||||
// }
|
|
||||||
// if (options.velocityUnits !== $velocityUnits) {
|
|
||||||
// $velocityUnits = options.velocityUnits;
|
|
||||||
// }
|
|
||||||
// if (options.temperatureUnits !== $temperatureUnits) {
|
|
||||||
// $temperatureUnits = options.temperatureUnits;
|
|
||||||
// }
|
|
||||||
// if (options.theme !== $mode) {
|
|
||||||
// setMode(options.theme);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
);
|
||||||
onMount(() => {
|
Promise.all(downloads).then((answers) => {
|
||||||
prevSettings.distanceMarkers = distanceMarkers.value;
|
const files = answers.filter((file) => file !== null) as GPXFile[];
|
||||||
prevSettings.directionMarkers = directionMarkers.value;
|
let ids: string[] = [];
|
||||||
prevSettings.distanceUnits = distanceUnits.value;
|
files.forEach((file, index) => {
|
||||||
prevSettings.velocityUnits = velocityUnits.value;
|
let id = `gpx-${index}-embed`;
|
||||||
prevSettings.temperatureUnits = temperatureUnits.value;
|
file._data.id = id;
|
||||||
prevSettings.theme = mode.current ?? 'system';
|
ids.push(id);
|
||||||
});
|
});
|
||||||
|
fileStateCollection.setEmbeddedFiles(files);
|
||||||
// $: if (browser && options) {
|
$fileOrder = ids;
|
||||||
// applyOptions();
|
selection.selectAll();
|
||||||
// }
|
});
|
||||||
|
if (allowedEmbeddingBasemaps.includes(options.basemap)) {
|
||||||
// $: if ($fileOrder) {
|
$currentBasemap = options.basemap;
|
||||||
// updateGPXData();
|
}
|
||||||
// }
|
if (!isSelected($selectedBasemapTree, options.basemap)) {
|
||||||
|
$selectedBasemapTree = toggle($selectedBasemapTree, options.basemap);
|
||||||
onDestroy(() => {
|
}
|
||||||
if (distanceMarkers.value !== prevSettings.distanceMarkers) {
|
$distanceMarkers = options.distanceMarkers;
|
||||||
distanceMarkers.value = prevSettings.distanceMarkers;
|
$directionMarkers = options.directionMarkers;
|
||||||
|
$distanceUnits = options.distanceUnits;
|
||||||
|
$velocityUnits = options.velocityUnits;
|
||||||
|
$temperatureUnits = options.temperatureUnits;
|
||||||
|
if (options.theme != 'system') {
|
||||||
|
setMode(options.theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (directionMarkers.value !== prevSettings.directionMarkers) {
|
additionalDatasets.set(
|
||||||
directionMarkers.value = prevSettings.directionMarkers;
|
[
|
||||||
|
options.elevation.speed ? 'speed' : null,
|
||||||
|
options.elevation.hr ? 'hr' : null,
|
||||||
|
options.elevation.cad ? 'cad' : null,
|
||||||
|
options.elevation.temp ? 'temp' : null,
|
||||||
|
options.elevation.power ? 'power' : null,
|
||||||
|
].filter((dataset) => dataset !== null)
|
||||||
|
);
|
||||||
|
elevationFill.set(options.elevation.fill == 'none' ? undefined : options.elevation.fill);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (distanceUnits.value !== prevSettings.distanceUnits) {
|
$effect(() => {
|
||||||
distanceUnits.value = prevSettings.distanceUnits;
|
options;
|
||||||
}
|
untrack(applyOptions);
|
||||||
|
|
||||||
if (velocityUnits.value !== prevSettings.velocityUnits) {
|
|
||||||
velocityUnits.value = prevSettings.velocityUnits;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (temperatureUnits.value !== prevSettings.temperatureUnits) {
|
|
||||||
temperatureUnits.value = prevSettings.temperatureUnits;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode.current !== prevSettings.theme) {
|
|
||||||
setMode(prevSettings.theme);
|
|
||||||
}
|
|
||||||
|
|
||||||
// $selection.clear();
|
|
||||||
// $fileObservers.clear();
|
|
||||||
fileOrder.value = fileOrder.value.filter((id) => !id.includes('embed'));
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="absolute flex flex-col h-full w-full border rounded-xl overflow-clip">
|
<div class="absolute flex flex-col h-full w-full border rounded-xl overflow-clip">
|
||||||
<div class="grow relative">
|
<div class="grow relative">
|
||||||
<Map
|
<Map
|
||||||
class="h-full {fileStateCollection.files.size > 1 ? 'horizontal' : ''}"
|
class="h-full {$fileStateCollection.size > 1 ? 'horizontal' : ''}"
|
||||||
accessToken={options.token}
|
maptilerKey={options.key}
|
||||||
geocoder={false}
|
geocoder={false}
|
||||||
geolocate={false}
|
geolocate={true}
|
||||||
hash={useHash}
|
hash={useHash}
|
||||||
/>
|
/>
|
||||||
<OpenIn files={options.files} ids={options.ids} />
|
<OpenIn files={options.files} ids={options.ids} />
|
||||||
<!-- <LayerControl /> -->
|
<LayerControl />
|
||||||
<!-- <GPXLayers /> -->
|
<GPXLayers />
|
||||||
{#if fileStateCollection.files.size > 1}
|
{#if $fileStateCollection.size > 1}
|
||||||
<div class="h-10 -translate-y-10 w-full pointer-events-none absolute z-30">
|
<div class="h-10 -translate-y-10 w-full pointer-events-none absolute z-30">
|
||||||
<!-- <FileList orientation="horizontal" /> -->
|
<FileList orientation="horizontal" />
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
@@ -237,26 +120,21 @@
|
|||||||
class="{options.elevation.show ? '' : 'h-10'} flex flex-row gap-2 px-2 sm:px-4"
|
class="{options.elevation.show ? '' : 'h-10'} flex flex-row gap-2 px-2 sm:px-4"
|
||||||
style={options.elevation.show ? `height: ${options.elevation.height}px` : ''}
|
style={options.elevation.show ? `height: ${options.elevation.height}px` : ''}
|
||||||
>
|
>
|
||||||
<!-- <GPXStatistics
|
<GPXStatistics
|
||||||
{gpxStatistics}
|
{gpxStatistics}
|
||||||
{slicedGPXStatistics}
|
{slicedGPXStatistics}
|
||||||
panelSize={options.elevation.height}
|
panelSize={options.elevation.height}
|
||||||
orientation={options.elevation.show ? 'vertical' : 'horizontal'}
|
orientation={options.elevation.show ? 'vertical' : 'horizontal'}
|
||||||
/> -->
|
/>
|
||||||
{#if options.elevation.show}
|
{#if options.elevation.show}
|
||||||
<!-- <ElevationProfile
|
<ElevationProfile
|
||||||
{gpxStatistics}
|
{gpxStatistics}
|
||||||
{slicedGPXStatistics}
|
{slicedGPXStatistics}
|
||||||
additionalDatasets={[
|
{hoveredPoint}
|
||||||
options.elevation.speed ? 'speed' : null,
|
{additionalDatasets}
|
||||||
options.elevation.hr ? 'hr' : null,
|
{elevationFill}
|
||||||
options.elevation.cad ? 'cad' : null,
|
|
||||||
options.elevation.temp ? 'temp' : null,
|
|
||||||
options.elevation.power ? 'power' : null,
|
|
||||||
].filter((dataset) => dataset !== null)}
|
|
||||||
elevationFill={options.elevation.fill}
|
|
||||||
showControls={options.elevation.controls}
|
showControls={options.elevation.controls}
|
||||||
/> -->
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -18,63 +18,61 @@
|
|||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
import {
|
import {
|
||||||
allowedEmbeddingBasemaps,
|
allowedEmbeddingBasemaps,
|
||||||
|
defaultEmbeddingOptions,
|
||||||
getCleanedEmbeddingOptions,
|
getCleanedEmbeddingOptions,
|
||||||
getDefaultEmbeddingOptions,
|
getMergedEmbeddingOptions,
|
||||||
} from './Embedding';
|
} from './embedding';
|
||||||
import { PUBLIC_MAPBOX_TOKEN } from '$env/static/public';
|
import { PUBLIC_MAPTILER_KEY } from '$env/static/public';
|
||||||
import Embedding from './Embedding.svelte';
|
import Embedding from './Embedding.svelte';
|
||||||
import { map } from '$lib/stores';
|
import { onDestroy } from 'svelte';
|
||||||
import { tick } from 'svelte';
|
|
||||||
import { base } from '$app/paths';
|
import { base } from '$app/paths';
|
||||||
|
import { map } from '$lib/components/map/map';
|
||||||
|
import { mode } from 'mode-watcher';
|
||||||
|
|
||||||
let options = getDefaultEmbeddingOptions();
|
let options = $state(
|
||||||
options.token = 'YOUR_MAPBOX_TOKEN';
|
getMergedEmbeddingOptions(
|
||||||
options.files = [
|
{
|
||||||
'https://raw.githubusercontent.com/gpxstudio/gpx.studio/main/gpx/test-data/simple.gpx',
|
key: 'YOUR_MAPTILER_KEY',
|
||||||
];
|
theme: mode.current,
|
||||||
|
},
|
||||||
|
defaultEmbeddingOptions
|
||||||
|
)
|
||||||
|
);
|
||||||
|
let files = $state(
|
||||||
|
'https://raw.githubusercontent.com/gpxstudio/gpx.studio/main/gpx/test-data/simple.gpx'
|
||||||
|
);
|
||||||
|
let driveIds = $state('');
|
||||||
|
|
||||||
let files = options.files[0];
|
let iframeOptions = $derived(
|
||||||
$: {
|
getMergedEmbeddingOptions(
|
||||||
let urls = files.split(',');
|
{
|
||||||
urls = urls.filter((url) => url.length > 0);
|
key:
|
||||||
if (JSON.stringify(urls) !== JSON.stringify(options.files)) {
|
options.key.length === 0 || options.key === 'YOUR_MAPTILER_KEY'
|
||||||
options.files = urls;
|
? PUBLIC_MAPTILER_KEY
|
||||||
}
|
: options.key,
|
||||||
}
|
files: files.split(',').filter((url) => url.length > 0),
|
||||||
let driveIds = '';
|
ids: driveIds.split(',').filter((id) => id.length > 0),
|
||||||
$: {
|
elevation: {
|
||||||
let ids = driveIds.split(',');
|
fill: options.elevation.fill === 'none' ? undefined : options.elevation.fill,
|
||||||
ids = ids.filter((id) => id.length > 0);
|
},
|
||||||
if (JSON.stringify(ids) !== JSON.stringify(options.ids)) {
|
},
|
||||||
options.ids = ids;
|
options
|
||||||
}
|
)
|
||||||
}
|
);
|
||||||
|
|
||||||
let manualCamera = false;
|
let manualCamera = $state(false);
|
||||||
|
let zoom = $state('0');
|
||||||
let zoom = '0';
|
let lat = $state('0');
|
||||||
let lat = '0';
|
let lon = $state('0');
|
||||||
let lon = '0';
|
let bearing = $state('0');
|
||||||
let bearing = '0';
|
let pitch = $state('0');
|
||||||
let pitch = '0';
|
let hash = $derived(manualCamera ? `#${zoom}/${lat}/${lon}/${bearing}/${pitch}` : '');
|
||||||
|
|
||||||
$: hash = manualCamera ? `#${zoom}/${lat}/${lon}/${bearing}/${pitch}` : '';
|
$effect(() => {
|
||||||
|
if (options.elevation.show || options.elevation.height) {
|
||||||
$: iframeOptions =
|
map.resize();
|
||||||
options.token.length === 0 || options.token === 'YOUR_MAPBOX_TOKEN'
|
|
||||||
? Object.assign({}, options, { token: PUBLIC_MAPBOX_TOKEN })
|
|
||||||
: options;
|
|
||||||
|
|
||||||
async function resizeMap() {
|
|
||||||
if ($map) {
|
|
||||||
await tick();
|
|
||||||
$map.resize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$: if (options.elevation.height || options.elevation.show) {
|
|
||||||
resizeMap();
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
function updateCamera() {
|
function updateCamera() {
|
||||||
if ($map) {
|
if ($map) {
|
||||||
@@ -87,9 +85,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$: if ($map) {
|
map.onLoad((map_) => {
|
||||||
$map.on('moveend', updateCamera);
|
map_.on('moveend', updateCamera);
|
||||||
|
});
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
if ($map) {
|
||||||
|
$map.off('moveend', updateCamera);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Card.Root id="embedding-playground">
|
<Card.Root id="embedding-playground">
|
||||||
@@ -98,26 +102,16 @@
|
|||||||
</Card.Header>
|
</Card.Header>
|
||||||
<Card.Content>
|
<Card.Content>
|
||||||
<fieldset class="flex flex-col gap-3">
|
<fieldset class="flex flex-col gap-3">
|
||||||
<Label for="token">{i18n._('embedding.mapbox_token')}</Label>
|
<Label for="key">{i18n._('embedding.maptiler_key')}</Label>
|
||||||
<Input id="token" type="text" class="h-8" bind:value={options.token} />
|
<Input id="key" type="text" class="h-8" bind:value={options.key} />
|
||||||
<Label for="file_urls">{i18n._('embedding.file_urls')}</Label>
|
<Label for="file_urls">{i18n._('embedding.file_urls')}</Label>
|
||||||
<Input id="file_urls" type="text" class="h-8" bind:value={files} />
|
<Input id="file_urls" type="text" class="h-8" bind:value={files} />
|
||||||
<Label for="drive_ids">{i18n._('embedding.drive_ids')}</Label>
|
<Label for="drive_ids">{i18n._('embedding.drive_ids')}</Label>
|
||||||
<Input id="drive_ids" type="text" class="h-8" bind:value={driveIds} />
|
<Input id="drive_ids" type="text" class="h-8" bind:value={driveIds} />
|
||||||
<Label for="basemap">{i18n._('embedding.basemap')}</Label>
|
<Label for="basemap">{i18n._('embedding.basemap')}</Label>
|
||||||
<Select.Root
|
<Select.Root type="single" bind:value={options.basemap}>
|
||||||
selected={{
|
|
||||||
value: options.basemap,
|
|
||||||
label: i18n._(`layers.label.${options.basemap}`),
|
|
||||||
}}
|
|
||||||
onSelectedChange={(selected) => {
|
|
||||||
if (selected?.value) {
|
|
||||||
options.basemap = selected?.value;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Select.Trigger id="basemap" class="w-full h-8">
|
<Select.Trigger id="basemap" class="w-full h-8">
|
||||||
<Select.Value />
|
{i18n._(`layers.label.${options.basemap}`)}
|
||||||
</Select.Trigger>
|
</Select.Trigger>
|
||||||
<Select.Content class="max-h-60 overflow-y-scroll">
|
<Select.Content class="max-h-60 overflow-y-scroll">
|
||||||
{#each allowedEmbeddingBasemaps as basemap}
|
{#each allowedEmbeddingBasemaps as basemap}
|
||||||
@@ -145,23 +139,11 @@
|
|||||||
<span class="shrink-0">
|
<span class="shrink-0">
|
||||||
{i18n._('embedding.fill_by')}
|
{i18n._('embedding.fill_by')}
|
||||||
</span>
|
</span>
|
||||||
<Select.Root
|
<Select.Root type="single" bind:value={options.elevation.fill}>
|
||||||
selected={{ value: 'none', label: i18n._('embedding.none') }}
|
|
||||||
onSelectedChange={(selected) => {
|
|
||||||
let value = selected?.value;
|
|
||||||
if (value === 'none') {
|
|
||||||
options.elevation.fill = undefined;
|
|
||||||
} else if (
|
|
||||||
value === 'slope' ||
|
|
||||||
value === 'surface' ||
|
|
||||||
value === 'highway'
|
|
||||||
) {
|
|
||||||
options.elevation.fill = value;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Select.Trigger class="grow h-8">
|
<Select.Trigger class="grow h-8">
|
||||||
<Select.Value />
|
{options.elevation.fill !== 'none'
|
||||||
|
? i18n._(`quantities.${options.elevation.fill}`)
|
||||||
|
: i18n._('embedding.none')}
|
||||||
</Select.Trigger>
|
</Select.Trigger>
|
||||||
<Select.Content>
|
<Select.Content>
|
||||||
<Select.Item value="slope">{i18n._('quantities.slope')}</Select.Item
|
<Select.Item value="slope">{i18n._('quantities.slope')}</Select.Item
|
||||||
@@ -331,7 +313,7 @@
|
|||||||
{i18n._('embedding.preview')}
|
{i18n._('embedding.preview')}
|
||||||
</Label>
|
</Label>
|
||||||
<div class="relative h-[600px]">
|
<div class="relative h-[600px]">
|
||||||
<Embedding bind:options={iframeOptions} bind:hash useHash={false} />
|
<Embedding options={iframeOptions} bind:hash useHash={false} />
|
||||||
</div>
|
</div>
|
||||||
<Label>
|
<Label>
|
||||||
{i18n._('embedding.code')}
|
{i18n._('embedding.code')}
|
||||||
@@ -339,7 +321,7 @@
|
|||||||
<pre
|
<pre
|
||||||
class="bg-primary text-primary-foreground p-3 rounded-md whitespace-normal break-all">
|
class="bg-primary text-primary-foreground p-3 rounded-md whitespace-normal break-all">
|
||||||
<code class="language-html">
|
<code class="language-html">
|
||||||
{`<iframe src="https://gpx.studio${base}/embed?options=${encodeURIComponent(JSON.stringify(getCleanedEmbeddingOptions(options)))}${hash}" width="100%" height="600px" frameborder="0" style="outline: none;"/>`}
|
{`<iframe src="https://gpx.studio${base}/embed?options=${encodeURIComponent(JSON.stringify(getCleanedEmbeddingOptions(iframeOptions)))}${hash}" width="100%" height="600px" frameborder="0" style="outline: none;"/>`}
|
||||||
</code>
|
</code>
|
||||||
</pre>
|
</pre>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { PUBLIC_MAPBOX_TOKEN } from '$env/static/public';
|
import { PUBLIC_MAPTILER_KEY } from '$env/static/public';
|
||||||
import { basemaps } from '$lib/assets/layers';
|
import { basemaps } from '$lib/assets/layers';
|
||||||
|
|
||||||
export type EmbeddingOptions = {
|
export type EmbeddingOptions = {
|
||||||
token: string;
|
key: string;
|
||||||
files: string[];
|
files: string[];
|
||||||
ids: string[];
|
ids: string[];
|
||||||
basemap: string;
|
basemap: string;
|
||||||
@@ -10,7 +10,7 @@ export type EmbeddingOptions = {
|
|||||||
show: boolean;
|
show: boolean;
|
||||||
height: number;
|
height: number;
|
||||||
controls: boolean;
|
controls: boolean;
|
||||||
fill: 'slope' | 'surface' | 'highway' | undefined;
|
fill: 'slope' | 'surface' | 'highway' | 'none';
|
||||||
speed: boolean;
|
speed: boolean;
|
||||||
hr: boolean;
|
hr: boolean;
|
||||||
cad: boolean;
|
cad: boolean;
|
||||||
@@ -26,15 +26,15 @@ export type EmbeddingOptions = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const defaultEmbeddingOptions = {
|
export const defaultEmbeddingOptions = {
|
||||||
token: '',
|
key: '',
|
||||||
files: [],
|
files: [],
|
||||||
ids: [],
|
ids: [],
|
||||||
basemap: 'mapboxOutdoors',
|
basemap: 'maptilerTopo',
|
||||||
elevation: {
|
elevation: {
|
||||||
show: true,
|
show: true,
|
||||||
height: 170,
|
height: 170,
|
||||||
controls: true,
|
controls: true,
|
||||||
fill: undefined,
|
fill: 'none',
|
||||||
speed: false,
|
speed: false,
|
||||||
hr: false,
|
hr: false,
|
||||||
cad: false,
|
cad: false,
|
||||||
@@ -49,10 +49,6 @@ export const defaultEmbeddingOptions = {
|
|||||||
theme: 'system',
|
theme: 'system',
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getDefaultEmbeddingOptions(): EmbeddingOptions {
|
|
||||||
return JSON.parse(JSON.stringify(defaultEmbeddingOptions));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getMergedEmbeddingOptions(
|
export function getMergedEmbeddingOptions(
|
||||||
options: any,
|
options: any,
|
||||||
defaultOptions: any = defaultEmbeddingOptions
|
defaultOptions: any = defaultEmbeddingOptions
|
||||||
@@ -111,7 +107,7 @@ export function getURLForGoogleDriveFile(fileId: string): string {
|
|||||||
|
|
||||||
export function convertOldEmbeddingOptions(options: URLSearchParams): any {
|
export function convertOldEmbeddingOptions(options: URLSearchParams): any {
|
||||||
let newOptions: any = {
|
let newOptions: any = {
|
||||||
token: PUBLIC_MAPBOX_TOKEN,
|
key: PUBLIC_MAPTILER_KEY,
|
||||||
files: [],
|
files: [],
|
||||||
ids: [],
|
ids: [],
|
||||||
};
|
};
|
||||||
@@ -127,7 +123,7 @@ export function convertOldEmbeddingOptions(options: URLSearchParams): any {
|
|||||||
if (options.has('source')) {
|
if (options.has('source')) {
|
||||||
let basemap = options.get('source')!;
|
let basemap = options.get('source')!;
|
||||||
if (basemap === 'satellite') {
|
if (basemap === 'satellite') {
|
||||||
newOptions.basemap = 'mapboxSatellite';
|
newOptions.basemap = 'maptilerSatellite';
|
||||||
} else if (basemap === 'otm') {
|
} else if (basemap === 'otm') {
|
||||||
newOptions.basemap = 'openTopoMap';
|
newOptions.basemap = 'openTopoMap';
|
||||||
} else if (basemap === 'ohm') {
|
} else if (basemap === 'ohm') {
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
SquareActivity,
|
SquareActivity,
|
||||||
} from '@lucide/svelte';
|
} from '@lucide/svelte';
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
import { GPXStatistics } from 'gpx';
|
import { GPXGlobalStatistics } from 'gpx';
|
||||||
import { ListRootItem } from '$lib/components/file-list/file-list';
|
import { ListRootItem } from '$lib/components/file-list/file-list';
|
||||||
import { fileStateCollection } from '$lib/logic/file-state';
|
import { fileStateCollection } from '$lib/logic/file-state';
|
||||||
import { selection } from '$lib/logic/selection';
|
import { selection } from '$lib/logic/selection';
|
||||||
@@ -48,24 +48,24 @@
|
|||||||
extensions: false,
|
extensions: false,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
let statistics = $gpxStatistics;
|
let statistics = $gpxStatistics.global;
|
||||||
if (exportState.current === ExportState.ALL) {
|
if (exportState.current === ExportState.ALL) {
|
||||||
statistics = Array.from(get(fileStateCollection).values())
|
statistics = Array.from(get(fileStateCollection).values())
|
||||||
.map((file) => file.statistics)
|
.map((file) => file.statistics)
|
||||||
.reduce((acc, cur) => {
|
.reduce((acc, cur) => {
|
||||||
if (cur !== undefined) {
|
if (cur !== undefined) {
|
||||||
acc.mergeWith(cur.getStatisticsFor(new ListRootItem()));
|
acc.mergeWith(cur.getStatisticsFor(new ListRootItem()).global);
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
}, new GPXStatistics());
|
}, new GPXGlobalStatistics());
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
time: statistics.global.time.total === 0,
|
time: statistics.time.total === 0,
|
||||||
hr: statistics.global.hr.count === 0,
|
hr: statistics.hr.count === 0,
|
||||||
cad: statistics.global.cad.count === 0,
|
cad: statistics.cad.count === 0,
|
||||||
atemp: statistics.global.atemp.count === 0,
|
atemp: statistics.atemp.count === 0,
|
||||||
power: statistics.global.power.count === 0,
|
power: statistics.power.count === 0,
|
||||||
extensions: Object.keys(statistics.global.extensions).length === 0,
|
extensions: Object.keys(statistics.extensions).length === 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -92,17 +92,17 @@
|
|||||||
class="fixed left-[50%] top-[50%] z-50 w-fit max-w-full translate-x-[-50%] translate-y-[-50%] flex flex-col items-center gap-3 border bg-background p-3 shadow-lg rounded-md"
|
class="fixed left-[50%] top-[50%] z-50 w-fit max-w-full translate-x-[-50%] translate-y-[-50%] flex flex-col items-center gap-3 border bg-background p-3 shadow-lg rounded-md"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="w-full flex flex-row items-center justify-center gap-4 border rounded-md p-2 bg-secondary"
|
class="w-full flex flex-col sm:flex-row items-center justify-center gap-1 sm:gap-2 border rounded-md p-2 bg-secondary"
|
||||||
>
|
>
|
||||||
<span>⚠️</span>
|
<span class="w-12 shrink-0 text-center text-xl">⚠️</span>
|
||||||
<span class="max-w-[80%] text-sm">
|
<span class="text-sm">
|
||||||
{i18n._('menu.support_message')}
|
{i18n._('menu.support_message')}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="w-full flex flex-row flex-wrap gap-2">
|
<div class="w-full flex flex-row flex-wrap gap-2">
|
||||||
<Button class="bg-support grow" href="https://ko-fi.com/gpxstudio" target="_blank">
|
<Button class="bg-support grow" href="https://ko-fi.com/gpxstudio" target="_blank">
|
||||||
{i18n._('menu.support_button')}
|
{i18n._('menu.support_button')}
|
||||||
<span class="ml-2">🙏</span>
|
<span>🙏</span>
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
@@ -117,7 +117,7 @@
|
|||||||
exportState.current = ExportState.NONE;
|
exportState.current = ExportState.NONE;
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Download size="16" class="mr-1" />
|
<Download size="16" />
|
||||||
{#if $fileStateCollection.size === 1 || (exportState.current === ExportState.SELECTION && $selection.size === 1)}
|
{#if $fileStateCollection.size === 1 || (exportState.current === ExportState.SELECTION && $selection.size === 1)}
|
||||||
{i18n._('menu.download_file')}
|
{i18n._('menu.download_file')}
|
||||||
{:else}
|
{:else}
|
||||||
|
|||||||
@@ -2,15 +2,15 @@
|
|||||||
import { ScrollArea } from '$lib/components/ui/scroll-area/index';
|
import { ScrollArea } from '$lib/components/ui/scroll-area/index';
|
||||||
import * as ContextMenu from '$lib/components/ui/context-menu';
|
import * as ContextMenu from '$lib/components/ui/context-menu';
|
||||||
import FileListNode from './FileListNode.svelte';
|
import FileListNode from './FileListNode.svelte';
|
||||||
import { setContext } from 'svelte';
|
import { onMount, setContext } from 'svelte';
|
||||||
import { ListFileItem, ListLevel, ListRootItem, allowedPastes } from './file-list';
|
import { ListFileItem, ListLevel, ListRootItem } from './file-list';
|
||||||
import { ClipboardPaste, FileStack, Plus } from '@lucide/svelte';
|
import { ClipboardPaste, FileStack, Plus } from '@lucide/svelte';
|
||||||
import Shortcut from '$lib/components/Shortcut.svelte';
|
import Shortcut from '$lib/components/Shortcut.svelte';
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
import { settings } from '$lib/logic/settings';
|
|
||||||
import { fileStateCollection } from '$lib/logic/file-state';
|
import { fileStateCollection } from '$lib/logic/file-state';
|
||||||
import { createFile, pasteSelection } from '$lib/logic/file-actions';
|
import { createFile, pasteSelection } from '$lib/logic/file-actions';
|
||||||
import { selection, copied } from '$lib/logic/selection';
|
import { selection, copied } from '$lib/logic/selection';
|
||||||
|
import { allowedPastes } from './sortable-file-list';
|
||||||
|
|
||||||
let {
|
let {
|
||||||
orientation,
|
orientation,
|
||||||
@@ -27,36 +27,25 @@
|
|||||||
setContext('orientation', orientation);
|
setContext('orientation', orientation);
|
||||||
setContext('recursive', recursive);
|
setContext('recursive', recursive);
|
||||||
|
|
||||||
const { treeFileView } = settings;
|
onMount(() => {
|
||||||
|
if (orientation === 'horizontal') {
|
||||||
// treeFileView.subscribe(($vertical) => {
|
selection.update(($selection) => {
|
||||||
// if ($vertical) {
|
$selection.forEach((item) => {
|
||||||
// selection.update(($selection) => {
|
if (!(item instanceof ListFileItem)) {
|
||||||
// $selection.forEach((item) => {
|
$selection.toggle(item);
|
||||||
// if ($selection.hasAnyChildren(item, false)) {
|
$selection.set(new ListFileItem(item.getFileId()), true);
|
||||||
// $selection.toggle(item);
|
}
|
||||||
// }
|
});
|
||||||
// });
|
return $selection;
|
||||||
// return $selection;
|
});
|
||||||
// });
|
}
|
||||||
// } else {
|
});
|
||||||
// selection.update(($selection) => {
|
|
||||||
// $selection.forEach((item) => {
|
|
||||||
// if (!(item instanceof ListFileItem)) {
|
|
||||||
// $selection.toggle(item);
|
|
||||||
// $selection.set(new ListFileItem(item.getFileId()), true);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// return $selection;
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ScrollArea
|
<ScrollArea
|
||||||
class="shrink-0 {orientation === 'vertical' ? 'p-0 pr-3' : 'h-10 px-1'}"
|
class="shrink-0 {orientation === 'vertical' ? 'p-0 pr-3' : 'h-10 px-1'}"
|
||||||
{orientation}
|
{orientation}
|
||||||
scrollbarXClasses={orientation === 'vertical' ? '' : 'mt-1 h-2'}
|
scrollbarXClasses={orientation === 'vertical' ? '' : 'hidden'}
|
||||||
scrollbarYClasses={orientation === 'vertical' ? '' : ''}
|
scrollbarYClasses={orientation === 'vertical' ? '' : ''}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
@@ -71,7 +60,7 @@
|
|||||||
<ContextMenu.Trigger class="grow" />
|
<ContextMenu.Trigger class="grow" />
|
||||||
<ContextMenu.Content>
|
<ContextMenu.Content>
|
||||||
<ContextMenu.Item onclick={createFile}>
|
<ContextMenu.Item onclick={createFile}>
|
||||||
<Plus size="16" class="mr-1" />
|
<Plus size="16" />
|
||||||
{i18n._('menu.new_file')}
|
{i18n._('menu.new_file')}
|
||||||
<Shortcut key="+" ctrl={true} />
|
<Shortcut key="+" ctrl={true} />
|
||||||
</ContextMenu.Item>
|
</ContextMenu.Item>
|
||||||
@@ -80,7 +69,7 @@
|
|||||||
onclick={() => selection.selectAll()}
|
onclick={() => selection.selectAll()}
|
||||||
disabled={$fileStateCollection.size === 0}
|
disabled={$fileStateCollection.size === 0}
|
||||||
>
|
>
|
||||||
<FileStack size="16" class="mr-1" />
|
<FileStack size="16" />
|
||||||
{i18n._('menu.select_all')}
|
{i18n._('menu.select_all')}
|
||||||
<Shortcut key="A" ctrl={true} />
|
<Shortcut key="A" ctrl={true} />
|
||||||
</ContextMenu.Item>
|
</ContextMenu.Item>
|
||||||
@@ -91,7 +80,7 @@
|
|||||||
!allowedPastes[$copied[0].level].includes(ListLevel.ROOT)}
|
!allowedPastes[$copied[0].level].includes(ListLevel.ROOT)}
|
||||||
onclick={pasteSelection}
|
onclick={pasteSelection}
|
||||||
>
|
>
|
||||||
<ClipboardPaste size="16" class="mr-1" />
|
<ClipboardPaste size="16" />
|
||||||
{i18n._('menu.paste')}
|
{i18n._('menu.paste')}
|
||||||
<Shortcut key="V" ctrl={true} />
|
<Shortcut key="V" ctrl={true} />
|
||||||
</ContextMenu.Item>
|
</ContextMenu.Item>
|
||||||
|
|||||||
@@ -58,17 +58,11 @@
|
|||||||
|
|
||||||
const { treeFileView } = settings;
|
const { treeFileView } = settings;
|
||||||
|
|
||||||
function openIfSelectedChild() {
|
$effect(() => {
|
||||||
if (collapsible && treeFileView.value && $selection.hasAnyChildren(item, false)) {
|
if (collapsible && $treeFileView && $selection.hasAnyChildren(item, false)) {
|
||||||
collapsible.openNode();
|
collapsible.openNode();
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
if ($selection) {
|
|
||||||
openIfSelectedChild();
|
|
||||||
}
|
|
||||||
|
|
||||||
// afterUpdate(openIfSelectedChild);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if node instanceof Map}
|
{#if node instanceof Map}
|
||||||
@@ -83,7 +77,7 @@
|
|||||||
<FileListNodeLabel {node} {item} {label} />
|
<FileListNodeLabel {node} {item} {label} />
|
||||||
{/snippet}
|
{/snippet}
|
||||||
{#snippet content()}
|
{#snippet content()}
|
||||||
<div class="ml-2">
|
<div class="ml-4">
|
||||||
{#key node}
|
{#key node}
|
||||||
<FileListNodeContent {node} {item} />
|
<FileListNodeContent {node} {item} />
|
||||||
{/key}
|
{/key}
|
||||||
|
|||||||
@@ -1,28 +1,13 @@
|
|||||||
<script lang="ts" context="module">
|
|
||||||
let dragging: Writable<ListLevel | null> = writable(null);
|
|
||||||
|
|
||||||
let updating = false;
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { GPXFile, Track, Waypoint, type AnyGPXTreeElement, type GPXTreeElement } from 'gpx';
|
import { GPXFile, Track, Waypoint, type AnyGPXTreeElement, type GPXTreeElement } from 'gpx';
|
||||||
import { getContext, onDestroy, onMount } from 'svelte';
|
import { getContext, onDestroy, onMount } from 'svelte';
|
||||||
import Sortable from 'sortablejs/Sortable';
|
import { type Readable } from 'svelte/store';
|
||||||
import { get, writable, type Readable, type Writable } from 'svelte/store';
|
|
||||||
import FileListNodeStore from './FileListNodeStore.svelte';
|
import FileListNodeStore from './FileListNodeStore.svelte';
|
||||||
import FileListNode from './FileListNode.svelte';
|
import FileListNode from './FileListNode.svelte';
|
||||||
import {
|
import FileListNodeContent from './FileListNodeContent.svelte';
|
||||||
ListFileItem,
|
import { ListFileItem, ListLevel, ListWaypointsItem, type ListItem } from './file-list';
|
||||||
ListLevel,
|
|
||||||
ListRootItem,
|
|
||||||
ListWaypointsItem,
|
|
||||||
allowedMoves,
|
|
||||||
type ListItem,
|
|
||||||
} from './file-list';
|
|
||||||
import { isMac } from '$lib/utils';
|
|
||||||
import type { GPXFileWithStatistics } from '$lib/logic/statistics-tree';
|
import type { GPXFileWithStatistics } from '$lib/logic/statistics-tree';
|
||||||
import { settings } from '$lib/logic/settings';
|
import { allowedMoves, dragging, SortableFileList } from './sortable-file-list';
|
||||||
import { getFileIds, moveItems } from '$lib/logic/file-actions';
|
|
||||||
|
|
||||||
let {
|
let {
|
||||||
node,
|
node,
|
||||||
@@ -32,13 +17,13 @@
|
|||||||
node:
|
node:
|
||||||
| Map<string, Readable<GPXFileWithStatistics | undefined>>
|
| Map<string, Readable<GPXFileWithStatistics | undefined>>
|
||||||
| GPXTreeElement<AnyGPXTreeElement>
|
| GPXTreeElement<AnyGPXTreeElement>
|
||||||
|
| Waypoint[]
|
||||||
| Waypoint;
|
| Waypoint;
|
||||||
item: ListItem;
|
item: ListItem;
|
||||||
waypointRoot?: boolean;
|
waypointRoot?: boolean;
|
||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
let container: HTMLElement;
|
let container: HTMLElement;
|
||||||
let elements: { [id: string]: HTMLElement } = {};
|
|
||||||
let sortableLevel: ListLevel =
|
let sortableLevel: ListLevel =
|
||||||
node instanceof Map
|
node instanceof Map
|
||||||
? ListLevel.FILE
|
? ListLevel.FILE
|
||||||
@@ -51,253 +36,32 @@
|
|||||||
: node instanceof Track
|
: node instanceof Track
|
||||||
? ListLevel.SEGMENT
|
? ListLevel.SEGMENT
|
||||||
: ListLevel.WAYPOINT;
|
: ListLevel.WAYPOINT;
|
||||||
let sortable: Sortable;
|
|
||||||
let orientation = getContext<'vertical' | 'horizontal'>('orientation');
|
let orientation = getContext<'vertical' | 'horizontal'>('orientation');
|
||||||
|
|
||||||
let destroyed = false;
|
let canDrop = $derived($dragging !== null && allowedMoves[$dragging].includes(sortableLevel));
|
||||||
let lastUpdateStart = 0;
|
|
||||||
function updateToSelection(e) {
|
|
||||||
if (destroyed) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
lastUpdateStart = Date.now();
|
let sortable: SortableFileList;
|
||||||
setTimeout(() => {
|
|
||||||
if (Date.now() - lastUpdateStart >= 40) {
|
|
||||||
if (updating) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
updating = true;
|
onMount(() => {
|
||||||
// Sortable updates selection
|
sortable = new SortableFileList(
|
||||||
let changed = getChangedIds();
|
container,
|
||||||
if (changed.length > 0) {
|
node,
|
||||||
selection.update(($selection) => {
|
item,
|
||||||
$selection.clear();
|
waypointRoot,
|
||||||
Object.entries(elements).forEach(([id, element]) => {
|
sortableLevel,
|
||||||
$selection.set(
|
orientation
|
||||||
item.extend(getRealId(id)),
|
|
||||||
element.classList.contains('sortable-selected')
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (
|
$effect(() => {
|
||||||
e.originalEvent &&
|
if (sortable && node) {
|
||||||
!(
|
sortable.updateElements();
|
||||||
e.originalEvent.ctrlKey ||
|
|
||||||
e.originalEvent.metaKey ||
|
|
||||||
e.originalEvent.shiftKey
|
|
||||||
) &&
|
|
||||||
($selection.size > 1 ||
|
|
||||||
!$selection.has(item.extend(getRealId(changed[0]))))
|
|
||||||
) {
|
|
||||||
// Fix bug that sometimes causes a single select to be treated as a multi-select
|
|
||||||
$selection.clear();
|
|
||||||
$selection.set(item.extend(getRealId(changed[0])), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $selection;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
updating = false;
|
|
||||||
}
|
|
||||||
}, 50);
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateFromSelection() {
|
|
||||||
if (destroyed || updating) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
updating = true;
|
|
||||||
// Selection updates sortable
|
|
||||||
let changed = getChangedIds();
|
|
||||||
for (let id of changed) {
|
|
||||||
let element = elements[id];
|
|
||||||
if (element) {
|
|
||||||
if ($selection.has(item.extend(id))) {
|
|
||||||
Sortable.utils.select(element);
|
|
||||||
element.scrollIntoView({
|
|
||||||
behavior: 'smooth',
|
|
||||||
block: 'nearest',
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
Sortable.utils.deselect(element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
updating = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$: if ($selection) {
|
|
||||||
updateFromSelection();
|
|
||||||
}
|
|
||||||
|
|
||||||
function syncFileOrder(order: string[]) {
|
|
||||||
if (!sortable || sortableLevel !== ListLevel.FILE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentOrder = sortable.toArray();
|
|
||||||
if (currentOrder.length !== order.length) {
|
|
||||||
sortable.sort(order);
|
|
||||||
} else {
|
|
||||||
for (let i = 0; i < currentOrder.length; i++) {
|
|
||||||
if (currentOrder[i] !== order[i]) {
|
|
||||||
sortable.sort(order);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const { fileOrder } = settings;
|
|
||||||
$effect(() => syncFileOrder(fileOrder.value));
|
|
||||||
|
|
||||||
function createSortable() {
|
|
||||||
sortable = Sortable.create(container, {
|
|
||||||
group: {
|
|
||||||
name: sortableLevel,
|
|
||||||
pull: allowedMoves[sortableLevel],
|
|
||||||
put: true,
|
|
||||||
},
|
|
||||||
direction: orientation,
|
|
||||||
forceAutoScrollFallback: true,
|
|
||||||
multiDrag: true,
|
|
||||||
multiDragKey: isMac() ? 'Meta' : 'Ctrl',
|
|
||||||
avoidImplicitDeselect: true,
|
|
||||||
onSelect: updateToSelection,
|
|
||||||
onDeselect: updateToSelection,
|
|
||||||
onStart: () => {
|
|
||||||
dragging.set(sortableLevel);
|
|
||||||
},
|
|
||||||
onEnd: () => {
|
|
||||||
dragging.set(null);
|
|
||||||
},
|
|
||||||
onSort: (e) => {
|
|
||||||
if (sortableLevel === ListLevel.FILE) {
|
|
||||||
let newFileOrder = sortable.toArray();
|
|
||||||
if (newFileOrder.length !== fileOrder.value.length) {
|
|
||||||
fileOrder.value = newFileOrder;
|
|
||||||
} else {
|
|
||||||
for (let i = 0; i < newFileOrder.length; i++) {
|
|
||||||
if (newFileOrder[i] !== fileOrder.value[i]) {
|
|
||||||
fileOrder.value = newFileOrder;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let fromItem = Sortable.get(e.from)._item;
|
|
||||||
let toItem = Sortable.get(e.to)._item;
|
|
||||||
|
|
||||||
if (item === toItem && !(fromItem instanceof ListRootItem)) {
|
|
||||||
// Event is triggered on source and destination list, only handle it once
|
|
||||||
let fromItems = [];
|
|
||||||
let toItems = [];
|
|
||||||
|
|
||||||
if (Sortable.get(e.from)._waypointRoot) {
|
|
||||||
fromItems = [fromItem.extend('waypoints')];
|
|
||||||
} else {
|
|
||||||
let oldIndices: number[] =
|
|
||||||
e.oldIndicies.length > 0
|
|
||||||
? e.oldIndicies.map((i) => i.index)
|
|
||||||
: [e.oldIndex];
|
|
||||||
oldIndices = oldIndices.filter((i) => i >= 0);
|
|
||||||
oldIndices.sort((a, b) => a - b);
|
|
||||||
|
|
||||||
fromItems = oldIndices.map((i) => fromItem.extend(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Sortable.get(e.from)._waypointRoot && Sortable.get(e.to)._waypointRoot) {
|
|
||||||
toItems = [toItem.extend('waypoints')];
|
|
||||||
} else {
|
|
||||||
if (Sortable.get(e.to)._waypointRoot) {
|
|
||||||
toItem = toItem.extend('waypoints');
|
|
||||||
}
|
|
||||||
|
|
||||||
let newIndices: number[] =
|
|
||||||
e.newIndicies.length > 0
|
|
||||||
? e.newIndicies.map((i) => i.index)
|
|
||||||
: [e.newIndex];
|
|
||||||
newIndices = newIndices.filter((i) => i >= 0);
|
|
||||||
newIndices.sort((a, b) => a - b);
|
|
||||||
|
|
||||||
if (toItem instanceof ListRootItem) {
|
|
||||||
let newFileIds = getFileIds(newIndices.length);
|
|
||||||
toItems = newIndices.map((i, index) => {
|
|
||||||
fileOrder.value.splice(i, 0, newFileIds[index]);
|
|
||||||
return item.extend(newFileIds[index]);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
toItems = newIndices.map((i) => toItem.extend(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
moveItems(fromItem, toItem, fromItems, toItems);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
Object.defineProperty(sortable, '_item', {
|
|
||||||
value: item,
|
|
||||||
writable: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
Object.defineProperty(sortable, '_waypointRoot', {
|
|
||||||
value: waypointRoot,
|
|
||||||
writable: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
createSortable();
|
|
||||||
destroyed = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
afterUpdate(() => {
|
|
||||||
elements = {};
|
|
||||||
container.childNodes.forEach((element) => {
|
|
||||||
if (element instanceof HTMLElement) {
|
|
||||||
let attr = element.getAttribute('data-id');
|
|
||||||
if (attr) {
|
|
||||||
if (node instanceof Map && !node.has(attr)) {
|
|
||||||
element.remove();
|
|
||||||
} else {
|
|
||||||
elements[attr] = element;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
syncFileOrder();
|
|
||||||
updateFromSelection();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
destroyed = true;
|
sortable.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
function getChangedIds() {
|
|
||||||
let changed: (string | number)[] = [];
|
|
||||||
Object.entries(elements).forEach(([id, element]) => {
|
|
||||||
let realId = getRealId(id);
|
|
||||||
let realItem = item.extend(realId);
|
|
||||||
let inSelection = get(selection).has(realItem);
|
|
||||||
let isSelected = element.classList.contains('sortable-selected');
|
|
||||||
if (inSelection !== isSelected) {
|
|
||||||
changed.push(realId);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return changed;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getRealId(id: string | number) {
|
|
||||||
return sortableLevel === ListLevel.FILE || sortableLevel === ListLevel.WAYPOINTS
|
|
||||||
? id
|
|
||||||
: parseInt(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
$: canDrop = $dragging !== null && allowedMoves[$dragging].includes(sortableLevel);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
@@ -343,7 +107,7 @@
|
|||||||
|
|
||||||
{#if node instanceof GPXFile && item instanceof ListFileItem}
|
{#if node instanceof GPXFile && item instanceof ListFileItem}
|
||||||
{#if !waypointRoot}
|
{#if !waypointRoot}
|
||||||
<svelte:self {node} {item} waypointRoot={true} />
|
<FileListNodeContent {node} {item} waypointRoot={true} />
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
@@ -357,20 +121,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.vertical :global(button) {
|
.vertical :global(button) {
|
||||||
@apply hover:bg-muted;
|
@apply hover:bg-[var(--selection)];
|
||||||
}
|
|
||||||
|
|
||||||
.vertical :global(.sortable-selected button) {
|
|
||||||
@apply hover:bg-accent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.vertical :global(.sortable-selected) {
|
.vertical :global(.sortable-selected) {
|
||||||
@apply bg-accent;
|
@apply bg-[var(--selection)];
|
||||||
}
|
}
|
||||||
|
|
||||||
.horizontal :global(button) {
|
.horizontal :global(button) {
|
||||||
@apply bg-accent;
|
@apply bg-[var(--selection)];
|
||||||
@apply hover:bg-muted;
|
@apply hover:bg-background;
|
||||||
}
|
}
|
||||||
|
|
||||||
.horizontal :global(.sortable-selected button) {
|
.horizontal :global(.sortable-selected button) {
|
||||||
|
|||||||
@@ -17,30 +17,30 @@
|
|||||||
Maximize,
|
Maximize,
|
||||||
Scissors,
|
Scissors,
|
||||||
FileStack,
|
FileStack,
|
||||||
FileX,
|
|
||||||
} from '@lucide/svelte';
|
} from '@lucide/svelte';
|
||||||
import {
|
import {
|
||||||
ListFileItem,
|
ListFileItem,
|
||||||
ListLevel,
|
ListLevel,
|
||||||
ListTrackItem,
|
ListTrackItem,
|
||||||
ListWaypointItem,
|
ListWaypointItem,
|
||||||
allowedPastes,
|
|
||||||
type ListItem,
|
type ListItem,
|
||||||
} from './file-list';
|
} from './file-list';
|
||||||
import { getContext } from 'svelte';
|
import { getContext } from 'svelte';
|
||||||
import { get } from 'svelte/store';
|
|
||||||
import { GPXTreeElement, Track, type AnyGPXTreeElement, Waypoint, GPXFile } from 'gpx';
|
import { GPXTreeElement, Track, type AnyGPXTreeElement, Waypoint, GPXFile } from 'gpx';
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
import MetadataDialog from '$lib/components/file-list/metadata/MetadataDialog.svelte';
|
import MetadataDialog from '$lib/components/file-list/metadata/MetadataDialog.svelte';
|
||||||
import { editMetadata } from '$lib/components/file-list/metadata/utils.svelte';
|
import { editMetadata } from '$lib/components/file-list/metadata/utils.svelte';
|
||||||
import StyleDialog from './style/StyleDialog.svelte';
|
import StyleDialog from '$lib/components/file-list/style/StyleDialog.svelte';
|
||||||
import { editStyle } from '$lib/components/file-list/style/utils.svelte';
|
import { editStyle } from '$lib/components/file-list/style/utils.svelte';
|
||||||
import { waypointPopup } from '$lib/components/map/gpx-layer/GPXLayerPopup';
|
|
||||||
import { getSymbolKey, symbols } from '$lib/assets/symbols';
|
import { getSymbolKey, symbols } from '$lib/assets/symbols';
|
||||||
import { selection, copied, cut } from '$lib/logic/selection';
|
import { selection, copied, cut } from '$lib/logic/selection';
|
||||||
import { map } from '$lib/components/map/map';
|
|
||||||
import { fileActions, pasteSelection } from '$lib/logic/file-actions';
|
import { fileActions, pasteSelection } from '$lib/logic/file-actions';
|
||||||
import { allHidden } from '$lib/logic/hidden';
|
import { allHidden } from '$lib/logic/hidden';
|
||||||
|
import { boundsManager } from '$lib/logic/bounds';
|
||||||
|
import { gpxColors, gpxLayers } from '$lib/components/map/gpx-layer/gpx-layers';
|
||||||
|
import { fileStateCollection } from '$lib/logic/file-state';
|
||||||
|
import { waypointPopup } from '$lib/components/map/gpx-layer/gpx-layer-popup';
|
||||||
|
import { allowedPastes } from './sortable-file-list';
|
||||||
|
|
||||||
let {
|
let {
|
||||||
node,
|
node,
|
||||||
@@ -57,43 +57,32 @@
|
|||||||
|
|
||||||
let singleSelection = $derived($selection.size === 1);
|
let singleSelection = $derived($selection.size === 1);
|
||||||
|
|
||||||
let nodeColors: string[] = []; /* $derived.by(() => {
|
let nodeColors: string[] = $derived.by(() => {
|
||||||
let colors: string[] = [];
|
let colors: string[] = [];
|
||||||
if (node && map.value) {
|
if (node) {
|
||||||
if (node instanceof GPXFile) {
|
if (node instanceof GPXFile) {
|
||||||
let defaultColor = undefined;
|
let defaultColor = $gpxColors.get(item.getFileId());
|
||||||
|
|
||||||
let layer = gpxLayers.get(item.getFileId());
|
|
||||||
if (layer) {
|
|
||||||
defaultColor = layer.layerColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
let style = node.getStyle(defaultColor);
|
let style = node.getStyle(defaultColor);
|
||||||
style.color.forEach((c) => {
|
colors = style.color;
|
||||||
if (!colors.includes(c)) {
|
|
||||||
colors.push(c);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (node instanceof Track) {
|
} else if (node instanceof Track) {
|
||||||
let style = node.getStyle();
|
let style = node.getStyle();
|
||||||
if (style) {
|
|
||||||
if (
|
if (
|
||||||
|
style &&
|
||||||
style['gpx_style:color'] &&
|
style['gpx_style:color'] &&
|
||||||
!nodeColors.includes(style['gpx_style:color'])
|
!colors.includes(style['gpx_style:color'])
|
||||||
) {
|
) {
|
||||||
nodeColors.push(style['gpx_style:color']);
|
colors.push(style['gpx_style:color']);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (colors.length === 0) {
|
if (colors.length === 0) {
|
||||||
let layer = gpxLayers.get(item.getFileId());
|
let defaultColor = $gpxColors.get(item.getFileId());
|
||||||
if (layer) {
|
if (defaultColor) {
|
||||||
colors.push(layer.layerColor);
|
colors.push(defaultColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return colors;
|
return colors;
|
||||||
});*/
|
});
|
||||||
|
|
||||||
let symbolKey = $derived(node instanceof Waypoint ? getSymbolKey(node.sym) : undefined);
|
let symbolKey = $derived(node instanceof Waypoint ? getSymbolKey(node.sym) : undefined);
|
||||||
|
|
||||||
@@ -116,8 +105,8 @@
|
|||||||
<ContextMenu.Root
|
<ContextMenu.Root
|
||||||
onOpenChange={(open) => {
|
onOpenChange={(open) => {
|
||||||
if (open) {
|
if (open) {
|
||||||
if (!get(selection).has(item)) {
|
if (!$selection.has(item)) {
|
||||||
selectItem(item);
|
selection.selectItem(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
@@ -125,7 +114,7 @@
|
|||||||
<ContextMenu.Trigger class="grow truncate">
|
<ContextMenu.Trigger class="grow truncate">
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
class="relative w-full p-0 px-1 border-none overflow-hidden focus-visible:ring-0 focus-visible:ring-offset-0 {orientation ===
|
class="relative w-full p-0 overflow-hidden focus-visible:ring-0 focus-visible:ring-offset-0 {orientation ===
|
||||||
'vertical'
|
'vertical'
|
||||||
? 'h-fit'
|
? 'h-fit'
|
||||||
: 'h-9 px-1.5 shadow-md'} pointer-events-auto"
|
: 'h-9 px-1.5 shadow-md'} pointer-events-auto"
|
||||||
@@ -171,11 +160,11 @@
|
|||||||
}}
|
}}
|
||||||
onmouseenter={() => {
|
onmouseenter={() => {
|
||||||
if (item instanceof ListWaypointItem) {
|
if (item instanceof ListWaypointItem) {
|
||||||
let layer = gpxLayers.get(item.getFileId());
|
let layer = gpxLayers.getLayer(item.getFileId());
|
||||||
let file = getFile(item.getFileId());
|
let file = fileStateCollection.getFile(item.getFileId());
|
||||||
if (layer && file) {
|
if (layer && file) {
|
||||||
let waypoint = file.wpt[item.getWaypointIndex()];
|
let waypoint = file.wpt[item.getWaypointIndex()];
|
||||||
if (waypoint) {
|
if (waypoint && !waypoint._data.hidden) {
|
||||||
waypointPopup?.setItem({
|
waypointPopup?.setItem({
|
||||||
item: waypoint,
|
item: waypoint,
|
||||||
fileId: item.getFileId(),
|
fileId: item.getFileId(),
|
||||||
@@ -186,7 +175,7 @@
|
|||||||
}}
|
}}
|
||||||
onmouseleave={() => {
|
onmouseleave={() => {
|
||||||
if (item instanceof ListWaypointItem) {
|
if (item instanceof ListWaypointItem) {
|
||||||
let layer = gpxLayers.get(item.getFileId());
|
let layer = gpxLayers.getLayer(item.getFileId());
|
||||||
if (layer) {
|
if (layer) {
|
||||||
waypointPopup?.setItem(null);
|
waypointPopup?.setItem(null);
|
||||||
}
|
}
|
||||||
@@ -194,13 +183,13 @@
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{#if item.level === ListLevel.SEGMENT}
|
{#if item.level === ListLevel.SEGMENT}
|
||||||
<Waypoints size="16" class="mr-1 shrink-0" />
|
<Waypoints size="16" class="mx-1 shrink-0" />
|
||||||
{:else if item.level === ListLevel.WAYPOINT}
|
{:else if item.level === ListLevel.WAYPOINT}
|
||||||
{#if symbolKey && symbols[symbolKey].icon}
|
{#if symbolKey && symbols[symbolKey].icon}
|
||||||
{@const SymbolIcon = symbols[symbolKey].icon}
|
{@const SymbolIcon = symbols[symbolKey].icon}
|
||||||
<SymbolIcon size="16" class="mr-1 shrink-0" />
|
<SymbolIcon size="16" class="mx-1 shrink-0" />
|
||||||
{:else}
|
{:else}
|
||||||
<MapPin size="16" class="mr-1 shrink-0" />
|
<MapPin size="16" class="mx-1 shrink-0" />
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
<span
|
<span
|
||||||
@@ -212,13 +201,10 @@
|
|||||||
</span>
|
</span>
|
||||||
{#if hidden}
|
{#if hidden}
|
||||||
<EyeOff
|
<EyeOff
|
||||||
size="12"
|
size="10"
|
||||||
class="shrink-0 mt-1 ml-1 {orientation === 'vertical'
|
class="shrink-0 size-3.5 ml-1 {orientation === 'vertical'
|
||||||
? 'mr-2'
|
|
||||||
: ''} {item.level === ListLevel.SEGMENT ||
|
|
||||||
item.level === ListLevel.WAYPOINT
|
|
||||||
? 'mr-3'
|
? 'mr-3'
|
||||||
: ''}"
|
: 'mt-0.5'}"
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</span>
|
</span>
|
||||||
@@ -230,12 +216,12 @@
|
|||||||
disabled={!singleSelection}
|
disabled={!singleSelection}
|
||||||
onclick={() => (editMetadata.current = true)}
|
onclick={() => (editMetadata.current = true)}
|
||||||
>
|
>
|
||||||
<Info size="16" class="mr-1" />
|
<Info size="16" />
|
||||||
{i18n._('menu.metadata.button')}
|
{i18n._('menu.metadata.button')}
|
||||||
<Shortcut key="I" ctrl={true} />
|
<Shortcut key="I" ctrl={true} />
|
||||||
</ContextMenu.Item>
|
</ContextMenu.Item>
|
||||||
<ContextMenu.Item onclick={() => (editStyle.current = true)}>
|
<ContextMenu.Item onclick={() => (editStyle.current = true)}>
|
||||||
<PaintBucket size="16" class="mr-1" />
|
<PaintBucket size="16" />
|
||||||
{i18n._('menu.style.button')}
|
{i18n._('menu.style.button')}
|
||||||
</ContextMenu.Item>
|
</ContextMenu.Item>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -249,10 +235,10 @@
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{#if $allHidden}
|
{#if $allHidden}
|
||||||
<Eye size="16" class="mr-1" />
|
<Eye size="16" />
|
||||||
{i18n._('menu.unhide')}
|
{i18n._('menu.unhide')}
|
||||||
{:else}
|
{:else}
|
||||||
<EyeOff size="16" class="mr-1" />
|
<EyeOff size="16" />
|
||||||
{i18n._('menu.hide')}
|
{i18n._('menu.hide')}
|
||||||
{/if}
|
{/if}
|
||||||
<Shortcut key="H" ctrl={true} />
|
<Shortcut key="H" ctrl={true} />
|
||||||
@@ -264,7 +250,7 @@
|
|||||||
disabled={!singleSelection}
|
disabled={!singleSelection}
|
||||||
onclick={() => fileActions.addNewTrack(item.getFileId())}
|
onclick={() => fileActions.addNewTrack(item.getFileId())}
|
||||||
>
|
>
|
||||||
<Plus size="16" class="mr-1" />
|
<Plus size="16" />
|
||||||
{i18n._('menu.new_track')}
|
{i18n._('menu.new_track')}
|
||||||
</ContextMenu.Item>
|
</ContextMenu.Item>
|
||||||
<ContextMenu.Separator />
|
<ContextMenu.Separator />
|
||||||
@@ -274,7 +260,7 @@
|
|||||||
onclick={() =>
|
onclick={() =>
|
||||||
fileActions.addNewSegment(item.getFileId(), item.getTrackIndex())}
|
fileActions.addNewSegment(item.getFileId(), item.getTrackIndex())}
|
||||||
>
|
>
|
||||||
<Plus size="16" class="mr-1" />
|
<Plus size="16" />
|
||||||
{i18n._('menu.new_segment')}
|
{i18n._('menu.new_segment')}
|
||||||
</ContextMenu.Item>
|
</ContextMenu.Item>
|
||||||
<ContextMenu.Separator />
|
<ContextMenu.Separator />
|
||||||
@@ -282,30 +268,30 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{#if item.level !== ListLevel.WAYPOINTS}
|
{#if item.level !== ListLevel.WAYPOINTS}
|
||||||
<ContextMenu.Item onclick={() => selection.selectAll()}>
|
<ContextMenu.Item onclick={() => selection.selectAll()}>
|
||||||
<FileStack size="16" class="mr-1" />
|
<FileStack size="16" />
|
||||||
{i18n._('menu.select_all')}
|
{i18n._('menu.select_all')}
|
||||||
<Shortcut key="A" ctrl={true} />
|
<Shortcut key="A" ctrl={true} />
|
||||||
</ContextMenu.Item>
|
</ContextMenu.Item>
|
||||||
{/if}
|
{/if}
|
||||||
<ContextMenu.Item onclick={centerMapOnSelection}>
|
<ContextMenu.Item onclick={() => boundsManager.centerMapOnSelection()}>
|
||||||
<Maximize size="16" class="mr-1" />
|
<Maximize size="16" />
|
||||||
{i18n._('menu.center')}
|
{i18n._('menu.center')}
|
||||||
<Shortcut key="⏎" ctrl={true} />
|
<Shortcut key="⏎" ctrl={true} />
|
||||||
</ContextMenu.Item>
|
</ContextMenu.Item>
|
||||||
<ContextMenu.Separator />
|
<ContextMenu.Separator />
|
||||||
<ContextMenu.Item onclick={fileActions.duplicateSelection}>
|
<ContextMenu.Item onclick={fileActions.duplicateSelection}>
|
||||||
<Copy size="16" class="mr-1" />
|
<Copy size="16" />
|
||||||
{i18n._('menu.duplicate')}
|
{i18n._('menu.duplicate')}
|
||||||
<Shortcut key="D" ctrl={true} /></ContextMenu.Item
|
<Shortcut key="D" ctrl={true} />
|
||||||
>
|
</ContextMenu.Item>
|
||||||
{#if orientation === 'vertical'}
|
{#if orientation === 'vertical'}
|
||||||
<ContextMenu.Item onclick={() => selection.copySelection()}>
|
<ContextMenu.Item onclick={() => selection.copySelection()}>
|
||||||
<ClipboardCopy size="16" class="mr-1" />
|
<ClipboardCopy size="16" />
|
||||||
{i18n._('menu.copy')}
|
{i18n._('menu.copy')}
|
||||||
<Shortcut key="C" ctrl={true} />
|
<Shortcut key="C" ctrl={true} />
|
||||||
</ContextMenu.Item>
|
</ContextMenu.Item>
|
||||||
<ContextMenu.Item onclick={() => selection.cutSelection()}>
|
<ContextMenu.Item onclick={() => selection.cutSelection()}>
|
||||||
<Scissors size="16" class="mr-1" />
|
<Scissors size="16" />
|
||||||
{i18n._('menu.cut')}
|
{i18n._('menu.cut')}
|
||||||
<Shortcut key="X" ctrl={true} />
|
<Shortcut key="X" ctrl={true} />
|
||||||
</ContextMenu.Item>
|
</ContextMenu.Item>
|
||||||
@@ -315,20 +301,15 @@
|
|||||||
!allowedPastes[$copied[0].level].includes(item.level)}
|
!allowedPastes[$copied[0].level].includes(item.level)}
|
||||||
onclick={pasteSelection}
|
onclick={pasteSelection}
|
||||||
>
|
>
|
||||||
<ClipboardPaste size="16" class="mr-1" />
|
<ClipboardPaste size="16" />
|
||||||
{i18n._('menu.paste')}
|
{i18n._('menu.paste')}
|
||||||
<Shortcut key="V" ctrl={true} />
|
<Shortcut key="V" ctrl={true} />
|
||||||
</ContextMenu.Item>
|
</ContextMenu.Item>
|
||||||
{/if}
|
{/if}
|
||||||
<ContextMenu.Separator />
|
<ContextMenu.Separator />
|
||||||
<ContextMenu.Item onclick={fileActions.deleteSelection}>
|
<ContextMenu.Item onclick={fileActions.deleteSelection}>
|
||||||
{#if item instanceof ListFileItem}
|
<Trash2 size="16" />
|
||||||
<FileX size="16" class="mr-1" />
|
|
||||||
{i18n._('menu.close')}
|
|
||||||
{:else}
|
|
||||||
<Trash2 size="16" class="mr-1" />
|
|
||||||
{i18n._('menu.delete')}
|
{i18n._('menu.delete')}
|
||||||
{/if}
|
|
||||||
<Shortcut key="⌫" ctrl={true} />
|
<Shortcut key="⌫" ctrl={true} />
|
||||||
</ContextMenu.Item>
|
</ContextMenu.Item>
|
||||||
</ContextMenu.Content>
|
</ContextMenu.Content>
|
||||||
|
|||||||
@@ -7,24 +7,6 @@ export enum ListLevel {
|
|||||||
WAYPOINT,
|
WAYPOINT,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const allowedMoves: Record<ListLevel, ListLevel[]> = {
|
|
||||||
[ListLevel.ROOT]: [],
|
|
||||||
[ListLevel.FILE]: [ListLevel.FILE],
|
|
||||||
[ListLevel.TRACK]: [ListLevel.FILE, ListLevel.TRACK],
|
|
||||||
[ListLevel.SEGMENT]: [ListLevel.FILE, ListLevel.TRACK, ListLevel.SEGMENT],
|
|
||||||
[ListLevel.WAYPOINTS]: [ListLevel.WAYPOINTS],
|
|
||||||
[ListLevel.WAYPOINT]: [ListLevel.WAYPOINTS, ListLevel.WAYPOINT],
|
|
||||||
};
|
|
||||||
|
|
||||||
export const allowedPastes: Record<ListLevel, ListLevel[]> = {
|
|
||||||
[ListLevel.ROOT]: [],
|
|
||||||
[ListLevel.FILE]: [ListLevel.ROOT, ListLevel.FILE],
|
|
||||||
[ListLevel.TRACK]: [ListLevel.ROOT, ListLevel.FILE, ListLevel.TRACK],
|
|
||||||
[ListLevel.SEGMENT]: [ListLevel.ROOT, ListLevel.FILE, ListLevel.TRACK, ListLevel.SEGMENT],
|
|
||||||
[ListLevel.WAYPOINTS]: [ListLevel.FILE, ListLevel.WAYPOINTS, ListLevel.WAYPOINT],
|
|
||||||
[ListLevel.WAYPOINT]: [ListLevel.FILE, ListLevel.WAYPOINTS, ListLevel.WAYPOINT],
|
|
||||||
};
|
|
||||||
|
|
||||||
export abstract class ListItem {
|
export abstract class ListItem {
|
||||||
[x: string]: any;
|
[x: string]: any;
|
||||||
level: ListLevel;
|
level: ListLevel;
|
||||||
|
|||||||
@@ -4,12 +4,12 @@
|
|||||||
import { Textarea } from '$lib/components/ui/textarea';
|
import { Textarea } from '$lib/components/ui/textarea';
|
||||||
import { Label } from '$lib/components/ui/label/index.js';
|
import { Label } from '$lib/components/ui/label/index.js';
|
||||||
import * as Popover from '$lib/components/ui/popover';
|
import * as Popover from '$lib/components/ui/popover';
|
||||||
import { dbUtils } from '$lib/db';
|
|
||||||
import { Save } from '@lucide/svelte';
|
import { Save } from '@lucide/svelte';
|
||||||
import { ListFileItem, ListTrackItem, type ListItem } from '../file-list';
|
import { ListFileItem, ListTrackItem, type ListItem } from '../file-list';
|
||||||
import { GPXTreeElement, Track, type AnyGPXTreeElement, Waypoint, GPXFile } from 'gpx';
|
import { GPXTreeElement, Track, type AnyGPXTreeElement, Waypoint, GPXFile } from 'gpx';
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
import { editMetadata } from '$lib/components/file-list/metadata/utils.svelte';
|
import { editMetadata } from '$lib/components/file-list/metadata/utils.svelte';
|
||||||
|
import { fileActionManager } from '$lib/logic/file-action-manager';
|
||||||
|
|
||||||
let {
|
let {
|
||||||
node,
|
node,
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Popover.Root bind:open>
|
<Popover.Root bind:open>
|
||||||
<Popover.Trigger />
|
<Popover.Trigger class="-mx-1" />
|
||||||
<Popover.Content side="top" sideOffset={22} alignOffset={30} class="flex flex-col gap-3">
|
<Popover.Content side="top" sideOffset={22} alignOffset={30} class="flex flex-col gap-3">
|
||||||
<Label for="name">{i18n._('menu.metadata.name')}</Label>
|
<Label for="name">{i18n._('menu.metadata.name')}</Label>
|
||||||
<Input bind:value={name} id="name" class="font-semibold h-8" />
|
<Input bind:value={name} id="name" class="font-semibold h-8" />
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onclick={() => {
|
onclick={() => {
|
||||||
dbUtils.applyToFile(item.getFileId(), (file) => {
|
fileActionManager.applyToFile(item.getFileId(), (file) => {
|
||||||
if (item instanceof ListFileItem && node instanceof GPXFile) {
|
if (item instanceof ListFileItem && node instanceof GPXFile) {
|
||||||
file.metadata.name = name;
|
file.metadata.name = name;
|
||||||
file.metadata.desc = description;
|
file.metadata.desc = description;
|
||||||
@@ -68,7 +68,7 @@
|
|||||||
open = false;
|
open = false;
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Save size="16" class="mr-1" />
|
<Save size="16" />
|
||||||
{i18n._('menu.metadata.save')}
|
{i18n._('menu.metadata.save')}
|
||||||
</Button>
|
</Button>
|
||||||
</Popover.Content>
|
</Popover.Content>
|
||||||
|
|||||||
284
website/src/lib/components/file-list/sortable-file-list.ts
Normal file
284
website/src/lib/components/file-list/sortable-file-list.ts
Normal file
@@ -0,0 +1,284 @@
|
|||||||
|
import { isMac } from '$lib/utils';
|
||||||
|
import Sortable, { type Direction } from 'sortablejs/Sortable';
|
||||||
|
import { ListItem, ListLevel, ListRootItem } from './file-list';
|
||||||
|
import { selection } from '$lib/logic/selection';
|
||||||
|
import { getFileIds, moveItems } from '$lib/logic/file-actions';
|
||||||
|
import { get, writable, type Readable } from 'svelte/store';
|
||||||
|
import { settings } from '$lib/logic/settings';
|
||||||
|
import type { GPXFileWithStatistics } from '$lib/logic/statistics-tree';
|
||||||
|
import type { AnyGPXTreeElement, GPXTreeElement, Waypoint } from 'gpx';
|
||||||
|
import { tick } from 'svelte';
|
||||||
|
|
||||||
|
const { fileOrder } = settings;
|
||||||
|
|
||||||
|
export const allowedMoves: Record<ListLevel, ListLevel[]> = {
|
||||||
|
[ListLevel.ROOT]: [],
|
||||||
|
[ListLevel.FILE]: [ListLevel.FILE],
|
||||||
|
[ListLevel.TRACK]: [ListLevel.FILE, ListLevel.TRACK],
|
||||||
|
[ListLevel.SEGMENT]: [ListLevel.FILE, ListLevel.TRACK, ListLevel.SEGMENT],
|
||||||
|
[ListLevel.WAYPOINTS]: [ListLevel.WAYPOINTS],
|
||||||
|
[ListLevel.WAYPOINT]: [ListLevel.WAYPOINTS, ListLevel.WAYPOINT],
|
||||||
|
};
|
||||||
|
|
||||||
|
export const allowedPastes: Record<ListLevel, ListLevel[]> = {
|
||||||
|
[ListLevel.ROOT]: [],
|
||||||
|
[ListLevel.FILE]: [ListLevel.ROOT, ListLevel.FILE],
|
||||||
|
[ListLevel.TRACK]: [ListLevel.ROOT, ListLevel.FILE, ListLevel.TRACK],
|
||||||
|
[ListLevel.SEGMENT]: [ListLevel.ROOT, ListLevel.FILE, ListLevel.TRACK, ListLevel.SEGMENT],
|
||||||
|
[ListLevel.WAYPOINTS]: [ListLevel.FILE, ListLevel.WAYPOINTS, ListLevel.WAYPOINT],
|
||||||
|
[ListLevel.WAYPOINT]: [ListLevel.FILE, ListLevel.WAYPOINTS, ListLevel.WAYPOINT],
|
||||||
|
};
|
||||||
|
|
||||||
|
export const dragging = writable<ListLevel | null>(null);
|
||||||
|
|
||||||
|
export class SortableFileList {
|
||||||
|
private _node:
|
||||||
|
| Map<string, Readable<GPXFileWithStatistics | undefined>>
|
||||||
|
| GPXTreeElement<AnyGPXTreeElement>
|
||||||
|
| Waypoint[]
|
||||||
|
| Waypoint;
|
||||||
|
private _item: ListItem;
|
||||||
|
private _sortableLevel: ListLevel;
|
||||||
|
private _container: HTMLElement;
|
||||||
|
private _sortable: Sortable | null = null;
|
||||||
|
private _elements: { [id: string]: HTMLElement } = {};
|
||||||
|
private _updatingSelection: boolean = false;
|
||||||
|
private _unsubscribes: (() => void)[] = [];
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
container: HTMLElement,
|
||||||
|
node:
|
||||||
|
| Map<string, Readable<GPXFileWithStatistics | undefined>>
|
||||||
|
| GPXTreeElement<AnyGPXTreeElement>
|
||||||
|
| Waypoint[]
|
||||||
|
| Waypoint,
|
||||||
|
item: ListItem,
|
||||||
|
waypointRoot: boolean,
|
||||||
|
sortableLevel: ListLevel,
|
||||||
|
orientation: Direction
|
||||||
|
) {
|
||||||
|
this._node = node;
|
||||||
|
this._item = item;
|
||||||
|
this._sortableLevel = sortableLevel;
|
||||||
|
this._container = container;
|
||||||
|
this._sortable = Sortable.create(container, {
|
||||||
|
group: {
|
||||||
|
name: sortableLevel,
|
||||||
|
pull: allowedMoves[sortableLevel],
|
||||||
|
put: true,
|
||||||
|
},
|
||||||
|
direction: orientation,
|
||||||
|
forceAutoScrollFallback: true,
|
||||||
|
multiDrag: true,
|
||||||
|
multiDragKey: isMac() ? 'Meta' : 'Ctrl',
|
||||||
|
avoidImplicitDeselect: true,
|
||||||
|
onSelect: (e: Sortable.SortableEvent) =>
|
||||||
|
setTimeout(() => this.updateToSelection(e), 50),
|
||||||
|
onDeselect: (e: Sortable.SortableEvent) =>
|
||||||
|
setTimeout(() => this.updateToSelection(e), 50),
|
||||||
|
onStart: () => dragging.set(sortableLevel),
|
||||||
|
onEnd: () => dragging.set(null),
|
||||||
|
onSort: (e: Sortable.SortableEvent) => this.onSort(e),
|
||||||
|
});
|
||||||
|
Object.defineProperty(this._sortable, '_item', {
|
||||||
|
value: item,
|
||||||
|
writable: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(this._sortable, '_waypointRoot', {
|
||||||
|
value: waypointRoot,
|
||||||
|
writable: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
this._unsubscribes.push(
|
||||||
|
selection.subscribe(() => tick().then(() => this.updateFromSelection()))
|
||||||
|
);
|
||||||
|
this._unsubscribes.push(fileOrder.subscribe(() => this.updateFromFileOrder()));
|
||||||
|
}
|
||||||
|
|
||||||
|
onSort(e: Sortable.SortableEvent) {
|
||||||
|
this.updateToFileOrder();
|
||||||
|
|
||||||
|
const from = Sortable.get(e.from);
|
||||||
|
const to = Sortable.get(e.to);
|
||||||
|
|
||||||
|
if (!from || !to) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let fromItem = from._item;
|
||||||
|
let toItem = to._item;
|
||||||
|
|
||||||
|
if (this._item === toItem && !(fromItem instanceof ListRootItem)) {
|
||||||
|
// Event is triggered on source and destination list, only handle it once
|
||||||
|
let fromItems = [];
|
||||||
|
let toItems = [];
|
||||||
|
|
||||||
|
if (from._waypointRoot) {
|
||||||
|
fromItems = [fromItem.extend('waypoints')];
|
||||||
|
} else {
|
||||||
|
let oldIndices: number[] =
|
||||||
|
e.oldIndicies.length > 0 ? e.oldIndicies.map((i) => i.index) : [e.oldIndex];
|
||||||
|
oldIndices = oldIndices.filter((i) => i >= 0);
|
||||||
|
oldIndices.sort((a, b) => a - b);
|
||||||
|
|
||||||
|
fromItems = oldIndices.map((i) => fromItem.extend(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (from._waypointRoot && to._waypointRoot) {
|
||||||
|
toItems = [toItem.extend('waypoints')];
|
||||||
|
} else {
|
||||||
|
if (to._waypointRoot) {
|
||||||
|
toItem = toItem.extend('waypoints');
|
||||||
|
}
|
||||||
|
|
||||||
|
let newIndices: number[] =
|
||||||
|
e.newIndicies.length > 0 ? e.newIndicies.map((i) => i.index) : [e.newIndex];
|
||||||
|
newIndices = newIndices.filter((i) => i >= 0);
|
||||||
|
newIndices.sort((a, b) => a - b);
|
||||||
|
|
||||||
|
if (toItem instanceof ListRootItem) {
|
||||||
|
let newFileIds = getFileIds(newIndices.length);
|
||||||
|
toItems = newIndices.map((i, index) => {
|
||||||
|
get(fileOrder).splice(i, 0, newFileIds[index]);
|
||||||
|
return this._item.extend(newFileIds[index]);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
toItems = newIndices.map((i) => toItem.extend(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
moveItems(fromItem, toItem, fromItems, toItems);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateFromSelection() {
|
||||||
|
const changed = this.getChangedIds();
|
||||||
|
if (changed.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const selection_ = get(selection);
|
||||||
|
for (let id of changed) {
|
||||||
|
let element = this._elements[id];
|
||||||
|
if (element) {
|
||||||
|
if (selection_.has(this._item.extend(id))) {
|
||||||
|
Sortable.utils.select(element);
|
||||||
|
element.scrollIntoView({
|
||||||
|
behavior: 'smooth',
|
||||||
|
block: 'nearest',
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Sortable.utils.deselect(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateToSelection(e: Sortable.SortableEvent) {
|
||||||
|
if (!this._sortable) return;
|
||||||
|
if (this._updatingSelection) return;
|
||||||
|
this._updatingSelection = true;
|
||||||
|
const changed = this.getChangedIds();
|
||||||
|
if (changed.length == 0) {
|
||||||
|
this._updatingSelection = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
selection.update(($selection) => {
|
||||||
|
$selection.clear();
|
||||||
|
Object.entries(this._elements).forEach(([id, element]) => {
|
||||||
|
$selection.set(
|
||||||
|
this._item.extend(this.getRealId(id)),
|
||||||
|
element.classList.contains('sortable-selected')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (
|
||||||
|
e.originalEvent &&
|
||||||
|
!(e.originalEvent.ctrlKey || e.originalEvent.metaKey || e.originalEvent.shiftKey) &&
|
||||||
|
($selection.size > 1 ||
|
||||||
|
!$selection.has(this._item.extend(this.getRealId(changed[0]))))
|
||||||
|
) {
|
||||||
|
// Fix bug that sometimes causes a single select to be treated as a multi-select
|
||||||
|
$selection.clear();
|
||||||
|
$selection.set(this._item.extend(this.getRealId(changed[0])), true);
|
||||||
|
}
|
||||||
|
return $selection;
|
||||||
|
});
|
||||||
|
this._updatingSelection = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateFromFileOrder() {
|
||||||
|
if (!this._sortable || this._sortableLevel !== ListLevel.FILE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileOrder_ = get(fileOrder);
|
||||||
|
const sortableOrder = this._sortable.toArray();
|
||||||
|
|
||||||
|
if (
|
||||||
|
fileOrder_.length !== sortableOrder.length ||
|
||||||
|
fileOrder_.some((value, index) => value !== sortableOrder[index])
|
||||||
|
) {
|
||||||
|
this._sortable.sort(fileOrder_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateToFileOrder() {
|
||||||
|
if (!this._sortable || this._sortableLevel !== ListLevel.FILE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileOrder_ = get(fileOrder);
|
||||||
|
const sortableOrder = this._sortable.toArray();
|
||||||
|
|
||||||
|
if (
|
||||||
|
fileOrder_.length !== sortableOrder.length ||
|
||||||
|
fileOrder_.some((value, index) => value !== sortableOrder[index])
|
||||||
|
) {
|
||||||
|
fileOrder.set(sortableOrder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateElements() {
|
||||||
|
this._elements = {};
|
||||||
|
this._container.childNodes.forEach((element) => {
|
||||||
|
if (element instanceof HTMLElement) {
|
||||||
|
let attr = element.getAttribute('data-id');
|
||||||
|
if (attr) {
|
||||||
|
if (this._node instanceof Map && !this._node.has(attr)) {
|
||||||
|
element.remove();
|
||||||
|
} else {
|
||||||
|
this._elements[attr] = element;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
destroy() {
|
||||||
|
this._sortable = null;
|
||||||
|
this._unsubscribes.forEach((unsubscribe) => unsubscribe());
|
||||||
|
this._unsubscribes = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
getChangedIds() {
|
||||||
|
let changed: (string | number)[] = [];
|
||||||
|
const selection_ = get(selection);
|
||||||
|
Object.entries(this._elements).forEach(([id, element]) => {
|
||||||
|
let realId = this.getRealId(id);
|
||||||
|
let realItem = this._item.extend(realId);
|
||||||
|
let inSelection = selection_.has(realItem);
|
||||||
|
let isSelected = element.classList.contains('sortable-selected');
|
||||||
|
if (inSelection !== isSelected) {
|
||||||
|
changed.push(realId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
getRealId(id: string | number) {
|
||||||
|
return this._sortableLevel === ListLevel.FILE || this._sortableLevel === ListLevel.WAYPOINTS
|
||||||
|
? id
|
||||||
|
: parseInt(id as string);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@
|
|||||||
import { Label } from '$lib/components/ui/label/index.js';
|
import { Label } from '$lib/components/ui/label/index.js';
|
||||||
import { Slider } from '$lib/components/ui/slider';
|
import { Slider } from '$lib/components/ui/slider';
|
||||||
import * as Popover from '$lib/components/ui/popover';
|
import * as Popover from '$lib/components/ui/popover';
|
||||||
import { dbUtils, getFile, settings } from '$lib/db';
|
|
||||||
import { Save } from '@lucide/svelte';
|
import { Save } from '@lucide/svelte';
|
||||||
import {
|
import {
|
||||||
ListFileItem,
|
ListFileItem,
|
||||||
@@ -12,10 +11,14 @@
|
|||||||
type ListItem,
|
type ListItem,
|
||||||
} from '$lib/components/file-list/file-list';
|
} from '$lib/components/file-list/file-list';
|
||||||
import { editStyle } from '$lib/components/file-list/style/utils.svelte';
|
import { editStyle } from '$lib/components/file-list/style/utils.svelte';
|
||||||
import { selection } from '../Selection';
|
|
||||||
import { gpxLayers } from '$lib/stores';
|
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
import type { LineStyleExtension } from 'gpx';
|
import type { LineStyleExtension } from 'gpx';
|
||||||
|
import { settings } from '$lib/logic/settings';
|
||||||
|
import { selection } from '$lib/logic/selection';
|
||||||
|
import { fileStateCollection } from '$lib/logic/file-state';
|
||||||
|
import { gpxLayers } from '$lib/components/map/gpx-layer/gpx-layers';
|
||||||
|
import { untrack } from 'svelte';
|
||||||
|
import { fileActions } from '$lib/logic/file-actions';
|
||||||
|
|
||||||
let {
|
let {
|
||||||
item,
|
item,
|
||||||
@@ -40,8 +43,8 @@
|
|||||||
|
|
||||||
$selection.forEach((item) => {
|
$selection.forEach((item) => {
|
||||||
if (item instanceof ListFileItem) {
|
if (item instanceof ListFileItem) {
|
||||||
let file = getFile(item.getFileId());
|
let file = fileStateCollection.getFile(item.getFileId());
|
||||||
let layer = gpxLayers.get(item.getFileId());
|
let layer = gpxLayers.getLayer(item.getFileId());
|
||||||
if (file && layer) {
|
if (file && layer) {
|
||||||
let style = file.getStyle();
|
let style = file.getStyle();
|
||||||
color = layer.layerColor;
|
color = layer.layerColor;
|
||||||
@@ -53,8 +56,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (item instanceof ListTrackItem) {
|
} else if (item instanceof ListTrackItem) {
|
||||||
let file = getFile(item.getFileId());
|
let file = fileStateCollection.getFile(item.getFileId());
|
||||||
let layer = gpxLayers.get(item.getFileId());
|
let layer = gpxLayers.getLayer(item.getFileId());
|
||||||
if (file && layer) {
|
if (file && layer) {
|
||||||
color = layer.layerColor;
|
color = layer.layerColor;
|
||||||
let track = file.trk[item.getTrackIndex()];
|
let track = file.trk[item.getTrackIndex()];
|
||||||
@@ -81,7 +84,7 @@
|
|||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if ($selection && open) {
|
if ($selection && open) {
|
||||||
setStyleInputs();
|
untrack(() => setStyleInputs());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -102,9 +105,9 @@
|
|||||||
if (widthChanged) {
|
if (widthChanged) {
|
||||||
style['gpx_style:width'] = width;
|
style['gpx_style:width'] = width;
|
||||||
}
|
}
|
||||||
dbUtils.setStyleToSelection(style);
|
fileActions.setStyleToSelection(style);
|
||||||
|
|
||||||
if (item instanceof ListFileItem && $selection.size === gpxLayers.size) {
|
if (item instanceof ListFileItem && $selection.size === fileStateCollection.size) {
|
||||||
if (style['gpx_style:opacity']) {
|
if (style['gpx_style:opacity']) {
|
||||||
$defaultOpacity = style['gpx_style:opacity'];
|
$defaultOpacity = style['gpx_style:opacity'];
|
||||||
}
|
}
|
||||||
@@ -118,7 +121,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Popover.Root bind:open>
|
<Popover.Root bind:open>
|
||||||
<Popover.Trigger />
|
<Popover.Trigger class="-mx-1" />
|
||||||
<Popover.Content side="top" sideOffset={22} alignOffset={30} class="flex flex-col gap-3">
|
<Popover.Content side="top" sideOffset={22} alignOffset={30} class="flex flex-col gap-3">
|
||||||
<Label class="flex flex-row gap-2 items-center justify-between">
|
<Label class="flex flex-row gap-2 items-center justify-between">
|
||||||
{i18n._('menu.style.color')}
|
{i18n._('menu.style.color')}
|
||||||
@@ -161,7 +164,7 @@
|
|||||||
disabled={!colorChanged && !opacityChanged && !widthChanged}
|
disabled={!colorChanged && !opacityChanged && !widthChanged}
|
||||||
onclick={applyStyle}
|
onclick={applyStyle}
|
||||||
>
|
>
|
||||||
<Save size="16" class="mr-1" />
|
<Save size="16" />
|
||||||
{i18n._('menu.metadata.save')}
|
{i18n._('menu.metadata.save')}
|
||||||
</Button>
|
</Button>
|
||||||
</Popover.Content>
|
</Popover.Content>
|
||||||
|
|||||||
@@ -1,11 +1,20 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { map } from '$lib/components/map/map.svelte';
|
import { map } from '$lib/components/map/map';
|
||||||
import { trackpointPopup } from '$lib/components/map/gpx-layer/GPXLayerPopup';
|
import { trackpointPopup } from '$lib/components/map/gpx-layer/gpx-layer-popup';
|
||||||
import { TrackPoint } from 'gpx';
|
import { TrackPoint } from 'gpx';
|
||||||
|
|
||||||
$effect(() => {
|
map.onLoad((map_) => {
|
||||||
if (map.current) {
|
map_.on('contextmenu', (e) => {
|
||||||
map.current.on('contextmenu', (e) => {
|
if (
|
||||||
|
map_.queryRenderedFeatures(e.point, {
|
||||||
|
layers: map_
|
||||||
|
.getLayersOrder()
|
||||||
|
.filter((layerId) => layerId.startsWith('routing-controls')),
|
||||||
|
}).length
|
||||||
|
) {
|
||||||
|
// Clicked on routing control, ignoring
|
||||||
|
return;
|
||||||
|
}
|
||||||
trackpointPopup?.setItem({
|
trackpointPopup?.setItem({
|
||||||
item: new TrackPoint({
|
item: new TrackPoint({
|
||||||
attributes: {
|
attributes: {
|
||||||
@@ -15,6 +24,5 @@
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,30 +1,25 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onDestroy, onMount } from 'svelte';
|
import { onDestroy, onMount } from 'svelte';
|
||||||
import mapboxgl from 'mapbox-gl';
|
|
||||||
import 'mapbox-gl/dist/mapbox-gl.css';
|
|
||||||
import '@mapbox/mapbox-gl-geocoder/dist/mapbox-gl-geocoder.css';
|
|
||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
import { PUBLIC_MAPBOX_TOKEN } from '$env/static/public';
|
|
||||||
import { page } from '$app/state';
|
import { page } from '$app/state';
|
||||||
import { map } from '$lib/components/map/map';
|
import { map } from '$lib/components/map/map';
|
||||||
|
import { PUBLIC_MAPTILER_KEY } from '$env/static/public';
|
||||||
|
|
||||||
let {
|
let {
|
||||||
accessToken = PUBLIC_MAPBOX_TOKEN,
|
maptilerKey = PUBLIC_MAPTILER_KEY,
|
||||||
geolocate = true,
|
geolocate = true,
|
||||||
geocoder = true,
|
geocoder = true,
|
||||||
hash = true,
|
hash = true,
|
||||||
class: className = '',
|
class: className = '',
|
||||||
}: {
|
}: {
|
||||||
accessToken?: string;
|
maptilerKey?: string;
|
||||||
geolocate?: boolean;
|
geolocate?: boolean;
|
||||||
geocoder?: boolean;
|
geocoder?: boolean;
|
||||||
hash?: boolean;
|
hash?: boolean;
|
||||||
class?: string;
|
class?: string;
|
||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
mapboxgl.accessToken = accessToken;
|
|
||||||
|
|
||||||
let webgl2Supported = $state(true);
|
let webgl2Supported = $state(true);
|
||||||
let embeddedApp = $state(false);
|
let embeddedApp = $state(false);
|
||||||
|
|
||||||
@@ -48,7 +43,7 @@
|
|||||||
language = 'en';
|
language = 'en';
|
||||||
}
|
}
|
||||||
|
|
||||||
map.init(PUBLIC_MAPBOX_TOKEN, language, hash, geocoder, geolocate);
|
map.init(maptilerKey, language, hash, geocoder, geolocate);
|
||||||
});
|
});
|
||||||
|
|
||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
@@ -81,21 +76,21 @@
|
|||||||
<style lang="postcss">
|
<style lang="postcss">
|
||||||
@reference "../../../app.css";
|
@reference "../../../app.css";
|
||||||
|
|
||||||
div :global(.mapboxgl-map) {
|
div :global(.maplibregl-map) {
|
||||||
@apply font-sans;
|
@apply font-sans;
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-ctrl-top-right > .mapboxgl-ctrl) {
|
div :global(.maplibregl-ctrl-top-right > .maplibregl-ctrl) {
|
||||||
@apply shadow-md;
|
@apply shadow-md;
|
||||||
@apply bg-background;
|
@apply bg-background;
|
||||||
@apply text-foreground;
|
@apply text-foreground;
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-ctrl-icon) {
|
div :global(.maplibregl-ctrl-icon) {
|
||||||
@apply dark:brightness-[4.7];
|
@apply dark:brightness-[4.7];
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-ctrl-geocoder) {
|
div :global(.maplibregl-ctrl-geocoder) {
|
||||||
@apply flex;
|
@apply flex;
|
||||||
@apply flex-row;
|
@apply flex-row;
|
||||||
@apply w-fit;
|
@apply w-fit;
|
||||||
@@ -110,36 +105,45 @@
|
|||||||
@apply text-foreground;
|
@apply text-foreground;
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-ctrl-geocoder .suggestions > li > a) {
|
div :global(.maplibregl-ctrl-geocoder .suggestions > li > a) {
|
||||||
@apply text-foreground;
|
@apply text-foreground;
|
||||||
@apply hover:text-accent-foreground;
|
@apply hover:text-accent-foreground;
|
||||||
@apply hover:bg-accent;
|
@apply hover:bg-accent;
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-ctrl-geocoder .suggestions > .active > a) {
|
div :global(.maplibregl-ctrl-geocoder .suggestions > .active > a) {
|
||||||
@apply bg-background;
|
@apply bg-background;
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-ctrl-geocoder--button) {
|
div :global(.maplibregl-ctrl-geocoder--button) {
|
||||||
@apply bg-transparent;
|
@apply bg-transparent;
|
||||||
@apply hover:bg-transparent;
|
@apply hover:bg-transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-ctrl-geocoder--icon) {
|
div :global(.maplibregl-ctrl-geocoder--icon) {
|
||||||
@apply fill-foreground;
|
@apply fill-foreground;
|
||||||
@apply hover:fill-accent-foreground;
|
@apply hover:fill-accent-foreground;
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-ctrl-geocoder--icon-search) {
|
div :global(.maplibregl-ctrl-geocoder--icon-search) {
|
||||||
@apply relative;
|
@apply relative;
|
||||||
@apply top-0;
|
@apply top-0;
|
||||||
@apply left-0;
|
@apply left-0;
|
||||||
@apply my-2;
|
|
||||||
@apply w-[29px];
|
@apply w-[29px];
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-ctrl-geocoder--input) {
|
div :global(.maplibregl-ctrl-geocoder--icon-loading) {
|
||||||
|
@apply -mt-1;
|
||||||
|
@apply mb-0;
|
||||||
|
}
|
||||||
|
|
||||||
|
div :global(.maplibregl-ctrl-geocoder--icon-close) {
|
||||||
|
@apply my-0;
|
||||||
|
}
|
||||||
|
|
||||||
|
div :global(.maplibregl-ctrl-geocoder--input) {
|
||||||
@apply relative;
|
@apply relative;
|
||||||
|
@apply h-8;
|
||||||
@apply w-64;
|
@apply w-64;
|
||||||
@apply py-0;
|
@apply py-0;
|
||||||
@apply pl-2;
|
@apply pl-2;
|
||||||
@@ -149,12 +153,12 @@
|
|||||||
@apply text-foreground;
|
@apply text-foreground;
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-ctrl-geocoder--collapsed .mapboxgl-ctrl-geocoder--input) {
|
div :global(.maplibregl-ctrl-geocoder--collapsed .maplibregl-ctrl-geocoder--input) {
|
||||||
@apply w-0;
|
@apply w-0;
|
||||||
@apply p-0;
|
@apply p-0;
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-ctrl-top-right) {
|
div :global(.maplibregl-ctrl-top-right) {
|
||||||
@apply z-40;
|
@apply z-40;
|
||||||
@apply flex;
|
@apply flex;
|
||||||
@apply flex-col;
|
@apply flex-col;
|
||||||
@@ -163,77 +167,76 @@
|
|||||||
@apply overflow-hidden;
|
@apply overflow-hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.horizontal :global(.mapboxgl-ctrl-bottom-left) {
|
.horizontal :global(.maplibregl-ctrl-bottom-left) {
|
||||||
@apply bottom-[42px];
|
@apply bottom-[42px];
|
||||||
}
|
}
|
||||||
|
|
||||||
.horizontal :global(.mapboxgl-ctrl-bottom-right) {
|
.horizontal :global(.maplibregl-ctrl-bottom-right) {
|
||||||
@apply bottom-[42px];
|
@apply bottom-[42px];
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-ctrl-attrib) {
|
div :global(.maplibregl-ctrl-attrib) {
|
||||||
@apply dark:bg-transparent;
|
@apply dark:bg-transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-compact-show.mapboxgl-ctrl-attrib) {
|
div :global(.maplibregl-compact-show.maplibregl-ctrl-attrib) {
|
||||||
@apply dark:bg-background;
|
@apply dark:bg-background;
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-ctrl-attrib-button) {
|
div :global(.maplibregl-ctrl-attrib-button) {
|
||||||
@apply dark:bg-foreground;
|
@apply dark:bg-foreground;
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-compact-show .mapboxgl-ctrl-attrib-button) {
|
div :global(.maplibregl-compact-show .maplibregl-ctrl-attrib-button) {
|
||||||
@apply dark:bg-foreground;
|
@apply dark:bg-foreground;
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-ctrl-attrib a) {
|
div :global(.maplibregl-ctrl-attrib a) {
|
||||||
@apply text-foreground;
|
@apply text-foreground;
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-popup) {
|
div :global(.maplibregl-popup) {
|
||||||
@apply w-fit;
|
|
||||||
@apply z-50;
|
@apply z-50;
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-popup-content) {
|
div :global(.maplibregl-popup-content) {
|
||||||
@apply p-0;
|
@apply p-0;
|
||||||
@apply bg-transparent;
|
@apply bg-transparent;
|
||||||
@apply shadow-none;
|
@apply shadow-none;
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-popup-anchor-top .mapboxgl-popup-tip) {
|
div :global(.maplibregl-popup-anchor-top .maplibregl-popup-tip) {
|
||||||
@apply border-b-background;
|
@apply border-b-background;
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-popup-anchor-top-left .mapboxgl-popup-tip) {
|
div :global(.maplibregl-popup-anchor-top-left .maplibregl-popup-tip) {
|
||||||
@apply border-b-background;
|
@apply border-b-background;
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-popup-anchor-top-right .mapboxgl-popup-tip) {
|
div :global(.maplibregl-popup-anchor-top-right .maplibregl-popup-tip) {
|
||||||
@apply border-b-background;
|
@apply border-b-background;
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-popup-anchor-bottom .mapboxgl-popup-tip) {
|
div :global(.maplibregl-popup-anchor-bottom .maplibregl-popup-tip) {
|
||||||
@apply border-t-background;
|
@apply border-t-background;
|
||||||
@apply drop-shadow-md;
|
@apply drop-shadow-md;
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-popup-anchor-bottom-left .mapboxgl-popup-tip) {
|
div :global(.maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip) {
|
||||||
@apply border-t-background;
|
@apply border-t-background;
|
||||||
@apply drop-shadow-md;
|
@apply drop-shadow-md;
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-popup-anchor-bottom-right .mapboxgl-popup-tip) {
|
div :global(.maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip) {
|
||||||
@apply border-t-background;
|
@apply border-t-background;
|
||||||
@apply drop-shadow-md;
|
@apply drop-shadow-md;
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-popup-anchor-left .mapboxgl-popup-tip) {
|
div :global(.maplibregl-popup-anchor-left .maplibregl-popup-tip) {
|
||||||
@apply border-r-background;
|
@apply border-r-background;
|
||||||
}
|
}
|
||||||
|
|
||||||
div :global(.mapboxgl-popup-anchor-right .mapboxgl-popup-tip) {
|
div :global(.maplibregl-popup-anchor-right .maplibregl-popup-tip) {
|
||||||
@apply border-l-background;
|
@apply border-l-background;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import CustomControl from './CustomControl';
|
import CustomControl from './custom-control';
|
||||||
import { map } from '$lib/components/map/map';
|
import { map } from '$lib/components/map/map';
|
||||||
import { onMount, type Snippet } from 'svelte';
|
import { onMount, type Snippet } from 'svelte';
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
let control: CustomControl | null = null;
|
let control: CustomControl | null = null;
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
map.onLoad((map: mapboxgl.Map) => {
|
map.onLoad((map: maplibregl.Map) => {
|
||||||
if (position.includes('right')) container.classList.add('float-right');
|
if (position.includes('right')) container.classList.add('float-right');
|
||||||
else container.classList.add('float-left');
|
else container.classList.add('float-left');
|
||||||
container.classList.remove('hidden');
|
container.classList.remove('hidden');
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { type Map, type IControl } from 'mapbox-gl';
|
import { type Map, type IControl } from 'maplibre-gl';
|
||||||
|
|
||||||
export default class CustomControl implements IControl {
|
export default class CustomControl implements IControl {
|
||||||
_map: Map | undefined;
|
_map: Map | undefined;
|
||||||
@@ -16,7 +16,8 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
class="w-full px-2 py-1 h-8 justify-start {className}"
|
size="sm"
|
||||||
|
class="justify-start {className}"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onclick={() => {
|
onclick={() => {
|
||||||
navigator.clipboard.writeText(
|
navigator.clipboard.writeText(
|
||||||
@@ -25,6 +26,6 @@
|
|||||||
onCopy();
|
onCopy();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ClipboardCopy size="16" class="mr-1" />
|
<ClipboardCopy size="16" />
|
||||||
{i18n._('menu.copy_coordinates')}
|
{i18n._('menu.copy_coordinates')}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -1,33 +1,28 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { onDestroy } from 'svelte';
|
||||||
import { gpxLayers } from '$lib/components/map/gpx-layer/gpx-layers';
|
import { gpxLayers } from '$lib/components/map/gpx-layer/gpx-layers';
|
||||||
import { onDestroy, onMount } from 'svelte';
|
|
||||||
// import { map, gpxLayers } from '$lib/stores';
|
|
||||||
// import { GPXLayer } from './gpx-layer';
|
|
||||||
import { DistanceMarkers } from '$lib/components/map/gpx-layer/distance-markers';
|
import { DistanceMarkers } from '$lib/components/map/gpx-layer/distance-markers';
|
||||||
import { StartEndMarkers } from '$lib/components/map/gpx-layer/start-end-markers';
|
import { StartEndMarkers } from '$lib/components/map/gpx-layer/start-end-markers';
|
||||||
// import { onDestroy } from 'svelte';
|
import { createPopups, removePopups } from '$lib/components/map/gpx-layer/gpx-layer-popup';
|
||||||
// import { createPopups, removePopups } from './GPXLayerPopup';
|
import { map } from '$lib/components/map/map';
|
||||||
|
|
||||||
let distanceMarkers: DistanceMarkers;
|
let distanceMarkers: DistanceMarkers;
|
||||||
let startEndMarkers: StartEndMarkers;
|
let startEndMarkers: StartEndMarkers;
|
||||||
|
|
||||||
// $: if ($map) {
|
map.onLoad((map_) => {
|
||||||
// createPopups($map);
|
|
||||||
// }
|
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
gpxLayers.init();
|
gpxLayers.init();
|
||||||
startEndMarkers = new StartEndMarkers();
|
startEndMarkers = new StartEndMarkers();
|
||||||
distanceMarkers = new DistanceMarkers();
|
distanceMarkers = new DistanceMarkers();
|
||||||
|
createPopups(map_);
|
||||||
});
|
});
|
||||||
|
|
||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
// removePopups();
|
|
||||||
if (startEndMarkers) {
|
if (startEndMarkers) {
|
||||||
startEndMarkers.remove();
|
startEndMarkers.remove();
|
||||||
}
|
}
|
||||||
if (distanceMarkers) {
|
if (distanceMarkers) {
|
||||||
distanceMarkers.remove();
|
distanceMarkers.remove();
|
||||||
}
|
}
|
||||||
|
removePopups();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,19 +1,18 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { TrackPoint } from 'gpx';
|
import type { TrackPoint } from 'gpx';
|
||||||
|
import { Button } from '$lib/components/ui/button';
|
||||||
import CopyCoordinates from '$lib/components/map/gpx-layer/CopyCoordinates.svelte';
|
import CopyCoordinates from '$lib/components/map/gpx-layer/CopyCoordinates.svelte';
|
||||||
import * as Card from '$lib/components/ui/card';
|
import * as Card from '$lib/components/ui/card';
|
||||||
import WithUnits from '$lib/components/WithUnits.svelte';
|
import WithUnits from '$lib/components/WithUnits.svelte';
|
||||||
import { Compass, Mountain, Timer } from '@lucide/svelte';
|
import { Compass, Earth, Mountain, Timer } from '@lucide/svelte';
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
import type { PopupItem } from '$lib/components/map/map';
|
import type { PopupItem } from '$lib/components/map/map-popup';
|
||||||
|
import { map } from '$lib/components/map/map';
|
||||||
|
|
||||||
let { trackpoint }: { trackpoint: PopupItem<TrackPoint> } = $props();
|
let { trackpoint }: { trackpoint: PopupItem<TrackPoint> } = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Card.Root class="border-none shadow-md text-base p-2">
|
<Card.Root class="border-none shadow-md text-base p-2">
|
||||||
<Card.Header class="p-0">
|
|
||||||
<Card.Title class="text-md"></Card.Title>
|
|
||||||
</Card.Header>
|
|
||||||
<Card.Content class="flex flex-col p-0 text-xs gap-1">
|
<Card.Content class="flex flex-col p-0 text-xs gap-1">
|
||||||
<div class="flex flex-row items-center gap-1">
|
<div class="flex flex-row items-center gap-1">
|
||||||
<Compass size="14" />
|
<Compass size="14" />
|
||||||
@@ -38,5 +37,17 @@
|
|||||||
onCopy={() => trackpoint.hide?.()}
|
onCopy={() => trackpoint.hide?.()}
|
||||||
class="mt-0.5"
|
class="mt-0.5"
|
||||||
/>
|
/>
|
||||||
|
{#if trackpoint.fileId === undefined}
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
class="justify-start"
|
||||||
|
href={`https://www.openstreetmap.org/edit?#map=${(($map?.getZoom() ?? 17) + 1).toFixed(0)}/${trackpoint.item.getLatitude().toFixed(5)}/${trackpoint.item.getLongitude().toFixed(5)}`}
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
|
<Earth size="14" />
|
||||||
|
{i18n._('menu.edit_osm')}
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
</Card.Content>
|
</Card.Content>
|
||||||
</Card.Root>
|
</Card.Root>
|
||||||
|
|||||||
@@ -11,12 +11,21 @@
|
|||||||
import sanitizeHtml from 'sanitize-html';
|
import sanitizeHtml from 'sanitize-html';
|
||||||
import type { Waypoint } from 'gpx';
|
import type { Waypoint } from 'gpx';
|
||||||
import { ScrollArea } from '$lib/components/ui/scroll-area/index.js';
|
import { ScrollArea } from '$lib/components/ui/scroll-area/index.js';
|
||||||
import type { PopupItem } from '$lib/components/map/map';
|
|
||||||
import { fileActions } from '$lib/logic/file-actions';
|
import { fileActions } from '$lib/logic/file-actions';
|
||||||
|
import type { PopupItem } from '$lib/components/map/map-popup';
|
||||||
|
import { selection } from '$lib/logic/selection';
|
||||||
|
import { ListFileItem } from '$lib/components/file-list/file-list';
|
||||||
|
|
||||||
export let waypoint: PopupItem<Waypoint>;
|
let {
|
||||||
|
waypoint,
|
||||||
|
}: {
|
||||||
|
waypoint: PopupItem<Waypoint>;
|
||||||
|
} = $props();
|
||||||
|
|
||||||
$: symbolKey = waypoint ? getSymbolKey(waypoint.item.sym) : undefined;
|
let selected = $derived(
|
||||||
|
waypoint.fileId ? $selection.hasAnyChildren(new ListFileItem(waypoint.fileId)) : false
|
||||||
|
);
|
||||||
|
let symbolKey = $derived(waypoint ? getSymbolKey(waypoint.item.sym) : undefined);
|
||||||
|
|
||||||
function sanitize(text: string | undefined): string {
|
function sanitize(text: string | undefined): string {
|
||||||
if (text === undefined) {
|
if (text === undefined) {
|
||||||
@@ -32,8 +41,8 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Card.Root class="border-none shadow-md text-base p-2 max-w-[50dvw]">
|
<Card.Root class="border-none shadow-md text-base p-2 max-w-[50dvw] gap-0">
|
||||||
<Card.Header class="p-0">
|
<Card.Header class="p-0 gap-0">
|
||||||
<Card.Title class="text-md">
|
<Card.Title class="text-md">
|
||||||
{#if waypoint.item.link && waypoint.item.link.attributes && waypoint.item.link.attributes.href}
|
{#if waypoint.item.link && waypoint.item.link.attributes && waypoint.item.link.attributes.href}
|
||||||
<a href={waypoint.item.link.attributes.href} target="_blank">
|
<a href={waypoint.item.link.attributes.href} target="_blank">
|
||||||
@@ -50,11 +59,8 @@
|
|||||||
{#if symbolKey}
|
{#if symbolKey}
|
||||||
<span>
|
<span>
|
||||||
{#if symbols[symbolKey].icon}
|
{#if symbols[symbolKey].icon}
|
||||||
<svelte:component
|
{@const Icon = symbols[symbolKey].icon}
|
||||||
this={symbols[symbolKey].icon}
|
<Icon size="12" class="inline-block mb-1" />
|
||||||
size="12"
|
|
||||||
class="inline-block mb-0.5"
|
|
||||||
/>
|
|
||||||
{:else}
|
{:else}
|
||||||
<span class="w-4 inline-block"></span>
|
<span class="w-4 inline-block"></span>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -80,17 +86,18 @@
|
|||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
<div class="mt-2 flex flex-col gap-1">
|
<div class="mt-2 flex flex-col gap-1">
|
||||||
<CopyCoordinates coordinates={waypoint.item.attributes} />
|
<CopyCoordinates coordinates={waypoint.item.attributes} />
|
||||||
{#if $currentTool === Tool.WAYPOINT}
|
{#if $currentTool === Tool.WAYPOINT && selected}
|
||||||
<Button
|
<Button
|
||||||
class="w-full px-2 py-1 h-8 justify-start"
|
class="p-1 has-[>svg]:px-2 h-8"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onclick={() => {
|
onclick={() => {
|
||||||
if (waypoint.fileId) {
|
if (waypoint.fileId) {
|
||||||
fileActions.deleteWaypoint(waypoint.fileId, waypoint.item._data.index);
|
fileActions.deleteWaypoint(waypoint.fileId, waypoint.item._data.index);
|
||||||
|
waypoint.hide?.();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Trash2 size="16" class="mr-1" />
|
<Trash2 size="16" />
|
||||||
{i18n._('menu.delete')}
|
{i18n._('menu.delete')}
|
||||||
<Shortcut shift={true} click={true} />
|
<Shortcut shift={true} click={true} />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -1,20 +1,15 @@
|
|||||||
import { settings } from '$lib/logic/settings';
|
import { settings } from '$lib/logic/settings';
|
||||||
import { gpxStatistics } from '$lib/logic/statistics';
|
import { gpxStatistics } from '$lib/logic/statistics';
|
||||||
import { getConvertedDistanceToKilometers } from '$lib/units';
|
import { getConvertedDistanceToKilometers } from '$lib/units';
|
||||||
import type { GeoJSONSource } from 'mapbox-gl';
|
|
||||||
import { get } from 'svelte/store';
|
import { get } from 'svelte/store';
|
||||||
import { map } from '$lib/components/map/map';
|
import { map } from '$lib/components/map/map';
|
||||||
|
import { allHidden } from '$lib/logic/hidden';
|
||||||
|
import type { GeoJSONSource } from 'maplibre-gl';
|
||||||
|
import { ANCHOR_LAYER_KEY } from '../style';
|
||||||
|
|
||||||
const { distanceMarkers, distanceUnits } = settings;
|
const { distanceMarkers, distanceUnits } = settings;
|
||||||
|
|
||||||
const stops = [
|
const levels = [100, 50, 25, 10, 5, 1];
|
||||||
[100, 0],
|
|
||||||
[50, 7],
|
|
||||||
[25, 8, 10],
|
|
||||||
[10, 10],
|
|
||||||
[5, 11],
|
|
||||||
[1, 13],
|
|
||||||
];
|
|
||||||
|
|
||||||
export class DistanceMarkers {
|
export class DistanceMarkers {
|
||||||
updateBinded: () => void = this.update.bind(this);
|
updateBinded: () => void = this.update.bind(this);
|
||||||
@@ -24,10 +19,11 @@ export class DistanceMarkers {
|
|||||||
this.unsubscribes.push(gpxStatistics.subscribe(this.updateBinded));
|
this.unsubscribes.push(gpxStatistics.subscribe(this.updateBinded));
|
||||||
this.unsubscribes.push(distanceMarkers.subscribe(this.updateBinded));
|
this.unsubscribes.push(distanceMarkers.subscribe(this.updateBinded));
|
||||||
this.unsubscribes.push(distanceUnits.subscribe(this.updateBinded));
|
this.unsubscribes.push(distanceUnits.subscribe(this.updateBinded));
|
||||||
|
this.unsubscribes.push(allHidden.subscribe(this.updateBinded));
|
||||||
this.unsubscribes.push(
|
this.unsubscribes.push(
|
||||||
map.subscribe((map_) => {
|
map.subscribe((map_) => {
|
||||||
if (map_) {
|
if (map_) {
|
||||||
map_.on('style.import.load', this.updateBinded);
|
map_.on('style.load', this.updateBinded);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -38,7 +34,7 @@ export class DistanceMarkers {
|
|||||||
if (!map_) return;
|
if (!map_) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (get(distanceMarkers)) {
|
if (get(distanceMarkers) && !get(allHidden)) {
|
||||||
let distanceSource: GeoJSONSource | undefined = map_.getSource('distance-markers');
|
let distanceSource: GeoJSONSource | undefined = map_.getSource('distance-markers');
|
||||||
if (distanceSource) {
|
if (distanceSource) {
|
||||||
distanceSource.setData(this.getDistanceMarkersGeoJSON());
|
distanceSource.setData(this.getDistanceMarkersGeoJSON());
|
||||||
@@ -48,22 +44,33 @@ export class DistanceMarkers {
|
|||||||
data: this.getDistanceMarkersGeoJSON(),
|
data: this.getDistanceMarkersGeoJSON(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
stops.forEach(([d, minzoom, maxzoom]) => {
|
if (!map_.getLayer('distance-markers')) {
|
||||||
if (!map_.getLayer(`distance-markers-${d}`)) {
|
map_.addLayer(
|
||||||
map_.addLayer({
|
{
|
||||||
id: `distance-markers-${d}`,
|
id: 'distance-markers',
|
||||||
type: 'symbol',
|
type: 'symbol',
|
||||||
source: 'distance-markers',
|
source: 'distance-markers',
|
||||||
filter:
|
filter: [
|
||||||
d === 5
|
'match',
|
||||||
? [
|
['get', 'level'],
|
||||||
|
100,
|
||||||
|
['>=', ['zoom'], 0],
|
||||||
|
50,
|
||||||
|
['>=', ['zoom'], 7],
|
||||||
|
25,
|
||||||
|
[
|
||||||
'any',
|
'any',
|
||||||
['==', ['get', 'level'], 5],
|
['all', ['>=', ['zoom'], 8], ['<=', ['zoom'], 9]],
|
||||||
['==', ['get', 'level'], 25],
|
['>=', ['zoom'], 11],
|
||||||
]
|
],
|
||||||
: ['==', ['get', 'level'], d],
|
10,
|
||||||
minzoom: minzoom,
|
['>=', ['zoom'], 10],
|
||||||
maxzoom: maxzoom ?? 24,
|
5,
|
||||||
|
['>=', ['zoom'], 11],
|
||||||
|
1,
|
||||||
|
['>=', ['zoom'], 13],
|
||||||
|
false,
|
||||||
|
],
|
||||||
layout: {
|
layout: {
|
||||||
'text-field': ['get', 'distance'],
|
'text-field': ['get', 'distance'],
|
||||||
'text-size': 14,
|
'text-size': 14,
|
||||||
@@ -74,17 +81,14 @@ export class DistanceMarkers {
|
|||||||
'text-halo-width': 2,
|
'text-halo-width': 2,
|
||||||
'text-halo-color': 'white',
|
'text-halo-color': 'white',
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
} else {
|
ANCHOR_LAYER_KEY.distanceMarkers
|
||||||
map_.moveLayer(`distance-markers-${d}`);
|
);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
stops.forEach(([d]) => {
|
if (map_.getLayer('distance-markers')) {
|
||||||
if (map_.getLayer(`distance-markers-${d}`)) {
|
map_.removeLayer('distance-markers');
|
||||||
map_.removeLayer(`distance-markers-${d}`);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// No reliable way to check if the map is ready to add sources and layers
|
// No reliable way to check if the map is ready to add sources and layers
|
||||||
@@ -99,35 +103,26 @@ export class DistanceMarkers {
|
|||||||
getDistanceMarkersGeoJSON(): GeoJSON.FeatureCollection {
|
getDistanceMarkersGeoJSON(): GeoJSON.FeatureCollection {
|
||||||
let statistics = get(gpxStatistics);
|
let statistics = get(gpxStatistics);
|
||||||
|
|
||||||
let features = [];
|
let features: GeoJSON.Feature[] = [];
|
||||||
let currentTargetDistance = 1;
|
let currentTargetDistance = 1;
|
||||||
for (let i = 0; i < statistics.local.distance.total.length; i++) {
|
statistics.forEachTrackPoint((trkpt, dist) => {
|
||||||
if (
|
if (dist >= getConvertedDistanceToKilometers(currentTargetDistance)) {
|
||||||
statistics.local.distance.total[i] >=
|
|
||||||
getConvertedDistanceToKilometers(currentTargetDistance)
|
|
||||||
) {
|
|
||||||
let distance = currentTargetDistance.toFixed(0);
|
let distance = currentTargetDistance.toFixed(0);
|
||||||
let [level, minzoom] = stops.find(([d]) => currentTargetDistance % d === 0) ?? [
|
let level = levels.find((level) => currentTargetDistance % level === 0) || 1;
|
||||||
0, 0,
|
|
||||||
];
|
|
||||||
features.push({
|
features.push({
|
||||||
type: 'Feature',
|
type: 'Feature',
|
||||||
geometry: {
|
geometry: {
|
||||||
type: 'Point',
|
type: 'Point',
|
||||||
coordinates: [
|
coordinates: [trkpt.getLongitude(), trkpt.getLatitude()],
|
||||||
statistics.local.points[i].getLongitude(),
|
|
||||||
statistics.local.points[i].getLatitude(),
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
properties: {
|
properties: {
|
||||||
distance,
|
distance,
|
||||||
level,
|
level,
|
||||||
minzoom,
|
|
||||||
},
|
},
|
||||||
} as GeoJSON.Feature);
|
} as GeoJSON.Feature);
|
||||||
currentTargetDistance += 1;
|
currentTargetDistance += 1;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: 'FeatureCollection',
|
type: 'FeatureCollection',
|
||||||
|
|||||||
@@ -3,13 +3,14 @@ import { MapPopup } from '$lib/components/map/map-popup';
|
|||||||
export let waypointPopup: MapPopup | null = null;
|
export let waypointPopup: MapPopup | null = null;
|
||||||
export let trackpointPopup: MapPopup | null = null;
|
export let trackpointPopup: MapPopup | null = null;
|
||||||
|
|
||||||
export function createPopups(map: mapboxgl.Map) {
|
export function createPopups(map: maplibregl.Map) {
|
||||||
removePopups();
|
removePopups();
|
||||||
waypointPopup = new MapPopup(map, {
|
waypointPopup = new MapPopup(map, {
|
||||||
closeButton: false,
|
closeButton: false,
|
||||||
focusAfterOpen: false,
|
focusAfterOpen: false,
|
||||||
maxWidth: undefined,
|
maxWidth: undefined,
|
||||||
offset: {
|
offset: {
|
||||||
|
center: [0, 0],
|
||||||
top: [0, 0],
|
top: [0, 0],
|
||||||
'top-left': [0, 0],
|
'top-left': [0, 0],
|
||||||
'top-right': [0, 0],
|
'top-right': [0, 0],
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
import { get, type Readable } from 'svelte/store';
|
import { get, type Readable } from 'svelte/store';
|
||||||
import mapboxgl from 'mapbox-gl';
|
import maplibregl, {
|
||||||
|
type GeoJSONSource,
|
||||||
|
type FilterSpecification,
|
||||||
|
type MapLayerMouseEvent,
|
||||||
|
type MapLayerTouchEvent,
|
||||||
|
} from 'maplibre-gl';
|
||||||
import { map } from '$lib/components/map/map';
|
import { map } from '$lib/components/map/map';
|
||||||
import { waypointPopup, trackpointPopup } from './gpx-layer-popup';
|
import { waypointPopup, trackpointPopup } from './gpx-layer-popup';
|
||||||
import {
|
import {
|
||||||
@@ -10,7 +15,7 @@ import {
|
|||||||
ListFileItem,
|
ListFileItem,
|
||||||
ListRootItem,
|
ListRootItem,
|
||||||
} from '$lib/components/file-list/file-list';
|
} from '$lib/components/file-list/file-list';
|
||||||
import { getClosestLinePoint, getElevation } from '$lib/utils';
|
import { getClosestLinePoint, getElevation, loadSVGIcon } from '$lib/utils';
|
||||||
import { selectedWaypoint } from '$lib/components/toolbar/tools/waypoint/waypoint';
|
import { selectedWaypoint } from '$lib/components/toolbar/tools/waypoint/waypoint';
|
||||||
import { MapPin, Square } from 'lucide-static';
|
import { MapPin, Square } from 'lucide-static';
|
||||||
import { getSymbolKey, symbols } from '$lib/assets/symbols';
|
import { getSymbolKey, symbols } from '$lib/assets/symbols';
|
||||||
@@ -22,6 +27,8 @@ import { fileActionManager } from '$lib/logic/file-action-manager';
|
|||||||
import { fileActions } from '$lib/logic/file-actions';
|
import { fileActions } from '$lib/logic/file-actions';
|
||||||
import { splitAs } from '$lib/components/toolbar/tools/scissors/scissors';
|
import { splitAs } from '$lib/components/toolbar/tools/scissors/scissors';
|
||||||
import { mapCursor, MapCursorState } from '$lib/logic/map-cursor';
|
import { mapCursor, MapCursorState } from '$lib/logic/map-cursor';
|
||||||
|
import { ANCHOR_LAYER_KEY } from '$lib/components/map/style';
|
||||||
|
import { gpxColors } from './gpx-layers';
|
||||||
|
|
||||||
const colors = [
|
const colors = [
|
||||||
'#ff0000',
|
'#ff0000',
|
||||||
@@ -43,26 +50,49 @@ for (let color of colors) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the color with the least amount of uses
|
// Get the color with the least amount of uses
|
||||||
function getColor() {
|
function getColor(fileId: string) {
|
||||||
let color = colors.reduce((a, b) => (colorCount[a] <= colorCount[b] ? a : b));
|
let color = colors.reduce((a, b) => (colorCount[a] <= colorCount[b] ? a : b));
|
||||||
colorCount[color]++;
|
colorCount[color]++;
|
||||||
|
gpxColors.update((colors) => {
|
||||||
|
colors.set(fileId, color);
|
||||||
|
return colors;
|
||||||
|
});
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
function decrementColor(color: string) {
|
function replaceColor(fileId: string, oldColor: string, newColor: string) {
|
||||||
|
if (colorCount.hasOwnProperty(oldColor)) {
|
||||||
|
colorCount[oldColor]--;
|
||||||
|
}
|
||||||
|
colorCount[newColor]++;
|
||||||
|
gpxColors.update((colors) => {
|
||||||
|
colors.set(fileId, newColor);
|
||||||
|
return colors;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeColor(fileId: string, color: string) {
|
||||||
if (colorCount.hasOwnProperty(color)) {
|
if (colorCount.hasOwnProperty(color)) {
|
||||||
colorCount[color]--;
|
colorCount[color]--;
|
||||||
}
|
}
|
||||||
|
gpxColors.update((colors) => {
|
||||||
|
colors.delete(fileId);
|
||||||
|
return colors;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMarkerForSymbol(symbol: string | undefined, layerColor: string) {
|
export function getSvgForSymbol(symbol?: string | undefined, layerColor?: string | undefined) {
|
||||||
let symbolSvg = symbol ? symbols[symbol]?.iconSvg : undefined;
|
let symbolSvg = symbol ? symbols[symbol]?.iconSvg : undefined;
|
||||||
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||||
${Square.replace('width="24"', 'width="12"')
|
${
|
||||||
|
layerColor
|
||||||
|
? Square.replace('width="24"', 'width="12"')
|
||||||
.replace('height="24"', 'height="12"')
|
.replace('height="24"', 'height="12"')
|
||||||
.replace('stroke="currentColor"', 'stroke="SteelBlue"')
|
.replace('stroke="currentColor"', 'stroke="SteelBlue"')
|
||||||
.replace('stroke-width="2"', 'stroke-width="1.5" x="9.6" y="0.4"')
|
.replace('stroke-width="2"', 'stroke-width="1.5" x="9.6" y="0.4"')
|
||||||
.replace('fill="none"', `fill="${layerColor}"`)}
|
.replace('fill="none"', `fill="${layerColor}"`)
|
||||||
|
: ''
|
||||||
|
}
|
||||||
${MapPin.replace('width="24"', '')
|
${MapPin.replace('width="24"', '')
|
||||||
.replace('height="24"', '')
|
.replace('height="24"', '')
|
||||||
.replace('stroke="currentColor"', '')
|
.replace('stroke="currentColor"', '')
|
||||||
@@ -87,26 +117,41 @@ export class GPXLayer {
|
|||||||
fileId: string;
|
fileId: string;
|
||||||
file: Readable<GPXFileWithStatistics | undefined>;
|
file: Readable<GPXFileWithStatistics | undefined>;
|
||||||
layerColor: string;
|
layerColor: string;
|
||||||
markers: mapboxgl.Marker[] = [];
|
|
||||||
selected: boolean = false;
|
selected: boolean = false;
|
||||||
draggable: boolean;
|
currentWaypointData: GeoJSON.FeatureCollection | null = null;
|
||||||
|
draggedWaypointIndex: number | null = null;
|
||||||
|
draggingStartingPosition: maplibregl.Point = new maplibregl.Point(0, 0);
|
||||||
unsubscribe: Function[] = [];
|
unsubscribe: Function[] = [];
|
||||||
|
|
||||||
updateBinded: () => void = this.update.bind(this);
|
updateBinded: () => void = this.update.bind(this);
|
||||||
layerOnMouseEnterBinded: (e: any) => void = this.layerOnMouseEnter.bind(this);
|
layerOnMouseEnterBinded: (e: any) => void = this.layerOnMouseEnter.bind(this);
|
||||||
layerOnMouseLeaveBinded: () => void = this.layerOnMouseLeave.bind(this);
|
layerOnMouseLeaveBinded: () => void = this.layerOnMouseLeave.bind(this);
|
||||||
layerOnMouseMoveBinded: (e: any) => void = this.layerOnMouseMove.bind(this);
|
layerOnMouseMoveBinded: (e: any) => void = this.layerOnMouseMove.bind(this);
|
||||||
layerOnClickBinded: (e: any) => void = this.layerOnClick.bind(this);
|
layerOnClickBinded: (e: MapLayerMouseEvent) => void = this.layerOnClick.bind(this);
|
||||||
layerOnContextMenuBinded: (e: any) => void = this.layerOnContextMenu.bind(this);
|
layerOnContextMenuBinded: (e: MapLayerMouseEvent) => void = this.layerOnContextMenu.bind(this);
|
||||||
|
waypointLayerOnMouseEnterBinded: (e: MapLayerMouseEvent) => void =
|
||||||
|
this.waypointLayerOnMouseEnter.bind(this);
|
||||||
|
waypointLayerOnMouseLeaveBinded: (e: MapLayerMouseEvent) => void =
|
||||||
|
this.waypointLayerOnMouseLeave.bind(this);
|
||||||
|
waypointLayerOnClickBinded: (e: MapLayerMouseEvent) => void =
|
||||||
|
this.waypointLayerOnClick.bind(this);
|
||||||
|
waypointLayerOnMouseDownBinded: (e: MapLayerMouseEvent) => void =
|
||||||
|
this.waypointLayerOnMouseDown.bind(this);
|
||||||
|
waypointLayerOnTouchStartBinded: (e: MapLayerTouchEvent) => void =
|
||||||
|
this.waypointLayerOnTouchStart.bind(this);
|
||||||
|
waypointLayerOnMouseMoveBinded: (e: MapLayerMouseEvent | MapLayerTouchEvent) => void =
|
||||||
|
this.waypointLayerOnMouseMove.bind(this);
|
||||||
|
waypointLayerOnMouseUpBinded: (e: MapLayerMouseEvent | MapLayerTouchEvent) => void =
|
||||||
|
this.waypointLayerOnMouseUp.bind(this);
|
||||||
|
|
||||||
constructor(fileId: string, file: Readable<GPXFileWithStatistics | undefined>) {
|
constructor(fileId: string, file: Readable<GPXFileWithStatistics | undefined>) {
|
||||||
this.fileId = fileId;
|
this.fileId = fileId;
|
||||||
this.file = file;
|
this.file = file;
|
||||||
this.layerColor = getColor();
|
this.layerColor = getColor(fileId);
|
||||||
this.unsubscribe.push(
|
this.unsubscribe.push(
|
||||||
map.subscribe(($map) => {
|
map.subscribe(($map) => {
|
||||||
if ($map) {
|
if ($map) {
|
||||||
$map.on('style.import.load', this.updateBinded);
|
$map.on('style.load', this.updateBinded);
|
||||||
this.update();
|
this.update();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -125,24 +170,13 @@ export class GPXLayer {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
this.unsubscribe.push(directionMarkers.subscribe(this.updateBinded));
|
this.unsubscribe.push(directionMarkers.subscribe(this.updateBinded));
|
||||||
this.unsubscribe.push(
|
|
||||||
currentTool.subscribe((tool) => {
|
|
||||||
if (tool === Tool.WAYPOINT && !this.draggable) {
|
|
||||||
this.draggable = true;
|
|
||||||
this.markers.forEach((marker) => marker.setDraggable(true));
|
|
||||||
} else if (tool !== Tool.WAYPOINT && this.draggable) {
|
|
||||||
this.draggable = false;
|
|
||||||
this.markers.forEach((marker) => marker.setDraggable(false));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
this.draggable = get(currentTool) === Tool.WAYPOINT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
const _map = get(map);
|
const _map = get(map);
|
||||||
|
const layerEventManager = map.layerEventManager;
|
||||||
let file = get(this.file)?.file;
|
let file = get(this.file)?.file;
|
||||||
if (!_map || !file) {
|
if (!_map || !layerEventManager || !file) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,12 +185,14 @@ export class GPXLayer {
|
|||||||
file._data.style.color &&
|
file._data.style.color &&
|
||||||
this.layerColor !== `#${file._data.style.color}`
|
this.layerColor !== `#${file._data.style.color}`
|
||||||
) {
|
) {
|
||||||
decrementColor(this.layerColor);
|
replaceColor(this.fileId, this.layerColor, `#${file._data.style.color}`);
|
||||||
this.layerColor = `#${file._data.style.color}`;
|
this.layerColor = `#${file._data.style.color}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.loadIcons();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let source = _map.getSource(this.fileId);
|
let source = _map.getSource(this.fileId) as GeoJSONSource | undefined;
|
||||||
if (source) {
|
if (source) {
|
||||||
source.setData(this.getGeoJSON());
|
source.setData(this.getGeoJSON());
|
||||||
} else {
|
} else {
|
||||||
@@ -167,7 +203,8 @@ export class GPXLayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!_map.getLayer(this.fileId)) {
|
if (!_map.getLayer(this.fileId)) {
|
||||||
_map.addLayer({
|
_map.addLayer(
|
||||||
|
{
|
||||||
id: this.fileId,
|
id: this.fileId,
|
||||||
type: 'line',
|
type: 'line',
|
||||||
source: this.fileId,
|
source: this.fileId,
|
||||||
@@ -180,15 +217,31 @@ export class GPXLayer {
|
|||||||
'line-width': ['get', 'width'],
|
'line-width': ['get', 'width'],
|
||||||
'line-opacity': ['get', 'opacity'],
|
'line-opacity': ['get', 'opacity'],
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
|
ANCHOR_LAYER_KEY.tracks
|
||||||
|
);
|
||||||
|
|
||||||
_map.on('click', this.fileId, this.layerOnClickBinded);
|
layerEventManager.on('click', this.fileId, this.layerOnClickBinded);
|
||||||
_map.on('contextmenu', this.fileId, this.layerOnContextMenuBinded);
|
layerEventManager.on('contextmenu', this.fileId, this.layerOnContextMenuBinded);
|
||||||
_map.on('mouseenter', this.fileId, this.layerOnMouseEnterBinded);
|
layerEventManager.on('mouseenter', this.fileId, this.layerOnMouseEnterBinded);
|
||||||
_map.on('mouseleave', this.fileId, this.layerOnMouseLeaveBinded);
|
layerEventManager.on('mouseleave', this.fileId, this.layerOnMouseLeaveBinded);
|
||||||
_map.on('mousemove', this.fileId, this.layerOnMouseMoveBinded);
|
layerEventManager.on('mousemove', this.fileId, this.layerOnMouseMoveBinded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let visibleTrackSegmentIds: string[] = [];
|
||||||
|
file.forEachSegment((segment, trackIndex, segmentIndex) => {
|
||||||
|
if (!segment._data.hidden) {
|
||||||
|
visibleTrackSegmentIds.push(`${trackIndex}-${segmentIndex}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const segmentFilter: FilterSpecification = [
|
||||||
|
'in',
|
||||||
|
['get', 'trackSegmentId'],
|
||||||
|
['literal', visibleTrackSegmentIds],
|
||||||
|
];
|
||||||
|
|
||||||
|
_map.setFilter(this.fileId, segmentFilter, { validate: false });
|
||||||
|
|
||||||
if (get(directionMarkers)) {
|
if (get(directionMarkers)) {
|
||||||
if (!_map.getLayer(this.fileId + '-direction')) {
|
if (!_map.getLayer(this.fileId + '-direction')) {
|
||||||
_map.addLayer(
|
_map.addLayer(
|
||||||
@@ -213,172 +266,136 @@ export class GPXLayer {
|
|||||||
'text-halo-color': 'white',
|
'text-halo-color': 'white',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
_map.getLayer('distance-markers') ? 'distance-markers' : undefined
|
ANCHOR_LAYER_KEY.directionMarkers
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_map.setFilter(this.fileId + '-direction', segmentFilter, { validate: false });
|
||||||
} else {
|
} else {
|
||||||
if (_map.getLayer(this.fileId + '-direction')) {
|
if (_map.getLayer(this.fileId + '-direction')) {
|
||||||
_map.removeLayer(this.fileId + '-direction');
|
_map.removeLayer(this.fileId + '-direction');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let visibleItems: [number, number][] = [];
|
let waypointSource = _map.getSource(this.fileId + '-waypoints') as
|
||||||
file.forEachSegment((segment, trackIndex, segmentIndex) => {
|
| GeoJSONSource
|
||||||
if (!segment._data.hidden) {
|
| undefined;
|
||||||
visibleItems.push([trackIndex, segmentIndex]);
|
this.currentWaypointData = this.getWaypointsGeoJSON();
|
||||||
|
if (waypointSource) {
|
||||||
|
waypointSource.setData(this.currentWaypointData);
|
||||||
|
} else {
|
||||||
|
_map.addSource(this.fileId + '-waypoints', {
|
||||||
|
type: 'geojson',
|
||||||
|
data: this.currentWaypointData,
|
||||||
|
promoteId: 'waypointIndex',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_map.getLayer(this.fileId + '-waypoints')) {
|
||||||
|
_map.addLayer(
|
||||||
|
{
|
||||||
|
id: this.fileId + '-waypoints',
|
||||||
|
type: 'symbol',
|
||||||
|
source: this.fileId + '-waypoints',
|
||||||
|
layout: {
|
||||||
|
'icon-image': ['get', 'icon'],
|
||||||
|
'icon-size': 0.3,
|
||||||
|
'icon-anchor': 'bottom',
|
||||||
|
'icon-padding': 0,
|
||||||
|
'icon-allow-overlap': true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ANCHOR_LAYER_KEY.waypoints
|
||||||
|
);
|
||||||
|
|
||||||
|
layerEventManager.on(
|
||||||
|
'mouseenter',
|
||||||
|
this.fileId + '-waypoints',
|
||||||
|
this.waypointLayerOnMouseEnterBinded
|
||||||
|
);
|
||||||
|
layerEventManager.on(
|
||||||
|
'mouseleave',
|
||||||
|
this.fileId + '-waypoints',
|
||||||
|
this.waypointLayerOnMouseLeaveBinded
|
||||||
|
);
|
||||||
|
layerEventManager.on(
|
||||||
|
'click',
|
||||||
|
this.fileId + '-waypoints',
|
||||||
|
this.waypointLayerOnClickBinded
|
||||||
|
);
|
||||||
|
layerEventManager.on(
|
||||||
|
'mousedown',
|
||||||
|
this.fileId + '-waypoints',
|
||||||
|
this.waypointLayerOnMouseDownBinded
|
||||||
|
);
|
||||||
|
layerEventManager.on(
|
||||||
|
'touchstart',
|
||||||
|
this.fileId + '-waypoints',
|
||||||
|
this.waypointLayerOnTouchStartBinded
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let visibleWaypoints: number[] = [];
|
||||||
|
file.wpt.forEach((waypoint, waypointIndex) => {
|
||||||
|
if (!waypoint._data.hidden) {
|
||||||
|
visibleWaypoints.push(waypointIndex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_map.setFilter(
|
_map.setFilter(
|
||||||
this.fileId,
|
this.fileId + '-waypoints',
|
||||||
[
|
['in', ['get', 'waypointIndex'], ['literal', visibleWaypoints]],
|
||||||
'any',
|
|
||||||
...visibleItems.map(([trackIndex, segmentIndex]) => [
|
|
||||||
'all',
|
|
||||||
['==', 'trackIndex', trackIndex],
|
|
||||||
['==', 'segmentIndex', segmentIndex],
|
|
||||||
]),
|
|
||||||
],
|
|
||||||
{ validate: false }
|
{ validate: false }
|
||||||
);
|
);
|
||||||
if (_map.getLayer(this.fileId + '-direction')) {
|
|
||||||
_map.setFilter(
|
|
||||||
this.fileId + '-direction',
|
|
||||||
[
|
|
||||||
'any',
|
|
||||||
...visibleItems.map(([trackIndex, segmentIndex]) => [
|
|
||||||
'all',
|
|
||||||
['==', 'trackIndex', trackIndex],
|
|
||||||
['==', 'segmentIndex', segmentIndex],
|
|
||||||
]),
|
|
||||||
],
|
|
||||||
{ validate: false }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// No reliable way to check if the map is ready to add sources and layers
|
// No reliable way to check if the map is ready to add sources and layers
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let markerIndex = 0;
|
|
||||||
|
|
||||||
if (get(selection).hasAnyChildren(new ListFileItem(this.fileId))) {
|
|
||||||
file.wpt.forEach((waypoint) => {
|
|
||||||
// Update markers
|
|
||||||
let symbolKey = getSymbolKey(waypoint.sym);
|
|
||||||
if (markerIndex < this.markers.length) {
|
|
||||||
this.markers[markerIndex].getElement().innerHTML = getMarkerForSymbol(
|
|
||||||
symbolKey,
|
|
||||||
this.layerColor
|
|
||||||
);
|
|
||||||
this.markers[markerIndex].setLngLat(waypoint.getCoordinates());
|
|
||||||
Object.defineProperty(this.markers[markerIndex], '_waypoint', {
|
|
||||||
value: waypoint,
|
|
||||||
writable: true,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
let element = document.createElement('div');
|
|
||||||
element.classList.add('w-8', 'h-8', 'drop-shadow-xl');
|
|
||||||
element.innerHTML = getMarkerForSymbol(symbolKey, this.layerColor);
|
|
||||||
let marker = new mapboxgl.Marker({
|
|
||||||
draggable: this.draggable,
|
|
||||||
element,
|
|
||||||
anchor: 'bottom',
|
|
||||||
}).setLngLat(waypoint.getCoordinates());
|
|
||||||
Object.defineProperty(marker, '_waypoint', { value: waypoint, writable: true });
|
|
||||||
let dragEndTimestamp = 0;
|
|
||||||
marker.getElement().addEventListener('mousemove', (e) => {
|
|
||||||
if (marker._isDragging) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
waypointPopup?.setItem({ item: marker._waypoint, fileId: this.fileId });
|
|
||||||
e.stopPropagation();
|
|
||||||
});
|
|
||||||
marker.getElement().addEventListener('click', (e) => {
|
|
||||||
if (dragEndTimestamp && Date.now() - dragEndTimestamp < 1000) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (get(currentTool) === Tool.WAYPOINT && e.shiftKey) {
|
|
||||||
fileActions.deleteWaypoint(this.fileId, marker._waypoint._data.index);
|
|
||||||
e.stopPropagation();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (get(treeFileView)) {
|
|
||||||
if (
|
|
||||||
(e.ctrlKey || e.metaKey) &&
|
|
||||||
get(selection).hasAnyChildren(
|
|
||||||
new ListWaypointsItem(this.fileId),
|
|
||||||
false
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
selection.addSelectItem(
|
|
||||||
new ListWaypointItem(this.fileId, marker._waypoint._data.index)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
selection.selectItem(
|
|
||||||
new ListWaypointItem(this.fileId, marker._waypoint._data.index)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else if (get(currentTool) === Tool.WAYPOINT) {
|
|
||||||
selectedWaypoint.set([marker._waypoint, this.fileId]);
|
|
||||||
} else {
|
|
||||||
waypointPopup?.setItem({ item: marker._waypoint, fileId: this.fileId });
|
|
||||||
}
|
|
||||||
e.stopPropagation();
|
|
||||||
});
|
|
||||||
marker.on('dragstart', () => {
|
|
||||||
mapCursor.notify(MapCursorState.WAYPOINT_DRAGGING, true);
|
|
||||||
marker.getElement().style.cursor = 'grabbing';
|
|
||||||
waypointPopup?.hide();
|
|
||||||
});
|
|
||||||
marker.on('dragend', (e) => {
|
|
||||||
mapCursor.notify(MapCursorState.WAYPOINT_DRAGGING, false);
|
|
||||||
marker.getElement().style.cursor = '';
|
|
||||||
getElevation([marker._waypoint]).then((ele) => {
|
|
||||||
fileActionManager.applyToFile(this.fileId, (file) => {
|
|
||||||
let latLng = marker.getLngLat();
|
|
||||||
let wpt = file.wpt[marker._waypoint._data.index];
|
|
||||||
wpt.setCoordinates({
|
|
||||||
lat: latLng.lat,
|
|
||||||
lon: latLng.lng,
|
|
||||||
});
|
|
||||||
wpt.ele = ele[0];
|
|
||||||
});
|
|
||||||
});
|
|
||||||
dragEndTimestamp = Date.now();
|
|
||||||
});
|
|
||||||
this.markers.push(marker);
|
|
||||||
}
|
|
||||||
markerIndex++;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
while (markerIndex < this.markers.length) {
|
|
||||||
// Remove extra markers
|
|
||||||
this.markers.pop()?.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.markers.forEach((marker) => {
|
|
||||||
if (!marker._waypoint._data.hidden) {
|
|
||||||
marker.addTo(_map);
|
|
||||||
} else {
|
|
||||||
marker.remove();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
remove() {
|
remove() {
|
||||||
const _map = get(map);
|
const _map = get(map);
|
||||||
if (_map) {
|
|
||||||
_map.off('click', this.fileId, this.layerOnClickBinded);
|
|
||||||
_map.off('contextmenu', this.fileId, this.layerOnContextMenuBinded);
|
|
||||||
_map.off('mouseenter', this.fileId, this.layerOnMouseEnterBinded);
|
|
||||||
_map.off('mouseleave', this.fileId, this.layerOnMouseLeaveBinded);
|
|
||||||
_map.off('mousemove', this.fileId, this.layerOnMouseMoveBinded);
|
|
||||||
_map.off('style.import.load', this.updateBinded);
|
|
||||||
|
|
||||||
|
if (_map) {
|
||||||
|
_map.off('style.load', this.updateBinded);
|
||||||
|
}
|
||||||
|
|
||||||
|
const layerEventManager = map.layerEventManager;
|
||||||
|
if (layerEventManager) {
|
||||||
|
layerEventManager.off('click', this.fileId, this.layerOnClickBinded);
|
||||||
|
layerEventManager.off('contextmenu', this.fileId, this.layerOnContextMenuBinded);
|
||||||
|
layerEventManager.off('mouseenter', this.fileId, this.layerOnMouseEnterBinded);
|
||||||
|
layerEventManager.off('mouseleave', this.fileId, this.layerOnMouseLeaveBinded);
|
||||||
|
layerEventManager.off('mousemove', this.fileId, this.layerOnMouseMoveBinded);
|
||||||
|
|
||||||
|
layerEventManager.off(
|
||||||
|
'mouseenter',
|
||||||
|
this.fileId + '-waypoints',
|
||||||
|
this.waypointLayerOnMouseEnterBinded
|
||||||
|
);
|
||||||
|
layerEventManager.off(
|
||||||
|
'mouseleave',
|
||||||
|
this.fileId + '-waypoints',
|
||||||
|
this.waypointLayerOnMouseLeaveBinded
|
||||||
|
);
|
||||||
|
layerEventManager.off(
|
||||||
|
'click',
|
||||||
|
this.fileId + '-waypoints',
|
||||||
|
this.waypointLayerOnClickBinded
|
||||||
|
);
|
||||||
|
layerEventManager.off(
|
||||||
|
'mousedown',
|
||||||
|
this.fileId + '-waypoints',
|
||||||
|
this.waypointLayerOnMouseDownBinded
|
||||||
|
);
|
||||||
|
layerEventManager.off(
|
||||||
|
'touchstart',
|
||||||
|
this.fileId + '-waypoints',
|
||||||
|
this.waypointLayerOnTouchStartBinded
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_map) {
|
||||||
if (_map.getLayer(this.fileId + '-direction')) {
|
if (_map.getLayer(this.fileId + '-direction')) {
|
||||||
_map.removeLayer(this.fileId + '-direction');
|
_map.removeLayer(this.fileId + '-direction');
|
||||||
}
|
}
|
||||||
@@ -388,15 +405,17 @@ export class GPXLayer {
|
|||||||
if (_map.getSource(this.fileId)) {
|
if (_map.getSource(this.fileId)) {
|
||||||
_map.removeSource(this.fileId);
|
_map.removeSource(this.fileId);
|
||||||
}
|
}
|
||||||
|
if (_map.getLayer(this.fileId + '-waypoints')) {
|
||||||
|
_map.removeLayer(this.fileId + '-waypoints');
|
||||||
|
}
|
||||||
|
if (_map.getSource(this.fileId + '-waypoints')) {
|
||||||
|
_map.removeSource(this.fileId + '-waypoints');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.markers.forEach((marker) => {
|
|
||||||
marker.remove();
|
|
||||||
});
|
|
||||||
|
|
||||||
this.unsubscribe.forEach((unsubscribe) => unsubscribe());
|
this.unsubscribe.forEach((unsubscribe) => unsubscribe());
|
||||||
|
|
||||||
decrementColor(this.layerColor);
|
removeColor(this.fileId, this.layerColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
moveToFront() {
|
moveToFront() {
|
||||||
@@ -405,13 +424,13 @@ export class GPXLayer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_map.getLayer(this.fileId)) {
|
if (_map.getLayer(this.fileId)) {
|
||||||
_map.moveLayer(this.fileId);
|
_map.moveLayer(this.fileId, ANCHOR_LAYER_KEY.tracks);
|
||||||
|
}
|
||||||
|
if (_map.getLayer(this.fileId + '-waypoints')) {
|
||||||
|
_map.moveLayer(this.fileId + '-waypoints', ANCHOR_LAYER_KEY.waypoints);
|
||||||
}
|
}
|
||||||
if (_map.getLayer(this.fileId + '-direction')) {
|
if (_map.getLayer(this.fileId + '-direction')) {
|
||||||
_map.moveLayer(
|
_map.moveLayer(this.fileId + '-direction', ANCHOR_LAYER_KEY.directionMarkers);
|
||||||
this.fileId + '-direction',
|
|
||||||
_map.getLayer('distance-markers') ? 'distance-markers' : undefined
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -452,7 +471,7 @@ export class GPXLayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
layerOnClick(e: any) {
|
layerOnClick(e: MapLayerMouseEvent) {
|
||||||
if (
|
if (
|
||||||
get(currentTool) === Tool.ROUTING &&
|
get(currentTool) === Tool.ROUTING &&
|
||||||
get(selection).hasAnyChildren(new ListRootItem(), true, ['waypoints'])
|
get(selection).hasAnyChildren(new ListRootItem(), true, ['waypoints'])
|
||||||
@@ -460,8 +479,8 @@ export class GPXLayer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let trackIndex = e.features[0].properties.trackIndex;
|
let trackIndex = e.features![0].properties!.trackIndex;
|
||||||
let segmentIndex = e.features[0].properties.segmentIndex;
|
let segmentIndex = e.features![0].properties!.segmentIndex;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
get(currentTool) === Tool.SCISSORS &&
|
get(currentTool) === Tool.SCISSORS &&
|
||||||
@@ -469,6 +488,11 @@ export class GPXLayer {
|
|||||||
new ListTrackSegmentItem(this.fileId, trackIndex, segmentIndex)
|
new ListTrackSegmentItem(this.fileId, trackIndex, segmentIndex)
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
|
if (get(map)?.queryRenderedFeatures(e.point, { layers: ['split-controls'] }).length) {
|
||||||
|
// Clicked on split control, ignoring
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
fileActions.split(get(splitAs), this.fileId, trackIndex, segmentIndex, {
|
fileActions.split(get(splitAs), this.fileId, trackIndex, segmentIndex, {
|
||||||
lat: e.lngLat.lat,
|
lat: e.lngLat.lat,
|
||||||
lon: e.lngLat.lng,
|
lon: e.lngLat.lng,
|
||||||
@@ -505,6 +529,179 @@ export class GPXLayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
waypointLayerOnMouseEnter(e: MapLayerMouseEvent) {
|
||||||
|
if (this.draggedWaypointIndex !== null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let file = get(this.file)?.file;
|
||||||
|
if (!file) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let waypointIndex = e.features![0].properties!.waypointIndex;
|
||||||
|
let waypoint = file.wpt[waypointIndex];
|
||||||
|
waypointPopup?.setItem({ item: waypoint, fileId: this.fileId });
|
||||||
|
|
||||||
|
mapCursor.notify(MapCursorState.WAYPOINT_HOVER, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
waypointLayerOnMouseLeave() {
|
||||||
|
mapCursor.notify(MapCursorState.WAYPOINT_HOVER, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
waypointLayerOnClick(e: MapLayerMouseEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
let waypointIndex = e.features![0].properties!.waypointIndex;
|
||||||
|
let file = get(this.file)?.file;
|
||||||
|
if (!file) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let waypoint = file.wpt[waypointIndex];
|
||||||
|
if (get(currentTool) === Tool.WAYPOINT) {
|
||||||
|
if (this.selected) {
|
||||||
|
if (e.originalEvent.shiftKey) {
|
||||||
|
fileActions.deleteWaypoint(this.fileId, waypointIndex);
|
||||||
|
} else {
|
||||||
|
selection.selectItem(new ListWaypointItem(this.fileId, waypointIndex));
|
||||||
|
selectedWaypoint.set([waypoint, this.fileId]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (get(treeFileView)) {
|
||||||
|
selection.selectItem(new ListWaypointItem(this.fileId, waypointIndex));
|
||||||
|
} else {
|
||||||
|
selection.selectItem(new ListFileItem(this.fileId));
|
||||||
|
}
|
||||||
|
selectedWaypoint.set([waypoint, this.fileId]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (get(treeFileView)) {
|
||||||
|
if ((e.originalEvent.ctrlKey || e.originalEvent.metaKey) && this.selected) {
|
||||||
|
selection.addSelectItem(new ListWaypointItem(this.fileId, waypointIndex));
|
||||||
|
} else {
|
||||||
|
selection.selectItem(new ListWaypointItem(this.fileId, waypointIndex));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!this.selected) {
|
||||||
|
selection.selectItem(new ListFileItem(this.fileId));
|
||||||
|
}
|
||||||
|
waypointPopup?.setItem({ item: waypoint, fileId: this.fileId });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
waypointLayerOnMouseDown(e: MapLayerMouseEvent) {
|
||||||
|
if (get(currentTool) !== Tool.WAYPOINT || !this.selected) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const _map = get(map);
|
||||||
|
if (!_map) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
_map.dragPan.disable();
|
||||||
|
|
||||||
|
this.draggedWaypointIndex = e.features![0].properties!.waypointIndex;
|
||||||
|
this.draggingStartingPosition = e.point;
|
||||||
|
waypointPopup?.hide();
|
||||||
|
|
||||||
|
_map.on('mousemove', this.waypointLayerOnMouseMoveBinded);
|
||||||
|
_map.once('mouseup', this.waypointLayerOnMouseUpBinded);
|
||||||
|
}
|
||||||
|
|
||||||
|
waypointLayerOnTouchStart(e: MapLayerTouchEvent) {
|
||||||
|
if (e.points.length !== 1 || get(currentTool) !== Tool.WAYPOINT || !this.selected) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const _map = get(map);
|
||||||
|
if (!_map) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.draggedWaypointIndex = e.features![0].properties!.waypointIndex;
|
||||||
|
this.draggingStartingPosition = e.point;
|
||||||
|
waypointPopup?.hide();
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
_map.dragPan.disable();
|
||||||
|
|
||||||
|
_map.on('touchmove', this.waypointLayerOnMouseMoveBinded);
|
||||||
|
_map.once('touchend', this.waypointLayerOnMouseUpBinded);
|
||||||
|
}
|
||||||
|
|
||||||
|
waypointLayerOnMouseMove(e: MapLayerMouseEvent | MapLayerTouchEvent) {
|
||||||
|
if (this.draggedWaypointIndex === null || e.point.equals(this.draggingStartingPosition)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mapCursor.notify(MapCursorState.WAYPOINT_DRAGGING, true);
|
||||||
|
|
||||||
|
(
|
||||||
|
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
|
||||||
|
| GeoJSONSource
|
||||||
|
| undefined;
|
||||||
|
if (waypointSource) {
|
||||||
|
waypointSource.updateData({
|
||||||
|
update: [
|
||||||
|
{
|
||||||
|
id: this.draggedWaypointIndex,
|
||||||
|
newGeometry: {
|
||||||
|
type: 'Point',
|
||||||
|
coordinates: [e.lngLat.lng, e.lngLat.lat],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
waypointLayerOnMouseUp(e: MapLayerMouseEvent | MapLayerTouchEvent) {
|
||||||
|
mapCursor.notify(MapCursorState.WAYPOINT_DRAGGING, false);
|
||||||
|
|
||||||
|
const _map = get(map);
|
||||||
|
if (!_map) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_map.dragPan.enable();
|
||||||
|
|
||||||
|
_map.off('mousemove', this.waypointLayerOnMouseMoveBinded);
|
||||||
|
_map.off('touchmove', this.waypointLayerOnMouseMoveBinded);
|
||||||
|
|
||||||
|
if (this.draggedWaypointIndex === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (e.point.equals(this.draggingStartingPosition)) {
|
||||||
|
this.draggedWaypointIndex = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
getElevation([
|
||||||
|
{
|
||||||
|
lat: e.lngLat.lat,
|
||||||
|
lon: e.lngLat.lng,
|
||||||
|
},
|
||||||
|
]).then((ele) => {
|
||||||
|
if (this.draggedWaypointIndex === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fileActionManager.applyToFile(this.fileId, (file) => {
|
||||||
|
let wpt = file.wpt[this.draggedWaypointIndex!];
|
||||||
|
wpt.setCoordinates({
|
||||||
|
lat: e.lngLat.lat,
|
||||||
|
lon: e.lngLat.lng,
|
||||||
|
});
|
||||||
|
wpt.ele = ele[0];
|
||||||
|
});
|
||||||
|
this.draggedWaypointIndex = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
getGeoJSON(): GeoJSON.FeatureCollection {
|
getGeoJSON(): GeoJSON.FeatureCollection {
|
||||||
let file = get(this.file)?.file;
|
let file = get(this.file)?.file;
|
||||||
if (!file) {
|
if (!file) {
|
||||||
@@ -542,6 +739,7 @@ export class GPXLayer {
|
|||||||
}
|
}
|
||||||
feature.properties.trackIndex = trackIndex;
|
feature.properties.trackIndex = trackIndex;
|
||||||
feature.properties.segmentIndex = segmentIndex;
|
feature.properties.segmentIndex = segmentIndex;
|
||||||
|
feature.properties.trackSegmentId = `${trackIndex}-${segmentIndex}`;
|
||||||
|
|
||||||
segmentIndex++;
|
segmentIndex++;
|
||||||
if (segmentIndex >= file.trk[trackIndex].trkseg.length) {
|
if (segmentIndex >= file.trk[trackIndex].trkseg.length) {
|
||||||
@@ -551,4 +749,52 @@ export class GPXLayer {
|
|||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getWaypointsGeoJSON(): GeoJSON.FeatureCollection {
|
||||||
|
let file = get(this.file)?.file;
|
||||||
|
|
||||||
|
let data: GeoJSON.FeatureCollection = {
|
||||||
|
type: 'FeatureCollection',
|
||||||
|
features: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!file) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
file.wpt.forEach((waypoint, index) => {
|
||||||
|
data.features.push({
|
||||||
|
type: 'Feature',
|
||||||
|
geometry: {
|
||||||
|
type: 'Point',
|
||||||
|
coordinates: [waypoint.getLongitude(), waypoint.getLatitude()],
|
||||||
|
},
|
||||||
|
properties: {
|
||||||
|
fileId: this.fileId,
|
||||||
|
waypointIndex: index,
|
||||||
|
icon: `waypoint-${getSymbolKey(waypoint.sym) ?? 'default'}-${this.layerColor}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
loadIcons() {
|
||||||
|
const _map = get(map);
|
||||||
|
let file = get(this.file)?.file;
|
||||||
|
if (!_map || !file) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let symbols = new Set<string | undefined>();
|
||||||
|
file.wpt.forEach((waypoint) => {
|
||||||
|
symbols.add(getSymbolKey(waypoint.sym));
|
||||||
|
});
|
||||||
|
|
||||||
|
symbols.forEach((symbol) => {
|
||||||
|
const iconId = `waypoint-${symbol ?? 'default'}-${this.layerColor}`;
|
||||||
|
loadSVGIcon(_map, iconId, getSvgForSymbol(symbol, this.layerColor));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { GPXFileStateCollectionObserver } from '$lib/logic/file-state';
|
import { GPXFileStateCollectionObserver } from '$lib/logic/file-state';
|
||||||
|
import { writable } from 'svelte/store';
|
||||||
import { GPXLayer } from './gpx-layer';
|
import { GPXLayer } from './gpx-layer';
|
||||||
|
|
||||||
export class GPXLayerCollection {
|
export class GPXLayerCollection {
|
||||||
@@ -14,9 +15,11 @@ export class GPXLayerCollection {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._fileStateCollectionObserver = new GPXFileStateCollectionObserver(
|
this._fileStateCollectionObserver = new GPXFileStateCollectionObserver(
|
||||||
(fileId, fileState) => {
|
(newFiles) => {
|
||||||
|
newFiles.forEach((fileState, fileId) => {
|
||||||
const layer = new GPXLayer(fileId, fileState);
|
const layer = new GPXLayer(fileId, fileState);
|
||||||
this._layers.set(fileId, layer);
|
this._layers.set(fileId, layer);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
(fileId) => {
|
(fileId) => {
|
||||||
const layer = this._layers.get(fileId);
|
const layer = this._layers.get(fileId);
|
||||||
@@ -33,6 +36,11 @@ export class GPXLayerCollection {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLayer(fileId: string): GPXLayer | undefined {
|
||||||
|
return this._layers.get(fileId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const gpxLayers = new GPXLayerCollection();
|
export const gpxLayers = new GPXLayerCollection();
|
||||||
|
export const gpxColors = writable(new Map<string, string>());
|
||||||
|
|||||||
@@ -1,54 +1,157 @@
|
|||||||
import { currentTool, Tool } from '$lib/components/toolbar/tools';
|
import { currentTool, Tool } from '$lib/components/toolbar/tools';
|
||||||
import { gpxStatistics, slicedGPXStatistics } from '$lib/logic/statistics';
|
import { gpxStatistics, hoveredPoint, slicedGPXStatistics } from '$lib/logic/statistics';
|
||||||
import mapboxgl from 'mapbox-gl';
|
import type { GeoJSONSource } from 'maplibre-gl';
|
||||||
import { get } from 'svelte/store';
|
import { get } from 'svelte/store';
|
||||||
import { map } from '$lib/components/map/map';
|
import { map } from '$lib/components/map/map';
|
||||||
|
import { allHidden } from '$lib/logic/hidden';
|
||||||
|
import { ANCHOR_LAYER_KEY } from '$lib/components/map/style';
|
||||||
|
import { loadSVGIcon } from '$lib/utils';
|
||||||
|
|
||||||
|
const startMarkerSVG = `<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<circle cx="8" cy="8" r="6" fill="#22c55e" stroke="white" stroke-width="1.5"/>
|
||||||
|
</svg>`;
|
||||||
|
|
||||||
|
const endMarkerSVG = `<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<defs>
|
||||||
|
<pattern id="checkerboard" x="0" y="0" width="5" height="5" patternUnits="userSpaceOnUse">
|
||||||
|
<rect x="0" y="0" width="2.5" height="2.5" fill="white"/>
|
||||||
|
<rect x="2.5" y="2.5" width="2.5" height="2.5" fill="white"/>
|
||||||
|
<rect x="2.5" y="0" width="2.5" height="2.5" fill="black"/>
|
||||||
|
<rect x="0" y="2.5" width="2.5" height="2.5" fill="black"/>
|
||||||
|
</pattern>
|
||||||
|
</defs>
|
||||||
|
<circle cx="8" cy="8" r="6" fill="url(#checkerboard)" stroke="white" stroke-width="1.5"/>
|
||||||
|
</svg>`;
|
||||||
|
const hoverMarkerSVG = `<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<circle cx="8" cy="8" r="6" fill="#00b8db" stroke="white" stroke-width="1.5"/>
|
||||||
|
</svg>`;
|
||||||
|
|
||||||
export class StartEndMarkers {
|
export class StartEndMarkers {
|
||||||
start: mapboxgl.Marker;
|
|
||||||
end: mapboxgl.Marker;
|
|
||||||
updateBinded: () => void = this.update.bind(this);
|
updateBinded: () => void = this.update.bind(this);
|
||||||
unsubscribes: (() => void)[] = [];
|
unsubscribes: (() => void)[] = [];
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
let startElement = document.createElement('div');
|
map.onLoad(() => this.update());
|
||||||
let endElement = document.createElement('div');
|
|
||||||
startElement.className = `h-4 w-4 rounded-full bg-green-500 border-2 border-white`;
|
|
||||||
endElement.className = `h-4 w-4 rounded-full border-2 border-white`;
|
|
||||||
endElement.style.background =
|
|
||||||
'repeating-conic-gradient(#fff 0 90deg, #000 0 180deg) 0 0/8px 8px round';
|
|
||||||
|
|
||||||
this.start = new mapboxgl.Marker({ element: startElement });
|
|
||||||
this.end = new mapboxgl.Marker({ element: endElement });
|
|
||||||
|
|
||||||
this.unsubscribes.push(gpxStatistics.subscribe(this.updateBinded));
|
this.unsubscribes.push(gpxStatistics.subscribe(this.updateBinded));
|
||||||
this.unsubscribes.push(slicedGPXStatistics.subscribe(this.updateBinded));
|
this.unsubscribes.push(slicedGPXStatistics.subscribe(this.updateBinded));
|
||||||
|
this.unsubscribes.push(hoveredPoint.subscribe(this.updateBinded));
|
||||||
this.unsubscribes.push(currentTool.subscribe(this.updateBinded));
|
this.unsubscribes.push(currentTool.subscribe(this.updateBinded));
|
||||||
|
this.unsubscribes.push(allHidden.subscribe(this.updateBinded));
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
const map_ = get(map);
|
const map_ = get(map);
|
||||||
if (!map_) return;
|
if (!map_) return;
|
||||||
|
|
||||||
|
this.loadIcons();
|
||||||
|
|
||||||
const tool = get(currentTool);
|
const tool = get(currentTool);
|
||||||
const statistics = get(slicedGPXStatistics)?.[0] ?? get(gpxStatistics);
|
const statistics = get(gpxStatistics);
|
||||||
if (statistics.local.points.length > 0 && tool !== Tool.ROUTING) {
|
const slicedStatistics = get(slicedGPXStatistics);
|
||||||
this.start.setLngLat(statistics.local.points[0].getCoordinates()).addTo(map_);
|
const hovered = get(hoveredPoint);
|
||||||
this.end
|
const hidden = get(allHidden);
|
||||||
.setLngLat(
|
if (!hidden) {
|
||||||
statistics.local.points[statistics.local.points.length - 1].getCoordinates()
|
const data: GeoJSON.FeatureCollection = {
|
||||||
)
|
type: 'FeatureCollection',
|
||||||
.addTo(map_);
|
features: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
if (statistics.global.length > 0 && tool !== Tool.ROUTING) {
|
||||||
|
const start = statistics
|
||||||
|
.getTrackPoint(slicedStatistics?.[1] ?? 0)!
|
||||||
|
.trkpt.getCoordinates();
|
||||||
|
const end = statistics
|
||||||
|
.getTrackPoint(slicedStatistics?.[2] ?? statistics.global.length - 1)!
|
||||||
|
.trkpt.getCoordinates();
|
||||||
|
data.features.push({
|
||||||
|
type: 'Feature',
|
||||||
|
geometry: {
|
||||||
|
type: 'Point',
|
||||||
|
coordinates: [start.lon, start.lat],
|
||||||
|
},
|
||||||
|
properties: {
|
||||||
|
icon: 'start-marker',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
data.features.push({
|
||||||
|
type: 'Feature',
|
||||||
|
geometry: {
|
||||||
|
type: 'Point',
|
||||||
|
coordinates: [end.lon, end.lat],
|
||||||
|
},
|
||||||
|
properties: {
|
||||||
|
icon: 'end-marker',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hovered) {
|
||||||
|
data.features.push({
|
||||||
|
type: 'Feature',
|
||||||
|
geometry: {
|
||||||
|
type: 'Point',
|
||||||
|
coordinates: [hovered.lon, hovered.lat],
|
||||||
|
},
|
||||||
|
properties: {
|
||||||
|
icon: 'hover-marker',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let source = map_.getSource('start-end-markers') as GeoJSONSource | undefined;
|
||||||
|
if (source) {
|
||||||
|
source.setData(data);
|
||||||
} else {
|
} else {
|
||||||
this.start.remove();
|
map_.addSource('start-end-markers', {
|
||||||
this.end.remove();
|
type: 'geojson',
|
||||||
|
data: data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!map_.getLayer('start-end-markers')) {
|
||||||
|
map_.addLayer(
|
||||||
|
{
|
||||||
|
id: 'start-end-markers',
|
||||||
|
type: 'symbol',
|
||||||
|
source: 'start-end-markers',
|
||||||
|
layout: {
|
||||||
|
'icon-image': ['get', 'icon'],
|
||||||
|
'icon-size': 0.2,
|
||||||
|
'icon-allow-overlap': true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ANCHOR_LAYER_KEY.startEndMarkers
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (map_.getLayer('start-end-markers')) {
|
||||||
|
map_.removeLayer('start-end-markers');
|
||||||
|
}
|
||||||
|
if (map_.getSource('start-end-markers')) {
|
||||||
|
map_.removeSource('start-end-markers');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
remove() {
|
remove() {
|
||||||
this.unsubscribes.forEach((unsubscribe) => unsubscribe());
|
this.unsubscribes.forEach((unsubscribe) => unsubscribe());
|
||||||
|
|
||||||
this.start.remove();
|
const map_ = get(map);
|
||||||
this.end.remove();
|
if (!map_) return;
|
||||||
|
|
||||||
|
if (map_.getLayer('start-end-markers')) {
|
||||||
|
map_.removeLayer('start-end-markers');
|
||||||
|
}
|
||||||
|
if (map_.getSource('start-end-markers')) {
|
||||||
|
map_.removeSource('start-end-markers');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
loadIcons() {
|
||||||
|
const map_ = get(map);
|
||||||
|
if (!map_) return;
|
||||||
|
loadSVGIcon(map_, 'start-marker', startMarkerSVG);
|
||||||
|
loadSVGIcon(map_, 'end-marker', endMarkerSVG);
|
||||||
|
loadSVGIcon(map_, 'hover-marker', hoverMarkerSVG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,11 +19,10 @@
|
|||||||
} from '@lucide/svelte';
|
} from '@lucide/svelte';
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
import { defaultBasemap, type CustomLayer } from '$lib/assets/layers';
|
import { defaultBasemap, type CustomLayer } from '$lib/assets/layers';
|
||||||
import { onDestroy, onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import Sortable from 'sortablejs/Sortable';
|
import { remove } from './utils';
|
||||||
import { customBasemapUpdate } from './utils';
|
|
||||||
import { settings } from '$lib/logic/settings';
|
import { settings } from '$lib/logic/settings';
|
||||||
import { map } from '$lib/components/map/map';
|
import { dndzone } from 'svelte-dnd-action';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
customLayers,
|
customLayers,
|
||||||
@@ -37,17 +36,18 @@
|
|||||||
customOverlayOrder,
|
customOverlayOrder,
|
||||||
} = settings;
|
} = settings;
|
||||||
|
|
||||||
let name: string = '';
|
let name: string = $state('');
|
||||||
let tileUrls: string[] = [''];
|
let tileUrls: string[] = $state(['']);
|
||||||
let maxZoom: number = 20;
|
let maxZoom: number = $state(20);
|
||||||
let layerType: 'basemap' | 'overlay' = 'basemap';
|
let layerType: 'basemap' | 'overlay' = $state('basemap');
|
||||||
let resourceType: 'raster' | 'vector' = 'raster';
|
let resourceType: 'raster' | 'vector' = $derived.by(() => {
|
||||||
|
if (tileUrls[0].length > 0 && tileUrls[0].includes('.json')) {
|
||||||
|
return 'vector';
|
||||||
|
}
|
||||||
|
return 'raster';
|
||||||
|
});
|
||||||
|
|
||||||
let basemapContainer: HTMLElement;
|
let selectedLayerId: string | undefined = $state(undefined);
|
||||||
let overlayContainer: HTMLElement;
|
|
||||||
|
|
||||||
let basemapSortable: Sortable;
|
|
||||||
let overlaySortable: Sortable;
|
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if ($customBasemapOrder.length === 0) {
|
if ($customBasemapOrder.length === 0) {
|
||||||
@@ -60,46 +60,31 @@
|
|||||||
(id) => $customLayers[id].layerType === 'overlay'
|
(id) => $customLayers[id].layerType === 'overlay'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
basemapSortable = Sortable.create(basemapContainer, {
|
|
||||||
onSort: (e) => {
|
|
||||||
$customBasemapOrder = basemapSortable.toArray();
|
|
||||||
$selectedBasemapTree.basemaps['custom'] = $customBasemapOrder.reduce((acc, id) => {
|
|
||||||
acc[id] = true;
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
overlaySortable = Sortable.create(overlayContainer, {
|
|
||||||
onSort: (e) => {
|
|
||||||
$customOverlayOrder = overlaySortable.toArray();
|
|
||||||
$selectedOverlayTree.overlays['custom'] = $customOverlayOrder.reduce((acc, id) => {
|
|
||||||
acc[id] = true;
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
basemapSortable.sort($customBasemapOrder);
|
let customBasemapItems: {
|
||||||
overlaySortable.sort($customOverlayOrder);
|
id: string;
|
||||||
});
|
name: string;
|
||||||
|
}[] = $derived(
|
||||||
|
$customBasemapOrder.map((id) => ({
|
||||||
|
id: id,
|
||||||
|
name: $customLayers[id].name,
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
let customOverlayItems: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}[] = $derived(
|
||||||
|
$customOverlayOrder.map((id) => ({
|
||||||
|
id: id,
|
||||||
|
name: $customLayers[id].name,
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
onDestroy(() => {
|
$effect(() => {
|
||||||
basemapSortable.destroy();
|
setDataFromSelectedLayer(selectedLayerId);
|
||||||
overlaySortable.destroy();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$: if (tileUrls[0].length > 0) {
|
|
||||||
if (
|
|
||||||
tileUrls[0].includes('.json') ||
|
|
||||||
(tileUrls[0].includes('api.mapbox.com/styles') && !tileUrls[0].includes('tiles'))
|
|
||||||
) {
|
|
||||||
resourceType = 'vector';
|
|
||||||
} else {
|
|
||||||
resourceType = 'raster';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function createLayer() {
|
function createLayer() {
|
||||||
if (selectedLayerId && $customLayers[selectedLayerId].layerType !== layerType) {
|
if (selectedLayerId && $customLayers[selectedLayerId].layerType !== layerType) {
|
||||||
deleteLayer(selectedLayerId);
|
deleteLayer(selectedLayerId);
|
||||||
@@ -143,8 +128,8 @@
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
$customLayers[layerId] = layer;
|
|
||||||
addLayer(layerId);
|
addLayer(layerId);
|
||||||
|
$customLayers[layerId] = layer;
|
||||||
selectedLayerId = undefined;
|
selectedLayerId = undefined;
|
||||||
setDataFromSelectedLayer();
|
setDataFromSelectedLayer();
|
||||||
}
|
}
|
||||||
@@ -167,9 +152,7 @@
|
|||||||
return $tree;
|
return $tree;
|
||||||
});
|
});
|
||||||
|
|
||||||
if ($currentBasemap === layerId) {
|
if ($currentBasemap !== layerId) {
|
||||||
$customBasemapUpdate++;
|
|
||||||
} else {
|
|
||||||
$currentBasemap = layerId;
|
$currentBasemap = layerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,22 +168,13 @@
|
|||||||
return $tree;
|
return $tree;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (
|
currentOverlays.update(($overlays) => {
|
||||||
$currentOverlays.overlays['custom'] &&
|
if (!$overlays.overlays.hasOwnProperty('custom')) {
|
||||||
$currentOverlays.overlays['custom'][layerId] &&
|
$overlays.overlays['custom'] = {};
|
||||||
$map
|
|
||||||
) {
|
|
||||||
try {
|
|
||||||
$map.removeImport(layerId);
|
|
||||||
} catch (e) {
|
|
||||||
// No reliable way to check if the map is ready to remove sources and layers
|
|
||||||
}
|
}
|
||||||
}
|
$overlays.overlays['custom'][layerId] = true;
|
||||||
|
return $overlays;
|
||||||
if (!$currentOverlays.overlays.hasOwnProperty('custom')) {
|
});
|
||||||
$currentOverlays.overlays['custom'] = {};
|
|
||||||
}
|
|
||||||
$currentOverlays.overlays['custom'][layerId] = true;
|
|
||||||
|
|
||||||
if (!$customOverlayOrder.includes(layerId)) {
|
if (!$customOverlayOrder.includes(layerId)) {
|
||||||
$customOverlayOrder = [...$customOverlayOrder, layerId];
|
$customOverlayOrder = [...$customOverlayOrder, layerId];
|
||||||
@@ -225,58 +199,22 @@
|
|||||||
$previousBasemap = defaultBasemap;
|
$previousBasemap = defaultBasemap;
|
||||||
}
|
}
|
||||||
|
|
||||||
$selectedBasemapTree.basemaps['custom'] = tryDeleteLayer(
|
$selectedBasemapTree = remove($selectedBasemapTree, layerId);
|
||||||
$selectedBasemapTree.basemaps['custom'],
|
|
||||||
layerId
|
|
||||||
);
|
|
||||||
if (Object.keys($selectedBasemapTree.basemaps['custom']).length === 0) {
|
|
||||||
$selectedBasemapTree.basemaps = tryDeleteLayer(
|
|
||||||
$selectedBasemapTree.basemaps,
|
|
||||||
'custom'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
$customBasemapOrder = $customBasemapOrder.filter((id) => id !== layerId);
|
$customBasemapOrder = $customBasemapOrder.filter((id) => id !== layerId);
|
||||||
} else {
|
} else {
|
||||||
$currentOverlays.overlays['custom'][layerId] = false;
|
if ($currentOverlays) {
|
||||||
if ($previousOverlays.overlays['custom']) {
|
$currentOverlays = remove($currentOverlays, layerId);
|
||||||
$previousOverlays.overlays['custom'] = tryDeleteLayer(
|
|
||||||
$previousOverlays.overlays['custom'],
|
|
||||||
layerId
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$selectedOverlayTree.overlays['custom'] = tryDeleteLayer(
|
|
||||||
$selectedOverlayTree.overlays['custom'],
|
|
||||||
layerId
|
|
||||||
);
|
|
||||||
if (Object.keys($selectedOverlayTree.overlays['custom']).length === 0) {
|
|
||||||
$selectedOverlayTree.overlays = tryDeleteLayer(
|
|
||||||
$selectedOverlayTree.overlays,
|
|
||||||
'custom'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
$previousOverlays = remove($previousOverlays, layerId);
|
||||||
|
$selectedOverlayTree = remove($selectedOverlayTree, layerId);
|
||||||
$customOverlayOrder = $customOverlayOrder.filter((id) => id !== layerId);
|
$customOverlayOrder = $customOverlayOrder.filter((id) => id !== layerId);
|
||||||
|
|
||||||
if (
|
|
||||||
$currentOverlays.overlays['custom'] &&
|
|
||||||
$currentOverlays.overlays['custom'][layerId] &&
|
|
||||||
$map
|
|
||||||
) {
|
|
||||||
try {
|
|
||||||
$map.removeImport(layerId);
|
|
||||||
} catch (e) {
|
|
||||||
// No reliable way to check if the map is ready to remove sources and layers
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$customLayers = tryDeleteLayer($customLayers, layerId);
|
$customLayers = tryDeleteLayer($customLayers, layerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
let selectedLayerId: string | undefined = undefined;
|
function setDataFromSelectedLayer(layerId?: string) {
|
||||||
|
if (layerId) {
|
||||||
function setDataFromSelectedLayer() {
|
const layer = $customLayers[layerId];
|
||||||
if (selectedLayerId) {
|
|
||||||
const layer = $customLayers[selectedLayerId];
|
|
||||||
name = layer.name;
|
name = layer.name;
|
||||||
tileUrls = layer.tileUrls;
|
tileUrls = layer.tileUrls;
|
||||||
maxZoom = layer.maxZoom;
|
maxZoom = layer.maxZoom;
|
||||||
@@ -290,8 +228,6 @@
|
|||||||
resourceType = 'raster';
|
resourceType = 'raster';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$: selectedLayerId, setDataFromSelectedLayer();
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
@@ -305,17 +241,37 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<div
|
<div
|
||||||
bind:this={basemapContainer}
|
|
||||||
class="ml-1.5 flex flex-col gap-1 {$customBasemapOrder.length > 0 ? 'mb-2' : ''}"
|
class="ml-1.5 flex flex-col gap-1 {$customBasemapOrder.length > 0 ? 'mb-2' : ''}"
|
||||||
|
use:dndzone={{
|
||||||
|
items: customBasemapItems,
|
||||||
|
type: 'basemap',
|
||||||
|
dropTargetStyle: {},
|
||||||
|
transformDraggedElement: (element) => {
|
||||||
|
if (element) {
|
||||||
|
element.style.opacity = '0.5';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
onconsider={(e) => {
|
||||||
|
customBasemapItems = e.detail.items;
|
||||||
|
}}
|
||||||
|
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;
|
||||||
|
}, {});
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{#each $customBasemapOrder as id (id)}
|
{#each customBasemapItems as item (item.id)}
|
||||||
<div class="flex flex-row items-center gap-2" data-id={id}>
|
<div class="flex flex-row items-center gap-2">
|
||||||
<Move size="12" />
|
<Move size="12" />
|
||||||
<span class="grow">{$customLayers[id].name}</span>
|
<span class="grow">{item.name}</span>
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="icon-sm"
|
size="icon-sm"
|
||||||
onclick={() => (selectedLayerId = id)}
|
onclick={() => (selectedLayerId = item.id)}
|
||||||
class="p-1 h-7"
|
class="p-1 h-7"
|
||||||
>
|
>
|
||||||
<Pencil size="16" />
|
<Pencil size="16" />
|
||||||
@@ -323,7 +279,7 @@
|
|||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="icon-sm"
|
size="icon-sm"
|
||||||
onclick={() => deleteLayer(id)}
|
onclick={() => deleteLayer(item.id)}
|
||||||
class="p-1 h-7"
|
class="p-1 h-7"
|
||||||
>
|
>
|
||||||
<Trash2 size="16" />
|
<Trash2 size="16" />
|
||||||
@@ -341,17 +297,37 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<div
|
<div
|
||||||
bind:this={overlayContainer}
|
|
||||||
class="ml-1.5 flex flex-col gap-1 {$customOverlayOrder.length > 0 ? 'mb-2' : ''}"
|
class="ml-1.5 flex flex-col gap-1 {$customOverlayOrder.length > 0 ? 'mb-2' : ''}"
|
||||||
|
use:dndzone={{
|
||||||
|
items: customOverlayItems,
|
||||||
|
type: 'overlay',
|
||||||
|
dropTargetStyle: {},
|
||||||
|
transformDraggedElement: (element) => {
|
||||||
|
if (element) {
|
||||||
|
element.style.opacity = '0.5';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
onconsider={(e) => {
|
||||||
|
customOverlayItems = e.detail.items;
|
||||||
|
}}
|
||||||
|
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;
|
||||||
|
}, {});
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{#each $customOverlayOrder as id (id)}
|
{#each customOverlayItems as item (item.id)}
|
||||||
<div class="flex flex-row items-center gap-2" data-id={id}>
|
<div class="flex flex-row items-center gap-2">
|
||||||
<Move size="12" />
|
<Move size="12" />
|
||||||
<span class="grow">{$customLayers[id].name}</span>
|
<span class="grow">{item.name}</span>
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="icon-sm"
|
size="icon-sm"
|
||||||
onclick={() => (selectedLayerId = id)}
|
onclick={() => (selectedLayerId = item.id)}
|
||||||
class="p-1 h-7"
|
class="p-1 h-7"
|
||||||
>
|
>
|
||||||
<Pencil size="16" />
|
<Pencil size="16" />
|
||||||
@@ -359,7 +335,7 @@
|
|||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="icon-sm"
|
size="icon-sm"
|
||||||
onclick={() => deleteLayer(id)}
|
onclick={() => deleteLayer(item.id)}
|
||||||
class="p-1 h-7"
|
class="p-1 h-7"
|
||||||
>
|
>
|
||||||
<Trash2 size="16" />
|
<Trash2 size="16" />
|
||||||
@@ -436,7 +412,7 @@
|
|||||||
{#if selectedLayerId}
|
{#if selectedLayerId}
|
||||||
<div class="mt-2 flex flex-row gap-2">
|
<div class="mt-2 flex flex-row gap-2">
|
||||||
<Button variant="outline" onclick={createLayer} class="grow">
|
<Button variant="outline" onclick={createLayer} class="grow">
|
||||||
<Save size="16" class="mr-1" />
|
<Save size="16" />
|
||||||
{i18n._('layers.custom_layers.update')}
|
{i18n._('layers.custom_layers.update')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="outline" onclick={() => (selectedLayerId = undefined)}>
|
<Button variant="outline" onclick={() => (selectedLayerId = undefined)}>
|
||||||
@@ -445,7 +421,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<Button variant="outline" class="mt-2" onclick={createLayer}>
|
<Button variant="outline" class="mt-2" onclick={createLayer}>
|
||||||
<CirclePlus size="16" class="mr-1" />
|
<CirclePlus size="16" />
|
||||||
{i18n._('layers.custom_layers.create')}
|
{i18n._('layers.custom_layers.create')}
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import CustomControl from '$lib/components/map/custom-control/CustomControl.svelte';
|
import CustomControl from '$lib/components/map/custom-control/CustomControl.svelte';
|
||||||
import LayerTree from './LayerTree.svelte';
|
import LayerTree from './LayerTree.svelte';
|
||||||
import { OverpassLayer } from './OverpassLayer';
|
import { OverpassLayer } from './overpass-layer';
|
||||||
import { Separator } from '$lib/components/ui/separator';
|
import { Separator } from '$lib/components/ui/separator';
|
||||||
import { ScrollArea } from '$lib/components/ui/scroll-area/index.js';
|
import { ScrollArea } from '$lib/components/ui/scroll-area/index.js';
|
||||||
import { Layers } from '@lucide/svelte';
|
import { Layers } from '@lucide/svelte';
|
||||||
import { basemaps, defaultBasemap, overlays } from '$lib/assets/layers';
|
|
||||||
import { settings } from '$lib/logic/settings';
|
import { settings } from '$lib/logic/settings';
|
||||||
import { map } from '$lib/components/map/map';
|
import { map } from '$lib/components/map/map';
|
||||||
import { customBasemapUpdate, getLayers } from './utils';
|
|
||||||
import type { ImportSpecification, StyleSpecification } from 'mapbox-gl';
|
|
||||||
|
|
||||||
let container: HTMLDivElement;
|
let container: HTMLDivElement;
|
||||||
let overpassLayer: OverpassLayer;
|
let overpassLayer: OverpassLayer;
|
||||||
@@ -22,122 +19,14 @@
|
|||||||
selectedBasemapTree,
|
selectedBasemapTree,
|
||||||
selectedOverlayTree,
|
selectedOverlayTree,
|
||||||
selectedOverpassTree,
|
selectedOverpassTree,
|
||||||
customLayers,
|
|
||||||
opacities,
|
|
||||||
} = settings;
|
} = settings;
|
||||||
|
|
||||||
function setStyle() {
|
map.onLoad((_map: maplibregl.Map) => {
|
||||||
if (!$map) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let basemap = basemaps.hasOwnProperty($currentBasemap)
|
|
||||||
? basemaps[$currentBasemap]
|
|
||||||
: ($customLayers[$currentBasemap] ?? basemaps[defaultBasemap]);
|
|
||||||
$map.removeImport('basemap');
|
|
||||||
if (typeof basemap === 'string') {
|
|
||||||
$map.addImport({ id: 'basemap', url: basemap }, 'overlays');
|
|
||||||
} else {
|
|
||||||
$map.addImport(
|
|
||||||
{
|
|
||||||
id: 'basemap',
|
|
||||||
url: '',
|
|
||||||
data: basemap as StyleSpecification,
|
|
||||||
},
|
|
||||||
'overlays'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
if ($map && ($currentBasemap || $customBasemapUpdate)) {
|
|
||||||
setStyle();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function addOverlay(id: string) {
|
|
||||||
if (!$map) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
let overlay = $customLayers.hasOwnProperty(id) ? $customLayers[id].value : overlays[id];
|
|
||||||
if (typeof overlay === 'string') {
|
|
||||||
$map.addImport({ id, url: overlay });
|
|
||||||
} else {
|
|
||||||
if ($opacities.hasOwnProperty(id)) {
|
|
||||||
overlay = {
|
|
||||||
...overlay,
|
|
||||||
layers: (overlay as StyleSpecification).layers.map((layer) => {
|
|
||||||
if (layer.type === 'raster') {
|
|
||||||
if (!layer.paint) {
|
|
||||||
layer.paint = {};
|
|
||||||
}
|
|
||||||
layer.paint['raster-opacity'] = $opacities[id];
|
|
||||||
}
|
|
||||||
return layer;
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
$map.addImport({
|
|
||||||
id,
|
|
||||||
url: '',
|
|
||||||
data: overlay as StyleSpecification,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
// No reliable way to check if the map is ready to add sources and layers
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateOverlays() {
|
|
||||||
if ($map && $currentOverlays && $opacities) {
|
|
||||||
let overlayLayers = getLayers($currentOverlays);
|
|
||||||
try {
|
|
||||||
let activeOverlays =
|
|
||||||
$map
|
|
||||||
.getStyle()
|
|
||||||
.imports?.reduce(
|
|
||||||
(
|
|
||||||
acc: Record<string, ImportSpecification>,
|
|
||||||
imprt: ImportSpecification
|
|
||||||
) => {
|
|
||||||
if (
|
|
||||||
!['basemap', 'overlays', 'glyphs-and-sprite'].includes(imprt.id)
|
|
||||||
) {
|
|
||||||
acc[imprt.id] = imprt;
|
|
||||||
}
|
|
||||||
return acc;
|
|
||||||
},
|
|
||||||
{}
|
|
||||||
) || {};
|
|
||||||
let toRemove = Object.keys(activeOverlays).filter((id) => !overlayLayers[id]);
|
|
||||||
toRemove.forEach((id) => {
|
|
||||||
$map?.removeImport(id);
|
|
||||||
});
|
|
||||||
let toAdd = Object.entries(overlayLayers)
|
|
||||||
.filter(([id, selected]) => selected && !activeOverlays.hasOwnProperty(id))
|
|
||||||
.map(([id]) => id);
|
|
||||||
toAdd.forEach((id) => {
|
|
||||||
addOverlay(id);
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
// No reliable way to check if the map is ready to add sources and layers
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
if ($map && $currentOverlays && $opacities) {
|
|
||||||
updateOverlays();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
map.onLoad((_map: mapboxgl.Map) => {
|
|
||||||
if (overpassLayer) {
|
if (overpassLayer) {
|
||||||
overpassLayer.remove();
|
overpassLayer.remove();
|
||||||
}
|
}
|
||||||
overpassLayer = new OverpassLayer(_map);
|
overpassLayer = new OverpassLayer(_map, map.layerEventManager!);
|
||||||
overpassLayer.add();
|
overpassLayer.add();
|
||||||
_map.on('style.import.load', updateOverlays);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let open = $state(false);
|
let open = $state(false);
|
||||||
@@ -221,8 +110,9 @@
|
|||||||
</CustomControl>
|
</CustomControl>
|
||||||
|
|
||||||
<svelte:window
|
<svelte:window
|
||||||
on:click={(e) => {
|
on:click={(e: MouseEvent) => {
|
||||||
if (open && !cancelEvents && !container.contains(e.target)) {
|
const target = e.target as Node | null;
|
||||||
|
if (open && !cancelEvents && target && container && !container.contains(target)) {
|
||||||
closeLayerControl();
|
closeLayerControl();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -13,12 +13,15 @@
|
|||||||
overlays,
|
overlays,
|
||||||
overlayTree,
|
overlayTree,
|
||||||
overpassTree,
|
overpassTree,
|
||||||
|
terrainSources,
|
||||||
} from '$lib/assets/layers';
|
} from '$lib/assets/layers';
|
||||||
import { getLayers, isSelected, toggle } from '$lib/components/map/layer-control/utils';
|
import { getLayers, isSelected, toggle } from '$lib/components/map/layer-control/utils';
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
import { map } from '$lib/components/map/map';
|
import { map } from '$lib/components/map/map';
|
||||||
import CustomLayers from './CustomLayers.svelte';
|
import CustomLayers from './CustomLayers.svelte';
|
||||||
import { settings } from '$lib/logic/settings';
|
import { settings } from '$lib/logic/settings';
|
||||||
|
import { untrack } from 'svelte';
|
||||||
|
import { extensionAPI } from '$lib/components/map/layer-control/extension-api';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
selectedBasemapTree,
|
selectedBasemapTree,
|
||||||
@@ -26,10 +29,14 @@
|
|||||||
selectedOverpassTree,
|
selectedOverpassTree,
|
||||||
currentBasemap,
|
currentBasemap,
|
||||||
currentOverlays,
|
currentOverlays,
|
||||||
|
currentOverpassQueries,
|
||||||
customLayers,
|
customLayers,
|
||||||
opacities,
|
opacities,
|
||||||
|
terrainSource,
|
||||||
} = settings;
|
} = settings;
|
||||||
|
|
||||||
|
const { isLayerFromExtension, getLayerName } = extensionAPI;
|
||||||
|
|
||||||
let { open = $bindable() }: { open: boolean } = $props();
|
let { open = $bindable() }: { open: boolean } = $props();
|
||||||
|
|
||||||
let accordionValue: string | undefined = $state(undefined);
|
let accordionValue: string | undefined = $state(undefined);
|
||||||
@@ -49,7 +56,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if ($selectedBasemapTree && $currentBasemap) {
|
if (open && $selectedBasemapTree && $currentBasemap) {
|
||||||
if (!isSelected($selectedBasemapTree, $currentBasemap)) {
|
if (!isSelected($selectedBasemapTree, $currentBasemap)) {
|
||||||
if (!isSelected($selectedBasemapTree, defaultBasemap)) {
|
if (!isSelected($selectedBasemapTree, defaultBasemap)) {
|
||||||
$selectedBasemapTree = toggle($selectedBasemapTree, defaultBasemap);
|
$selectedBasemapTree = toggle($selectedBasemapTree, defaultBasemap);
|
||||||
@@ -60,7 +67,9 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if ($selectedOverlayTree && $currentOverlays) {
|
if (open && $selectedOverlayTree) {
|
||||||
|
untrack(() => {
|
||||||
|
if ($currentOverlays) {
|
||||||
let overlayLayers = getLayers($currentOverlays);
|
let overlayLayers = getLayers($currentOverlays);
|
||||||
let toRemove = Object.entries(overlayLayers).filter(
|
let toRemove = Object.entries(overlayLayers).filter(
|
||||||
([id, checked]) => checked && !isSelected($selectedOverlayTree, id)
|
([id, checked]) => checked && !isSelected($selectedOverlayTree, id)
|
||||||
@@ -75,6 +84,29 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (open && $selectedOverpassTree) {
|
||||||
|
untrack(() => {
|
||||||
|
if ($currentOverpassQueries) {
|
||||||
|
let overlayLayers = getLayers($currentOverpassQueries);
|
||||||
|
let toRemove = Object.entries(overlayLayers).filter(
|
||||||
|
([id, checked]) => checked && !isSelected($selectedOverpassTree, id)
|
||||||
|
);
|
||||||
|
if (toRemove.length > 0) {
|
||||||
|
currentOverpassQueries.update((tree) => {
|
||||||
|
toRemove.forEach(([id]) => {
|
||||||
|
toggle(tree, id);
|
||||||
|
});
|
||||||
|
return tree;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Sheet.Root bind:open>
|
<Sheet.Root bind:open>
|
||||||
@@ -130,21 +162,29 @@
|
|||||||
type="single"
|
type="single"
|
||||||
onValueChange={setOpacityFromSelection}
|
onValueChange={setOpacityFromSelection}
|
||||||
>
|
>
|
||||||
<Select.Trigger class="h-8 mr-1 w-full">
|
<Select.Trigger class="mr-1 w-full" size="sm">
|
||||||
{#if selectedOverlay}
|
{#if selectedOverlay}
|
||||||
{#if isSelected($selectedOverlayTree, selectedOverlay)}
|
{#if isSelected($selectedOverlayTree, selectedOverlay)}
|
||||||
{i18n._(`layers.label.${selectedOverlay}`)}
|
{#if $isLayerFromExtension(selectedOverlay)}
|
||||||
|
{$getLayerName(selectedOverlay)}
|
||||||
{:else if $customLayers.hasOwnProperty(selectedOverlay)}
|
{:else if $customLayers.hasOwnProperty(selectedOverlay)}
|
||||||
{$customLayers[selectedOverlay].name}
|
{$customLayers[selectedOverlay].name}
|
||||||
|
{:else}
|
||||||
|
{i18n._(`layers.label.${selectedOverlay}`)}
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
</Select.Trigger>
|
</Select.Trigger>
|
||||||
<Select.Content class="h-fit max-h-[40dvh] overflow-y-auto">
|
<Select.Content class="h-fit max-h-[40dvh] overflow-y-auto">
|
||||||
{#each Object.keys(overlays) as id}
|
{#each Object.keys(overlays) as id}
|
||||||
{#if isSelected($selectedOverlayTree, id)}
|
{#if isSelected($selectedOverlayTree, id)}
|
||||||
<Select.Item value={id}
|
<Select.Item value={id}>
|
||||||
>{i18n._(`layers.label.${id}`)}</Select.Item
|
{#if $isLayerFromExtension(id)}
|
||||||
>
|
{$getLayerName(id)}
|
||||||
|
{:else}
|
||||||
|
{i18n._(`layers.label.${id}`)}
|
||||||
|
{/if}
|
||||||
|
</Select.Item>
|
||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
{#each Object.entries($customLayers) as [id, layer]}
|
{#each Object.entries($customLayers) as [id, layer]}
|
||||||
@@ -173,7 +213,9 @@
|
|||||||
isSelected($currentOverlays, selectedOverlay)
|
isSelected($currentOverlays, selectedOverlay)
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
$map.removeImport(selectedOverlay);
|
if ($map.getLayer(selectedOverlay)) {
|
||||||
|
$map.removeLayer(selectedOverlay);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// No reliable way to check if the map is ready to remove sources and layers
|
// No reliable way to check if the map is ready to remove sources and layers
|
||||||
}
|
}
|
||||||
@@ -195,6 +237,23 @@
|
|||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
</Accordion.Content>
|
</Accordion.Content>
|
||||||
</Accordion.Item>
|
</Accordion.Item>
|
||||||
|
<Accordion.Item value="terrain-source">
|
||||||
|
<Accordion.Trigger>{i18n._('layers.terrain')}</Accordion.Trigger>
|
||||||
|
<Accordion.Content class="flex flex-col gap-3 overflow-visible">
|
||||||
|
<Select.Root bind:value={$terrainSource} type="single">
|
||||||
|
<Select.Trigger class="mr-1 w-full" size="sm">
|
||||||
|
{i18n._(`layers.label.${$terrainSource}`)}
|
||||||
|
</Select.Trigger>
|
||||||
|
<Select.Content class="h-fit max-h-[40dvh] overflow-y-auto">
|
||||||
|
{#each Object.keys(terrainSources) as id}
|
||||||
|
<Select.Item value={id}>
|
||||||
|
{i18n._(`layers.label.${id}`)}
|
||||||
|
</Select.Item>
|
||||||
|
{/each}
|
||||||
|
</Select.Content>
|
||||||
|
</Select.Root>
|
||||||
|
</Accordion.Content>
|
||||||
|
</Accordion.Item>
|
||||||
</Accordion.Root>
|
</Accordion.Root>
|
||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
</Sheet.Header>
|
</Sheet.Header>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
import { anySelectedLayer } from './utils';
|
import { anySelectedLayer } from './utils';
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
import { settings } from '$lib/logic/settings';
|
import { settings } from '$lib/logic/settings';
|
||||||
|
import { extensionAPI } from '$lib/components/map/layer-control/extension-api';
|
||||||
|
|
||||||
let {
|
let {
|
||||||
name,
|
name,
|
||||||
@@ -25,6 +26,7 @@
|
|||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
const { customLayers } = settings;
|
const { customLayers } = settings;
|
||||||
|
const { isLayerFromExtension, getLayerName } = extensionAPI;
|
||||||
|
|
||||||
$effect.pre(() => {
|
$effect.pre(() => {
|
||||||
if (checked !== undefined) {
|
if (checked !== undefined) {
|
||||||
@@ -72,6 +74,8 @@
|
|||||||
<Label for="{name}-{id}" class="flex flex-row items-center gap-1">
|
<Label for="{name}-{id}" class="flex flex-row items-center gap-1">
|
||||||
{#if $customLayers.hasOwnProperty(id)}
|
{#if $customLayers.hasOwnProperty(id)}
|
||||||
{$customLayers[id].name}
|
{$customLayers[id].name}
|
||||||
|
{:else if $isLayerFromExtension(id)}
|
||||||
|
{$getLayerName(id)}
|
||||||
{:else}
|
{:else}
|
||||||
{i18n._(`layers.label.${id}`)}
|
{i18n._(`layers.label.${id}`)}
|
||||||
{/if}
|
{/if}
|
||||||
@@ -81,7 +85,7 @@
|
|||||||
{:else if anySelectedLayer(node[id])}
|
{:else if anySelectedLayer(node[id])}
|
||||||
<CollapsibleTreeNode {id}>
|
<CollapsibleTreeNode {id}>
|
||||||
{#snippet trigger()}
|
{#snippet trigger()}
|
||||||
<span>{i18n._(`layers.label.${id}`)}</span>
|
<span>{i18n._(`layers.label.${id}`, id)}</span>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
{#snippet content()}
|
{#snippet content()}
|
||||||
<div class="ml-2">
|
<div class="ml-2">
|
||||||
|
|||||||
@@ -5,22 +5,27 @@
|
|||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
import { ScrollArea } from '$lib/components/ui/scroll-area/index.js';
|
import { ScrollArea } from '$lib/components/ui/scroll-area/index.js';
|
||||||
import type { WaypointType } from 'gpx';
|
import type { WaypointType } from 'gpx';
|
||||||
import type { PopupItem } from '$lib/components/map/map';
|
import type { PopupItem } from '$lib/components/map/map-popup';
|
||||||
import { fileActions } from '$lib/logic/file-actions';
|
import { fileActions } from '$lib/logic/file-actions';
|
||||||
import { selection } from '$lib/logic/selection';
|
import { selection } from '$lib/logic/selection';
|
||||||
|
|
||||||
export let poi: PopupItem<any>;
|
let {
|
||||||
|
poi,
|
||||||
|
}: {
|
||||||
|
poi: PopupItem<any>;
|
||||||
|
} = $props();
|
||||||
|
|
||||||
let tags: { [key: string]: string } = {};
|
let tags: Record<string, string> = $derived(poi ? JSON.parse(poi.item.tags) : {});
|
||||||
let name = '';
|
let name = $derived.by(() => {
|
||||||
$: if (poi) {
|
if (poi) {
|
||||||
tags = JSON.parse(poi.item.tags);
|
|
||||||
if (tags.name !== undefined && tags.name !== '') {
|
if (tags.name !== undefined && tags.name !== '') {
|
||||||
name = tags.name;
|
return tags.name;
|
||||||
} else {
|
} else {
|
||||||
name = i18n._(`layers.label.${poi.item.query}`);
|
return i18n._(`layers.label.${poi.item.query}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return '';
|
||||||
|
});
|
||||||
|
|
||||||
function addToFile() {
|
function addToFile() {
|
||||||
const desc = Object.entries(tags)
|
const desc = Object.entries(tags)
|
||||||
@@ -47,33 +52,33 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Card.Root class="border-none shadow-md text-base p-2 max-w-[50dvw]">
|
<Card.Root class="border-none shadow-md text-base p-2 max-w-[50dvw] gap-0">
|
||||||
<Card.Header class="p-0">
|
<Card.Header class="p-0 gap-0">
|
||||||
<Card.Title class="text-md">
|
<Card.Title class="text-md flex flex-row">
|
||||||
<div class="flex flex-row gap-3">
|
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
{name}
|
<p>{name}</p>
|
||||||
<div class="text-muted-foreground text-sm font-normal">
|
<div class="text-muted-foreground text-xs font-normal">
|
||||||
{poi.item.lat.toFixed(6)}° {poi.item.lon.toFixed(6)}°
|
{poi.item.lat.toFixed(6)}° {poi.item.lon.toFixed(6)}°
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
class="ml-auto p-1.5 h-8"
|
class="ml-auto"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
href="https://www.openstreetmap.org/edit?editor=id&{poi.item.type ??
|
size="icon-sm"
|
||||||
'node'}={poi.item.id}"
|
href="https://www.openstreetmap.org/edit?editor=id&{poi.item.type ?? 'node'}={poi
|
||||||
|
.item.id}"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
>
|
>
|
||||||
<PencilLine size="16" />
|
<PencilLine size="16" />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
|
||||||
</Card.Title>
|
</Card.Title>
|
||||||
</Card.Header>
|
</Card.Header>
|
||||||
<Card.Content class="flex flex-col p-0 text-sm mt-1 whitespace-normal break-all">
|
<Card.Content class="flex flex-col gap-1 p-0 text-sm whitespace-normal break-all">
|
||||||
<ScrollArea class="flex flex-col" viewportClasses="max-h-[30dvh]">
|
<ScrollArea class="flex flex-col max-h-[30dvh]">
|
||||||
{#if tags.image || tags['image:0']}
|
{#if tags.image || tags['image:0']}
|
||||||
<div class="w-full rounded-md overflow-clip my-2 max-w-96 mx-auto">
|
<div class="w-full rounded-md overflow-clip my-2 max-w-96 mx-auto">
|
||||||
<!-- svelte-ignore a11y-missing-attribute -->
|
<!-- svelte-ignore a11y_missing_attribute -->
|
||||||
<img src={tags.image ?? tags['image:0']} />
|
<img src={tags.image ?? tags['image:0']} />
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -81,7 +86,7 @@
|
|||||||
{#each Object.entries(tags) as [key, value]}
|
{#each Object.entries(tags) as [key, value]}
|
||||||
{#if key !== 'name' && !key.includes('image')}
|
{#if key !== 'name' && !key.includes('image')}
|
||||||
<span class="font-mono">{key}</span>
|
<span class="font-mono">{key}</span>
|
||||||
{#if key === 'website' || key.startsWith('website:') || key === 'contact:website' || key === 'contact:facebook' || key === 'contact:instagram' || key === 'contact:twitter'}
|
{#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" class="text-link underline">{value}</a>
|
||||||
{:else if key === 'phone' || key === 'contact:phone'}
|
{:else if key === 'phone' || key === 'contact:phone'}
|
||||||
<a href={'tel:' + value} class="text-link underline">{value}</a>
|
<a href={'tel:' + value} class="text-link underline">{value}</a>
|
||||||
@@ -94,8 +99,14 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
<Button class="mt-2" variant="outline" disabled={$selection.size === 0} onclick={addToFile}>
|
<Button
|
||||||
<MapPin size="16" class="mr-1" />
|
size="sm"
|
||||||
|
class="mt-1 justify-start"
|
||||||
|
variant="outline"
|
||||||
|
disabled={$selection.size === 0}
|
||||||
|
onclick={addToFile}
|
||||||
|
>
|
||||||
|
<MapPin size="14" />
|
||||||
{i18n._('toolbar.waypoint.add')}
|
{i18n._('toolbar.waypoint.add')}
|
||||||
</Button>
|
</Button>
|
||||||
</Card.Content>
|
</Card.Content>
|
||||||
|
|||||||
213
website/src/lib/components/map/layer-control/extension-api.ts
Normal file
213
website/src/lib/components/map/layer-control/extension-api.ts
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
import { settings } from '$lib/logic/settings';
|
||||||
|
import { derived, get, writable, type Writable } from 'svelte/store';
|
||||||
|
import { isSelected, remove, removeAll } from './utils';
|
||||||
|
import { overlays, overlayTree } from '$lib/assets/layers';
|
||||||
|
import { browser } from '$app/environment';
|
||||||
|
import { map } from '$lib/components/map/map';
|
||||||
|
|
||||||
|
const { currentOverlays, previousOverlays, selectedOverlayTree } = settings;
|
||||||
|
|
||||||
|
export type CustomOverlay = {
|
||||||
|
extensionName: string;
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
tileUrls: string[];
|
||||||
|
maxZoom?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export class ExtensionAPI {
|
||||||
|
private _overlays: Writable<Map<string, CustomOverlay>> = writable(new Map());
|
||||||
|
|
||||||
|
init() {
|
||||||
|
if (browser && !window.hasOwnProperty('gpxstudio')) {
|
||||||
|
Object.defineProperty(window, 'gpxstudio', {
|
||||||
|
value: this,
|
||||||
|
});
|
||||||
|
addEventListener('beforeunload', () => {
|
||||||
|
this.destroy();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ensureLoaded(): Promise<void> {
|
||||||
|
let unsubscribe: () => void;
|
||||||
|
const promise = new Promise<void>((resolve) => {
|
||||||
|
map.onLoad(() => {
|
||||||
|
unsubscribe = currentOverlays.subscribe((current) => {
|
||||||
|
if (current) {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
promise.finally(() => {
|
||||||
|
unsubscribe?.();
|
||||||
|
});
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
addOrUpdateOverlay(overlay: CustomOverlay) {
|
||||||
|
if (
|
||||||
|
!overlay.extensionName ||
|
||||||
|
!overlay.id ||
|
||||||
|
!overlay.name ||
|
||||||
|
!overlay.tileUrls ||
|
||||||
|
overlay.tileUrls.length === 0
|
||||||
|
) {
|
||||||
|
throw new Error(
|
||||||
|
'Overlay must have an extensionName, id, name, and at least one tile URL.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
overlay.id = this.getOverlayId(overlay.id);
|
||||||
|
|
||||||
|
this._overlays.update(($overlays) => {
|
||||||
|
$overlays.set(overlay.id, overlay);
|
||||||
|
return $overlays;
|
||||||
|
});
|
||||||
|
|
||||||
|
overlays[overlay.id] = {
|
||||||
|
version: 8,
|
||||||
|
sources: {
|
||||||
|
[overlay.id]: {
|
||||||
|
type: 'raster',
|
||||||
|
tiles: overlay.tileUrls,
|
||||||
|
tileSize: overlay.tileUrls.some((url) => url.includes('512')) ? 512 : 256,
|
||||||
|
maxzoom: overlay.maxZoom ?? 22,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
layers: [
|
||||||
|
{
|
||||||
|
id: overlay.id,
|
||||||
|
type: 'raster',
|
||||||
|
source: overlay.id,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!overlayTree.overlays.hasOwnProperty(overlay.extensionName)) {
|
||||||
|
overlayTree.overlays[overlay.extensionName] = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
overlayTree.overlays[overlay.extensionName][overlay.id] = true;
|
||||||
|
|
||||||
|
selectedOverlayTree.update((selected) => {
|
||||||
|
if (!selected.overlays.hasOwnProperty(overlay.extensionName)) {
|
||||||
|
selected.overlays[overlay.extensionName] = {};
|
||||||
|
}
|
||||||
|
selected.overlays[overlay.extensionName][overlay.id] = true;
|
||||||
|
return selected;
|
||||||
|
});
|
||||||
|
|
||||||
|
const current = get(currentOverlays);
|
||||||
|
let show = false;
|
||||||
|
if (current && isSelected(current, overlay.id)) {
|
||||||
|
show = true;
|
||||||
|
try {
|
||||||
|
get(map)?.removeLayer(overlay.id);
|
||||||
|
} catch (e) {
|
||||||
|
// No reliable way to check if the map is ready to remove sources and layers
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
currentOverlays.update((current) => {
|
||||||
|
if (!current.overlays.hasOwnProperty(overlay.extensionName)) {
|
||||||
|
current.overlays[overlay.extensionName] = {};
|
||||||
|
}
|
||||||
|
current.overlays[overlay.extensionName][overlay.id] = show;
|
||||||
|
return current;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
filterOverlays(ids: string[]) {
|
||||||
|
ids = ids.map((id) => this.getOverlayId(id));
|
||||||
|
const idsToRemove = Array.from(get(this._overlays).keys()).filter(
|
||||||
|
(id) => !ids.includes(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
currentOverlays.update((current) => {
|
||||||
|
removeAll(current, idsToRemove);
|
||||||
|
return current;
|
||||||
|
});
|
||||||
|
previousOverlays.update((previous) => {
|
||||||
|
removeAll(previous, idsToRemove);
|
||||||
|
return previous;
|
||||||
|
});
|
||||||
|
selectedOverlayTree.update((selected) => {
|
||||||
|
removeAll(selected, idsToRemove);
|
||||||
|
return selected;
|
||||||
|
});
|
||||||
|
Object.keys(overlays).forEach((id) => {
|
||||||
|
if (idsToRemove.includes(id)) {
|
||||||
|
delete overlays[id];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
removeAll(overlayTree, idsToRemove);
|
||||||
|
this._overlays.update(($overlays) => {
|
||||||
|
$overlays.forEach((_, id) => {
|
||||||
|
if (idsToRemove.includes(id)) {
|
||||||
|
$overlays.delete(id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return $overlays;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
updateOverlaysOrder(ids: string[]) {
|
||||||
|
ids = ids.map((id) => this.getOverlayId(id));
|
||||||
|
selectedOverlayTree.update((selected) => {
|
||||||
|
let 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)
|
||||||
|
) {
|
||||||
|
isSelected[id] = selected.overlays[overlay.extensionName][id];
|
||||||
|
delete selected.overlays[overlay.extensionName][id];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Object.entries(isSelected).forEach(([id, value]) => {
|
||||||
|
const overlay = get(this._overlays).get(id)!;
|
||||||
|
selected.overlays[overlay.extensionName][id] = value;
|
||||||
|
});
|
||||||
|
return selected;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
isLayerFromExtension = derived(this._overlays, ($overlays) => {
|
||||||
|
return (id: string) => $overlays.has(id);
|
||||||
|
});
|
||||||
|
|
||||||
|
getLayerName = derived(this._overlays, ($overlays) => {
|
||||||
|
return (id: string) => $overlays.get(id)?.name || '';
|
||||||
|
});
|
||||||
|
|
||||||
|
private getOverlayId(id: string): string {
|
||||||
|
return `extension-${id}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private destroy() {
|
||||||
|
const ids = Array.from(get(this._overlays).keys());
|
||||||
|
currentOverlays.update((current) => {
|
||||||
|
ids.forEach((id) => {
|
||||||
|
remove(current, id);
|
||||||
|
});
|
||||||
|
return current;
|
||||||
|
});
|
||||||
|
previousOverlays.update((previous) => {
|
||||||
|
ids.forEach((id) => {
|
||||||
|
remove(previous, id);
|
||||||
|
});
|
||||||
|
return previous;
|
||||||
|
});
|
||||||
|
selectedOverlayTree.update((selected) => {
|
||||||
|
ids.forEach((id) => {
|
||||||
|
remove(selected, id);
|
||||||
|
});
|
||||||
|
return selected;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const extensionAPI = new ExtensionAPI();
|
||||||
@@ -6,6 +6,10 @@ import { overpassQueryData } from '$lib/assets/layers';
|
|||||||
import { MapPopup } from '$lib/components/map/map-popup';
|
import { MapPopup } from '$lib/components/map/map-popup';
|
||||||
import { settings } from '$lib/logic/settings';
|
import { settings } from '$lib/logic/settings';
|
||||||
import { db } from '$lib/db';
|
import { db } from '$lib/db';
|
||||||
|
import type { GeoJSONSource } from 'maplibre-gl';
|
||||||
|
import { ANCHOR_LAYER_KEY } from '../style';
|
||||||
|
import type { MapLayerEventManager } from '$lib/components/map/map-layer-event-manager';
|
||||||
|
import { loadSVGIcon } from '$lib/utils';
|
||||||
|
|
||||||
const { currentOverpassQueries } = settings;
|
const { currentOverpassQueries } = settings;
|
||||||
|
|
||||||
@@ -20,11 +24,12 @@ liveQuery(() => db.overpassdata.toArray()).subscribe((pois) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export class OverpassLayer {
|
export class OverpassLayer {
|
||||||
overpassUrl = 'https://overpass.private.coffee/api/interpreter';
|
overpassUrl = 'https://maps.mail.ru/osm/tools/overpass/api/interpreter';
|
||||||
minZoom = 12;
|
minZoom = 12;
|
||||||
queryZoom = 12;
|
queryZoom = 12;
|
||||||
expirationTime = 7 * 24 * 3600 * 1000;
|
expirationTime = 7 * 24 * 3600 * 1000;
|
||||||
map: mapboxgl.Map;
|
map: maplibregl.Map;
|
||||||
|
layerEventManager: MapLayerEventManager;
|
||||||
popup: MapPopup;
|
popup: MapPopup;
|
||||||
|
|
||||||
currentQueries: Set<string> = new Set();
|
currentQueries: Set<string> = new Set();
|
||||||
@@ -35,8 +40,9 @@ export class OverpassLayer {
|
|||||||
updateBinded = this.update.bind(this);
|
updateBinded = this.update.bind(this);
|
||||||
onHoverBinded = this.onHover.bind(this);
|
onHoverBinded = this.onHover.bind(this);
|
||||||
|
|
||||||
constructor(map: mapboxgl.Map) {
|
constructor(map: maplibregl.Map, layerEventManager: MapLayerEventManager) {
|
||||||
this.map = map;
|
this.map = map;
|
||||||
|
this.layerEventManager = layerEventManager;
|
||||||
this.popup = new MapPopup(map, {
|
this.popup = new MapPopup(map, {
|
||||||
closeButton: false,
|
closeButton: false,
|
||||||
focusAfterOpen: false,
|
focusAfterOpen: false,
|
||||||
@@ -47,7 +53,7 @@ export class OverpassLayer {
|
|||||||
|
|
||||||
add() {
|
add() {
|
||||||
this.map.on('moveend', this.queryIfNeededBinded);
|
this.map.on('moveend', this.queryIfNeededBinded);
|
||||||
this.map.on('style.import.load', this.updateBinded);
|
this.map.on('style.load', this.updateBinded);
|
||||||
this.unsubscribes.push(data.subscribe(this.updateBinded));
|
this.unsubscribes.push(data.subscribe(this.updateBinded));
|
||||||
this.unsubscribes.push(
|
this.unsubscribes.push(
|
||||||
currentOverpassQueries.subscribe(() => {
|
currentOverpassQueries.subscribe(() => {
|
||||||
@@ -71,10 +77,17 @@ export class OverpassLayer {
|
|||||||
update() {
|
update() {
|
||||||
this.loadIcons();
|
this.loadIcons();
|
||||||
|
|
||||||
let d = get(data);
|
const fullData = get(data);
|
||||||
|
const queries = getCurrentQueries();
|
||||||
|
const d: GeoJSON.FeatureCollection = {
|
||||||
|
type: 'FeatureCollection',
|
||||||
|
features: fullData.features.filter((feature) =>
|
||||||
|
queries.includes(feature.properties!.query)
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let source = this.map.getSource('overpass');
|
let source = this.map.getSource('overpass') as GeoJSONSource | undefined;
|
||||||
if (source) {
|
if (source) {
|
||||||
source.setData(d);
|
source.setData(d);
|
||||||
} else {
|
} else {
|
||||||
@@ -85,7 +98,8 @@ export class OverpassLayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!this.map.getLayer('overpass')) {
|
if (!this.map.getLayer('overpass')) {
|
||||||
this.map.addLayer({
|
this.map.addLayer(
|
||||||
|
{
|
||||||
id: 'overpass',
|
id: 'overpass',
|
||||||
type: 'symbol',
|
type: 'symbol',
|
||||||
source: 'overpass',
|
source: 'overpass',
|
||||||
@@ -95,13 +109,13 @@ export class OverpassLayer {
|
|||||||
'icon-padding': 0,
|
'icon-padding': 0,
|
||||||
'icon-allow-overlap': ['step', ['zoom'], false, 14, true],
|
'icon-allow-overlap': ['step', ['zoom'], false, 14, true],
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
|
ANCHOR_LAYER_KEY.overpass
|
||||||
|
);
|
||||||
|
|
||||||
this.map.on('mouseenter', 'overpass', this.onHoverBinded);
|
this.layerEventManager.on('mouseenter', 'overpass', this.onHoverBinded);
|
||||||
this.map.on('click', 'overpass', this.onHoverBinded);
|
this.layerEventManager.on('click', 'overpass', this.onHoverBinded);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.map.setFilter('overpass', ['in', 'query', ...getCurrentQueries()]);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// No reliable way to check if the map is ready to add sources and layers
|
// No reliable way to check if the map is ready to add sources and layers
|
||||||
}
|
}
|
||||||
@@ -109,7 +123,9 @@ export class OverpassLayer {
|
|||||||
|
|
||||||
remove() {
|
remove() {
|
||||||
this.map.off('moveend', this.queryIfNeededBinded);
|
this.map.off('moveend', this.queryIfNeededBinded);
|
||||||
this.map.off('style.import.load', this.updateBinded);
|
this.map.off('style.load', this.updateBinded);
|
||||||
|
this.layerEventManager.off('mouseenter', 'overpass', this.onHoverBinded);
|
||||||
|
this.layerEventManager.off('click', 'overpass', this.onHoverBinded);
|
||||||
this.unsubscribes.forEach((unsubscribe) => unsubscribe());
|
this.unsubscribes.forEach((unsubscribe) => unsubscribe());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -242,27 +258,16 @@ export class OverpassLayer {
|
|||||||
loadIcons() {
|
loadIcons() {
|
||||||
let currentQueries = getCurrentQueries();
|
let currentQueries = getCurrentQueries();
|
||||||
currentQueries.forEach((query) => {
|
currentQueries.forEach((query) => {
|
||||||
if (!this.map.hasImage(`overpass-${query}`)) {
|
loadSVGIcon(
|
||||||
let icon = new Image(100, 100);
|
this.map,
|
||||||
icon.onload = () => {
|
`overpass-${query}`,
|
||||||
if (!this.map.hasImage(`overpass-${query}`)) {
|
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40">
|
||||||
this.map.addImage(`overpass-${query}`, icon);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Lucide icons are SVG files with a 24x24 viewBox
|
|
||||||
// Create a new SVG with a 32x32 viewBox and center the icon in a circle
|
|
||||||
icon.src =
|
|
||||||
'data:image/svg+xml,' +
|
|
||||||
encodeURIComponent(`
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40">
|
|
||||||
<circle cx="20" cy="20" r="20" fill="${overpassQueryData[query].icon.color}" />
|
<circle cx="20" cy="20" r="20" fill="${overpassQueryData[query].icon.color}" />
|
||||||
<g transform="translate(8 8)">
|
<g transform="translate(8 8)">
|
||||||
${overpassQueryData[query].icon.svg.replace('stroke="currentColor"', 'stroke="white"')}
|
${overpassQueryData[query].icon.svg.replace('stroke="currentColor"', 'stroke="white"')}
|
||||||
</g>
|
</g>
|
||||||
</svg>
|
</svg>`
|
||||||
`);
|
);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -283,8 +288,10 @@ function getQuery(query: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getQueryItem(tags: Record<string, string | boolean | string[]>) {
|
function getQueryItem(tags: Record<string, string | string[]>) {
|
||||||
let arrayEntry = Object.entries(tags).find(([_, value]) => Array.isArray(value));
|
let arrayEntry = Object.entries(tags).find((entry): entry is [string, string[]] =>
|
||||||
|
Array.isArray(entry[1])
|
||||||
|
);
|
||||||
if (arrayEntry !== undefined) {
|
if (arrayEntry !== undefined) {
|
||||||
return arrayEntry[1]
|
return arrayEntry[1]
|
||||||
.map(
|
.map(
|
||||||
@@ -309,7 +316,7 @@ function belongsToQuery(element: any, query: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function belongsToQueryItem(element: any, tags: Record<string, string | boolean | string[]>) {
|
function belongsToQueryItem(element: any, tags: Record<string, string | string[]>) {
|
||||||
return Object.entries(tags).every(([tag, value]) =>
|
return Object.entries(tags).every(([tag, value]) =>
|
||||||
Array.isArray(value) ? value.includes(element.tags[tag]) : element.tags[tag] === value
|
Array.isArray(value) ? value.includes(element.tags[tag]) : element.tags[tag] === value
|
||||||
);
|
);
|
||||||
@@ -55,4 +55,24 @@ export function toggle(node: LayerTreeType, id: string) {
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const customBasemapUpdate = writable(0);
|
export function remove(node: LayerTreeType, id: string) {
|
||||||
|
Object.keys(node).forEach((key) => {
|
||||||
|
if (key === id) {
|
||||||
|
delete node[key];
|
||||||
|
} else if (typeof node[key] !== 'boolean') {
|
||||||
|
remove(node[key], id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function removeAll(node: LayerTreeType, ids: string[]) {
|
||||||
|
Object.keys(node).forEach((key) => {
|
||||||
|
if (ids.includes(key)) {
|
||||||
|
delete node[key];
|
||||||
|
} else if (typeof node[key] !== 'boolean') {
|
||||||
|
removeAll(node[key], ids);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|||||||
281
website/src/lib/components/map/map-layer-event-manager.ts
Normal file
281
website/src/lib/components/map/map-layer-event-manager.ts
Normal file
@@ -0,0 +1,281 @@
|
|||||||
|
import { fileStateCollection } from '$lib/logic/file-state';
|
||||||
|
import maplibregl from 'maplibre-gl';
|
||||||
|
|
||||||
|
type MapLayerMouseEventListener = (e: maplibregl.MapLayerMouseEvent) => void;
|
||||||
|
type MapLayerTouchEventListener = (e: maplibregl.MapLayerTouchEvent) => void;
|
||||||
|
type MapLayerListener = {
|
||||||
|
features: maplibregl.MapGeoJSONFeature[];
|
||||||
|
mousemoves: MapLayerMouseEventListener[];
|
||||||
|
mouseenters: MapLayerMouseEventListener[];
|
||||||
|
mouseleaves: MapLayerMouseEventListener[];
|
||||||
|
mousedowns: MapLayerMouseEventListener[];
|
||||||
|
clicks: MapLayerMouseEventListener[];
|
||||||
|
contextmenus: MapLayerMouseEventListener[];
|
||||||
|
touchstarts: MapLayerTouchEventListener[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export class MapLayerEventManager {
|
||||||
|
private _map: maplibregl.Map;
|
||||||
|
private _listeners: Record<string, MapLayerListener> = {};
|
||||||
|
|
||||||
|
constructor(map: maplibregl.Map) {
|
||||||
|
this._map = map;
|
||||||
|
this._map.on('mousemove', this._handleMouseMove.bind(this));
|
||||||
|
this._map.on('click', this._handleMouseClick.bind(this, 'click'));
|
||||||
|
this._map.on('contextmenu', this._handleMouseClick.bind(this, 'contextmenu'));
|
||||||
|
this._map.on('mousedown', this._handleMouseClick.bind(this, 'mousedown'));
|
||||||
|
this._map.on('touchstart', this._handleTouchStart.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
on(
|
||||||
|
eventType:
|
||||||
|
| 'mousemove'
|
||||||
|
| 'mouseenter'
|
||||||
|
| 'mouseleave'
|
||||||
|
| 'mousedown'
|
||||||
|
| 'click'
|
||||||
|
| 'contextmenu'
|
||||||
|
| 'touchstart',
|
||||||
|
|
||||||
|
layerId: string,
|
||||||
|
listener: MapLayerMouseEventListener | MapLayerTouchEventListener
|
||||||
|
) {
|
||||||
|
if (!this._listeners[layerId]) {
|
||||||
|
this._listeners[layerId] = {
|
||||||
|
features: [],
|
||||||
|
mousemoves: [],
|
||||||
|
mouseenters: [],
|
||||||
|
mouseleaves: [],
|
||||||
|
mousedowns: [],
|
||||||
|
clicks: [],
|
||||||
|
contextmenus: [],
|
||||||
|
touchstarts: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
switch (eventType) {
|
||||||
|
case 'mousemove':
|
||||||
|
this._listeners[layerId].mousemoves.push(listener as MapLayerMouseEventListener);
|
||||||
|
break;
|
||||||
|
case 'mouseenter':
|
||||||
|
this._listeners[layerId].mouseenters.push(listener as MapLayerMouseEventListener);
|
||||||
|
break;
|
||||||
|
case 'mouseleave':
|
||||||
|
this._listeners[layerId].mouseleaves.push(listener as MapLayerMouseEventListener);
|
||||||
|
break;
|
||||||
|
case 'mousedown':
|
||||||
|
this._listeners[layerId].mousedowns.push(listener as MapLayerMouseEventListener);
|
||||||
|
break;
|
||||||
|
case 'click':
|
||||||
|
this._listeners[layerId].clicks.push(listener as MapLayerMouseEventListener);
|
||||||
|
break;
|
||||||
|
case 'contextmenu':
|
||||||
|
this._listeners[layerId].contextmenus.push(listener as MapLayerMouseEventListener);
|
||||||
|
break;
|
||||||
|
case 'touchstart':
|
||||||
|
this._listeners[layerId].touchstarts.push(listener as MapLayerTouchEventListener);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
off(
|
||||||
|
eventType:
|
||||||
|
| 'mousemove'
|
||||||
|
| 'mouseenter'
|
||||||
|
| 'mouseleave'
|
||||||
|
| 'mousedown'
|
||||||
|
| 'click'
|
||||||
|
| 'contextmenu'
|
||||||
|
| 'touchstart',
|
||||||
|
layerId: string,
|
||||||
|
listener: MapLayerMouseEventListener | MapLayerTouchEventListener
|
||||||
|
) {
|
||||||
|
if (this._listeners[layerId]) {
|
||||||
|
switch (eventType) {
|
||||||
|
case 'mousemove':
|
||||||
|
this._listeners[layerId].mousemoves = this._listeners[
|
||||||
|
layerId
|
||||||
|
].mousemoves.filter((l) => l !== listener);
|
||||||
|
break;
|
||||||
|
case 'mouseenter':
|
||||||
|
this._listeners[layerId].mouseenters = this._listeners[
|
||||||
|
layerId
|
||||||
|
].mouseenters.filter((l) => l !== listener);
|
||||||
|
break;
|
||||||
|
case 'mouseleave':
|
||||||
|
this._listeners[layerId].mouseleaves = this._listeners[
|
||||||
|
layerId
|
||||||
|
].mouseleaves.filter((l) => l !== listener);
|
||||||
|
break;
|
||||||
|
case 'mousedown':
|
||||||
|
this._listeners[layerId].mousedowns = this._listeners[
|
||||||
|
layerId
|
||||||
|
].mousedowns.filter((l) => l !== listener);
|
||||||
|
break;
|
||||||
|
case 'click':
|
||||||
|
this._listeners[layerId].clicks = this._listeners[layerId].clicks.filter(
|
||||||
|
(l) => l !== listener
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case 'contextmenu':
|
||||||
|
this._listeners[layerId].contextmenus = this._listeners[
|
||||||
|
layerId
|
||||||
|
].contextmenus.filter((l) => l !== listener);
|
||||||
|
break;
|
||||||
|
case 'touchstart':
|
||||||
|
this._listeners[layerId].touchstarts = this._listeners[
|
||||||
|
layerId
|
||||||
|
].touchstarts.filter((l) => l !== listener);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
this._listeners[layerId].mousemoves.length === 0 &&
|
||||||
|
this._listeners[layerId].mouseenters.length === 0 &&
|
||||||
|
this._listeners[layerId].mouseleaves.length === 0 &&
|
||||||
|
this._listeners[layerId].mousedowns.length === 0 &&
|
||||||
|
this._listeners[layerId].clicks.length === 0 &&
|
||||||
|
this._listeners[layerId].contextmenus.length === 0 &&
|
||||||
|
this._listeners[layerId].touchstarts.length === 0
|
||||||
|
) {
|
||||||
|
delete this._listeners[layerId];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private _handleMouseMove(e: maplibregl.MapMouseEvent) {
|
||||||
|
const featuresByLayer = this._getRenderedFeaturesByLayer(e);
|
||||||
|
Object.keys(this._listeners).forEach((layerId) => {
|
||||||
|
const features = featuresByLayer[layerId] || [];
|
||||||
|
const listener = this._listeners[layerId];
|
||||||
|
if ((features.length == 0) != (listener.features.length == 0)) {
|
||||||
|
if (features.length > 0) {
|
||||||
|
if (listener.mouseenters.length > 0) {
|
||||||
|
const event = new maplibregl.MapMouseEvent(
|
||||||
|
'mouseenter',
|
||||||
|
e.target,
|
||||||
|
e.originalEvent,
|
||||||
|
{
|
||||||
|
features: featuresByLayer[layerId]!,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
listener.mouseenters.forEach((l) => l(event));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (listener.mouseleaves.length > 0) {
|
||||||
|
const event = new maplibregl.MapMouseEvent(
|
||||||
|
'mouseleave',
|
||||||
|
e.target,
|
||||||
|
e.originalEvent
|
||||||
|
);
|
||||||
|
listener.mouseleaves.forEach((l) => l(event));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (features.length > 0 && listener.mousemoves.length > 0) {
|
||||||
|
const event = new maplibregl.MapMouseEvent('mousemove', e.target, e.originalEvent, {
|
||||||
|
features: featuresByLayer[layerId]!,
|
||||||
|
});
|
||||||
|
listener.mousemoves.forEach((l) => l(event));
|
||||||
|
}
|
||||||
|
listener.features = features;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private _handleMouseClick(type: string, e: maplibregl.MapMouseEvent) {
|
||||||
|
const featuresByLayer = this._getRenderedFeaturesByLayer(e);
|
||||||
|
Object.keys(this._listeners).forEach((layerId) => {
|
||||||
|
const features = featuresByLayer[layerId] || [];
|
||||||
|
const listener = this._listeners[layerId];
|
||||||
|
if (features.length > 0) {
|
||||||
|
if (type === 'click' && listener.clicks.length > 0) {
|
||||||
|
const event = new maplibregl.MapMouseEvent('click', e.target, e.originalEvent, {
|
||||||
|
features: features,
|
||||||
|
});
|
||||||
|
listener.clicks.forEach((l) => l(event));
|
||||||
|
} else if (type === 'contextmenu' && listener.contextmenus.length > 0) {
|
||||||
|
const event = new maplibregl.MapMouseEvent(
|
||||||
|
'contextmenu',
|
||||||
|
e.target,
|
||||||
|
e.originalEvent,
|
||||||
|
{
|
||||||
|
features: features,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
listener.contextmenus.forEach((l) => l(event));
|
||||||
|
} else if (type === 'mousedown' && listener.mousedowns.length > 0) {
|
||||||
|
const event = new maplibregl.MapMouseEvent(
|
||||||
|
'mousedown',
|
||||||
|
e.target,
|
||||||
|
e.originalEvent,
|
||||||
|
{
|
||||||
|
features: features,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
listener.mousedowns.forEach((l) => l(event));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private _handleTouchStart(e: maplibregl.MapTouchEvent) {
|
||||||
|
const featuresByLayer = this._getRenderedFeaturesByLayer(e);
|
||||||
|
Object.keys(this._listeners).forEach((layerId) => {
|
||||||
|
const features = featuresByLayer[layerId] || [];
|
||||||
|
const listener = this._listeners[layerId];
|
||||||
|
if (features.length > 0) {
|
||||||
|
const event: maplibregl.MapLayerTouchEvent = new maplibregl.MapTouchEvent(
|
||||||
|
'touchstart',
|
||||||
|
e.target,
|
||||||
|
e.originalEvent
|
||||||
|
);
|
||||||
|
event.features = featuresByLayer[layerId]!;
|
||||||
|
listener.touchstarts.forEach((l) => l(event));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private _getBounds(point: maplibregl.Point) {
|
||||||
|
const delta = 30;
|
||||||
|
return new maplibregl.LngLatBounds(
|
||||||
|
this._map.unproject([point.x - delta, point.y + delta]),
|
||||||
|
this._map.unproject([point.x + delta, point.y - delta])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _filterLayersIntersectingBounds(
|
||||||
|
layerIds: string[],
|
||||||
|
bounds: maplibregl.LngLatBounds
|
||||||
|
): string[] {
|
||||||
|
let result = layerIds.filter((layerId) => {
|
||||||
|
if (!this._map.getLayer(layerId)) return false;
|
||||||
|
const fileId = layerId.replace('-waypoints', '');
|
||||||
|
if (fileId === layerId) {
|
||||||
|
return fileStateCollection.getStatistics(fileId)?.intersectsBBox(bounds) ?? true;
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
fileStateCollection.getStatistics(fileId)?.intersectsWaypointBBox(bounds) ??
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _getRenderedFeaturesByLayer(e: maplibregl.MapMouseEvent | maplibregl.MapTouchEvent) {
|
||||||
|
const layerIds = this._filterLayersIntersectingBounds(
|
||||||
|
Object.keys(this._listeners),
|
||||||
|
this._getBounds(e.point)
|
||||||
|
);
|
||||||
|
const features =
|
||||||
|
layerIds.length > 0
|
||||||
|
? this._map.queryRenderedFeatures(e.point, { layers: layerIds })
|
||||||
|
: [];
|
||||||
|
const featuresByLayer: Record<string, maplibregl.MapGeoJSONFeature[]> = {};
|
||||||
|
features.forEach((f) => {
|
||||||
|
if (!featuresByLayer[f.layer.id]) {
|
||||||
|
featuresByLayer[f.layer.id] = [];
|
||||||
|
}
|
||||||
|
featuresByLayer[f.layer.id].push(f);
|
||||||
|
});
|
||||||
|
return featuresByLayer;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { TrackPoint, Waypoint } from 'gpx';
|
import { TrackPoint, Waypoint } from 'gpx';
|
||||||
import mapboxgl from 'mapbox-gl';
|
import maplibregl from 'maplibre-gl';
|
||||||
import { mount, tick } from 'svelte';
|
import { mount, tick, unmount } from 'svelte';
|
||||||
import { get, writable, type Writable } from 'svelte/store';
|
import { get, writable, type Writable } from 'svelte/store';
|
||||||
import MapPopupComponent from '$lib/components/map/MapPopup.svelte';
|
import MapPopupComponent from '$lib/components/map/MapPopup.svelte';
|
||||||
|
|
||||||
@@ -11,15 +11,15 @@ export type PopupItem<T = Waypoint | TrackPoint | any> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export class MapPopup {
|
export class MapPopup {
|
||||||
map: mapboxgl.Map;
|
map: maplibregl.Map;
|
||||||
popup: mapboxgl.Popup;
|
popup: maplibregl.Popup;
|
||||||
item: Writable<PopupItem | null> = writable(null);
|
item: Writable<PopupItem | null> = writable(null);
|
||||||
component: ReturnType<typeof mount>;
|
component: ReturnType<typeof mount>;
|
||||||
maybeHideBinded = this.maybeHide.bind(this);
|
maybeHideBinded = this.maybeHide.bind(this);
|
||||||
|
|
||||||
constructor(map: mapboxgl.Map, options?: mapboxgl.PopupOptions) {
|
constructor(map: maplibregl.Map, options?: maplibregl.PopupOptions) {
|
||||||
this.map = map;
|
this.map = map;
|
||||||
this.popup = new mapboxgl.Popup(options);
|
this.popup = new maplibregl.Popup(options);
|
||||||
this.component = mount(MapPopupComponent, {
|
this.component = mount(MapPopupComponent, {
|
||||||
target: document.body,
|
target: document.body,
|
||||||
props: {
|
props: {
|
||||||
@@ -51,7 +51,7 @@ export class MapPopup {
|
|||||||
this.map.on('mousemove', this.maybeHideBinded);
|
this.map.on('mousemove', this.maybeHideBinded);
|
||||||
}
|
}
|
||||||
|
|
||||||
maybeHide(e: mapboxgl.MapMouseEvent) {
|
maybeHide(e: maplibregl.MapMouseEvent) {
|
||||||
const item = get(this.item);
|
const item = get(this.item);
|
||||||
if (item === null) {
|
if (item === null) {
|
||||||
this.hide();
|
this.hide();
|
||||||
@@ -69,16 +69,16 @@ export class MapPopup {
|
|||||||
|
|
||||||
remove() {
|
remove() {
|
||||||
this.popup.remove();
|
this.popup.remove();
|
||||||
this.component.$destroy();
|
unmount(this.component);
|
||||||
}
|
}
|
||||||
|
|
||||||
getCoordinates() {
|
getCoordinates() {
|
||||||
const item = get(this.item);
|
const item = get(this.item);
|
||||||
if (item === null) {
|
if (item === null) {
|
||||||
return new mapboxgl.LngLat(0, 0);
|
return new maplibregl.LngLat(0, 0);
|
||||||
}
|
}
|
||||||
return item.item instanceof Waypoint || item.item instanceof TrackPoint
|
return item.item instanceof Waypoint || item.item instanceof TrackPoint
|
||||||
? item.item.getCoordinates()
|
? item.item.getCoordinates()
|
||||||
: new mapboxgl.LngLat(item.item.lon, item.item.lat);
|
: new maplibregl.LngLat(item.item.lon, item.item.lat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,99 +1,80 @@
|
|||||||
import mapboxgl from 'mapbox-gl';
|
import maplibregl from 'maplibre-gl';
|
||||||
import MapboxGeocoder from '@mapbox/mapbox-gl-geocoder';
|
import 'maplibre-gl/dist/maplibre-gl.css';
|
||||||
|
import MaplibreGeocoder, {
|
||||||
|
type MaplibreGeocoderFeatureResults,
|
||||||
|
} from '@maplibre/maplibre-gl-geocoder';
|
||||||
|
import '@maplibre/maplibre-gl-geocoder/dist/maplibre-gl-geocoder.css';
|
||||||
import { get, writable, type Writable } from 'svelte/store';
|
import { get, writable, type Writable } from 'svelte/store';
|
||||||
import { settings } from '$lib/logic/settings';
|
import { settings } from '$lib/logic/settings';
|
||||||
|
import { tick } from 'svelte';
|
||||||
|
import { ANCHOR_LAYER_KEY, StyleManager } from '$lib/components/map/style';
|
||||||
|
import { MapLayerEventManager } from '$lib/components/map/map-layer-event-manager';
|
||||||
|
|
||||||
const { treeFileView, elevationProfile, bottomPanelSize, rightPanelSize, distanceUnits } = settings;
|
const { treeFileView, elevationProfile, bottomPanelSize, rightPanelSize, distanceUnits } = settings;
|
||||||
|
|
||||||
let fitBoundsOptions: mapboxgl.MapOptions['fitBoundsOptions'] = {
|
let fitBoundsOptions: maplibregl.MapOptions['fitBoundsOptions'] = {
|
||||||
maxZoom: 15,
|
maxZoom: 15,
|
||||||
linear: true,
|
linear: true,
|
||||||
easing: () => 1,
|
easing: () => 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
export class MapboxGLMap {
|
export class MapLibreGLMap {
|
||||||
private _map: Writable<mapboxgl.Map | null> = writable(null);
|
private _maptilerKey: string = '';
|
||||||
private _onLoadCallbacks: ((map: mapboxgl.Map) => void)[] = [];
|
private _map: maplibregl.Map | null = null;
|
||||||
|
private _mapStore: Writable<maplibregl.Map | null> = writable(null);
|
||||||
|
private _styleManager: StyleManager | null = null;
|
||||||
|
private _onLoadCallbacks: ((map: maplibregl.Map) => void)[] = [];
|
||||||
private _unsubscribes: (() => void)[] = [];
|
private _unsubscribes: (() => void)[] = [];
|
||||||
|
private callOnLoadBinded: () => void = this.callOnLoad.bind(this);
|
||||||
|
public layerEventManager: MapLayerEventManager | null = null;
|
||||||
|
|
||||||
subscribe(run: (value: mapboxgl.Map | null) => void, invalidate?: () => void) {
|
subscribe(run: (value: maplibregl.Map | null) => void, invalidate?: () => void) {
|
||||||
return this._map.subscribe(run, invalidate);
|
return this._mapStore.subscribe(run, invalidate);
|
||||||
}
|
}
|
||||||
|
|
||||||
init(
|
init(
|
||||||
accessToken: string,
|
maptilerKey: string,
|
||||||
language: string,
|
language: string,
|
||||||
hash: boolean,
|
hash: boolean,
|
||||||
geocoder: boolean,
|
geocoder: boolean,
|
||||||
geolocate: boolean
|
geolocate: boolean
|
||||||
) {
|
) {
|
||||||
const map = new mapboxgl.Map({
|
this._maptilerKey = maptilerKey;
|
||||||
|
this._styleManager = new StyleManager(this._mapStore, this._maptilerKey);
|
||||||
|
const map = new maplibregl.Map({
|
||||||
container: 'map',
|
container: 'map',
|
||||||
style: {
|
style: {
|
||||||
version: 8,
|
version: 8,
|
||||||
sources: {},
|
projection: {
|
||||||
layers: [],
|
type: 'globe',
|
||||||
imports: [
|
|
||||||
{
|
|
||||||
id: 'glyphs-and-sprite', // make Mapbox glyphs and sprite available to other styles
|
|
||||||
url: '',
|
|
||||||
data: {
|
|
||||||
version: 8,
|
|
||||||
sources: {},
|
|
||||||
layers: [],
|
|
||||||
glyphs: 'mapbox://fonts/mapbox/{fontstack}/{range}.pbf',
|
|
||||||
sprite: `https://api.mapbox.com/styles/v1/mapbox/outdoors-v12/sprite?access_token=${accessToken}`,
|
|
||||||
},
|
},
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'basemap',
|
|
||||||
url: '',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'overlays',
|
|
||||||
url: '',
|
|
||||||
data: {
|
|
||||||
version: 8,
|
|
||||||
sources: {},
|
sources: {},
|
||||||
layers: [],
|
layers: [],
|
||||||
},
|
},
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
projection: 'globe',
|
|
||||||
zoom: 0,
|
zoom: 0,
|
||||||
hash: hash,
|
hash: hash,
|
||||||
language,
|
|
||||||
attributionControl: false,
|
|
||||||
logoPosition: 'bottom-right',
|
|
||||||
boxZoom: false,
|
boxZoom: false,
|
||||||
|
maxPitch: 85,
|
||||||
});
|
});
|
||||||
|
this.layerEventManager = new MapLayerEventManager(map);
|
||||||
map.addControl(
|
map.addControl(
|
||||||
new mapboxgl.AttributionControl({
|
new maplibregl.NavigationControl({
|
||||||
compact: true,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
map.addControl(
|
|
||||||
new mapboxgl.NavigationControl({
|
|
||||||
visualizePitch: true,
|
visualizePitch: true,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
if (geocoder) {
|
if (geocoder) {
|
||||||
let geocoder = new MapboxGeocoder({
|
let geocoder = new MaplibreGeocoder(
|
||||||
mapboxgl: mapboxgl,
|
{
|
||||||
enableEventLogging: false,
|
forwardGeocode: async (config) => {
|
||||||
collapsed: true,
|
const results: MaplibreGeocoderFeatureResults = {
|
||||||
flyTo: fitBoundsOptions,
|
features: [],
|
||||||
language,
|
type: 'FeatureCollection',
|
||||||
localGeocoder: () => [],
|
};
|
||||||
localGeocoderOnly: true,
|
try {
|
||||||
externalGeocoder: (query: string) =>
|
const request = `https://nominatim.openstreetmap.org/search?format=json&q=${config.query}&limit=5&accept-language=${language}`;
|
||||||
fetch(
|
const response = await fetch(request);
|
||||||
`https://nominatim.openstreetmap.org/search?format=json&q=${query}&limit=5&accept-language=${language}`
|
const geojson = await response.json();
|
||||||
)
|
results.features = geojson.map((result: any) => {
|
||||||
.then((response) => response.json())
|
|
||||||
.then((data) => {
|
|
||||||
return data.map((result: any) => {
|
|
||||||
return {
|
return {
|
||||||
type: 'Feature',
|
type: 'Feature',
|
||||||
geometry: {
|
geometry: {
|
||||||
@@ -103,73 +84,43 @@ export class MapboxGLMap {
|
|||||||
place_name: result.display_name,
|
place_name: result.display_name,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}),
|
} catch (e) {}
|
||||||
});
|
return results;
|
||||||
let onKeyDown = geocoder._onKeyDown;
|
},
|
||||||
geocoder._onKeyDown = (e: KeyboardEvent) => {
|
},
|
||||||
// Trigger search on Enter key only
|
{
|
||||||
if (e.key === 'Enter') {
|
maplibregl: maplibregl,
|
||||||
onKeyDown.apply(geocoder, [{ target: geocoder._inputEl }]);
|
enableEventLogging: false,
|
||||||
} else if (geocoder._typeahead.data.length > 0) {
|
collapsed: true,
|
||||||
geocoder._typeahead.clear();
|
flyTo: fitBoundsOptions,
|
||||||
|
language,
|
||||||
}
|
}
|
||||||
};
|
);
|
||||||
map.addControl(geocoder);
|
map.addControl(geocoder);
|
||||||
}
|
}
|
||||||
if (geolocate) {
|
if (geolocate) {
|
||||||
map.addControl(
|
map.addControl(
|
||||||
new mapboxgl.GeolocateControl({
|
new maplibregl.GeolocateControl({
|
||||||
positionOptions: {
|
positionOptions: {
|
||||||
enableHighAccuracy: true,
|
enableHighAccuracy: true,
|
||||||
},
|
},
|
||||||
fitBoundsOptions,
|
fitBoundsOptions,
|
||||||
trackUserLocation: true,
|
trackUserLocation: true,
|
||||||
showUserHeading: true,
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const scaleControl = new mapboxgl.ScaleControl({
|
const scaleControl = new maplibregl.ScaleControl({
|
||||||
unit: get(distanceUnits),
|
unit: get(distanceUnits),
|
||||||
});
|
});
|
||||||
map.addControl(scaleControl);
|
map.addControl(scaleControl);
|
||||||
map.on('style.load', () => {
|
|
||||||
map.addSource('mapbox-dem', {
|
|
||||||
type: 'raster-dem',
|
|
||||||
url: 'mapbox://mapbox.mapbox-terrain-dem-v1',
|
|
||||||
tileSize: 512,
|
|
||||||
maxzoom: 14,
|
|
||||||
});
|
|
||||||
if (map.getPitch() > 0) {
|
|
||||||
map.setTerrain({
|
|
||||||
source: 'mapbox-dem',
|
|
||||||
exaggeration: 1,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
map.setFog({
|
|
||||||
color: 'rgb(186, 210, 235)',
|
|
||||||
'high-color': 'rgb(36, 92, 223)',
|
|
||||||
'horizon-blend': 0.1,
|
|
||||||
'space-color': 'rgb(156, 240, 255)',
|
|
||||||
});
|
|
||||||
map.on('pitch', () => {
|
|
||||||
if (map.getPitch() > 0) {
|
|
||||||
map.setTerrain({
|
|
||||||
source: 'mapbox-dem',
|
|
||||||
exaggeration: 1,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
map.setTerrain(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
map.on('load', () => {
|
map.on('load', () => {
|
||||||
this._map.set(map); // only set the store after the map has loaded
|
this._map = map;
|
||||||
|
this._mapStore.set(map); // only set the store after the map has loaded
|
||||||
window._map = map; // entry point for extensions
|
window._map = map; // entry point for extensions
|
||||||
|
this.resize();
|
||||||
scaleControl.setUnit(get(distanceUnits));
|
scaleControl.setUnit(get(distanceUnits));
|
||||||
|
|
||||||
this._onLoadCallbacks.forEach((callback) => callback(map));
|
|
||||||
this._onLoadCallbacks = [];
|
|
||||||
});
|
});
|
||||||
|
map.on('style.load', this.callOnLoadBinded);
|
||||||
|
|
||||||
this._unsubscribes.push(treeFileView.subscribe(() => this.resize()));
|
this._unsubscribes.push(treeFileView.subscribe(() => this.resize()));
|
||||||
this._unsubscribes.push(elevationProfile.subscribe(() => this.resize()));
|
this._unsubscribes.push(elevationProfile.subscribe(() => this.resize()));
|
||||||
@@ -182,144 +133,48 @@ export class MapboxGLMap {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
onLoad(callback: (map: mapboxgl.Map) => void) {
|
|
||||||
const map = get(this._map);
|
|
||||||
if (map) {
|
|
||||||
callback(map);
|
|
||||||
} else {
|
|
||||||
this._onLoadCallbacks.push(callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
const map = get(this._map);
|
if (this._map) {
|
||||||
if (map) {
|
this._map.remove();
|
||||||
map.remove();
|
this._mapStore.set(null);
|
||||||
this._map.set(null);
|
|
||||||
}
|
}
|
||||||
this._unsubscribes.forEach((unsubscribe) => unsubscribe());
|
this._unsubscribes.forEach((unsubscribe) => unsubscribe());
|
||||||
this._unsubscribes = [];
|
this._unsubscribes = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
resize() {
|
resize() {
|
||||||
const map = get(this._map);
|
if (this._map) {
|
||||||
if (map) {
|
tick().then(() => {
|
||||||
map.resize();
|
this._map?.resize();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toggle3D() {
|
toggle3D() {
|
||||||
const map = get(this._map);
|
if (this._map) {
|
||||||
if (map) {
|
if (this._map.getPitch() === 0) {
|
||||||
if (map.getPitch() === 0) {
|
this._map.easeTo({ pitch: 70 });
|
||||||
map.easeTo({ pitch: 70 });
|
|
||||||
} else {
|
} else {
|
||||||
map.easeTo({ pitch: 0 });
|
this._map.easeTo({ pitch: 0 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onLoad(callback: (map: maplibregl.Map) => void) {
|
||||||
|
if (this._map) {
|
||||||
|
callback(this._map);
|
||||||
|
} else {
|
||||||
|
this._onLoadCallbacks.push(callback);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const map = new MapboxGLMap();
|
callOnLoad() {
|
||||||
|
if (this._map && this._map.getLayer(ANCHOR_LAYER_KEY.overlays)) {
|
||||||
|
this._onLoadCallbacks.forEach((callback) => callback(this._map!));
|
||||||
|
this._onLoadCallbacks = [];
|
||||||
|
this._map.off('style.load', this.callOnLoadBinded);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// const targetMapBounds: {
|
export const map = new MapLibreGLMap();
|
||||||
// bounds: mapboxgl.LngLatBounds;
|
|
||||||
// ids: string[];
|
|
||||||
// total: number;
|
|
||||||
// } = $state({
|
|
||||||
// bounds: new mapboxgl.LngLatBounds([180, 90, -180, -90]),
|
|
||||||
// ids: [],
|
|
||||||
// total: 0,
|
|
||||||
// });
|
|
||||||
|
|
||||||
// $effect(() => {
|
|
||||||
// if (
|
|
||||||
// map.current === null ||
|
|
||||||
// targetMapBounds.ids.length > 0 ||
|
|
||||||
// (targetMapBounds.bounds.getSouth() === 90 &&
|
|
||||||
// targetMapBounds.bounds.getWest() === 180 &&
|
|
||||||
// targetMapBounds.bounds.getNorth() === -90 &&
|
|
||||||
// targetMapBounds.bounds.getEast() === -180)
|
|
||||||
// ) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// let currentZoom = map.current.getZoom();
|
|
||||||
// let currentBounds = map.current.getBounds();
|
|
||||||
// if (
|
|
||||||
// targetMapBounds.total !== get(fileObservers).size &&
|
|
||||||
// currentBounds &&
|
|
||||||
// currentZoom > 2 // Extend current bounds only if the map is zoomed in
|
|
||||||
// ) {
|
|
||||||
// // There are other files on the map
|
|
||||||
// if (
|
|
||||||
// currentBounds.contains(targetMapBounds.bounds.getSouthEast()) &&
|
|
||||||
// currentBounds.contains(targetMapBounds.bounds.getNorthWest())
|
|
||||||
// ) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// targetMapBounds.bounds.extend(currentBounds.getSouthWest());
|
|
||||||
// targetMapBounds.bounds.extend(currentBounds.getNorthEast());
|
|
||||||
// }
|
|
||||||
|
|
||||||
// map.current.fitBounds(targetMapBounds.bounds, { padding: 80, linear: true, easing: () => 1 });
|
|
||||||
// });
|
|
||||||
|
|
||||||
// export function initTargetMapBounds(ids: string[]) {
|
|
||||||
// targetMapBounds.bounds = new mapboxgl.LngLatBounds([180, 90, -180, -90]);
|
|
||||||
// targetMapBounds.ids = ids;
|
|
||||||
// targetMapBounds.total = ids.length;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// export function updateTargetMapBounds(
|
|
||||||
// id: string,
|
|
||||||
// bounds: { southWest: Coordinates; northEast: Coordinates }
|
|
||||||
// ) {
|
|
||||||
// if (targetMapBounds.ids.indexOf(id) === -1) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (
|
|
||||||
// bounds.southWest.lat !== 90 ||
|
|
||||||
// bounds.southWest.lon !== 180 ||
|
|
||||||
// bounds.northEast.lat !== -90 ||
|
|
||||||
// bounds.northEast.lon !== -180
|
|
||||||
// ) {
|
|
||||||
// // Avoid update for empty (new) files
|
|
||||||
// targetMapBounds.ids = targetMapBounds.ids.filter((x) => x !== id);
|
|
||||||
// targetMapBounds.bounds.extend(bounds.southWest);
|
|
||||||
// targetMapBounds.bounds.extend(bounds.northEast);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// export function centerMapOnSelection() {
|
|
||||||
// let selected = get(selection).getSelected();
|
|
||||||
// let bounds = new mapboxgl.LngLatBounds();
|
|
||||||
|
|
||||||
// if (selected.find((item) => item instanceof ListWaypointItem)) {
|
|
||||||
// applyToOrderedSelectedItemsFromFile((fileId, level, items) => {
|
|
||||||
// let file = getFile(fileId);
|
|
||||||
// if (file) {
|
|
||||||
// items.forEach((item) => {
|
|
||||||
// if (item instanceof ListWaypointItem) {
|
|
||||||
// let waypoint = file.wpt[item.getWaypointIndex()];
|
|
||||||
// if (waypoint) {
|
|
||||||
// bounds.extend([waypoint.getLongitude(), waypoint.getLatitude()]);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// } else {
|
|
||||||
// let selectionBounds = get(gpxStatistics).global.bounds;
|
|
||||||
// bounds.setNorthEast(selectionBounds.northEast);
|
|
||||||
// bounds.setSouthWest(selectionBounds.southWest);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// get(map)?.fitBounds(bounds, {
|
|
||||||
// padding: 80,
|
|
||||||
// easing: () => 1,
|
|
||||||
// maxZoom: 15,
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -2,11 +2,9 @@
|
|||||||
import { streetViewEnabled } from '$lib/components/map/street-view-control/utils';
|
import { streetViewEnabled } from '$lib/components/map/street-view-control/utils';
|
||||||
import { map } from '$lib/components/map/map';
|
import { map } from '$lib/components/map/map';
|
||||||
import CustomControl from '$lib/components/map/custom-control/CustomControl.svelte';
|
import CustomControl from '$lib/components/map/custom-control/CustomControl.svelte';
|
||||||
import Tooltip from '$lib/components/Tooltip.svelte';
|
|
||||||
import { Toggle } from '$lib/components/ui/toggle';
|
|
||||||
import { PersonStanding, X } from '@lucide/svelte';
|
import { PersonStanding, X } from '@lucide/svelte';
|
||||||
import { MapillaryLayer } from './Mapillary';
|
import { MapillaryLayer } from './mapillary';
|
||||||
import { GoogleRedirect } from './Google';
|
import { GoogleRedirect } from './google';
|
||||||
import { settings } from '$lib/logic/settings';
|
import { settings } from '$lib/logic/settings';
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
@@ -22,9 +20,14 @@
|
|||||||
let container: HTMLElement;
|
let container: HTMLElement;
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
map.onLoad((map: mapboxgl.Map) => {
|
map.onLoad((map_: maplibregl.Map) => {
|
||||||
googleRedirect = new GoogleRedirect(map);
|
googleRedirect = new GoogleRedirect(map_);
|
||||||
mapillaryLayer = new MapillaryLayer(map, container, mapillaryOpen);
|
mapillaryLayer = new MapillaryLayer(
|
||||||
|
map_,
|
||||||
|
map.layerEventManager!,
|
||||||
|
container,
|
||||||
|
mapillaryOpen
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import { mapCursor, MapCursorState } from '$lib/logic/map-cursor';
|
import { mapCursor, MapCursorState } from '$lib/logic/map-cursor';
|
||||||
import type mapboxgl from 'mapbox-gl';
|
|
||||||
|
|
||||||
export class GoogleRedirect {
|
export class GoogleRedirect {
|
||||||
map: mapboxgl.Map;
|
map: maplibregl.Map;
|
||||||
enabled = false;
|
enabled = false;
|
||||||
|
|
||||||
constructor(map: mapboxgl.Map) {
|
constructor(map: maplibregl.Map) {
|
||||||
this.map = map;
|
this.map = map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,7 +24,7 @@ export class GoogleRedirect {
|
|||||||
this.map.off('click', this.openStreetView);
|
this.map.off('click', this.openStreetView);
|
||||||
}
|
}
|
||||||
|
|
||||||
openStreetView(e: mapboxgl.MapMouseEvent) {
|
openStreetView(e: maplibregl.MapMouseEvent) {
|
||||||
window.open(
|
window.open(
|
||||||
`https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=${e.lngLat.lat},${e.lngLat.lng}`
|
`https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=${e.lngLat.lat},${e.lngLat.lng}`
|
||||||
);
|
);
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
import mapboxgl, { type LayerSpecification, type VectorSourceSpecification } from 'mapbox-gl';
|
import maplibregl, { type LayerSpecification, type VectorSourceSpecification } from 'maplibre-gl';
|
||||||
import { Viewer, type ViewerBearingEvent } from 'mapillary-js/dist/mapillary.module';
|
import { Viewer, type ViewerBearingEvent } from 'mapillary-js/dist/mapillary.module';
|
||||||
import 'mapillary-js/dist/mapillary.css';
|
import 'mapillary-js/dist/mapillary.css';
|
||||||
import { mapCursor, MapCursorState } from '$lib/logic/map-cursor';
|
import { mapCursor, MapCursorState } from '$lib/logic/map-cursor';
|
||||||
|
import { ANCHOR_LAYER_KEY } from '../style';
|
||||||
|
import type { MapLayerEventManager } from '$lib/components/map/map-layer-event-manager';
|
||||||
|
|
||||||
const mapillarySource: VectorSourceSpecification = {
|
const mapillarySource: VectorSourceSpecification = {
|
||||||
type: 'vector',
|
type: 'vector',
|
||||||
@@ -41,8 +43,9 @@ const mapillaryImageLayer: LayerSpecification = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export class MapillaryLayer {
|
export class MapillaryLayer {
|
||||||
map: mapboxgl.Map;
|
map: maplibregl.Map;
|
||||||
marker: mapboxgl.Marker;
|
layerEventManager: MapLayerEventManager;
|
||||||
|
marker: maplibregl.Marker;
|
||||||
viewer: Viewer;
|
viewer: Viewer;
|
||||||
|
|
||||||
active = false;
|
active = false;
|
||||||
@@ -52,8 +55,14 @@ export class MapillaryLayer {
|
|||||||
onMouseEnterBinded = this.onMouseEnter.bind(this);
|
onMouseEnterBinded = this.onMouseEnter.bind(this);
|
||||||
onMouseLeaveBinded = this.onMouseLeave.bind(this);
|
onMouseLeaveBinded = this.onMouseLeave.bind(this);
|
||||||
|
|
||||||
constructor(map: mapboxgl.Map, container: HTMLElement, popupOpen: { value: boolean }) {
|
constructor(
|
||||||
|
map: maplibregl.Map,
|
||||||
|
layerEventManager: MapLayerEventManager,
|
||||||
|
container: HTMLElement,
|
||||||
|
popupOpen: { value: boolean }
|
||||||
|
) {
|
||||||
this.map = map;
|
this.map = map;
|
||||||
|
this.layerEventManager = layerEventManager;
|
||||||
|
|
||||||
this.viewer = new Viewer({
|
this.viewer = new Viewer({
|
||||||
accessToken: 'MLY|4381405525255083|3204871ec181638c3c31320490f03011',
|
accessToken: 'MLY|4381405525255083|3204871ec181638c3c31320490f03011',
|
||||||
@@ -61,15 +70,12 @@ export class MapillaryLayer {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const element = document.createElement('div');
|
const element = document.createElement('div');
|
||||||
element.className = 'mapboxgl-user-location mapboxgl-user-location-show-heading';
|
element.className = 'maplibregl-user-location maplibregl-user-location-show-heading';
|
||||||
const dot = document.createElement('div');
|
const dot = document.createElement('div');
|
||||||
dot.className = 'mapboxgl-user-location-dot';
|
dot.className = 'maplibregl-user-location-dot';
|
||||||
const heading = document.createElement('div');
|
|
||||||
heading.className = 'mapboxgl-user-location-heading';
|
|
||||||
element.appendChild(dot);
|
element.appendChild(dot);
|
||||||
element.appendChild(heading);
|
|
||||||
|
|
||||||
this.marker = new mapboxgl.Marker({
|
this.marker = new maplibregl.Marker({
|
||||||
rotationAlignment: 'map',
|
rotationAlignment: 'map',
|
||||||
element,
|
element,
|
||||||
});
|
});
|
||||||
@@ -99,20 +105,20 @@ export class MapillaryLayer {
|
|||||||
this.map.addSource('mapillary', mapillarySource);
|
this.map.addSource('mapillary', mapillarySource);
|
||||||
}
|
}
|
||||||
if (!this.map.getLayer('mapillary-sequence')) {
|
if (!this.map.getLayer('mapillary-sequence')) {
|
||||||
this.map.addLayer(mapillarySequenceLayer);
|
this.map.addLayer(mapillarySequenceLayer, ANCHOR_LAYER_KEY.mapillary);
|
||||||
}
|
}
|
||||||
if (!this.map.getLayer('mapillary-image')) {
|
if (!this.map.getLayer('mapillary-image')) {
|
||||||
this.map.addLayer(mapillaryImageLayer);
|
this.map.addLayer(mapillaryImageLayer, ANCHOR_LAYER_KEY.mapillary);
|
||||||
}
|
}
|
||||||
this.map.on('style.load', this.addBinded);
|
this.map.on('style.load', this.addBinded);
|
||||||
this.map.on('mouseenter', 'mapillary-image', this.onMouseEnterBinded);
|
this.layerEventManager.on('mouseenter', 'mapillary-image', this.onMouseEnterBinded);
|
||||||
this.map.on('mouseleave', 'mapillary-image', this.onMouseLeaveBinded);
|
this.layerEventManager.on('mouseleave', 'mapillary-image', this.onMouseLeaveBinded);
|
||||||
}
|
}
|
||||||
|
|
||||||
remove() {
|
remove() {
|
||||||
this.map.off('style.load', this.addBinded);
|
this.map.off('style.load', this.addBinded);
|
||||||
this.map.off('mouseenter', 'mapillary-image', this.onMouseEnterBinded);
|
this.layerEventManager.off('mouseenter', 'mapillary-image', this.onMouseEnterBinded);
|
||||||
this.map.off('mouseleave', 'mapillary-image', this.onMouseLeaveBinded);
|
this.layerEventManager.off('mouseleave', 'mapillary-image', this.onMouseLeaveBinded);
|
||||||
|
|
||||||
if (this.map.getLayer('mapillary-image')) {
|
if (this.map.getLayer('mapillary-image')) {
|
||||||
this.map.removeLayer('mapillary-image');
|
this.map.removeLayer('mapillary-image');
|
||||||
@@ -134,7 +140,13 @@ export class MapillaryLayer {
|
|||||||
this.popupOpen.value = false;
|
this.popupOpen.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
onMouseEnter(e: mapboxgl.MapMouseEvent) {
|
onMouseEnter(e: maplibregl.MapLayerMouseEvent) {
|
||||||
|
if (
|
||||||
|
e.features &&
|
||||||
|
e.features.length > 0 &&
|
||||||
|
e.features[0].properties &&
|
||||||
|
e.features[0].properties.id
|
||||||
|
) {
|
||||||
this.active = true;
|
this.active = true;
|
||||||
|
|
||||||
this.viewer.resize();
|
this.viewer.resize();
|
||||||
@@ -142,6 +154,7 @@ export class MapillaryLayer {
|
|||||||
|
|
||||||
mapCursor.notify(MapCursorState.MAPILLARY_HOVER, true);
|
mapCursor.notify(MapCursorState.MAPILLARY_HOVER, true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMouseLeave() {
|
onMouseLeave() {
|
||||||
mapCursor.notify(MapCursorState.MAPILLARY_HOVER, false);
|
mapCursor.notify(MapCursorState.MAPILLARY_HOVER, false);
|
||||||
231
website/src/lib/components/map/style.ts
Normal file
231
website/src/lib/components/map/style.ts
Normal file
@@ -0,0 +1,231 @@
|
|||||||
|
import { settings } from '$lib/logic/settings';
|
||||||
|
import { get, type Writable } from 'svelte/store';
|
||||||
|
import {
|
||||||
|
basemaps,
|
||||||
|
defaultBasemap,
|
||||||
|
maptilerKeyPlaceHolder,
|
||||||
|
overlays,
|
||||||
|
terrainSources,
|
||||||
|
} from '$lib/assets/layers';
|
||||||
|
import { getLayers } from '$lib/components/map/layer-control/utils';
|
||||||
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
|
|
||||||
|
const { currentBasemap, currentOverlays, customLayers, opacities, terrainSource } = settings;
|
||||||
|
|
||||||
|
const emptySource: maplibregl.GeoJSONSourceSpecification = {
|
||||||
|
type: 'geojson',
|
||||||
|
data: {
|
||||||
|
type: 'FeatureCollection',
|
||||||
|
features: [],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
export const ANCHOR_LAYER_KEY = {
|
||||||
|
overlays: 'overlays-end',
|
||||||
|
mapillary: 'mapillary-end',
|
||||||
|
tracks: 'tracks-end',
|
||||||
|
directionMarkers: 'direction-markers-end',
|
||||||
|
distanceMarkers: 'distance-markers-end',
|
||||||
|
startEndMarkers: 'start-end-markers-end',
|
||||||
|
interactions: 'interactions-end',
|
||||||
|
overpass: 'overpass-end',
|
||||||
|
waypoints: 'waypoints-end',
|
||||||
|
routingControls: 'routing-controls-end',
|
||||||
|
};
|
||||||
|
const anchorLayers: maplibregl.LayerSpecification[] = Object.values(ANCHOR_LAYER_KEY).map((id) => ({
|
||||||
|
id: id,
|
||||||
|
type: 'symbol',
|
||||||
|
source: 'empty-source',
|
||||||
|
}));
|
||||||
|
|
||||||
|
export class StyleManager {
|
||||||
|
private _map: Writable<maplibregl.Map | null>;
|
||||||
|
private _maptilerKey: string;
|
||||||
|
private _pastOverlays: Set<string> = new Set();
|
||||||
|
|
||||||
|
constructor(map: Writable<maplibregl.Map | null>, maptilerKey: string) {
|
||||||
|
this._map = map;
|
||||||
|
this._maptilerKey = maptilerKey;
|
||||||
|
this._map.subscribe((map_) => {
|
||||||
|
if (map_) {
|
||||||
|
this.updateBasemap();
|
||||||
|
map_.on('style.load', () => this.updateOverlays());
|
||||||
|
map_.on('pitch', () => this.updateTerrain());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
currentBasemap.subscribe(() => this.updateBasemap());
|
||||||
|
currentOverlays.subscribe(() => this.updateOverlays());
|
||||||
|
opacities.subscribe(() => this.updateOverlays());
|
||||||
|
terrainSource.subscribe(() => this.updateTerrain());
|
||||||
|
customLayers.subscribe(() => this.updateBasemap());
|
||||||
|
}
|
||||||
|
|
||||||
|
updateBasemap() {
|
||||||
|
const map_ = get(this._map);
|
||||||
|
if (!map_) return;
|
||||||
|
this.buildStyle().then((style) => map_.setStyle(style));
|
||||||
|
}
|
||||||
|
|
||||||
|
async buildStyle(): Promise<maplibregl.StyleSpecification> {
|
||||||
|
const custom = get(customLayers);
|
||||||
|
|
||||||
|
const style: maplibregl.StyleSpecification = {
|
||||||
|
version: 8,
|
||||||
|
projection: {
|
||||||
|
type: 'globe',
|
||||||
|
},
|
||||||
|
sources: {
|
||||||
|
'empty-source': emptySource,
|
||||||
|
},
|
||||||
|
layers: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
let basemap = get(currentBasemap);
|
||||||
|
const basemapInfo = basemaps[basemap] ?? custom[basemap]?.value ?? basemaps[defaultBasemap];
|
||||||
|
const basemapStyle = await this.get(basemapInfo);
|
||||||
|
|
||||||
|
this.merge(style, basemapStyle);
|
||||||
|
|
||||||
|
const terrain = this.getCurrentTerrain();
|
||||||
|
style.sources[terrain.source] = terrainSources[terrain.source];
|
||||||
|
style.terrain = terrain.exaggeration > 0 ? terrain : undefined;
|
||||||
|
|
||||||
|
style.layers.push(...anchorLayers);
|
||||||
|
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateOverlays() {
|
||||||
|
const map_ = get(this._map);
|
||||||
|
if (!map_) return;
|
||||||
|
if (!map_.getSource('empty-source')) return;
|
||||||
|
|
||||||
|
const custom = get(customLayers);
|
||||||
|
const overlayOpacities = get(opacities);
|
||||||
|
try {
|
||||||
|
const layers = getLayers(get(currentOverlays) ?? {});
|
||||||
|
for (let overlay in layers) {
|
||||||
|
if (!layers[overlay]) {
|
||||||
|
if (this._pastOverlays.has(overlay)) {
|
||||||
|
const overlayInfo = custom[overlay]?.value ?? overlays[overlay];
|
||||||
|
const overlayStyle = await this.get(overlayInfo);
|
||||||
|
for (let layer of overlayStyle.layers ?? []) {
|
||||||
|
if (map_.getLayer(layer.id)) {
|
||||||
|
map_.removeLayer(layer.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this._pastOverlays.delete(overlay);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const overlayInfo = custom[overlay]?.value ?? overlays[overlay];
|
||||||
|
const overlayStyle = await this.get(overlayInfo);
|
||||||
|
const opacity = overlayOpacities[overlay];
|
||||||
|
|
||||||
|
for (let sourceId in overlayStyle.sources) {
|
||||||
|
if (!map_.getSource(sourceId)) {
|
||||||
|
map_.addSource(sourceId, overlayStyle.sources[sourceId]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let layer of overlayStyle.layers ?? []) {
|
||||||
|
if (!map_.getLayer(layer.id)) {
|
||||||
|
if (opacity !== undefined) {
|
||||||
|
if (layer.type === 'raster') {
|
||||||
|
if (!layer.paint) {
|
||||||
|
layer.paint = {};
|
||||||
|
}
|
||||||
|
layer.paint['raster-opacity'] = opacity;
|
||||||
|
} else if (layer.type === 'hillshade') {
|
||||||
|
if (!layer.paint) {
|
||||||
|
layer.paint = {};
|
||||||
|
}
|
||||||
|
layer.paint['hillshade-exaggeration'] = opacity / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
map_.addLayer(layer, ANCHOR_LAYER_KEY.overlays);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this._pastOverlays.add(overlay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTerrain() {
|
||||||
|
const map_ = get(this._map);
|
||||||
|
if (!map_) return;
|
||||||
|
|
||||||
|
const mapTerrain = map_.getTerrain();
|
||||||
|
const terrain = this.getCurrentTerrain();
|
||||||
|
if (JSON.stringify(mapTerrain) !== JSON.stringify(terrain)) {
|
||||||
|
if (terrain.exaggeration > 0) {
|
||||||
|
if (!map_.getSource(terrain.source)) {
|
||||||
|
map_.addSource(terrain.source, terrainSources[terrain.source]);
|
||||||
|
}
|
||||||
|
map_.setTerrain(terrain);
|
||||||
|
} else {
|
||||||
|
map_.setTerrain(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async get(
|
||||||
|
styleInfo: maplibregl.StyleSpecification | string
|
||||||
|
): Promise<maplibregl.StyleSpecification> {
|
||||||
|
if (typeof styleInfo === 'string') {
|
||||||
|
let styleUrl = styleInfo as string;
|
||||||
|
if (styleUrl.includes(maptilerKeyPlaceHolder)) {
|
||||||
|
styleUrl = styleUrl.replace(maptilerKeyPlaceHolder, this._maptilerKey);
|
||||||
|
}
|
||||||
|
const response = await fetch(styleUrl, { cache: 'force-cache' });
|
||||||
|
const style = await response.json();
|
||||||
|
return style;
|
||||||
|
} else {
|
||||||
|
return styleInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
merge(style: maplibregl.StyleSpecification, other: maplibregl.StyleSpecification) {
|
||||||
|
style.sources = { ...style.sources, ...other.sources };
|
||||||
|
for (let layer of other.layers ?? []) {
|
||||||
|
if (layer.type === 'symbol' && layer.layout && layer.layout['text-field']) {
|
||||||
|
const textField = layer.layout['text-field'];
|
||||||
|
if (
|
||||||
|
Array.isArray(textField) &&
|
||||||
|
textField.length >= 2 &&
|
||||||
|
textField[0] === 'coalesce' &&
|
||||||
|
Array.isArray(textField[1]) &&
|
||||||
|
textField[1][0] === 'get' &&
|
||||||
|
typeof textField[1][1] === 'string' &&
|
||||||
|
textField[1][1].startsWith('name')
|
||||||
|
) {
|
||||||
|
layer.layout['text-field'] = [
|
||||||
|
'coalesce',
|
||||||
|
['get', `name:${i18n.lang}`],
|
||||||
|
['get', 'name'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
style.layers.push(layer);
|
||||||
|
}
|
||||||
|
if (other.sprite && !style.sprite) {
|
||||||
|
style.sprite = other.sprite;
|
||||||
|
}
|
||||||
|
if (other.glyphs && !style.glyphs) {
|
||||||
|
style.glyphs = other.glyphs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getCurrentTerrain() {
|
||||||
|
const terrain = get(terrainSource);
|
||||||
|
const source = terrainSources[terrain];
|
||||||
|
if (source.url && source.url.includes(maptilerKeyPlaceHolder)) {
|
||||||
|
source.url = source.url.replace(maptilerKeyPlaceHolder, this._maptilerKey);
|
||||||
|
}
|
||||||
|
const map_ = get(this._map);
|
||||||
|
return {
|
||||||
|
source: terrain,
|
||||||
|
exaggeration: !map_ || map_.getPitch() === 0 ? 0 : 1,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
import Clean from '$lib/components/toolbar/tools/Clean.svelte';
|
import Clean from '$lib/components/toolbar/tools/Clean.svelte';
|
||||||
import Reduce from '$lib/components/toolbar/tools/reduce/Reduce.svelte';
|
import Reduce from '$lib/components/toolbar/tools/reduce/Reduce.svelte';
|
||||||
import RoutingControlPopup from '$lib/components/toolbar/tools/routing/RoutingControlPopup.svelte';
|
import RoutingControlPopup from '$lib/components/toolbar/tools/routing/RoutingControlPopup.svelte';
|
||||||
import mapboxgl from 'mapbox-gl';
|
import maplibregl from 'maplibre-gl';
|
||||||
import { settings } from '$lib/logic/settings';
|
import { settings } from '$lib/logic/settings';
|
||||||
|
|
||||||
let {
|
let {
|
||||||
@@ -23,11 +23,11 @@
|
|||||||
const { minimizeRoutingMenu } = settings;
|
const { minimizeRoutingMenu } = settings;
|
||||||
|
|
||||||
let popupElement: HTMLDivElement | undefined = $state(undefined);
|
let popupElement: HTMLDivElement | undefined = $state(undefined);
|
||||||
let popup: mapboxgl.Popup | undefined = $derived.by(() => {
|
let popup: maplibregl.Popup | undefined = $derived.by(() => {
|
||||||
if (!popupElement) {
|
if (!popupElement) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
let popup = new mapboxgl.Popup({
|
let popup = new maplibregl.Popup({
|
||||||
closeButton: false,
|
closeButton: false,
|
||||||
maxWidth: undefined,
|
maxWidth: undefined,
|
||||||
});
|
});
|
||||||
@@ -38,7 +38,9 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if $currentTool !== null}
|
{#if $currentTool !== null}
|
||||||
<div class="translate-x-1 h-full animate-in animate-out {className}">
|
<div
|
||||||
|
class="translate-x-1 h-full animate-in fade-in-0 zoom-in-95 slide-in-from-left-2 {className}"
|
||||||
|
>
|
||||||
<div class="rounded-md shadow-md pointer-events-auto">
|
<div class="rounded-md shadow-md pointer-events-auto">
|
||||||
<Card.Root class="rounded-md border-none py-2.5">
|
<Card.Root class="rounded-md border-none py-2.5">
|
||||||
<Card.Content class="px-2.5">
|
<Card.Content class="px-2.5">
|
||||||
|
|||||||
@@ -16,10 +16,11 @@
|
|||||||
import { getURLForLanguage } from '$lib/utils';
|
import { getURLForLanguage } from '$lib/utils';
|
||||||
import { Trash2 } from '@lucide/svelte';
|
import { Trash2 } from '@lucide/svelte';
|
||||||
import { map } from '$lib/components/map/map';
|
import { map } from '$lib/components/map/map';
|
||||||
import type { GeoJSONSource } from 'mapbox-gl';
|
import type { GeoJSONSource } from 'maplibre-gl';
|
||||||
import { selection } from '$lib/logic/selection';
|
import { selection } from '$lib/logic/selection';
|
||||||
import { fileActions } from '$lib/logic/file-actions';
|
import { fileActions } from '$lib/logic/file-actions';
|
||||||
import { mapCursor, MapCursorState } from '$lib/logic/map-cursor';
|
import { mapCursor, MapCursorState } from '$lib/logic/map-cursor';
|
||||||
|
import { ANCHOR_LAYER_KEY } from '$lib/components/map/style';
|
||||||
|
|
||||||
let props: {
|
let props: {
|
||||||
class?: string;
|
class?: string;
|
||||||
@@ -28,7 +29,7 @@
|
|||||||
let cleanType = $state(CleanType.INSIDE);
|
let cleanType = $state(CleanType.INSIDE);
|
||||||
let deleteTrackpoints = $state(true);
|
let deleteTrackpoints = $state(true);
|
||||||
let deleteWaypoints = $state(true);
|
let deleteWaypoints = $state(true);
|
||||||
let rectangleCoordinates: mapboxgl.LngLat[] = $state([]);
|
let rectangleCoordinates: maplibregl.LngLat[] = $state([]);
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if ($map) {
|
if ($map) {
|
||||||
@@ -63,7 +64,8 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!$map.getLayer('rectangle')) {
|
if (!$map.getLayer('rectangle')) {
|
||||||
$map.addLayer({
|
$map.addLayer(
|
||||||
|
{
|
||||||
id: 'rectangle',
|
id: 'rectangle',
|
||||||
type: 'fill',
|
type: 'fill',
|
||||||
source: 'rectangle',
|
source: 'rectangle',
|
||||||
@@ -71,7 +73,9 @@
|
|||||||
'fill-color': 'SteelBlue',
|
'fill-color': 'SteelBlue',
|
||||||
'fill-opacity': 0.5,
|
'fill-opacity': 0.5,
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
|
ANCHOR_LAYER_KEY.interactions
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,7 +181,7 @@
|
|||||||
rectangleCoordinates = [];
|
rectangleCoordinates = [];
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Trash2 size="16" class="mr-1" />
|
<Trash2 size="16" />
|
||||||
{i18n._('toolbar.clean.button')}
|
{i18n._('toolbar.clean.button')}
|
||||||
</Button>
|
</Button>
|
||||||
<Help link={getURLForLanguage(i18n.lang, '/help/toolbar/clean')}>
|
<Help link={getURLForLanguage(i18n.lang, '/help/toolbar/clean')}>
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import Help from '$lib/components/Help.svelte';
|
import Help from '$lib/components/Help.svelte';
|
||||||
import { MountainSnow } from '@lucide/svelte';
|
import { MountainSnow } from '@lucide/svelte';
|
||||||
import { map } from '$lib/components/map/map';
|
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
import { getURLForLanguage } from '$lib/utils';
|
import { getURLForLanguage } from '$lib/utils';
|
||||||
import { selection } from '$lib/logic/selection';
|
import { selection } from '$lib/logic/selection';
|
||||||
@@ -20,13 +19,9 @@
|
|||||||
variant="outline"
|
variant="outline"
|
||||||
class="whitespace-normal h-fit"
|
class="whitespace-normal h-fit"
|
||||||
disabled={!validSelection}
|
disabled={!validSelection}
|
||||||
onclick={async () => {
|
onclick={() => fileActions.addElevationToSelection()}
|
||||||
if ($map) {
|
|
||||||
fileActions.addElevationToSelection($map);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<MountainSnow size="16" class="mr-1 shrink-0" />
|
<MountainSnow size="16" class="shrink-0" />
|
||||||
{i18n._('toolbar.elevation.button')}
|
{i18n._('toolbar.elevation.button')}
|
||||||
</Button>
|
</Button>
|
||||||
<Help link={getURLForLanguage(i18n.lang, '/help/toolbar/elevation')}>
|
<Help link={getURLForLanguage(i18n.lang, '/help/toolbar/elevation')}>
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
<div class="flex flex-col gap-3 w-full max-w-80 {props.class ?? ''}">
|
<div class="flex flex-col gap-3 w-full max-w-80 {props.class ?? ''}">
|
||||||
<Button variant="outline" disabled={!validSelection} onclick={fileActions.extractSelection}>
|
<Button variant="outline" disabled={!validSelection} onclick={fileActions.extractSelection}>
|
||||||
<Ungroup size="16" class="mr-1" />
|
<Ungroup size="16" />
|
||||||
{i18n._('toolbar.extract.button')}
|
{i18n._('toolbar.extract.button')}
|
||||||
</Button>
|
</Button>
|
||||||
<Help link={getURLForLanguage(i18n.lang, '/help/toolbar/extract')}>
|
<Help link={getURLForLanguage(i18n.lang, '/help/toolbar/extract')}>
|
||||||
|
|||||||
@@ -86,7 +86,7 @@
|
|||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Group size="16" class="mr-1 shrink-0" />
|
<Group size="16" class="shrink-0" />
|
||||||
{i18n._('toolbar.merge.merge_selection')}
|
{i18n._('toolbar.merge.merge_selection')}
|
||||||
</Button>
|
</Button>
|
||||||
<Help link={getURLForLanguage(i18n.lang, '/help/toolbar/merge')}>
|
<Help link={getURLForLanguage(i18n.lang, '/help/toolbar/merge')}>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
} from '$lib/units';
|
} from '$lib/units';
|
||||||
import { CalendarDate, type DateValue } from '@internationalized/date';
|
import { CalendarDate, type DateValue } from '@internationalized/date';
|
||||||
import { CalendarClock, CirclePlay, CircleStop, CircleX, Timer, Zap } from '@lucide/svelte';
|
import { CalendarClock, CirclePlay, CircleStop, CircleX, Timer, Zap } from '@lucide/svelte';
|
||||||
import { tick } from 'svelte';
|
import { untrack } from 'svelte';
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
import {
|
import {
|
||||||
ListFileItem,
|
ListFileItem,
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
let endTime: string | undefined = $state(undefined);
|
let endTime: string | undefined = $state(undefined);
|
||||||
let movingTime: number | undefined = $state(undefined);
|
let movingTime: number | undefined = $state(undefined);
|
||||||
let speed: number | undefined = $state(undefined);
|
let speed: number | undefined = $state(undefined);
|
||||||
let artificial = $state(false);
|
let artificial = $state(true);
|
||||||
|
|
||||||
function toCalendarDate(date: Date): CalendarDate {
|
function toCalendarDate(date: Date): CalendarDate {
|
||||||
return new CalendarDate(date.getFullYear(), date.getMonth() + 1, date.getDate());
|
return new CalendarDate(date.getFullYear(), date.getMonth() + 1, date.getDate());
|
||||||
@@ -87,7 +87,7 @@
|
|||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if ($gpxStatistics && $velocityUnits && $distanceUnits) {
|
if ($gpxStatistics && $velocityUnits && $distanceUnits) {
|
||||||
setGPXData();
|
untrack(() => setGPXData());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -188,7 +188,7 @@
|
|||||||
<div class="flex flex-row gap-2 justify-center">
|
<div class="flex flex-row gap-2 justify-center">
|
||||||
<div class="flex flex-col gap-2 grow">
|
<div class="flex flex-col gap-2 grow">
|
||||||
<Label for="speed" class="flex flex-row">
|
<Label for="speed" class="flex flex-row">
|
||||||
<Zap size="16" class="mr-1" />
|
<Zap size="16" />
|
||||||
{#if $velocityUnits === 'speed'}
|
{#if $velocityUnits === 'speed'}
|
||||||
{i18n._('quantities.speed')}
|
{i18n._('quantities.speed')}
|
||||||
{:else}
|
{:else}
|
||||||
@@ -204,7 +204,9 @@
|
|||||||
min={0.01}
|
min={0.01}
|
||||||
disabled={!canUpdate}
|
disabled={!canUpdate}
|
||||||
bind:value={speed}
|
bind:value={speed}
|
||||||
onchange={updateDataFromSpeed}
|
onchange={() => {
|
||||||
|
untrack(() => updateDataFromSpeed());
|
||||||
|
}}
|
||||||
class="text-sm"
|
class="text-sm"
|
||||||
/>
|
/>
|
||||||
<span class="text-sm shrink-0">
|
<span class="text-sm shrink-0">
|
||||||
@@ -221,7 +223,9 @@
|
|||||||
bind:value={speed}
|
bind:value={speed}
|
||||||
showHours={false}
|
showHours={false}
|
||||||
disabled={!canUpdate}
|
disabled={!canUpdate}
|
||||||
onChange={updateDataFromSpeed}
|
onChange={() => {
|
||||||
|
untrack(() => updateDataFromSpeed());
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<span class="text-sm shrink-0">
|
<span class="text-sm shrink-0">
|
||||||
{#if $distanceUnits === 'imperial'}
|
{#if $distanceUnits === 'imperial'}
|
||||||
@@ -237,18 +241,20 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col gap-2 grow">
|
<div class="flex flex-col gap-2 grow">
|
||||||
<Label for="duration" class="flex flex-row">
|
<Label for="duration" class="flex flex-row">
|
||||||
<Timer size="16" class="mr-1" />
|
<Timer size="16" />
|
||||||
{i18n._('toolbar.time.total_time')}
|
{i18n._('toolbar.time.total_time')}
|
||||||
</Label>
|
</Label>
|
||||||
<TimePicker
|
<TimePicker
|
||||||
bind:value={movingTime}
|
bind:value={movingTime}
|
||||||
disabled={!canUpdate}
|
disabled={!canUpdate}
|
||||||
onChange={updateDataFromTotalTime}
|
onChange={() => {
|
||||||
|
untrack(() => updateDataFromTotalTime());
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Label class="flex flex-row">
|
<Label class="flex flex-row">
|
||||||
<CirclePlay size="16" class="mr-1" />
|
<CirclePlay size="16" />
|
||||||
{i18n._('toolbar.time.start')}
|
{i18n._('toolbar.time.start')}
|
||||||
</Label>
|
</Label>
|
||||||
<div class="flex flex-row gap-2">
|
<div class="flex flex-row gap-2">
|
||||||
@@ -258,22 +264,23 @@
|
|||||||
locale={i18n.lang}
|
locale={i18n.lang}
|
||||||
placeholder={i18n._('toolbar.time.pick_date')}
|
placeholder={i18n._('toolbar.time.pick_date')}
|
||||||
class="w-fit grow"
|
class="w-fit grow"
|
||||||
onValueChange={async () => {
|
onchange={() => {
|
||||||
await tick();
|
untrack(() => updateEnd());
|
||||||
updateEnd();
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<input
|
<Input
|
||||||
type="time"
|
type="time"
|
||||||
step={1}
|
step={1}
|
||||||
disabled={!canUpdate}
|
disabled={!canUpdate}
|
||||||
bind:value={startTime}
|
bind:value={startTime}
|
||||||
class="w-fit"
|
class="w-fit"
|
||||||
onchange={updateEnd}
|
onchange={() => {
|
||||||
|
untrack(() => updateEnd());
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Label class="flex flex-row">
|
<Label class="flex flex-row">
|
||||||
<CircleStop size="16" class="mr-1" />
|
<CircleStop size="16" />
|
||||||
{i18n._('toolbar.time.end')}
|
{i18n._('toolbar.time.end')}
|
||||||
</Label>
|
</Label>
|
||||||
<div class="flex flex-row gap-2">
|
<div class="flex flex-row gap-2">
|
||||||
@@ -283,18 +290,19 @@
|
|||||||
locale={i18n.lang}
|
locale={i18n.lang}
|
||||||
placeholder={i18n._('toolbar.time.pick_date')}
|
placeholder={i18n._('toolbar.time.pick_date')}
|
||||||
class="w-fit grow"
|
class="w-fit grow"
|
||||||
onValueChange={async () => {
|
onchange={() => {
|
||||||
await tick();
|
untrack(() => updateStart());
|
||||||
updateStart();
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<input
|
<Input
|
||||||
type="time"
|
type="time"
|
||||||
step={1}
|
step={1}
|
||||||
disabled={!canUpdate}
|
disabled={!canUpdate}
|
||||||
bind:value={endTime}
|
bind:value={endTime}
|
||||||
class="w-fit"
|
class="w-fit"
|
||||||
onchange={updateStart}
|
onchange={() => {
|
||||||
|
untrack(() => updateStart());
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{#if $gpxStatistics.global.time.moving === 0 || $gpxStatistics.global.time.moving === undefined}
|
{#if $gpxStatistics.global.time.moving === 0 || $gpxStatistics.global.time.moving === undefined}
|
||||||
@@ -316,7 +324,8 @@
|
|||||||
if (
|
if (
|
||||||
startDate === undefined ||
|
startDate === undefined ||
|
||||||
startTime === undefined ||
|
startTime === undefined ||
|
||||||
effectiveSpeed === undefined
|
effectiveSpeed === undefined ||
|
||||||
|
movingTime === undefined
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -337,44 +346,44 @@
|
|||||||
let fileId = item.getFileId();
|
let fileId = item.getFileId();
|
||||||
fileActionManager.applyToFile(fileId, (file) => {
|
fileActionManager.applyToFile(fileId, (file) => {
|
||||||
if (item instanceof ListFileItem) {
|
if (item instanceof ListFileItem) {
|
||||||
if (artificial || !$gpxStatistics.global.time.moving) {
|
if (artificial && !$gpxStatistics.global.time.moving) {
|
||||||
file.createArtificialTimestamps(
|
file.createArtificialTimestamps(
|
||||||
getDate(startDate, startTime),
|
getDate(startDate!, startTime!),
|
||||||
movingTime
|
movingTime!
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
file.changeTimestamps(
|
file.changeTimestamps(
|
||||||
getDate(startDate, startTime),
|
getDate(startDate!, startTime!),
|
||||||
effectiveSpeed,
|
effectiveSpeed,
|
||||||
ratio
|
ratio
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if (item instanceof ListTrackItem) {
|
} else if (item instanceof ListTrackItem) {
|
||||||
if (artificial || !$gpxStatistics.global.time.moving) {
|
if (artificial && !$gpxStatistics.global.time.moving) {
|
||||||
file.createArtificialTimestamps(
|
file.createArtificialTimestamps(
|
||||||
getDate(startDate, startTime),
|
getDate(startDate!, startTime!),
|
||||||
movingTime,
|
movingTime!,
|
||||||
item.getTrackIndex()
|
item.getTrackIndex()
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
file.changeTimestamps(
|
file.changeTimestamps(
|
||||||
getDate(startDate, startTime),
|
getDate(startDate!, startTime!),
|
||||||
effectiveSpeed,
|
effectiveSpeed,
|
||||||
ratio,
|
ratio,
|
||||||
item.getTrackIndex()
|
item.getTrackIndex()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if (item instanceof ListTrackSegmentItem) {
|
} else if (item instanceof ListTrackSegmentItem) {
|
||||||
if (artificial || !$gpxStatistics.global.time.moving) {
|
if (artificial && !$gpxStatistics.global.time.moving) {
|
||||||
file.createArtificialTimestamps(
|
file.createArtificialTimestamps(
|
||||||
getDate(startDate, startTime),
|
getDate(startDate!, startTime!),
|
||||||
movingTime,
|
movingTime!,
|
||||||
item.getTrackIndex(),
|
item.getTrackIndex(),
|
||||||
item.getSegmentIndex()
|
item.getSegmentIndex()
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
file.changeTimestamps(
|
file.changeTimestamps(
|
||||||
getDate(startDate, startTime),
|
getDate(startDate!, startTime!),
|
||||||
effectiveSpeed,
|
effectiveSpeed,
|
||||||
ratio,
|
ratio,
|
||||||
item.getTrackIndex(),
|
item.getTrackIndex(),
|
||||||
@@ -385,10 +394,10 @@
|
|||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<CalendarClock size="16" class="mr-1 shrink-0" />
|
<CalendarClock size="16" class="shrink-0" />
|
||||||
{i18n._('toolbar.time.update')}
|
{i18n._('toolbar.time.update')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="outline" onclick={setGPXData}>
|
<Button variant="outline" size="icon" onclick={setGPXData}>
|
||||||
<CircleX size="16" />
|
<CircleX size="16" />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
@@ -400,15 +409,3 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</Help>
|
</Help>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style lang="postcss">
|
|
||||||
@reference "../../../../app.css";
|
|
||||||
|
|
||||||
div :global(input[type='time']) {
|
|
||||||
/*
|
|
||||||
Style copy-pasted from shadcn-svelte Input.
|
|
||||||
Needed to use native time input to avoid a bug with 2-level bind:value.
|
|
||||||
*/
|
|
||||||
@apply flex h-10 rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { Label } from '$lib/components/ui/label/index.js';
|
import { Label } from '$lib/components/ui/label/index.js';
|
||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import { Slider } from '$lib/components/ui/slider';
|
import { Slider } from '$lib/components/ui/slider';
|
||||||
import { ListItem, ListRootItem } from '$lib/components/file-list/file-list';
|
import { ListRootItem } from '$lib/components/file-list/file-list';
|
||||||
import Help from '$lib/components/Help.svelte';
|
import Help from '$lib/components/Help.svelte';
|
||||||
import { Funnel } from '@lucide/svelte';
|
import { Funnel } from '@lucide/svelte';
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
@@ -10,13 +10,11 @@
|
|||||||
import { onDestroy } from 'svelte';
|
import { onDestroy } from 'svelte';
|
||||||
import { getURLForLanguage } from '$lib/utils';
|
import { getURLForLanguage } from '$lib/utils';
|
||||||
import { selection } from '$lib/logic/selection';
|
import { selection } from '$lib/logic/selection';
|
||||||
import { minTolerance, ReducedGPXLayerCollection, tolerance } from './reduce';
|
import { minTolerance, ReducedGPXLayerCollection, tolerance } from './utils.svelte';
|
||||||
|
|
||||||
let props: { class?: string } = $props();
|
let props: { class?: string } = $props();
|
||||||
|
|
||||||
let sliderValue = $state([50]);
|
let sliderValue = $state([50]);
|
||||||
let maxPoints = $state(0);
|
|
||||||
let currentPoints = $state(0);
|
|
||||||
const maxTolerance = 10000;
|
const maxTolerance = 10000;
|
||||||
|
|
||||||
let validSelection = $derived(
|
let validSelection = $derived(
|
||||||
@@ -46,10 +44,10 @@
|
|||||||
</Label>
|
</Label>
|
||||||
<Label class="flex flex-row justify-between">
|
<Label class="flex flex-row justify-between">
|
||||||
<span>{i18n._('toolbar.reduce.number_of_points')}</span>
|
<span>{i18n._('toolbar.reduce.number_of_points')}</span>
|
||||||
<span class="font-normal">{currentPoints}/{maxPoints}</span>
|
<span class="font-normal">{reducedLayers.currentPoints}/{reducedLayers.maxPoints}</span>
|
||||||
</Label>
|
</Label>
|
||||||
<Button variant="outline" disabled={!validSelection} onclick={() => reducedLayers.reduce()}>
|
<Button variant="outline" disabled={!validSelection} onclick={() => reducedLayers.reduce()}>
|
||||||
<Funnel size="16" class="mr-1" />
|
<Funnel size="16" />
|
||||||
{i18n._('toolbar.reduce.button')}
|
{i18n._('toolbar.reduce.button')}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { ListItem, ListTrackSegmentItem } from '$lib/components/file-list/file-list';
|
import { ListItem, ListTrackSegmentItem } from '$lib/components/file-list/file-list';
|
||||||
import { map } from '$lib/components/map/map';
|
import { map } from '$lib/components/map/map';
|
||||||
|
import { ANCHOR_LAYER_KEY } from '$lib/components/map/style';
|
||||||
import { fileActions } from '$lib/logic/file-actions';
|
import { fileActions } from '$lib/logic/file-actions';
|
||||||
import { GPXFileStateCollectionObserver, type GPXFileState } from '$lib/logic/file-state';
|
import { GPXFileStateCollectionObserver, type GPXFileState } from '$lib/logic/file-state';
|
||||||
import { selection } from '$lib/logic/selection';
|
import { selection } from '$lib/logic/selection';
|
||||||
import { ramerDouglasPeucker, TrackPoint, type SimplifiedTrackPoint } from 'gpx';
|
import { ramerDouglasPeucker, TrackPoint, type SimplifiedTrackPoint } from 'gpx';
|
||||||
import type { GeoJSONSource } from 'mapbox-gl';
|
import type { GeoJSONSource } from 'maplibre-gl';
|
||||||
import { get, writable } from 'svelte/store';
|
import { get, writable } from 'svelte/store';
|
||||||
|
|
||||||
export const minTolerance = 0.1;
|
export const minTolerance = 0.1;
|
||||||
@@ -28,17 +29,15 @@ export class ReducedGPXLayer {
|
|||||||
|
|
||||||
update() {
|
update() {
|
||||||
const file = this._fileState.file;
|
const file = this._fileState.file;
|
||||||
const stats = this._fileState.statistics;
|
if (!file) {
|
||||||
if (!file || !stats) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
file.forEachSegment((segment, trackIndex, segmentIndex) => {
|
file.forEachSegment((segment, trackIndex, segmentIndex) => {
|
||||||
let segmentItem = new ListTrackSegmentItem(file._data.id, trackIndex, segmentIndex);
|
let segmentItem = new ListTrackSegmentItem(file._data.id, trackIndex, segmentIndex);
|
||||||
let statistics = stats.getStatisticsFor(segmentItem);
|
|
||||||
this._updateSimplified(segmentItem.getFullId(), [
|
this._updateSimplified(segmentItem.getFullId(), [
|
||||||
segmentItem,
|
segmentItem,
|
||||||
statistics.local.points.length,
|
segment.trkpt.length,
|
||||||
ramerDouglasPeucker(statistics.local.points, minTolerance),
|
ramerDouglasPeucker(segment.trkpt, minTolerance),
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -53,16 +52,23 @@ export const tolerance = writable<number>(0);
|
|||||||
export class ReducedGPXLayerCollection {
|
export class ReducedGPXLayerCollection {
|
||||||
private _layers: Map<string, ReducedGPXLayer> = new Map();
|
private _layers: Map<string, ReducedGPXLayer> = new Map();
|
||||||
private _simplified: Map<string, [ListItem, number, SimplifiedTrackPoint[]]>;
|
private _simplified: Map<string, [ListItem, number, SimplifiedTrackPoint[]]>;
|
||||||
private _fileStateCollectionOberver: GPXFileStateCollectionObserver;
|
private _currentPoints = $state(0);
|
||||||
|
private _maxPoints = $state(0);
|
||||||
|
private _fileStateCollectionObserver: GPXFileStateCollectionObserver;
|
||||||
private _updateSimplified = this.updateSimplified.bind(this);
|
private _updateSimplified = this.updateSimplified.bind(this);
|
||||||
private _unsubscribes: (() => void)[] = [];
|
private _unsubscribes: (() => void)[] = [];
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._layers = new Map();
|
this._layers = new Map();
|
||||||
this._simplified = new Map();
|
this._simplified = new Map();
|
||||||
this._fileStateCollectionOberver = new GPXFileStateCollectionObserver(
|
this._fileStateCollectionObserver = new GPXFileStateCollectionObserver(
|
||||||
(fileId, fileState) => {
|
(newFiles) => {
|
||||||
this._layers.set(fileId, new ReducedGPXLayer(fileState, this._updateSimplified));
|
newFiles.forEach((fileState, fileId) => {
|
||||||
|
this._layers.set(
|
||||||
|
fileId,
|
||||||
|
new ReducedGPXLayer(fileState, this._updateSimplified)
|
||||||
|
);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
(fileId) => {
|
(fileId) => {
|
||||||
this._layers.get(fileId)?.destroy();
|
this._layers.get(fileId)?.destroy();
|
||||||
@@ -91,8 +97,8 @@ export class ReducedGPXLayerCollection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
let maxPoints = 0;
|
this._currentPoints = 0;
|
||||||
let currentPoints = 0;
|
this._maxPoints = 0;
|
||||||
|
|
||||||
let data: GeoJSON.FeatureCollection = {
|
let data: GeoJSON.FeatureCollection = {
|
||||||
type: 'FeatureCollection',
|
type: 'FeatureCollection',
|
||||||
@@ -104,12 +110,12 @@ export class ReducedGPXLayerCollection {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
maxPoints += maxPts;
|
this._maxPoints += maxPts;
|
||||||
|
|
||||||
let current = points.filter(
|
let current = points.filter(
|
||||||
(point) => point.distance === undefined || point.distance >= get(tolerance)
|
(point) => point.distance === undefined || point.distance >= get(tolerance)
|
||||||
);
|
);
|
||||||
currentPoints += current.length;
|
this._currentPoints += current.length;
|
||||||
|
|
||||||
data.features.push({
|
data.features.push({
|
||||||
type: 'Feature',
|
type: 'Feature',
|
||||||
@@ -139,7 +145,8 @@ export class ReducedGPXLayerCollection {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!map_.getLayer('simplified')) {
|
if (!map_.getLayer('simplified')) {
|
||||||
map_.addLayer({
|
map_.addLayer(
|
||||||
|
{
|
||||||
id: 'simplified',
|
id: 'simplified',
|
||||||
type: 'line',
|
type: 'line',
|
||||||
source: 'simplified',
|
source: 'simplified',
|
||||||
@@ -147,9 +154,9 @@ export class ReducedGPXLayerCollection {
|
|||||||
'line-color': 'white',
|
'line-color': 'white',
|
||||||
'line-width': 3,
|
'line-width': 3,
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
} else {
|
ANCHOR_LAYER_KEY.interactions
|
||||||
map_.moveLayer('simplified');
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,8 +175,16 @@ export class ReducedGPXLayerCollection {
|
|||||||
fileActions.reduce(itemsAndPoints);
|
fileActions.reduce(itemsAndPoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get currentPoints() {
|
||||||
|
return this._currentPoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
get maxPoints() {
|
||||||
|
return this._maxPoints;
|
||||||
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
this._fileStateCollectionOberver.destroy();
|
this._fileStateCollectionObserver.destroy();
|
||||||
this._unsubscribes.forEach((unsubscribe) => unsubscribe());
|
this._unsubscribes.forEach((unsubscribe) => unsubscribe());
|
||||||
|
|
||||||
const map_ = get(map);
|
const map_ = get(map);
|
||||||
@@ -15,13 +15,13 @@
|
|||||||
Route,
|
Route,
|
||||||
TriangleAlert,
|
TriangleAlert,
|
||||||
ArrowRightLeft,
|
ArrowRightLeft,
|
||||||
Home,
|
House,
|
||||||
RouteOff,
|
RouteOff,
|
||||||
Repeat,
|
Repeat,
|
||||||
SquareArrowUpLeft,
|
SquareArrowUpLeft,
|
||||||
SquareArrowOutDownRight,
|
SquareArrowOutDownRight,
|
||||||
} from '@lucide/svelte';
|
} from '@lucide/svelte';
|
||||||
import { brouterProfiles } from '$lib/components/toolbar/tools/routing/routing';
|
import { routingProfiles } from '$lib/components/toolbar/tools/routing/routing';
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
import { slide } from 'svelte/transition';
|
import { slide } from 'svelte/transition';
|
||||||
import {
|
import {
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
import { selection } from '$lib/logic/selection';
|
import { selection } from '$lib/logic/selection';
|
||||||
import { fileActions, getFileIds, newGPXFile } from '$lib/logic/file-actions';
|
import { fileActions, getFileIds, newGPXFile } from '$lib/logic/file-actions';
|
||||||
import { mapCursor, MapCursorState } from '$lib/logic/map-cursor';
|
import { mapCursor, MapCursorState } from '$lib/logic/map-cursor';
|
||||||
import { RoutingControls, routingControls } from './RoutingControls';
|
import { RoutingControls, routingControls } from './routing-controls';
|
||||||
|
|
||||||
let {
|
let {
|
||||||
minimized = $bindable(false),
|
minimized = $bindable(false),
|
||||||
@@ -51,7 +51,7 @@
|
|||||||
}: {
|
}: {
|
||||||
minimized?: boolean;
|
minimized?: boolean;
|
||||||
minimizable?: boolean;
|
minimizable?: boolean;
|
||||||
popup?: mapboxgl.Popup;
|
popup?: maplibregl.Popup;
|
||||||
popupElement?: HTMLDivElement;
|
popupElement?: HTMLDivElement;
|
||||||
class?: string;
|
class?: string;
|
||||||
} = $props();
|
} = $props();
|
||||||
@@ -84,11 +84,13 @@
|
|||||||
onMount(() => {
|
onMount(() => {
|
||||||
if ($map && popup && popupElement) {
|
if ($map && popup && popupElement) {
|
||||||
fileStateCollectionObserver = new GPXFileStateCollectionObserver(
|
fileStateCollectionObserver = new GPXFileStateCollectionObserver(
|
||||||
(fileId, fileState) => {
|
(newFiles) => {
|
||||||
|
newFiles.forEach((fileState, fileId) => {
|
||||||
routingControls.set(
|
routingControls.set(
|
||||||
fileId,
|
fileId,
|
||||||
new RoutingControls(fileId, fileState, popup, popupElement)
|
new RoutingControls(fileId, fileState, popup, popupElement)
|
||||||
);
|
);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
(fileId) => {
|
(fileId) => {
|
||||||
const controls = routingControls.get(fileId);
|
const controls = routingControls.get(fileId);
|
||||||
@@ -127,7 +129,7 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<div class="flex flex-col gap-3 w-full max-w-80 animate-in animate-out {className ?? ''}">
|
<div class="flex flex-col gap-3 w-full max-w-80 {className ?? ''}">
|
||||||
<div class="flex flex-col gap-3">
|
<div class="flex flex-col gap-3">
|
||||||
<Label class="justify-between">
|
<Label class="justify-between">
|
||||||
<span class="flex flex-row items-center gap-1">
|
<span class="flex flex-row items-center gap-1">
|
||||||
@@ -161,11 +163,11 @@
|
|||||||
{i18n._('toolbar.routing.activity')}
|
{i18n._('toolbar.routing.activity')}
|
||||||
</span>
|
</span>
|
||||||
<Select.Root type="single" bind:value={$routingProfile}>
|
<Select.Root type="single" bind:value={$routingProfile}>
|
||||||
<Select.Trigger class="h-8 grow">
|
<Select.Trigger class="grow" size="sm">
|
||||||
{i18n._(`toolbar.routing.activities.${$routingProfile}`)}
|
{i18n._(`toolbar.routing.activities.${$routingProfile}`)}
|
||||||
</Select.Trigger>
|
</Select.Trigger>
|
||||||
<Select.Content>
|
<Select.Content>
|
||||||
{#each Object.keys(brouterProfiles) as profile}
|
{#each Object.keys(routingProfiles) as profile}
|
||||||
<Select.Item value={profile}
|
<Select.Item value={profile}
|
||||||
>{i18n._(
|
>{i18n._(
|
||||||
`toolbar.routing.activities.${profile}`
|
`toolbar.routing.activities.${profile}`
|
||||||
@@ -193,7 +195,7 @@
|
|||||||
disabled={!validSelection}
|
disabled={!validSelection}
|
||||||
onclick={fileActions.reverseSelection}
|
onclick={fileActions.reverseSelection}
|
||||||
>
|
>
|
||||||
<ArrowRightLeft size="12" />{i18n._('toolbar.routing.reverse.button')}
|
<ArrowRightLeft class="size-3" />{i18n._('toolbar.routing.reverse.button')}
|
||||||
</ButtonWithTooltip>
|
</ButtonWithTooltip>
|
||||||
<ButtonWithTooltip
|
<ButtonWithTooltip
|
||||||
label={i18n._('toolbar.routing.route_back_to_start.tooltip')}
|
label={i18n._('toolbar.routing.route_back_to_start.tooltip')}
|
||||||
@@ -229,7 +231,7 @@
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Home size="12" />{i18n._('toolbar.routing.route_back_to_start.button')}
|
<House class="size-3" />{i18n._('toolbar.routing.route_back_to_start.button')}
|
||||||
</ButtonWithTooltip>
|
</ButtonWithTooltip>
|
||||||
<ButtonWithTooltip
|
<ButtonWithTooltip
|
||||||
label={i18n._('toolbar.routing.round_trip.tooltip')}
|
label={i18n._('toolbar.routing.round_trip.tooltip')}
|
||||||
@@ -238,7 +240,7 @@
|
|||||||
disabled={!validSelection}
|
disabled={!validSelection}
|
||||||
onclick={fileActions.createRoundTripForSelection}
|
onclick={fileActions.createRoundTripForSelection}
|
||||||
>
|
>
|
||||||
<Repeat size="12" />{i18n._('toolbar.routing.round_trip.button')}
|
<Repeat class="size-3" />{i18n._('toolbar.routing.round_trip.button')}
|
||||||
</ButtonWithTooltip>
|
</ButtonWithTooltip>
|
||||||
</div>
|
</div>
|
||||||
<div class="w-full flex flex-row gap-2 items-end justify-between">
|
<div class="w-full flex flex-row gap-2 items-end justify-between">
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import * as Card from '$lib/components/ui/card';
|
import * as Card from '$lib/components/ui/card';
|
||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import Shortcut from '$lib/components/Shortcut.svelte';
|
import Shortcut from '$lib/components/Shortcut.svelte';
|
||||||
import { canChangeStart } from './RoutingControls';
|
import { canChangeStart } from './routing-controls';
|
||||||
import { CirclePlay, Trash2 } from '@lucide/svelte';
|
import { CirclePlay, Trash2 } from '@lucide/svelte';
|
||||||
|
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div bind:this={element} class="hidden">
|
<div bind:this={element} class="hidden">
|
||||||
<Card.Root class="border-none shadow-md text-base">
|
<Card.Root class="border-none shadow-md text-base p-0 gap-0 rounded-lg">
|
||||||
<Card.Content class="flex flex-col p-1">
|
<Card.Content class="flex flex-col p-1">
|
||||||
{#if $canChangeStart}
|
{#if $canChangeStart}
|
||||||
<Button
|
<Button
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
variant="ghost"
|
variant="ghost"
|
||||||
onclick={() => element?.dispatchEvent(new CustomEvent('change-start'))}
|
onclick={() => element?.dispatchEvent(new CustomEvent('change-start'))}
|
||||||
>
|
>
|
||||||
<CirclePlay size="16" class="mr-1" />
|
<CirclePlay size="16" />
|
||||||
{i18n._('toolbar.routing.start_loop_here')}
|
{i18n._('toolbar.routing.start_loop_here')}
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
variant="ghost"
|
variant="ghost"
|
||||||
onclick={() => element?.dispatchEvent(new CustomEvent('delete'))}
|
onclick={() => element?.dispatchEvent(new CustomEvent('delete'))}
|
||||||
>
|
>
|
||||||
<Trash2 size="16" class="mr-1" />
|
<Trash2 size="16" />
|
||||||
{i18n._('menu.delete')}
|
{i18n._('menu.delete')}
|
||||||
<Shortcut shift={true} click={true} />
|
<Shortcut shift={true} click={true} />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -1,864 +0,0 @@
|
|||||||
import { distance, type Coordinates, TrackPoint, TrackSegment, Track, projectedPoint } from 'gpx';
|
|
||||||
import { get, writable, type Readable } from 'svelte/store';
|
|
||||||
import mapboxgl from 'mapbox-gl';
|
|
||||||
import { route } from './routing';
|
|
||||||
import { toast } from 'svelte-sonner';
|
|
||||||
import {
|
|
||||||
ListFileItem,
|
|
||||||
ListTrackItem,
|
|
||||||
ListTrackSegmentItem,
|
|
||||||
} from '$lib/components/file-list/file-list';
|
|
||||||
import { getClosestLinePoint } from '$lib/utils';
|
|
||||||
import type { GPXFileWithStatistics } from '$lib/logic/statistics-tree';
|
|
||||||
import { mapCursor, MapCursorState } from '$lib/logic/map-cursor';
|
|
||||||
import { settings } from '$lib/logic/settings';
|
|
||||||
import { selection } from '$lib/logic/selection';
|
|
||||||
import { currentTool, Tool } from '$lib/components/toolbar/tools';
|
|
||||||
import { streetViewEnabled } from '$lib/components/map/street-view-control/utils';
|
|
||||||
import { fileActionManager } from '$lib/logic/file-action-manager';
|
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
|
||||||
import { map } from '$lib/components/map/map';
|
|
||||||
|
|
||||||
const { streetViewSource } = settings;
|
|
||||||
export const canChangeStart = writable(false);
|
|
||||||
|
|
||||||
function stopPropagation(e: any) {
|
|
||||||
e.stopPropagation();
|
|
||||||
}
|
|
||||||
|
|
||||||
export class RoutingControls {
|
|
||||||
active: boolean = false;
|
|
||||||
fileId: string = '';
|
|
||||||
file: Readable<GPXFileWithStatistics | undefined>;
|
|
||||||
anchors: AnchorWithMarker[] = [];
|
|
||||||
shownAnchors: AnchorWithMarker[] = [];
|
|
||||||
popup: mapboxgl.Popup;
|
|
||||||
popupElement: HTMLElement;
|
|
||||||
temporaryAnchor: AnchorWithMarker;
|
|
||||||
lastDragEvent = 0;
|
|
||||||
fileUnsubscribe: () => void = () => {};
|
|
||||||
unsubscribes: Function[] = [];
|
|
||||||
|
|
||||||
toggleAnchorsForZoomLevelAndBoundsBinded: () => void =
|
|
||||||
this.toggleAnchorsForZoomLevelAndBounds.bind(this);
|
|
||||||
showTemporaryAnchorBinded: (e: any) => void = this.showTemporaryAnchor.bind(this);
|
|
||||||
updateTemporaryAnchorBinded: (e: any) => void = this.updateTemporaryAnchor.bind(this);
|
|
||||||
appendAnchorBinded: (e: mapboxgl.MapMouseEvent) => void = this.appendAnchor.bind(this);
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
fileId: string,
|
|
||||||
file: Readable<GPXFileWithStatistics | undefined>,
|
|
||||||
popup: mapboxgl.Popup,
|
|
||||||
popupElement: HTMLElement
|
|
||||||
) {
|
|
||||||
this.fileId = fileId;
|
|
||||||
this.file = file;
|
|
||||||
this.popup = popup;
|
|
||||||
this.popupElement = popupElement;
|
|
||||||
|
|
||||||
let point = new TrackPoint({
|
|
||||||
attributes: {
|
|
||||||
lat: 0,
|
|
||||||
lon: 0,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
this.temporaryAnchor = this.createAnchor(point, new TrackSegment(), 0, 0);
|
|
||||||
this.temporaryAnchor.marker.getElement().classList.remove('z-10'); // Show below the other markers
|
|
||||||
|
|
||||||
this.unsubscribes.push(selection.subscribe(this.addIfNeeded.bind(this)));
|
|
||||||
this.unsubscribes.push(currentTool.subscribe(this.addIfNeeded.bind(this)));
|
|
||||||
}
|
|
||||||
|
|
||||||
addIfNeeded() {
|
|
||||||
let routing = get(currentTool) === Tool.ROUTING;
|
|
||||||
if (!routing) {
|
|
||||||
if (this.active) {
|
|
||||||
this.remove();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let selected = get(selection).hasAnyChildren(new ListFileItem(this.fileId), true, [
|
|
||||||
'waypoints',
|
|
||||||
]);
|
|
||||||
if (selected) {
|
|
||||||
if (this.active) {
|
|
||||||
this.updateControls();
|
|
||||||
} else {
|
|
||||||
this.add();
|
|
||||||
}
|
|
||||||
} else if (this.active) {
|
|
||||||
this.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
add() {
|
|
||||||
const map_ = get(map);
|
|
||||||
if (!map_) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.active = true;
|
|
||||||
|
|
||||||
map_.on('move', this.toggleAnchorsForZoomLevelAndBoundsBinded);
|
|
||||||
map_.on('click', this.appendAnchorBinded);
|
|
||||||
map_.on('mousemove', this.fileId, this.showTemporaryAnchorBinded);
|
|
||||||
map_.on('click', this.fileId, stopPropagation);
|
|
||||||
|
|
||||||
this.fileUnsubscribe = this.file.subscribe(this.updateControls.bind(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
updateControls() {
|
|
||||||
// Update the markers when the file changes
|
|
||||||
let file = get(this.file)?.file;
|
|
||||||
if (!file) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let anchorIndex = 0;
|
|
||||||
file.forEachSegment((segment, trackIndex, segmentIndex) => {
|
|
||||||
if (
|
|
||||||
get(selection).hasAnyParent(
|
|
||||||
new ListTrackSegmentItem(this.fileId, trackIndex, segmentIndex)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
for (let point of segment.trkpt) {
|
|
||||||
// Update the existing anchors (could be improved by matching the existing anchors with the new ones?)
|
|
||||||
if (point._data.anchor) {
|
|
||||||
if (anchorIndex < this.anchors.length) {
|
|
||||||
this.anchors[anchorIndex].point = point;
|
|
||||||
this.anchors[anchorIndex].segment = segment;
|
|
||||||
this.anchors[anchorIndex].trackIndex = trackIndex;
|
|
||||||
this.anchors[anchorIndex].segmentIndex = segmentIndex;
|
|
||||||
this.anchors[anchorIndex].marker.setLngLat(point.getCoordinates());
|
|
||||||
} else {
|
|
||||||
this.anchors.push(
|
|
||||||
this.createAnchor(point, segment, trackIndex, segmentIndex)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
anchorIndex++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
while (anchorIndex < this.anchors.length) {
|
|
||||||
// Remove the extra anchors
|
|
||||||
this.anchors.pop()?.marker.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.toggleAnchorsForZoomLevelAndBounds();
|
|
||||||
}
|
|
||||||
|
|
||||||
remove() {
|
|
||||||
const map_ = get(map);
|
|
||||||
if (!map_) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.active = false;
|
|
||||||
|
|
||||||
for (let anchor of this.anchors) {
|
|
||||||
anchor.marker.remove();
|
|
||||||
}
|
|
||||||
map_.off('move', this.toggleAnchorsForZoomLevelAndBoundsBinded);
|
|
||||||
map_.off('click', this.appendAnchorBinded);
|
|
||||||
map_.off('mousemove', this.fileId, this.showTemporaryAnchorBinded);
|
|
||||||
map_.off('click', this.fileId, stopPropagation);
|
|
||||||
map_.off('mousemove', this.updateTemporaryAnchorBinded);
|
|
||||||
this.temporaryAnchor.marker.remove();
|
|
||||||
|
|
||||||
this.fileUnsubscribe();
|
|
||||||
}
|
|
||||||
|
|
||||||
createAnchor(
|
|
||||||
point: TrackPoint,
|
|
||||||
segment: TrackSegment,
|
|
||||||
trackIndex: number,
|
|
||||||
segmentIndex: number
|
|
||||||
): AnchorWithMarker {
|
|
||||||
let element = document.createElement('div');
|
|
||||||
element.className = `h-5 w-5 xs:h-4 xs:w-4 md:h-3 md:w-3 rounded-full bg-white border-2 border-black cursor-pointer`;
|
|
||||||
|
|
||||||
let marker = new mapboxgl.Marker({
|
|
||||||
draggable: true,
|
|
||||||
className: 'z-10',
|
|
||||||
element,
|
|
||||||
}).setLngLat(point.getCoordinates());
|
|
||||||
|
|
||||||
let anchor = {
|
|
||||||
point,
|
|
||||||
segment,
|
|
||||||
trackIndex,
|
|
||||||
segmentIndex,
|
|
||||||
marker,
|
|
||||||
inZoom: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
marker.on('dragstart', (e) => {
|
|
||||||
this.lastDragEvent = Date.now();
|
|
||||||
mapCursor.notify(MapCursorState.TRACKPOINT_DRAGGING, true);
|
|
||||||
element.classList.remove('cursor-pointer');
|
|
||||||
element.classList.add('cursor-grabbing');
|
|
||||||
});
|
|
||||||
marker.on('dragend', (e) => {
|
|
||||||
this.lastDragEvent = Date.now();
|
|
||||||
mapCursor.notify(MapCursorState.TRACKPOINT_DRAGGING, false);
|
|
||||||
element.classList.remove('cursor-grabbing');
|
|
||||||
element.classList.add('cursor-pointer');
|
|
||||||
this.moveAnchor(anchor);
|
|
||||||
});
|
|
||||||
let handleAnchorClick = this.handleClickForAnchor(anchor, marker);
|
|
||||||
marker.getElement().addEventListener('click', handleAnchorClick);
|
|
||||||
marker.getElement().addEventListener('contextmenu', handleAnchorClick);
|
|
||||||
|
|
||||||
return anchor;
|
|
||||||
}
|
|
||||||
|
|
||||||
handleClickForAnchor(anchor: Anchor, marker: mapboxgl.Marker) {
|
|
||||||
return (e: any) => {
|
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
|
|
||||||
if (Date.now() - this.lastDragEvent < 100) {
|
|
||||||
// Prevent click event during drag
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (marker === this.temporaryAnchor.marker) {
|
|
||||||
this.turnIntoPermanentAnchor();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.shiftKey) {
|
|
||||||
this.deleteAnchor(anchor);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
canChangeStart.update(() => {
|
|
||||||
if (anchor.point._data.index === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
let segment = anchor.segment;
|
|
||||||
if (
|
|
||||||
distance(
|
|
||||||
segment.trkpt[0].getCoordinates(),
|
|
||||||
segment.trkpt[segment.trkpt.length - 1].getCoordinates()
|
|
||||||
) > 1000
|
|
||||||
) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
marker.setPopup(this.popup);
|
|
||||||
marker.togglePopup();
|
|
||||||
|
|
||||||
let deleteThisAnchor = this.getDeleteAnchor(anchor);
|
|
||||||
this.popupElement.addEventListener('delete', deleteThisAnchor); // Register the delete event for this anchor
|
|
||||||
let startLoopAtThisAnchor = this.getStartLoopAtAnchor(anchor);
|
|
||||||
this.popupElement.addEventListener('change-start', startLoopAtThisAnchor); // Register the start loop event for this anchor
|
|
||||||
this.popup.once('close', () => {
|
|
||||||
this.popupElement.removeEventListener('delete', deleteThisAnchor);
|
|
||||||
this.popupElement.removeEventListener('change-start', startLoopAtThisAnchor);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
toggleAnchorsForZoomLevelAndBounds() {
|
|
||||||
const map_ = get(map);
|
|
||||||
if (!map_) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show markers only if they are in the current zoom level and bounds
|
|
||||||
this.shownAnchors.splice(0, this.shownAnchors.length);
|
|
||||||
|
|
||||||
let center = map_.getCenter();
|
|
||||||
let bottomLeft = map_.unproject([0, map_.getCanvas().height]);
|
|
||||||
let topRight = map_.unproject([map_.getCanvas().width, 0]);
|
|
||||||
let diagonal = bottomLeft.distanceTo(topRight);
|
|
||||||
|
|
||||||
let zoom = map_.getZoom();
|
|
||||||
this.anchors.forEach((anchor) => {
|
|
||||||
anchor.inZoom = anchor.point._data.zoom <= zoom;
|
|
||||||
if (anchor.inZoom && center.distanceTo(anchor.marker.getLngLat()) < diagonal) {
|
|
||||||
anchor.marker.addTo(map_);
|
|
||||||
this.shownAnchors.push(anchor);
|
|
||||||
} else {
|
|
||||||
anchor.marker.remove();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
showTemporaryAnchor(e: any) {
|
|
||||||
const map_ = get(map);
|
|
||||||
if (!map_) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.temporaryAnchor.marker.getElement().classList.contains('cursor-grabbing')) {
|
|
||||||
// Do not not change the source point if it is already being dragged
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (get(streetViewEnabled)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
!get(selection).hasAnyParent(
|
|
||||||
new ListTrackSegmentItem(
|
|
||||||
this.fileId,
|
|
||||||
e.features[0].properties.trackIndex,
|
|
||||||
e.features[0].properties.segmentIndex
|
|
||||||
)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.temporaryAnchorCloseToOtherAnchor(e)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.temporaryAnchor.point.setCoordinates({
|
|
||||||
lat: e.lngLat.lat,
|
|
||||||
lon: e.lngLat.lng,
|
|
||||||
});
|
|
||||||
this.temporaryAnchor.marker.setLngLat(e.lngLat).addTo(map_);
|
|
||||||
|
|
||||||
map_.on('mousemove', this.updateTemporaryAnchorBinded);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateTemporaryAnchor(e: any) {
|
|
||||||
const map_ = get(map);
|
|
||||||
if (!map_) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.temporaryAnchor.marker.getElement().classList.contains('cursor-grabbing')) {
|
|
||||||
// Do not hide if it is being dragged, and stop listening for mousemove
|
|
||||||
map_.off('mousemove', this.updateTemporaryAnchorBinded);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
e.point.dist(map_.project(this.temporaryAnchor.point.getCoordinates())) > 20 ||
|
|
||||||
this.temporaryAnchorCloseToOtherAnchor(e)
|
|
||||||
) {
|
|
||||||
// Hide if too far from the layer
|
|
||||||
this.temporaryAnchor.marker.remove();
|
|
||||||
map_.off('mousemove', this.updateTemporaryAnchorBinded);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.temporaryAnchor.marker.setLngLat(e.lngLat); // Update the position of the temporary anchor
|
|
||||||
}
|
|
||||||
|
|
||||||
temporaryAnchorCloseToOtherAnchor(e: any) {
|
|
||||||
const map_ = get(map);
|
|
||||||
if (!map_) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let anchor of this.shownAnchors) {
|
|
||||||
if (e.point.dist(map_.project(anchor.marker.getLngLat())) < 10) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
async moveAnchor(anchorWithMarker: AnchorWithMarker) {
|
|
||||||
// Move the anchor and update the route from and to the neighbouring anchors
|
|
||||||
let coordinates = {
|
|
||||||
lat: anchorWithMarker.marker.getLngLat().lat,
|
|
||||||
lon: anchorWithMarker.marker.getLngLat().lng,
|
|
||||||
};
|
|
||||||
|
|
||||||
let anchor = anchorWithMarker as Anchor;
|
|
||||||
if (anchorWithMarker === this.temporaryAnchor) {
|
|
||||||
// Temporary anchor, need to find the closest point of the segment and create an anchor for it
|
|
||||||
this.temporaryAnchor.marker.remove();
|
|
||||||
anchor = this.getPermanentAnchor();
|
|
||||||
}
|
|
||||||
|
|
||||||
let [previousAnchor, nextAnchor] = this.getNeighbouringAnchors(anchor);
|
|
||||||
|
|
||||||
let anchors = [];
|
|
||||||
let targetCoordinates = [];
|
|
||||||
|
|
||||||
if (previousAnchor !== null) {
|
|
||||||
anchors.push(previousAnchor);
|
|
||||||
targetCoordinates.push(previousAnchor.point.getCoordinates());
|
|
||||||
}
|
|
||||||
|
|
||||||
anchors.push(anchor);
|
|
||||||
targetCoordinates.push(coordinates);
|
|
||||||
|
|
||||||
if (nextAnchor !== null) {
|
|
||||||
anchors.push(nextAnchor);
|
|
||||||
targetCoordinates.push(nextAnchor.point.getCoordinates());
|
|
||||||
}
|
|
||||||
|
|
||||||
let success = await this.routeBetweenAnchors(anchors, targetCoordinates);
|
|
||||||
|
|
||||||
if (!success) {
|
|
||||||
// Route failed, revert the anchor to the previous position
|
|
||||||
anchorWithMarker.marker.setLngLat(anchorWithMarker.point.getCoordinates());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getPermanentAnchor(): Anchor {
|
|
||||||
let file = get(this.file)?.file;
|
|
||||||
|
|
||||||
// Find the point closest to the temporary anchor
|
|
||||||
let minDetails: any = { distance: Number.MAX_VALUE };
|
|
||||||
let minAnchor = this.temporaryAnchor as Anchor;
|
|
||||||
file?.forEachSegment((segment, trackIndex, segmentIndex) => {
|
|
||||||
if (
|
|
||||||
get(selection).hasAnyParent(
|
|
||||||
new ListTrackSegmentItem(this.fileId, trackIndex, segmentIndex)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
let details: any = {};
|
|
||||||
let closest = getClosestLinePoint(
|
|
||||||
segment.trkpt,
|
|
||||||
this.temporaryAnchor.point,
|
|
||||||
details
|
|
||||||
);
|
|
||||||
if (details.distance < minDetails.distance) {
|
|
||||||
minDetails = details;
|
|
||||||
minAnchor = {
|
|
||||||
point: closest,
|
|
||||||
segment,
|
|
||||||
trackIndex,
|
|
||||||
segmentIndex,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (minAnchor.point._data.anchor) {
|
|
||||||
minAnchor.point = minAnchor.point.clone();
|
|
||||||
if (minDetails.before) {
|
|
||||||
minAnchor.point._data.index = minAnchor.point._data.index + 0.5;
|
|
||||||
} else {
|
|
||||||
minAnchor.point._data.index = minAnchor.point._data.index - 0.5;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return minAnchor;
|
|
||||||
}
|
|
||||||
|
|
||||||
turnIntoPermanentAnchor() {
|
|
||||||
let file = get(this.file)?.file;
|
|
||||||
|
|
||||||
// Find the point closest to the temporary anchor
|
|
||||||
let minDetails: any = { distance: Number.MAX_VALUE };
|
|
||||||
let minInfo = {
|
|
||||||
point: this.temporaryAnchor.point,
|
|
||||||
trackIndex: -1,
|
|
||||||
segmentIndex: -1,
|
|
||||||
trkptIndex: -1,
|
|
||||||
};
|
|
||||||
|
|
||||||
file?.forEachSegment((segment, trackIndex, segmentIndex) => {
|
|
||||||
if (
|
|
||||||
get(selection).hasAnyParent(
|
|
||||||
new ListTrackSegmentItem(this.fileId, trackIndex, segmentIndex)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
let details: any = {};
|
|
||||||
getClosestLinePoint(segment.trkpt, this.temporaryAnchor.point, details);
|
|
||||||
if (details.distance < minDetails.distance) {
|
|
||||||
minDetails = details;
|
|
||||||
let before = details.before ? details.index : details.index - 1;
|
|
||||||
|
|
||||||
let projectedPt = projectedPoint(
|
|
||||||
segment.trkpt[before],
|
|
||||||
segment.trkpt[before + 1],
|
|
||||||
this.temporaryAnchor.point
|
|
||||||
);
|
|
||||||
let ratio =
|
|
||||||
distance(segment.trkpt[before], projectedPt) /
|
|
||||||
distance(segment.trkpt[before], segment.trkpt[before + 1]);
|
|
||||||
|
|
||||||
let point = segment.trkpt[before].clone();
|
|
||||||
point.setCoordinates(projectedPt);
|
|
||||||
point.ele =
|
|
||||||
(1 - ratio) * (segment.trkpt[before].ele ?? 0) +
|
|
||||||
ratio * (segment.trkpt[before + 1].ele ?? 0);
|
|
||||||
point.time =
|
|
||||||
segment.trkpt[before].time && segment.trkpt[before + 1].time
|
|
||||||
? new Date(
|
|
||||||
(1 - ratio) * segment.trkpt[before].time.getTime() +
|
|
||||||
ratio * segment.trkpt[before + 1].time.getTime()
|
|
||||||
)
|
|
||||||
: undefined;
|
|
||||||
point._data = {
|
|
||||||
anchor: true,
|
|
||||||
zoom: 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
minInfo = {
|
|
||||||
point,
|
|
||||||
trackIndex,
|
|
||||||
segmentIndex,
|
|
||||||
trkptIndex: before + 1,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (minInfo.trackIndex !== -1) {
|
|
||||||
fileActionManager.applyToFile(this.fileId, (file) =>
|
|
||||||
file.replaceTrackPoints(
|
|
||||||
minInfo.trackIndex,
|
|
||||||
minInfo.segmentIndex,
|
|
||||||
minInfo.trkptIndex,
|
|
||||||
minInfo.trkptIndex - 1,
|
|
||||||
[minInfo.point]
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getDeleteAnchor(anchor: Anchor) {
|
|
||||||
return () => this.deleteAnchor(anchor);
|
|
||||||
}
|
|
||||||
|
|
||||||
async deleteAnchor(anchor: Anchor) {
|
|
||||||
// Remove the anchor and route between the neighbouring anchors if they exist
|
|
||||||
this.popup.remove();
|
|
||||||
|
|
||||||
let [previousAnchor, nextAnchor] = this.getNeighbouringAnchors(anchor);
|
|
||||||
|
|
||||||
if (previousAnchor === null && nextAnchor === null) {
|
|
||||||
// Only one point, remove it
|
|
||||||
fileActionManager.applyToFile(this.fileId, (file) =>
|
|
||||||
file.replaceTrackPoints(anchor.trackIndex, anchor.segmentIndex, 0, 0, [])
|
|
||||||
);
|
|
||||||
} else if (previousAnchor === null) {
|
|
||||||
// First point, remove trackpoints until nextAnchor
|
|
||||||
fileActionManager.applyToFile(this.fileId, (file) =>
|
|
||||||
file.replaceTrackPoints(
|
|
||||||
anchor.trackIndex,
|
|
||||||
anchor.segmentIndex,
|
|
||||||
0,
|
|
||||||
nextAnchor.point._data.index - 1,
|
|
||||||
[]
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} else if (nextAnchor === null) {
|
|
||||||
// Last point, remove trackpoints from previousAnchor
|
|
||||||
fileActionManager.applyToFile(this.fileId, (file) => {
|
|
||||||
let segment = file.getSegment(anchor.trackIndex, anchor.segmentIndex);
|
|
||||||
file.replaceTrackPoints(
|
|
||||||
anchor.trackIndex,
|
|
||||||
anchor.segmentIndex,
|
|
||||||
previousAnchor.point._data.index + 1,
|
|
||||||
segment.trkpt.length - 1,
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// Route between previousAnchor and nextAnchor
|
|
||||||
this.routeBetweenAnchors(
|
|
||||||
[previousAnchor, nextAnchor],
|
|
||||||
[previousAnchor.point.getCoordinates(), nextAnchor.point.getCoordinates()]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getStartLoopAtAnchor(anchor: Anchor) {
|
|
||||||
return () => this.startLoopAtAnchor(anchor);
|
|
||||||
}
|
|
||||||
|
|
||||||
startLoopAtAnchor(anchor: Anchor) {
|
|
||||||
this.popup.remove();
|
|
||||||
|
|
||||||
let fileWithStats = get(this.file);
|
|
||||||
if (!fileWithStats) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let speed = fileWithStats.statistics.getStatisticsFor(
|
|
||||||
new ListTrackSegmentItem(this.fileId, anchor.trackIndex, anchor.segmentIndex)
|
|
||||||
).global.speed.moving;
|
|
||||||
|
|
||||||
let segment = anchor.segment;
|
|
||||||
fileActionManager.applyToFile(this.fileId, (file) => {
|
|
||||||
file.replaceTrackPoints(
|
|
||||||
anchor.trackIndex,
|
|
||||||
anchor.segmentIndex,
|
|
||||||
segment.trkpt.length,
|
|
||||||
segment.trkpt.length - 1,
|
|
||||||
segment.trkpt.slice(0, anchor.point._data.index),
|
|
||||||
speed > 0 ? speed : undefined
|
|
||||||
);
|
|
||||||
file.crop(
|
|
||||||
anchor.point._data.index,
|
|
||||||
anchor.point._data.index + segment.trkpt.length - 1,
|
|
||||||
[anchor.trackIndex],
|
|
||||||
[anchor.segmentIndex]
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async appendAnchor(e: mapboxgl.MapMouseEvent) {
|
|
||||||
// Add a new anchor to the end of the last segment
|
|
||||||
if (get(streetViewEnabled) && get(streetViewSource) === 'google') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.appendAnchorWithCoordinates({
|
|
||||||
lat: e.lngLat.lat,
|
|
||||||
lon: e.lngLat.lng,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async appendAnchorWithCoordinates(coordinates: Coordinates) {
|
|
||||||
// Add a new anchor to the end of the last segment
|
|
||||||
let selected = selection.getOrderedSelection();
|
|
||||||
if (selected.length === 0 || selected[selected.length - 1].getFileId() !== this.fileId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let item = selected[selected.length - 1];
|
|
||||||
|
|
||||||
let lastAnchor = this.anchors[this.anchors.length - 1];
|
|
||||||
|
|
||||||
let newPoint = new TrackPoint({
|
|
||||||
attributes: coordinates,
|
|
||||||
});
|
|
||||||
newPoint._data.anchor = true;
|
|
||||||
newPoint._data.zoom = 0;
|
|
||||||
|
|
||||||
if (!lastAnchor) {
|
|
||||||
fileActionManager.applyToFile(this.fileId, (file) => {
|
|
||||||
let trackIndex = file.trk.length > 0 ? file.trk.length - 1 : 0;
|
|
||||||
if (item instanceof ListTrackItem || item instanceof ListTrackSegmentItem) {
|
|
||||||
trackIndex = item.getTrackIndex();
|
|
||||||
}
|
|
||||||
let segmentIndex =
|
|
||||||
file.trk.length > 0 && file.trk[trackIndex].trkseg.length > 0
|
|
||||||
? file.trk[trackIndex].trkseg.length - 1
|
|
||||||
: 0;
|
|
||||||
if (item instanceof ListTrackSegmentItem) {
|
|
||||||
segmentIndex = item.getSegmentIndex();
|
|
||||||
}
|
|
||||||
if (file.trk.length === 0) {
|
|
||||||
let track = new Track();
|
|
||||||
track.replaceTrackPoints(0, 0, 0, [newPoint]);
|
|
||||||
file.replaceTracks(0, 0, [track]);
|
|
||||||
} else if (file.trk[trackIndex].trkseg.length === 0) {
|
|
||||||
let segment = new TrackSegment();
|
|
||||||
segment.replaceTrackPoints(0, 0, [newPoint]);
|
|
||||||
file.replaceTrackSegments(trackIndex, 0, 0, [segment]);
|
|
||||||
} else {
|
|
||||||
file.replaceTrackPoints(trackIndex, segmentIndex, 0, 0, [newPoint]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
newPoint._data.index = lastAnchor.segment.trkpt.length - 1; // Do as if the point was the last point in the segment
|
|
||||||
let newAnchor = {
|
|
||||||
point: newPoint,
|
|
||||||
segment: lastAnchor.segment,
|
|
||||||
trackIndex: lastAnchor.trackIndex,
|
|
||||||
segmentIndex: lastAnchor.segmentIndex,
|
|
||||||
};
|
|
||||||
|
|
||||||
await this.routeBetweenAnchors(
|
|
||||||
[lastAnchor, newAnchor],
|
|
||||||
[lastAnchor.point.getCoordinates(), newAnchor.point.getCoordinates()]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
getNeighbouringAnchors(anchor: Anchor): [Anchor | null, Anchor | null] {
|
|
||||||
let previousAnchor: Anchor | null = null;
|
|
||||||
let nextAnchor: Anchor | null = null;
|
|
||||||
|
|
||||||
for (let i = 0; i < this.anchors.length; i++) {
|
|
||||||
if (this.anchors[i].segment === anchor.segment && this.anchors[i].inZoom) {
|
|
||||||
if (this.anchors[i].point._data.index < anchor.point._data.index) {
|
|
||||||
if (
|
|
||||||
!previousAnchor ||
|
|
||||||
this.anchors[i].point._data.index > previousAnchor.point._data.index
|
|
||||||
) {
|
|
||||||
previousAnchor = this.anchors[i];
|
|
||||||
}
|
|
||||||
} else if (this.anchors[i].point._data.index > anchor.point._data.index) {
|
|
||||||
if (
|
|
||||||
!nextAnchor ||
|
|
||||||
this.anchors[i].point._data.index < nextAnchor.point._data.index
|
|
||||||
) {
|
|
||||||
nextAnchor = this.anchors[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return [previousAnchor, nextAnchor];
|
|
||||||
}
|
|
||||||
|
|
||||||
async routeBetweenAnchors(
|
|
||||||
anchors: Anchor[],
|
|
||||||
targetCoordinates: Coordinates[]
|
|
||||||
): Promise<boolean> {
|
|
||||||
let segment = anchors[0].segment;
|
|
||||||
|
|
||||||
let fileWithStats = get(this.file);
|
|
||||||
if (!fileWithStats) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (anchors.length === 1) {
|
|
||||||
// Only one anchor, update the point in the segment
|
|
||||||
fileActionManager.applyToFile(this.fileId, (file) =>
|
|
||||||
file.replaceTrackPoints(anchors[0].trackIndex, anchors[0].segmentIndex, 0, 0, [
|
|
||||||
new TrackPoint({
|
|
||||||
attributes: targetCoordinates[0],
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
let response: TrackPoint[];
|
|
||||||
try {
|
|
||||||
response = await route(targetCoordinates);
|
|
||||||
} catch (e: any) {
|
|
||||||
if (e.message.includes('from-position not mapped in existing datafile')) {
|
|
||||||
toast.error(i18n._('toolbar.routing.error.from'));
|
|
||||||
} else if (e.message.includes('via1-position not mapped in existing datafile')) {
|
|
||||||
toast.error(i18n._('toolbar.routing.error.via'));
|
|
||||||
} else if (e.message.includes('to-position not mapped in existing datafile')) {
|
|
||||||
toast.error(i18n._('toolbar.routing.error.to'));
|
|
||||||
} else if (e.message.includes('Time-out')) {
|
|
||||||
toast.error(i18n._('toolbar.routing.error.timeout'));
|
|
||||||
} else {
|
|
||||||
toast.error(e.message);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (anchors[0].point._data.index === 0) {
|
|
||||||
// First anchor is the first point of the segment
|
|
||||||
anchors[0].point = response[0]; // replace the first anchor
|
|
||||||
anchors[0].point._data.index = 0;
|
|
||||||
} else if (
|
|
||||||
anchors[0].point._data.index === segment.trkpt.length - 1 &&
|
|
||||||
distance(anchors[0].point.getCoordinates(), response[0].getCoordinates()) < 1
|
|
||||||
) {
|
|
||||||
// First anchor is the last point of the segment, and the new point is close enough
|
|
||||||
anchors[0].point = response[0]; // replace the first anchor
|
|
||||||
anchors[0].point._data.index = segment.trkpt.length - 1;
|
|
||||||
} else {
|
|
||||||
anchors[0].point = anchors[0].point.clone(); // Clone the anchor to assign new properties
|
|
||||||
response.splice(0, 0, anchors[0].point); // Insert it in the response to keep it
|
|
||||||
}
|
|
||||||
|
|
||||||
if (anchors[anchors.length - 1].point._data.index === segment.trkpt.length - 1) {
|
|
||||||
// Last anchor is the last point of the segment
|
|
||||||
anchors[anchors.length - 1].point = response[response.length - 1]; // replace the last anchor
|
|
||||||
anchors[anchors.length - 1].point._data.index = segment.trkpt.length - 1;
|
|
||||||
} else {
|
|
||||||
anchors[anchors.length - 1].point = anchors[anchors.length - 1].point.clone(); // Clone the anchor to assign new properties
|
|
||||||
response.push(anchors[anchors.length - 1].point); // Insert it in the response to keep it
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 1; i < anchors.length - 1; i++) {
|
|
||||||
// Find the closest point to the intermediate anchor
|
|
||||||
// and transfer the marker to that point
|
|
||||||
anchors[i].point = getClosestLinePoint(response.slice(1, -1), targetCoordinates[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
anchors.forEach((anchor) => {
|
|
||||||
anchor.point._data.anchor = true;
|
|
||||||
anchor.point._data.zoom = 0; // Make these anchors permanent
|
|
||||||
});
|
|
||||||
|
|
||||||
let stats = fileWithStats.statistics.getStatisticsFor(
|
|
||||||
new ListTrackSegmentItem(this.fileId, anchors[0].trackIndex, anchors[0].segmentIndex)
|
|
||||||
);
|
|
||||||
let speed: number | undefined = undefined;
|
|
||||||
let startTime = anchors[0].point.time;
|
|
||||||
|
|
||||||
if (stats.global.speed.moving > 0) {
|
|
||||||
let replacingDistance = 0;
|
|
||||||
for (let i = 1; i < response.length; i++) {
|
|
||||||
replacingDistance +=
|
|
||||||
distance(response[i - 1].getCoordinates(), response[i].getCoordinates()) / 1000;
|
|
||||||
}
|
|
||||||
let replacedDistance =
|
|
||||||
stats.local.distance.moving[anchors[anchors.length - 1].point._data.index] -
|
|
||||||
stats.local.distance.moving[anchors[0].point._data.index];
|
|
||||||
|
|
||||||
let newDistance = stats.global.distance.moving + replacingDistance - replacedDistance;
|
|
||||||
let newTime = (newDistance / stats.global.speed.moving) * 3600;
|
|
||||||
|
|
||||||
let remainingTime =
|
|
||||||
stats.global.time.moving -
|
|
||||||
(stats.local.time.moving[anchors[anchors.length - 1].point._data.index] -
|
|
||||||
stats.local.time.moving[anchors[0].point._data.index]);
|
|
||||||
let replacingTime = newTime - remainingTime;
|
|
||||||
|
|
||||||
if (replacingTime <= 0) {
|
|
||||||
// Fallback to simple time difference
|
|
||||||
replacingTime =
|
|
||||||
stats.local.time.total[anchors[anchors.length - 1].point._data.index] -
|
|
||||||
stats.local.time.total[anchors[0].point._data.index];
|
|
||||||
}
|
|
||||||
|
|
||||||
speed = (replacingDistance / replacingTime) * 3600;
|
|
||||||
|
|
||||||
if (startTime === undefined) {
|
|
||||||
// Replacing the first point
|
|
||||||
let endIndex = anchors[anchors.length - 1].point._data.index;
|
|
||||||
startTime = new Date(
|
|
||||||
(segment.trkpt[endIndex].time?.getTime() ?? 0) -
|
|
||||||
(replacingTime +
|
|
||||||
stats.local.time.total[endIndex] -
|
|
||||||
stats.local.time.moving[endIndex]) *
|
|
||||||
1000
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fileActionManager.applyToFile(this.fileId, (file) =>
|
|
||||||
file.replaceTrackPoints(
|
|
||||||
anchors[0].trackIndex,
|
|
||||||
anchors[0].segmentIndex,
|
|
||||||
anchors[0].point._data.index,
|
|
||||||
anchors[anchors.length - 1].point._data.index,
|
|
||||||
response,
|
|
||||||
speed,
|
|
||||||
startTime
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
destroy() {
|
|
||||||
this.remove();
|
|
||||||
this.unsubscribes.forEach((unsubscribe) => unsubscribe());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const routingControls: Map<string, RoutingControls> = new Map();
|
|
||||||
|
|
||||||
type Anchor = {
|
|
||||||
segment: TrackSegment;
|
|
||||||
trackIndex: number;
|
|
||||||
segmentIndex: number;
|
|
||||||
point: TrackPoint;
|
|
||||||
};
|
|
||||||
|
|
||||||
type AnchorWithMarker = Anchor & {
|
|
||||||
marker: mapboxgl.Marker;
|
|
||||||
inZoom: boolean;
|
|
||||||
};
|
|
||||||
1115
website/src/lib/components/toolbar/tools/routing/routing-controls.ts
Normal file
1115
website/src/lib/components/toolbar/tools/routing/routing-controls.ts
Normal file
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,7 @@ import { get } from 'svelte/store';
|
|||||||
|
|
||||||
const { routing, routingProfile, privateRoads } = settings;
|
const { routing, routingProfile, privateRoads } = settings;
|
||||||
|
|
||||||
export const brouterProfiles: { [key: string]: string } = {
|
export const routingProfiles: { [key: string]: string } = {
|
||||||
bike: 'Trekking-dry',
|
bike: 'Trekking-dry',
|
||||||
racing_bike: 'fastbike',
|
racing_bike: 'fastbike',
|
||||||
gravel_bike: 'gravel',
|
gravel_bike: 'gravel',
|
||||||
@@ -19,7 +19,7 @@ export const brouterProfiles: { [key: string]: string } = {
|
|||||||
|
|
||||||
export function route(points: Coordinates[]): Promise<TrackPoint[]> {
|
export function route(points: Coordinates[]): Promise<TrackPoint[]> {
|
||||||
if (get(routing)) {
|
if (get(routing)) {
|
||||||
return getRoute(points, brouterProfiles[get(routingProfile)], get(privateRoads));
|
return getRoute(points, routingProfiles[get(routingProfile)], get(privateRoads));
|
||||||
} else {
|
} else {
|
||||||
return getIntermediatePoints(points);
|
return getIntermediatePoints(points);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,21 @@ import { ramerDouglasPeucker, type GPXFile, type TrackSegment } from 'gpx';
|
|||||||
|
|
||||||
const earthRadius = 6371008.8;
|
const earthRadius = 6371008.8;
|
||||||
|
|
||||||
|
export const MIN_ANCHOR_ZOOM = 0;
|
||||||
|
export const MAX_ANCHOR_ZOOM = 22;
|
||||||
|
|
||||||
export function getZoomLevelForDistance(latitude: number, distance?: number): number {
|
export function getZoomLevelForDistance(latitude: number, distance?: number): number {
|
||||||
if (distance === undefined) {
|
if (distance === undefined) {
|
||||||
return 0;
|
return MIN_ANCHOR_ZOOM;
|
||||||
}
|
}
|
||||||
|
|
||||||
const rad = Math.PI / 180;
|
const rad = Math.PI / 180;
|
||||||
const lat = latitude * rad;
|
const lat = latitude * rad;
|
||||||
|
|
||||||
return Math.min(22, Math.max(0, Math.log2((earthRadius * Math.cos(lat)) / distance)));
|
return Math.min(
|
||||||
|
MAX_ANCHOR_ZOOM,
|
||||||
|
Math.max(MIN_ANCHOR_ZOOM, Math.round(Math.log2((earthRadius * Math.cos(lat)) / distance)))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateAnchorPoints(file: GPXFile) {
|
export function updateAnchorPoints(file: GPXFile) {
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
import { map } from '$lib/components/map/map';
|
import { map } from '$lib/components/map/map';
|
||||||
import { get } from 'svelte/store';
|
import { get } from 'svelte/store';
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
import { onDestroy, tick } from 'svelte';
|
import { onDestroy, onMount, untrack } from 'svelte';
|
||||||
import { Crop } from '@lucide/svelte';
|
import { Crop } from '@lucide/svelte';
|
||||||
import { SplitControls } from './split-controls';
|
import { SplitControls } from './split-controls';
|
||||||
import { getURLForLanguage } from '$lib/utils';
|
import { getURLForLanguage } from '$lib/utils';
|
||||||
@@ -23,33 +23,27 @@
|
|||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
let splitControls: SplitControls | undefined = undefined;
|
let splitControls: SplitControls | undefined = undefined;
|
||||||
let canCrop = $state(false);
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
if ($map) {
|
|
||||||
if (splitControls) {
|
|
||||||
splitControls.destroy();
|
|
||||||
}
|
|
||||||
splitControls = new SplitControls($map);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let validSelection = $derived(
|
let validSelection = $derived(
|
||||||
$selection.hasAnyChildren(new ListRootItem(), true, ['waypoints']) &&
|
$selection.hasAnyChildren(new ListRootItem(), true, ['waypoints']) &&
|
||||||
$gpxStatistics.local.points.length > 0
|
$gpxStatistics.global.length > 0
|
||||||
);
|
);
|
||||||
|
let maxSliderValue = $derived(
|
||||||
|
validSelection && $gpxStatistics.global.length > 0 ? $gpxStatistics.global.length - 1 : 1
|
||||||
|
);
|
||||||
|
let sliderValues = $derived([0, maxSliderValue]);
|
||||||
|
let canCrop = $derived(sliderValues[0] != 0 || sliderValues[1] != maxSliderValue);
|
||||||
|
|
||||||
let maxSliderValue = $state(1);
|
onMount(() => {
|
||||||
let sliderValues = $state([0, 1]);
|
if ($map) {
|
||||||
|
splitControls = new SplitControls($map, map.layerEventManager!);
|
||||||
function updateCanCrop() {
|
|
||||||
canCrop = sliderValues[0] != 0 || sliderValues[1] != maxSliderValue;
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
function updateSlicedGPXStatistics() {
|
function updateSlicedGPXStatistics() {
|
||||||
if (validSelection && canCrop) {
|
if (validSelection && canCrop) {
|
||||||
$slicedGPXStatistics = [
|
$slicedGPXStatistics = [
|
||||||
get(gpxStatistics).slice(sliderValues[0], sliderValues[1]),
|
get(gpxStatistics).sliced(sliderValues[0], sliderValues[1]),
|
||||||
sliderValues[0],
|
sliderValues[0],
|
||||||
sliderValues[1],
|
sliderValues[1],
|
||||||
];
|
];
|
||||||
@@ -64,26 +58,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateSliderLimits() {
|
|
||||||
if (validSelection && $gpxStatistics.local.points.length > 0) {
|
|
||||||
maxSliderValue = $gpxStatistics.local.points.length - 1;
|
|
||||||
} else {
|
|
||||||
maxSliderValue = 1;
|
|
||||||
}
|
|
||||||
await tick();
|
|
||||||
sliderValues = [0, maxSliderValue];
|
|
||||||
}
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
if ($gpxStatistics.local.points.length - 1 != maxSliderValue) {
|
|
||||||
updateSliderLimits();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (sliderValues) {
|
if (sliderValues) {
|
||||||
updateCanCrop();
|
untrack(() => updateSlicedGPXStatistics());
|
||||||
updateSlicedGPXStatistics();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -93,8 +70,7 @@
|
|||||||
($slicedGPXStatistics[1] !== sliderValues[0] ||
|
($slicedGPXStatistics[1] !== sliderValues[0] ||
|
||||||
$slicedGPXStatistics[2] !== sliderValues[1])
|
$slicedGPXStatistics[2] !== sliderValues[1])
|
||||||
) {
|
) {
|
||||||
updateSliderValues();
|
untrack(() => updateSliderValues());
|
||||||
updateCanCrop();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -102,7 +78,6 @@
|
|||||||
$slicedGPXStatistics = undefined;
|
$slicedGPXStatistics = undefined;
|
||||||
if (splitControls) {
|
if (splitControls) {
|
||||||
splitControls.destroy();
|
splitControls.destroy();
|
||||||
splitControls = undefined;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@@ -122,7 +97,7 @@
|
|||||||
disabled={!validSelection || !canCrop}
|
disabled={!validSelection || !canCrop}
|
||||||
onclick={() => fileActions.cropSelection(sliderValues[0], sliderValues[1])}
|
onclick={() => fileActions.cropSelection(sliderValues[0], sliderValues[1])}
|
||||||
>
|
>
|
||||||
<Crop size="16" class="mr-1" />{i18n._('toolbar.scissors.crop')}
|
<Crop size="16" />{i18n._('toolbar.scissors.crop')}
|
||||||
</Button>
|
</Button>
|
||||||
<Separator />
|
<Separator />
|
||||||
<Label class="flex flex-row flex-wrap gap-3 items-center">
|
<Label class="flex flex-row flex-wrap gap-3 items-center">
|
||||||
@@ -130,7 +105,7 @@
|
|||||||
{i18n._('toolbar.scissors.split_as')}
|
{i18n._('toolbar.scissors.split_as')}
|
||||||
</span>
|
</span>
|
||||||
<Select.Root bind:value={$splitAs} type="single">
|
<Select.Root bind:value={$splitAs} type="single">
|
||||||
<Select.Trigger class="h-8 w-fit grow">
|
<Select.Trigger class="w-fit grow" size="sm">
|
||||||
{i18n._('gpx.' + $splitAs)}
|
{i18n._('gpx.' + $splitAs)}
|
||||||
</Select.Trigger>
|
</Select.Trigger>
|
||||||
<Select.Content>
|
<Select.Content>
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import { TrackPoint, TrackSegment } from 'gpx';
|
|
||||||
import mapboxgl from 'mapbox-gl';
|
|
||||||
import { ListTrackSegmentItem } from '$lib/components/file-list/file-list';
|
import { ListTrackSegmentItem } from '$lib/components/file-list/file-list';
|
||||||
import { currentTool, Tool } from '$lib/components/toolbar/tools';
|
import { currentTool, Tool } from '$lib/components/toolbar/tools';
|
||||||
import { splitAs } from '$lib/components/toolbar/tools/scissors/scissors';
|
import { splitAs } from '$lib/components/toolbar/tools/scissors/scissors';
|
||||||
@@ -9,19 +7,34 @@ import { gpxStatistics } from '$lib/logic/statistics';
|
|||||||
import { get } from 'svelte/store';
|
import { get } from 'svelte/store';
|
||||||
import { fileStateCollection } from '$lib/logic/file-state';
|
import { fileStateCollection } from '$lib/logic/file-state';
|
||||||
import { fileActions } from '$lib/logic/file-actions';
|
import { fileActions } from '$lib/logic/file-actions';
|
||||||
|
import { mapCursor, MapCursorState } from '$lib/logic/map-cursor';
|
||||||
|
import type { GeoJSONSource } 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';
|
||||||
|
|
||||||
export class SplitControls {
|
export class SplitControls {
|
||||||
active: boolean = false;
|
map: maplibregl.Map;
|
||||||
map: mapboxgl.Map;
|
layerEventManager: MapLayerEventManager;
|
||||||
controls: ControlWithMarker[] = [];
|
|
||||||
shownControls: ControlWithMarker[] = [];
|
|
||||||
unsubscribes: Function[] = [];
|
unsubscribes: Function[] = [];
|
||||||
|
|
||||||
toggleControlsForZoomLevelAndBoundsBinded: () => void =
|
layerOnMouseEnterBinded: (e: any) => void = this.layerOnMouseEnter.bind(this);
|
||||||
this.toggleControlsForZoomLevelAndBounds.bind(this);
|
layerOnMouseLeaveBinded: () => void = this.layerOnMouseLeave.bind(this);
|
||||||
|
layerOnClickBinded: (e: any) => void = this.layerOnClick.bind(this);
|
||||||
|
|
||||||
constructor(map: mapboxgl.Map) {
|
constructor(map: maplibregl.Map, layerEventManager: MapLayerEventManager) {
|
||||||
this.map = map;
|
this.map = map;
|
||||||
|
this.layerEventManager = layerEventManager;
|
||||||
|
loadSVGIcon(
|
||||||
|
this.map,
|
||||||
|
'split-control',
|
||||||
|
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40">
|
||||||
|
<circle cx="20" cy="20" r="20" fill="white" />
|
||||||
|
<g transform="translate(8 8)">
|
||||||
|
${Scissors.replace('stroke="currentColor"', 'stroke="black"')}
|
||||||
|
</g>
|
||||||
|
</svg>`
|
||||||
|
);
|
||||||
|
|
||||||
this.unsubscribes.push(gpxStatistics.subscribe(this.addIfNeeded.bind(this)));
|
this.unsubscribes.push(gpxStatistics.subscribe(this.addIfNeeded.bind(this)));
|
||||||
this.unsubscribes.push(currentTool.subscribe(this.addIfNeeded.bind(this)));
|
this.unsubscribes.push(currentTool.subscribe(this.addIfNeeded.bind(this)));
|
||||||
@@ -31,29 +44,18 @@ export class SplitControls {
|
|||||||
addIfNeeded() {
|
addIfNeeded() {
|
||||||
let scissors = get(currentTool) === Tool.SCISSORS;
|
let scissors = get(currentTool) === Tool.SCISSORS;
|
||||||
if (!scissors) {
|
if (!scissors) {
|
||||||
if (this.active) {
|
|
||||||
this.remove();
|
this.remove();
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.active) {
|
|
||||||
this.updateControls();
|
this.updateControls();
|
||||||
} else {
|
|
||||||
this.add();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
add() {
|
|
||||||
this.active = true;
|
|
||||||
|
|
||||||
this.map.on('zoom', this.toggleControlsForZoomLevelAndBoundsBinded);
|
|
||||||
this.map.on('move', this.toggleControlsForZoomLevelAndBoundsBinded);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateControls() {
|
updateControls() {
|
||||||
// Update the markers when the files change
|
let data: GeoJSON.FeatureCollection = {
|
||||||
let controlIndex = 0;
|
type: 'FeatureCollection',
|
||||||
|
features: [],
|
||||||
|
};
|
||||||
selection.applyToOrderedSelectedItemsFromFile((fileId, level, items) => {
|
selection.applyToOrderedSelectedItemsFromFile((fileId, level, items) => {
|
||||||
let file = fileStateCollection.getFile(fileId);
|
let file = fileStateCollection.getFile(fileId);
|
||||||
|
|
||||||
@@ -64,30 +66,23 @@ export class SplitControls {
|
|||||||
new ListTrackSegmentItem(fileId, trackIndex, segmentIndex)
|
new ListTrackSegmentItem(fileId, trackIndex, segmentIndex)
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
for (let point of segment.trkpt.slice(1, -1)) {
|
for (let i = 1; i < segment.trkpt.length - 1; i++) {
|
||||||
// Update the existing controls (could be improved by matching the existing controls with the new ones?)
|
let point = segment.trkpt[i];
|
||||||
if (point._data.anchor) {
|
if (point._data.anchor) {
|
||||||
if (controlIndex < this.controls.length) {
|
data.features.push({
|
||||||
this.controls[controlIndex].fileId = fileId;
|
type: 'Feature',
|
||||||
this.controls[controlIndex].point = point;
|
geometry: {
|
||||||
this.controls[controlIndex].segment = segment;
|
type: 'Point',
|
||||||
this.controls[controlIndex].trackIndex = trackIndex;
|
coordinates: [point.getLongitude(), point.getLatitude()],
|
||||||
this.controls[controlIndex].segmentIndex = segmentIndex;
|
},
|
||||||
this.controls[controlIndex].marker.setLngLat(
|
properties: {
|
||||||
point.getCoordinates()
|
fileId: fileId,
|
||||||
);
|
trackIndex: trackIndex,
|
||||||
} else {
|
segmentIndex: segmentIndex,
|
||||||
this.controls.push(
|
pointIndex: i,
|
||||||
this.createControl(
|
minZoom: point._data.zoom,
|
||||||
point,
|
},
|
||||||
segment,
|
});
|
||||||
fileId,
|
|
||||||
trackIndex,
|
|
||||||
segmentIndex
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
controlIndex++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,86 +90,86 @@ export class SplitControls {
|
|||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
while (controlIndex < this.controls.length) {
|
try {
|
||||||
// Remove the extra controls
|
let source = this.map.getSource('split-controls') as GeoJSONSource | undefined;
|
||||||
this.controls.pop()?.marker.remove();
|
if (source) {
|
||||||
|
source.setData(data);
|
||||||
|
} else {
|
||||||
|
this.map.addSource('split-controls', {
|
||||||
|
type: 'geojson',
|
||||||
|
data: data,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.toggleControlsForZoomLevelAndBounds();
|
if (!this.map.getLayer('split-controls')) {
|
||||||
|
this.map.addLayer(
|
||||||
|
{
|
||||||
|
id: 'split-controls',
|
||||||
|
type: 'symbol',
|
||||||
|
source: 'split-controls',
|
||||||
|
layout: {
|
||||||
|
'icon-image': 'split-control',
|
||||||
|
'icon-size': 0.25,
|
||||||
|
'icon-padding': 0,
|
||||||
|
},
|
||||||
|
filter: ['<=', ['get', 'minZoom'], ['zoom']],
|
||||||
|
},
|
||||||
|
ANCHOR_LAYER_KEY.interactions
|
||||||
|
);
|
||||||
|
|
||||||
|
this.layerEventManager.on(
|
||||||
|
'mouseenter',
|
||||||
|
'split-controls',
|
||||||
|
this.layerOnMouseEnterBinded
|
||||||
|
);
|
||||||
|
this.layerEventManager.on(
|
||||||
|
'mouseleave',
|
||||||
|
'split-controls',
|
||||||
|
this.layerOnMouseLeaveBinded
|
||||||
|
);
|
||||||
|
this.layerEventManager.on('click', 'split-controls', this.layerOnClickBinded);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// No reliable way to check if the map is ready to add sources and layers
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
remove() {
|
remove() {
|
||||||
this.active = false;
|
this.layerEventManager.off('mouseenter', 'split-controls', this.layerOnMouseEnterBinded);
|
||||||
|
this.layerEventManager.off('mouseleave', 'split-controls', this.layerOnMouseLeaveBinded);
|
||||||
|
this.layerEventManager.off('click', 'split-controls', this.layerOnClickBinded);
|
||||||
|
|
||||||
for (let control of this.controls) {
|
try {
|
||||||
control.marker.remove();
|
if (this.map.getLayer('split-controls')) {
|
||||||
}
|
this.map.removeLayer('split-controls');
|
||||||
this.map.off('zoom', this.toggleControlsForZoomLevelAndBoundsBinded);
|
|
||||||
this.map.off('move', this.toggleControlsForZoomLevelAndBoundsBinded);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleControlsForZoomLevelAndBounds() {
|
if (this.map.getSource('split-controls')) {
|
||||||
// Show markers only if they are in the current zoom level and bounds
|
this.map.removeSource('split-controls');
|
||||||
this.shownControls.splice(0, this.shownControls.length);
|
}
|
||||||
|
} catch (e) {
|
||||||
let southWest = this.map.unproject([0, this.map.getCanvas().height]);
|
// No reliable way to check if the map is ready to remove sources and layers
|
||||||
let northEast = this.map.unproject([this.map.getCanvas().width, 0]);
|
|
||||||
let bounds = new mapboxgl.LngLatBounds(southWest, northEast);
|
|
||||||
|
|
||||||
let zoom = this.map.getZoom();
|
|
||||||
this.controls.forEach((control) => {
|
|
||||||
control.inZoom = control.point._data.zoom <= zoom;
|
|
||||||
if (control.inZoom && bounds.contains(control.marker.getLngLat())) {
|
|
||||||
control.marker.addTo(this.map);
|
|
||||||
this.shownControls.push(control);
|
|
||||||
} else {
|
|
||||||
control.marker.remove();
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
createControl(
|
layerOnMouseEnter(e: any) {
|
||||||
point: TrackPoint,
|
mapCursor.notify(MapCursorState.SPLIT_CONTROL, true);
|
||||||
segment: TrackSegment,
|
}
|
||||||
fileId: string,
|
|
||||||
trackIndex: number,
|
|
||||||
segmentIndex: number
|
|
||||||
): ControlWithMarker {
|
|
||||||
let element = document.createElement('div');
|
|
||||||
element.className = `h-6 w-6 p-0.5 rounded-full bg-white border-2 border-black cursor-pointer`;
|
|
||||||
element.innerHTML = Scissors.replace('width="24"', '')
|
|
||||||
.replace('height="24"', '')
|
|
||||||
.replace('stroke="currentColor"', 'stroke="black"');
|
|
||||||
|
|
||||||
let marker = new mapboxgl.Marker({
|
layerOnMouseLeave() {
|
||||||
draggable: true,
|
mapCursor.notify(MapCursorState.SPLIT_CONTROL, false);
|
||||||
className: 'z-10',
|
}
|
||||||
element,
|
|
||||||
}).setLngLat(point.getCoordinates());
|
|
||||||
|
|
||||||
let control = {
|
layerOnClick(e: maplibregl.MapLayerMouseEvent) {
|
||||||
point,
|
let coordinates = (e.features![0].geometry as GeoJSON.Point).coordinates;
|
||||||
segment,
|
|
||||||
fileId,
|
|
||||||
trackIndex,
|
|
||||||
segmentIndex,
|
|
||||||
marker,
|
|
||||||
inZoom: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
marker.getElement().addEventListener('click', (e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
fileActions.split(
|
fileActions.split(
|
||||||
get(splitAs),
|
get(splitAs),
|
||||||
control.fileId,
|
e.features![0].properties!.fileId,
|
||||||
control.trackIndex,
|
e.features![0].properties!.trackIndex,
|
||||||
control.segmentIndex,
|
e.features![0].properties!.segmentIndex,
|
||||||
control.point.getCoordinates(),
|
{ lon: coordinates[0], lat: coordinates[1] },
|
||||||
control.point._data.index
|
e.features![0].properties!.pointIndex
|
||||||
);
|
);
|
||||||
});
|
|
||||||
|
|
||||||
return control;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
@@ -182,16 +177,3 @@ export class SplitControls {
|
|||||||
this.unsubscribes.forEach((unsubscribe) => unsubscribe());
|
this.unsubscribes.forEach((unsubscribe) => unsubscribe());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Control = {
|
|
||||||
segment: TrackSegment;
|
|
||||||
fileId: string;
|
|
||||||
trackIndex: number;
|
|
||||||
segmentIndex: number;
|
|
||||||
point: TrackPoint;
|
|
||||||
};
|
|
||||||
|
|
||||||
type ControlWithMarker = Control & {
|
|
||||||
marker: mapboxgl.Marker;
|
|
||||||
inZoom: boolean;
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
import { fileActions } from '$lib/logic/file-actions';
|
import { fileActions } from '$lib/logic/file-actions';
|
||||||
import { map } from '$lib/components/map/map';
|
import { map } from '$lib/components/map/map';
|
||||||
import { mapCursor, MapCursorState } from '$lib/logic/map-cursor';
|
import { mapCursor, MapCursorState } from '$lib/logic/map-cursor';
|
||||||
|
import maplibregl from 'maplibre-gl';
|
||||||
|
import { getSvgForSymbol } from '$lib/components/map/gpx-layer/gpx-layer';
|
||||||
|
|
||||||
let props: {
|
let props: {
|
||||||
class?: string;
|
class?: string;
|
||||||
@@ -39,6 +41,21 @@
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let marker: maplibregl.Marker | null = null;
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
if ($selectedWaypoint) {
|
||||||
|
selectedWaypoint.reset();
|
||||||
|
} else {
|
||||||
|
name = '';
|
||||||
|
description = '';
|
||||||
|
link = '';
|
||||||
|
sym = '';
|
||||||
|
longitude = 0;
|
||||||
|
latitude = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if ($selectedWaypoint) {
|
if ($selectedWaypoint) {
|
||||||
const wpt = $selectedWaypoint[0];
|
const wpt = $selectedWaypoint[0];
|
||||||
@@ -54,14 +71,7 @@
|
|||||||
latitude = parseFloat(wpt.getLatitude().toFixed(6));
|
latitude = parseFloat(wpt.getLatitude().toFixed(6));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
untrack(() => {
|
untrack(reset);
|
||||||
name = '';
|
|
||||||
description = '';
|
|
||||||
link = '';
|
|
||||||
sym = '';
|
|
||||||
longitude = 0;
|
|
||||||
latitude = 0;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -85,14 +95,14 @@
|
|||||||
desc: description.length > 0 ? description : undefined,
|
desc: description.length > 0 ? description : undefined,
|
||||||
cmt: description.length > 0 ? description : undefined,
|
cmt: description.length > 0 ? description : undefined,
|
||||||
link: link.length > 0 ? { attributes: { href: link } } : undefined,
|
link: link.length > 0 ? { attributes: { href: link } } : undefined,
|
||||||
sym: sym,
|
sym: sym.length > 0 ? sym : undefined,
|
||||||
},
|
},
|
||||||
selectedWaypoint.wpt && selectedWaypoint.fileId
|
selectedWaypoint.wpt && selectedWaypoint.fileId
|
||||||
? new ListWaypointItem(selectedWaypoint.fileId, selectedWaypoint.wpt._data.index)
|
? new ListWaypointItem(selectedWaypoint.fileId, selectedWaypoint.wpt._data.index)
|
||||||
: undefined
|
: undefined
|
||||||
);
|
);
|
||||||
|
|
||||||
selectedWaypoint.reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setCoordinates(e: any) {
|
function setCoordinates(e: any) {
|
||||||
@@ -100,6 +110,37 @@
|
|||||||
longitude = e.lngLat.lng.toFixed(6);
|
longitude = e.lngLat.lng.toFixed(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if ($selectedWaypoint) {
|
||||||
|
if (marker) {
|
||||||
|
marker.remove();
|
||||||
|
marker = null;
|
||||||
|
}
|
||||||
|
} else if (latitude != 0 || longitude != 0) {
|
||||||
|
if ($map) {
|
||||||
|
if (marker) {
|
||||||
|
marker.setLngLat([longitude, latitude]).getElement().innerHTML =
|
||||||
|
getSvgForSymbol(symbolKey);
|
||||||
|
} else {
|
||||||
|
let element = document.createElement('div');
|
||||||
|
element.classList.add('w-8', 'h-8');
|
||||||
|
element.innerHTML = getSvgForSymbol(symbolKey);
|
||||||
|
marker = new maplibregl.Marker({
|
||||||
|
element,
|
||||||
|
anchor: 'bottom',
|
||||||
|
})
|
||||||
|
.setLngLat([longitude, latitude])
|
||||||
|
.addTo($map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (marker) {
|
||||||
|
marker.remove();
|
||||||
|
marker = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if ($map) {
|
if ($map) {
|
||||||
$map.on('click', setCoordinates);
|
$map.on('click', setCoordinates);
|
||||||
@@ -112,6 +153,10 @@
|
|||||||
$map.off('click', setCoordinates);
|
$map.off('click', setCoordinates);
|
||||||
mapCursor.notify(MapCursorState.TOOL_WITH_CROSSHAIR, false);
|
mapCursor.notify(MapCursorState.TOOL_WITH_CROSSHAIR, false);
|
||||||
}
|
}
|
||||||
|
if (marker) {
|
||||||
|
marker.remove();
|
||||||
|
marker = null;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -129,19 +174,27 @@
|
|||||||
bind:value={description}
|
bind:value={description}
|
||||||
id="description"
|
id="description"
|
||||||
disabled={!canCreate && !$selectedWaypoint}
|
disabled={!canCreate && !$selectedWaypoint}
|
||||||
|
class="min-h-8 h-8 py-1 px-3 text-sm"
|
||||||
/>
|
/>
|
||||||
<Label for="symbol">{i18n._('toolbar.waypoint.icon')}</Label>
|
<Label for="symbol">{i18n._('toolbar.waypoint.icon')}</Label>
|
||||||
<Select.Root bind:value={sym} type="single">
|
<Select.Root bind:value={sym} type="single">
|
||||||
<Select.Trigger
|
<Select.Trigger
|
||||||
id="symbol"
|
id="symbol"
|
||||||
class="w-full h-8"
|
size="sm"
|
||||||
|
class="w-full"
|
||||||
disabled={!canCreate && !$selectedWaypoint}
|
disabled={!canCreate && !$selectedWaypoint}
|
||||||
>
|
>
|
||||||
|
<span class="flex flex-row gap-1.5 items-center">
|
||||||
{#if symbolKey}
|
{#if symbolKey}
|
||||||
|
{#if symbols[symbolKey].icon}
|
||||||
|
{@const Component = symbols[symbolKey].icon}
|
||||||
|
<Component size="14" />
|
||||||
|
{/if}
|
||||||
{i18n._(`gpx.symbol.${symbolKey}`)}
|
{i18n._(`gpx.symbol.${symbolKey}`)}
|
||||||
{:else}
|
{:else}
|
||||||
{sym}
|
{sym}
|
||||||
{/if}
|
{/if}
|
||||||
|
</span>
|
||||||
</Select.Trigger>
|
</Select.Trigger>
|
||||||
<Select.Content class="max-h-60 overflow-y-scroll">
|
<Select.Content class="max-h-60 overflow-y-scroll">
|
||||||
{#each sortedSymbols as [key, symbol]}
|
{#each sortedSymbols as [key, symbol]}
|
||||||
@@ -149,7 +202,7 @@
|
|||||||
<span>
|
<span>
|
||||||
{#if symbol.icon}
|
{#if symbol.icon}
|
||||||
{@const Component = symbol.icon}
|
{@const Component = symbol.icon}
|
||||||
<Component size="14" class="inline-block align-sub mr-0.5" />
|
<Component size="14" class="inline-block align-sub" />
|
||||||
{:else}
|
{:else}
|
||||||
<span class="w-4 inline-block"></span>
|
<span class="w-4 inline-block"></span>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -203,14 +256,14 @@
|
|||||||
onclick={createOrUpdateWaypoint}
|
onclick={createOrUpdateWaypoint}
|
||||||
>
|
>
|
||||||
{#if $selectedWaypoint}
|
{#if $selectedWaypoint}
|
||||||
<Save size="16" class="mr-1 shrink-0" />
|
<Save size="16" class="shrink-0" />
|
||||||
{i18n._('menu.metadata.save')}
|
{i18n._('menu.metadata.save')}
|
||||||
{:else}
|
{:else}
|
||||||
<MapPin size="16" class="mr-1 shrink-0" />
|
<MapPin size="16" class="shrink-0" />
|
||||||
{i18n._('toolbar.waypoint.create')}
|
{i18n._('toolbar.waypoint.create')}
|
||||||
{/if}
|
{/if}
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="outline" onclick={() => selectedWaypoint.reset()}>
|
<Button variant="outline" size="icon" onclick={reset}>
|
||||||
<CircleX size="16" />
|
<CircleX size="16" />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -12,12 +12,14 @@
|
|||||||
disabled = false,
|
disabled = false,
|
||||||
locale,
|
locale,
|
||||||
class: className = '',
|
class: className = '',
|
||||||
|
onchange = () => {},
|
||||||
}: {
|
}: {
|
||||||
value?: DateValue;
|
value?: DateValue;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
locale: string;
|
locale: string;
|
||||||
class?: string;
|
class?: string;
|
||||||
|
onchange?: (date: DateValue | undefined) => void;
|
||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
const df = new DateFormatter(locale, {
|
const df = new DateFormatter(locale, {
|
||||||
@@ -43,6 +45,6 @@
|
|||||||
{value ? df.format(value.toDate(getLocalTimeZone())) : placeholder}
|
{value ? df.format(value.toDate(getLocalTimeZone())) : placeholder}
|
||||||
</Popover.Trigger>
|
</Popover.Trigger>
|
||||||
<Popover.Content bind:ref={contentRef} class="w-auto p-0">
|
<Popover.Content bind:ref={contentRef} class="w-auto p-0">
|
||||||
<Calendar type="single" captionLayout="dropdown" bind:value />
|
<Calendar type="single" captionLayout="dropdown" bind:value onValueChange={onchange} />
|
||||||
</Popover.Content>
|
</Popover.Content>
|
||||||
</Popover.Root>
|
</Popover.Root>
|
||||||
|
|||||||
@@ -1,26 +1,45 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Input } from '$lib/components/ui/input';
|
import { Input } from '$lib/components/ui/input';
|
||||||
|
|
||||||
export let value: string | number;
|
let {
|
||||||
|
id,
|
||||||
|
value = $bindable(),
|
||||||
|
disabled,
|
||||||
|
oninput = () => {},
|
||||||
|
onchange = () => {},
|
||||||
|
onkeypress = () => {},
|
||||||
|
onfocusin = () => {},
|
||||||
|
class: className,
|
||||||
|
}: {
|
||||||
|
id: string;
|
||||||
|
value: string | number;
|
||||||
|
disabled?: boolean;
|
||||||
|
oninput?: (e: Event) => void;
|
||||||
|
onchange?: (e: Event) => void;
|
||||||
|
onkeypress?: (e: KeyboardEvent) => void;
|
||||||
|
onfocusin?: (e: FocusEvent) => void;
|
||||||
|
class?: string;
|
||||||
|
} = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<Input
|
<Input
|
||||||
|
{id}
|
||||||
type="text"
|
type="text"
|
||||||
step={1}
|
step={1}
|
||||||
bind:value
|
bind:value
|
||||||
on:input
|
{disabled}
|
||||||
on:change
|
{oninput}
|
||||||
on:keypress
|
{onchange}
|
||||||
on:focusin={() => {
|
{onkeypress}
|
||||||
|
onfocusin={(e) => {
|
||||||
let input = document.activeElement;
|
let input = document.activeElement;
|
||||||
if (input instanceof HTMLInputElement) {
|
if (input instanceof HTMLInputElement) {
|
||||||
input.select();
|
input.select();
|
||||||
}
|
}
|
||||||
|
onfocusin(e);
|
||||||
}}
|
}}
|
||||||
on:focusin
|
class="w-[22px] {className ?? ''}"
|
||||||
class="w-[22px] {$$props.class ?? ''}"
|
|
||||||
{...$$restProps}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -29,8 +48,11 @@
|
|||||||
|
|
||||||
div :global(input) {
|
div :global(input) {
|
||||||
@apply px-0.5;
|
@apply px-0.5;
|
||||||
|
@apply py-0;
|
||||||
|
@apply bg-transparent;
|
||||||
@apply text-right;
|
@apply text-right;
|
||||||
@apply border-none;
|
@apply border-none;
|
||||||
|
@apply shadow-none;
|
||||||
@apply focus:ring-0;
|
@apply focus:ring-0;
|
||||||
@apply focus:ring-offset-0;
|
@apply focus:ring-offset-0;
|
||||||
@apply focus:outline-none;
|
@apply focus:outline-none;
|
||||||
|
|||||||
@@ -1,14 +1,22 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { untrack } from 'svelte';
|
||||||
import TimeComponentInput from './TimeComponentInput.svelte';
|
import TimeComponentInput from './TimeComponentInput.svelte';
|
||||||
|
|
||||||
export let showHours = true;
|
let {
|
||||||
export let value: number | undefined = undefined;
|
showHours = true,
|
||||||
export let disabled: boolean = false;
|
value = $bindable(),
|
||||||
export let onChange = () => {};
|
disabled = false,
|
||||||
|
onChange = () => {},
|
||||||
|
}: {
|
||||||
|
showHours?: boolean;
|
||||||
|
value?: number;
|
||||||
|
disabled?: boolean;
|
||||||
|
onChange?: () => void;
|
||||||
|
} = $props();
|
||||||
|
|
||||||
let hours: string | number = '--';
|
let hours: string | number = $state('--');
|
||||||
let minutes: string | number = '--';
|
let minutes: string | number = $state('--');
|
||||||
let seconds: string | number = '--';
|
let seconds: string | number = $state('--');
|
||||||
|
|
||||||
function maybeParseInt(value: string | number): number {
|
function maybeParseInt(value: string | number): number {
|
||||||
if (value === '--' || value === '') {
|
if (value === '--' || value === '') {
|
||||||
@@ -17,25 +25,31 @@
|
|||||||
return typeof value === 'string' ? parseInt(value) : value;
|
return typeof value === 'string' ? parseInt(value) : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function computeValue() {
|
function computeValue(): number {
|
||||||
return Math.max(
|
return Math.max(
|
||||||
maybeParseInt(hours) * 3600 + maybeParseInt(minutes) * 60 + maybeParseInt(seconds),
|
maybeParseInt(hours) * 3600 + maybeParseInt(minutes) * 60 + maybeParseInt(seconds),
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateValue() {
|
$effect(() => {
|
||||||
value = computeValue();
|
const val = computeValue();
|
||||||
}
|
untrack(() => {
|
||||||
|
value = val;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
$: hours, minutes, seconds, updateValue();
|
$effect(() => {
|
||||||
|
if (value === undefined) {
|
||||||
$: if (value === undefined) {
|
untrack(() => {
|
||||||
hours = '--';
|
hours = '--';
|
||||||
minutes = '--';
|
minutes = '--';
|
||||||
seconds = '--';
|
seconds = '--';
|
||||||
} else if (value !== computeValue()) {
|
});
|
||||||
let rounded = Math.max(Math.round(value), 1);
|
} else {
|
||||||
|
untrack(() => {
|
||||||
|
if (value != computeValue()) {
|
||||||
|
let rounded = Math.max(Math.round(value!), 1);
|
||||||
if (showHours) {
|
if (showHours) {
|
||||||
hours = Math.floor(rounded / 3600);
|
hours = Math.floor(rounded / 3600);
|
||||||
minutes = Math.floor((rounded % 3600) / 60)
|
minutes = Math.floor((rounded % 3600) / 60)
|
||||||
@@ -46,17 +60,25 @@
|
|||||||
}
|
}
|
||||||
seconds = (rounded % 60).toString().padStart(2, '0');
|
seconds = (rounded % 60).toString().padStart(2, '0');
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let container: HTMLDivElement;
|
let container: HTMLDivElement;
|
||||||
let countKeyPress = 0;
|
let countKeyPress = 0;
|
||||||
function onKeyPress(e) {
|
function onKeyPress(e: KeyboardEvent) {
|
||||||
if (['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'].includes(e.key)) {
|
const target = e.target as HTMLInputElement | null;
|
||||||
|
if (target && ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'].includes(e.key)) {
|
||||||
countKeyPress++;
|
countKeyPress++;
|
||||||
if (countKeyPress === 2) {
|
if (countKeyPress === 2) {
|
||||||
if (e.target.id === 'hours') {
|
const nextInput =
|
||||||
container.querySelector('#minutes')?.focus();
|
target.id === 'hours'
|
||||||
} else if (e.target.id === 'minutes') {
|
? (container.querySelector('#minutes') as HTMLInputElement)
|
||||||
container.querySelector('#seconds')?.focus();
|
: target.id === 'minutes'
|
||||||
|
? (container.querySelector('#seconds') as HTMLInputElement)
|
||||||
|
: null;
|
||||||
|
if (nextInput) {
|
||||||
|
nextInput.focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,7 +87,7 @@
|
|||||||
|
|
||||||
<div
|
<div
|
||||||
bind:this={container}
|
bind:this={container}
|
||||||
class="flex flex-row items-center w-full min-w-fit border rounded-md px-3 focus-within:outline-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 {disabled
|
class="h-9 flex flex-row items-center w-full min-w-fit border rounded-md px-3 focus-within:outline-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 {disabled
|
||||||
? 'opacity-50 cursor-not-allowed'
|
? 'opacity-50 cursor-not-allowed'
|
||||||
: ''}"
|
: ''}"
|
||||||
>
|
>
|
||||||
@@ -75,7 +97,7 @@
|
|||||||
bind:value={hours}
|
bind:value={hours}
|
||||||
{disabled}
|
{disabled}
|
||||||
class="w-[30px]"
|
class="w-[30px]"
|
||||||
on:input={() => {
|
oninput={() => {
|
||||||
if (typeof hours === 'string') {
|
if (typeof hours === 'string') {
|
||||||
hours = parseInt(hours);
|
hours = parseInt(hours);
|
||||||
}
|
}
|
||||||
@@ -87,8 +109,8 @@
|
|||||||
}
|
}
|
||||||
onChange();
|
onChange();
|
||||||
}}
|
}}
|
||||||
on:keypress={onKeyPress}
|
onkeypress={onKeyPress}
|
||||||
on:focusin={() => {
|
onfocusin={() => {
|
||||||
countKeyPress = 0;
|
countKeyPress = 0;
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@@ -98,7 +120,7 @@
|
|||||||
id="minutes"
|
id="minutes"
|
||||||
bind:value={minutes}
|
bind:value={minutes}
|
||||||
{disabled}
|
{disabled}
|
||||||
on:input={() => {
|
oninput={() => {
|
||||||
if (typeof minutes === 'string') {
|
if (typeof minutes === 'string') {
|
||||||
minutes = parseInt(minutes);
|
minutes = parseInt(minutes);
|
||||||
}
|
}
|
||||||
@@ -113,8 +135,8 @@
|
|||||||
minutes = minutes.toString().padStart(showHours ? 2 : 1, '0');
|
minutes = minutes.toString().padStart(showHours ? 2 : 1, '0');
|
||||||
onChange();
|
onChange();
|
||||||
}}
|
}}
|
||||||
on:keypress={onKeyPress}
|
onkeypress={onKeyPress}
|
||||||
on:focusin={() => {
|
onfocusin={() => {
|
||||||
countKeyPress = 0;
|
countKeyPress = 0;
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@@ -123,7 +145,7 @@
|
|||||||
id="seconds"
|
id="seconds"
|
||||||
bind:value={seconds}
|
bind:value={seconds}
|
||||||
{disabled}
|
{disabled}
|
||||||
on:input={() => {
|
oninput={() => {
|
||||||
if (typeof seconds === 'string') {
|
if (typeof seconds === 'string') {
|
||||||
seconds = parseInt(seconds);
|
seconds = parseInt(seconds);
|
||||||
}
|
}
|
||||||
@@ -138,8 +160,8 @@
|
|||||||
seconds = seconds.toString().padStart(2, '0');
|
seconds = seconds.toString().padStart(2, '0');
|
||||||
onChange();
|
onChange();
|
||||||
}}
|
}}
|
||||||
on:keypress={onKeyPress}
|
onkeypress={onKeyPress}
|
||||||
on:focusin={() => {
|
onfocusin={() => {
|
||||||
countKeyPress = 0;
|
countKeyPress = 0;
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@@ -155,6 +177,7 @@
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
div :global(input[type='number']) {
|
div :global(input[type='number']) {
|
||||||
|
appearance: textfield;
|
||||||
-moz-appearance: textfield;
|
-moz-appearance: textfield;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ title: Files and statistics
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { ChartNoAxesColumn } from '@lucide/svelte';
|
import { ChartNoAxesColumn } from '@lucide/svelte';
|
||||||
import DocsNote from '$lib/components/docs/DocsNote.svelte';
|
import DocsNote from '$lib/components/docs/DocsNote.svelte';
|
||||||
import ElevationProfile from '$lib/components/ElevationProfile.svelte';
|
import ElevationProfile from '$lib/components/elevation-profile/ElevationProfile.svelte';
|
||||||
import GPXStatistics from '$lib/components/GPXStatistics.svelte';
|
import GPXStatistics from '$lib/components/GPXStatistics.svelte';
|
||||||
import { exampleGPXFile } from '$lib/assets/example';
|
import { exampleGPXFile } from '$lib/assets/example';
|
||||||
import { writable } from 'svelte/store';
|
import { writable } from 'svelte/store';
|
||||||
@@ -13,7 +13,7 @@ title: Files and statistics
|
|||||||
let gpxStatistics = writable(exampleGPXFile.getStatistics());
|
let gpxStatistics = writable(exampleGPXFile.getStatistics());
|
||||||
let slicedGPXStatistics = writable(undefined);
|
let slicedGPXStatistics = writable(undefined);
|
||||||
let additionalDatasets = writable(['speed', 'atemp']);
|
let additionalDatasets = writable(['speed', 'atemp']);
|
||||||
let elevationFill = writable<'slope' | 'surface' | undefined>(undefined);
|
let elevationFill = writable(undefined);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
# { title }
|
# { title }
|
||||||
@@ -84,8 +84,8 @@ You can also use the mouse wheel to zoom in and out on the elevation profile, an
|
|||||||
<ElevationProfile
|
<ElevationProfile
|
||||||
{gpxStatistics}
|
{gpxStatistics}
|
||||||
{slicedGPXStatistics}
|
{slicedGPXStatistics}
|
||||||
additionalDatasets={$additionalDatasets}
|
{additionalDatasets}
|
||||||
elevationFill={$elevationFill}
|
{elevationFill}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col items-center -mt-6">
|
<div class="flex flex-col items-center -mt-6">
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { HeartHandshake } from '@lucide/svelte';
|
import { HeartHandshake } from '@lucide/svelte';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
## <HeartHandshake size="18" class="mr-1 inline-block align-baseline" /> Help keep the website free (and ad-free)
|
## <HeartHandshake size="18" class="inline-block align-baseline" /> Help keep the website free (and ad-free)
|
||||||
|
|
||||||
Each time you add or move GPS points, our servers calculate the best route on the road network.
|
Each time you add or move GPS points, our servers calculate the best route on the road network.
|
||||||
We also use APIs from <a href="https://mapbox.com" target="_blank">Mapbox</a> to display beautiful maps, retrieve elevation data and allow you to search for places.
|
We also use APIs from <a href="https://mapbox.com" target="_blank">Mapbox</a> to display beautiful maps, retrieve elevation data and allow you to search for places.
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { Languages } from '@lucide/svelte';
|
import { Languages } from '@lucide/svelte';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
## <Languages size="18" class="mr-1 inline-block align-baseline" /> Translation
|
## <Languages size="18" class="inline-block align-baseline" /> Translation
|
||||||
|
|
||||||
The website is translated by volunteers using a collaborative translation platform.
|
The website is translated by volunteers using a collaborative translation platform.
|
||||||
You can contribute by adding or improving translations on our <a href="https://crowdin.com/project/gpxstudio" target="_blank">Crowdin project</a>.
|
You can contribute by adding or improving translations on our <a href="https://crowdin.com/project/gpxstudio" target="_blank">Crowdin project</a>.
|
||||||
|
|||||||
@@ -29,13 +29,13 @@ You can also drag and drop files directly from your file system into the window.
|
|||||||
|
|
||||||
Create a copy of the currently selected files.
|
Create a copy of the currently selected files.
|
||||||
|
|
||||||
### <FileX size="16" class="inline-block" style="margin-bottom: 2px" /> Close
|
### <FileX size="16" class="inline-block" style="margin-bottom: 2px" /> Delete
|
||||||
|
|
||||||
Close the currently selected files.
|
Delete the currently selected files.
|
||||||
|
|
||||||
### <FileX size="16" class="inline-block" style="margin-bottom: 2px" /> Close all
|
### <FileX size="16" class="inline-block" style="margin-bottom: 2px" /> Delete all
|
||||||
|
|
||||||
Close all files.
|
Delete all files.
|
||||||
|
|
||||||
### <Download size="16" class="inline-block" style="margin-bottom: 2px" /> Export...
|
### <Download size="16" class="inline-block" style="margin-bottom: 2px" /> Export...
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ title: Toolbar
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Toolbar from '$lib/components/toolbar/Toolbar.svelte';
|
import Toolbar from '$lib/components/toolbar/Toolbar.svelte';
|
||||||
import { currentTool, Tool } from '$lib/stores';
|
import { currentTool, Tool } from '$lib/components/toolbar/tools';
|
||||||
import { onMount, onDestroy } from 'svelte';
|
import { onMount, onDestroy } from 'svelte';
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ title: Route planning and editing
|
|||||||
---
|
---
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { Pencil, Route, Bike, TriangleAlert, ArrowRightLeft, Home, Repeat, Trash2, CirclePlay, SquareArrowUpLeft } from '@lucide/svelte';
|
import { Pencil, Route, Bike, TriangleAlert, ArrowRightLeft, House, Repeat, Trash2, CirclePlay, SquareArrowUpLeft } from '@lucide/svelte';
|
||||||
import DocsNote from '$lib/components/docs/DocsNote.svelte';
|
import DocsNote from '$lib/components/docs/DocsNote.svelte';
|
||||||
import Routing from '$lib/components/toolbar/tools/routing/Routing.svelte';
|
import Routing from '$lib/components/toolbar/tools/routing/Routing.svelte';
|
||||||
import DocsImage from '$lib/components/docs/DocsImage.svelte';
|
import DocsImage from '$lib/components/docs/DocsImage.svelte';
|
||||||
@@ -71,7 +71,7 @@ The following tools automate some common route modification operations.
|
|||||||
|
|
||||||
Reverse the direction of the route.
|
Reverse the direction of the route.
|
||||||
|
|
||||||
### <Home size="16" class="inline-block" style="margin-bottom: 2px" /> Back to start
|
### <House size="16" class="inline-block" style="margin-bottom: 2px" /> Back to start
|
||||||
|
|
||||||
Connect the last point of the route with the starting point, using the chosen routing settings.
|
Connect the last point of the route with the starting point, using the chosen routing settings.
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user