mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-03-13 16:22:59 +00:00
Compare commits
6 Commits
0ab3b77db8
...
bfd0d90abc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bfd0d90abc | ||
|
|
dba01e1826 | ||
|
|
2189c76edd | ||
|
|
6f8c9d66db | ||
|
|
9408ce10c7 | ||
|
|
9895c3c304 |
@@ -18,7 +18,7 @@
|
|||||||
Construction,
|
Construction,
|
||||||
} from '@lucide/svelte';
|
} from '@lucide/svelte';
|
||||||
import type { Readable, Writable } from 'svelte/store';
|
import type { Readable, Writable } from 'svelte/store';
|
||||||
import type { GPXGlobalStatistics, GPXStatisticsGroup } from 'gpx';
|
import type { Coordinates, GPXGlobalStatistics, GPXStatisticsGroup } from 'gpx';
|
||||||
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 { ElevationProfile } from '$lib/components/elevation-profile/elevation-profile';
|
import { ElevationProfile } from '$lib/components/elevation-profile/elevation-profile';
|
||||||
@@ -28,12 +28,14 @@
|
|||||||
let {
|
let {
|
||||||
gpxStatistics,
|
gpxStatistics,
|
||||||
slicedGPXStatistics,
|
slicedGPXStatistics,
|
||||||
|
hoveredPoint,
|
||||||
additionalDatasets,
|
additionalDatasets,
|
||||||
elevationFill,
|
elevationFill,
|
||||||
showControls = true,
|
showControls = true,
|
||||||
}: {
|
}: {
|
||||||
gpxStatistics: Readable<GPXStatisticsGroup>;
|
gpxStatistics: Readable<GPXStatisticsGroup>;
|
||||||
slicedGPXStatistics: Writable<[GPXGlobalStatistics, number, number] | undefined>;
|
slicedGPXStatistics: Writable<[GPXGlobalStatistics, number, number] | undefined>;
|
||||||
|
hoveredPoint: Writable<Coordinates | null>;
|
||||||
additionalDatasets: Writable<string[]>;
|
additionalDatasets: Writable<string[]>;
|
||||||
elevationFill: Writable<'slope' | 'surface' | 'highway' | undefined>;
|
elevationFill: Writable<'slope' | 'surface' | 'highway' | undefined>;
|
||||||
showControls?: boolean;
|
showControls?: boolean;
|
||||||
@@ -47,6 +49,7 @@
|
|||||||
elevationProfile = new ElevationProfile(
|
elevationProfile = new ElevationProfile(
|
||||||
gpxStatistics,
|
gpxStatistics,
|
||||||
slicedGPXStatistics,
|
slicedGPXStatistics,
|
||||||
|
hoveredPoint,
|
||||||
additionalDatasets,
|
additionalDatasets,
|
||||||
elevationFill,
|
elevationFill,
|
||||||
canvas,
|
canvas,
|
||||||
|
|||||||
@@ -20,10 +20,8 @@ import Chart, {
|
|||||||
type ScriptableLineSegmentContext,
|
type ScriptableLineSegmentContext,
|
||||||
type TooltipItem,
|
type TooltipItem,
|
||||||
} from 'chart.js/auto';
|
} from 'chart.js/auto';
|
||||||
import maplibregl from 'maplibre-gl';
|
|
||||||
import { get, type Readable, type Writable } from 'svelte/store';
|
import { get, type Readable, type Writable } from 'svelte/store';
|
||||||
import { map } from '$lib/components/map/map';
|
import type { Coordinates, GPXGlobalStatistics, GPXStatisticsGroup } from 'gpx';
|
||||||
import type { GPXGlobalStatistics, GPXStatisticsGroup } from 'gpx';
|
|
||||||
import { mode } from 'mode-watcher';
|
import { mode } from 'mode-watcher';
|
||||||
import { getHighwayColor, getSlopeColor, getSurfaceColor } from '$lib/assets/colors';
|
import { getHighwayColor, getSlopeColor, getSurfaceColor } from '$lib/assets/colors';
|
||||||
|
|
||||||
@@ -42,7 +40,7 @@ interface ElevationProfilePoint {
|
|||||||
length: number;
|
length: number;
|
||||||
};
|
};
|
||||||
extensions: Record<string, any>;
|
extensions: Record<string, any>;
|
||||||
coordinates: [number, number];
|
coordinates: Coordinates;
|
||||||
index: number;
|
index: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,18 +48,19 @@ export class ElevationProfile {
|
|||||||
private _chart: Chart | null = null;
|
private _chart: Chart | null = null;
|
||||||
private _canvas: HTMLCanvasElement;
|
private _canvas: HTMLCanvasElement;
|
||||||
private _overlay: HTMLCanvasElement;
|
private _overlay: HTMLCanvasElement;
|
||||||
private _marker: maplibregl.Marker | null = null;
|
|
||||||
private _dragging = false;
|
private _dragging = false;
|
||||||
private _panning = false;
|
private _panning = false;
|
||||||
|
|
||||||
private _gpxStatistics: Readable<GPXStatisticsGroup>;
|
private _gpxStatistics: Readable<GPXStatisticsGroup>;
|
||||||
private _slicedGPXStatistics: Writable<[GPXGlobalStatistics, number, number] | undefined>;
|
private _slicedGPXStatistics: Writable<[GPXGlobalStatistics, number, number] | undefined>;
|
||||||
|
private _hoveredPoint: Writable<Coordinates | null>;
|
||||||
private _additionalDatasets: Readable<string[]>;
|
private _additionalDatasets: Readable<string[]>;
|
||||||
private _elevationFill: Readable<'slope' | 'surface' | 'highway' | undefined>;
|
private _elevationFill: Readable<'slope' | 'surface' | 'highway' | undefined>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
gpxStatistics: Readable<GPXStatisticsGroup>,
|
gpxStatistics: Readable<GPXStatisticsGroup>,
|
||||||
slicedGPXStatistics: Writable<[GPXGlobalStatistics, number, number] | undefined>,
|
slicedGPXStatistics: Writable<[GPXGlobalStatistics, number, number] | undefined>,
|
||||||
|
hoveredPoint: Writable<Coordinates | null>,
|
||||||
additionalDatasets: Readable<string[]>,
|
additionalDatasets: Readable<string[]>,
|
||||||
elevationFill: Readable<'slope' | 'surface' | 'highway' | undefined>,
|
elevationFill: Readable<'slope' | 'surface' | 'highway' | undefined>,
|
||||||
canvas: HTMLCanvasElement,
|
canvas: HTMLCanvasElement,
|
||||||
@@ -69,17 +68,12 @@ export class ElevationProfile {
|
|||||||
) {
|
) {
|
||||||
this._gpxStatistics = gpxStatistics;
|
this._gpxStatistics = gpxStatistics;
|
||||||
this._slicedGPXStatistics = slicedGPXStatistics;
|
this._slicedGPXStatistics = slicedGPXStatistics;
|
||||||
|
this._hoveredPoint = hoveredPoint;
|
||||||
this._additionalDatasets = additionalDatasets;
|
this._additionalDatasets = additionalDatasets;
|
||||||
this._elevationFill = elevationFill;
|
this._elevationFill = elevationFill;
|
||||||
this._canvas = canvas;
|
this._canvas = canvas;
|
||||||
this._overlay = overlay;
|
this._overlay = overlay;
|
||||||
|
|
||||||
let element = document.createElement('div');
|
|
||||||
element.className = 'h-4 w-4 rounded-full bg-cyan-500 border-2 border-white';
|
|
||||||
this._marker = new maplibregl.Marker({
|
|
||||||
element,
|
|
||||||
});
|
|
||||||
|
|
||||||
import('chartjs-plugin-zoom').then((module) => {
|
import('chartjs-plugin-zoom').then((module) => {
|
||||||
Chart.register(module.default);
|
Chart.register(module.default);
|
||||||
this.initialize();
|
this.initialize();
|
||||||
@@ -162,14 +156,10 @@ export class ElevationProfile {
|
|||||||
label: (context: TooltipItem<'line'>) => {
|
label: (context: TooltipItem<'line'>) => {
|
||||||
let point = context.raw as ElevationProfilePoint;
|
let point = context.raw as ElevationProfilePoint;
|
||||||
if (context.datasetIndex === 0) {
|
if (context.datasetIndex === 0) {
|
||||||
const map_ = get(map);
|
|
||||||
if (map_ && this._marker) {
|
|
||||||
if (this._dragging) {
|
if (this._dragging) {
|
||||||
this._marker.remove();
|
this._hoveredPoint.set(null);
|
||||||
} else {
|
} else {
|
||||||
this._marker.setLngLat(point.coordinates);
|
this._hoveredPoint.set(point.coordinates);
|
||||||
this._marker.addTo(map_);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return `${i18n._('quantities.elevation')}: ${getElevationWithUnits(point.y, false)}`;
|
return `${i18n._('quantities.elevation')}: ${getElevationWithUnits(point.y, false)}`;
|
||||||
} else if (context.datasetIndex === 1) {
|
} else if (context.datasetIndex === 1) {
|
||||||
@@ -312,10 +302,7 @@ export class ElevationProfile {
|
|||||||
events: ['mouseout'],
|
events: ['mouseout'],
|
||||||
afterEvent: (chart: Chart, args: { event: ChartEvent }) => {
|
afterEvent: (chart: Chart, args: { event: ChartEvent }) => {
|
||||||
if (args.event.type === 'mouseout') {
|
if (args.event.type === 'mouseout') {
|
||||||
const map_ = get(map);
|
this._hoveredPoint.set(null);
|
||||||
if (map_ && this._marker) {
|
|
||||||
this._marker.remove();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -637,8 +624,5 @@ export class ElevationProfile {
|
|||||||
this._chart.destroy();
|
this._chart.destroy();
|
||||||
this._chart = null;
|
this._chart = null;
|
||||||
}
|
}
|
||||||
if (this._marker) {
|
|
||||||
this._marker.remove();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
import { setMode } from 'mode-watcher';
|
import { setMode } from 'mode-watcher';
|
||||||
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, slicedGPXStatistics } from '$lib/logic/statistics';
|
import { gpxStatistics, hoveredPoint, slicedGPXStatistics } from '$lib/logic/statistics';
|
||||||
import { loadFile } from '$lib/logic/file-actions';
|
import { loadFile } from '$lib/logic/file-actions';
|
||||||
import { selection } from '$lib/logic/selection';
|
import { selection } from '$lib/logic/selection';
|
||||||
import { untrack } from 'svelte';
|
import { untrack } from 'svelte';
|
||||||
@@ -102,7 +102,7 @@
|
|||||||
<div class="grow relative">
|
<div class="grow relative">
|
||||||
<Map
|
<Map
|
||||||
class="h-full {$fileStateCollection.size > 1 ? 'horizontal' : ''}"
|
class="h-full {$fileStateCollection.size > 1 ? 'horizontal' : ''}"
|
||||||
accessToken={options.token}
|
maptilerKey={options.key}
|
||||||
geocoder={false}
|
geocoder={false}
|
||||||
geolocate={true}
|
geolocate={true}
|
||||||
hash={useHash}
|
hash={useHash}
|
||||||
@@ -130,6 +130,7 @@
|
|||||||
<ElevationProfile
|
<ElevationProfile
|
||||||
{gpxStatistics}
|
{gpxStatistics}
|
||||||
{slicedGPXStatistics}
|
{slicedGPXStatistics}
|
||||||
|
{hoveredPoint}
|
||||||
{additionalDatasets}
|
{additionalDatasets}
|
||||||
{elevationFill}
|
{elevationFill}
|
||||||
showControls={options.elevation.controls}
|
showControls={options.elevation.controls}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
let options = $state(
|
let options = $state(
|
||||||
getMergedEmbeddingOptions(
|
getMergedEmbeddingOptions(
|
||||||
{
|
{
|
||||||
token: 'YOUR_MAPTILER_KEY',
|
key: 'YOUR_MAPTILER_KEY',
|
||||||
theme: mode.current,
|
theme: mode.current,
|
||||||
},
|
},
|
||||||
defaultEmbeddingOptions
|
defaultEmbeddingOptions
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
let iframeOptions = $derived(
|
let iframeOptions = $derived(
|
||||||
getMergedEmbeddingOptions(
|
getMergedEmbeddingOptions(
|
||||||
{
|
{
|
||||||
token:
|
key:
|
||||||
options.key.length === 0 || options.key === 'YOUR_MAPTILER_KEY'
|
options.key.length === 0 || options.key === 'YOUR_MAPTILER_KEY'
|
||||||
? PUBLIC_MAPTILER_KEY
|
? PUBLIC_MAPTILER_KEY
|
||||||
: options.key,
|
: options.key,
|
||||||
|
|||||||
@@ -15,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';
|
||||||
@@ -227,6 +227,56 @@ export class GPXLayer {
|
|||||||
layerEventManager.on('mouseleave', this.fileId, this.layerOnMouseLeaveBinded);
|
layerEventManager.on('mouseleave', this.fileId, this.layerOnMouseLeaveBinded);
|
||||||
layerEventManager.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 (!_map.getLayer(this.fileId + '-direction')) {
|
||||||
|
_map.addLayer(
|
||||||
|
{
|
||||||
|
id: this.fileId + '-direction',
|
||||||
|
type: 'symbol',
|
||||||
|
source: this.fileId,
|
||||||
|
layout: {
|
||||||
|
'text-field': '»',
|
||||||
|
'text-offset': [0, -0.1],
|
||||||
|
'text-keep-upright': false,
|
||||||
|
'text-max-angle': 361,
|
||||||
|
'text-allow-overlap': true,
|
||||||
|
'text-font': ['Open Sans Bold'],
|
||||||
|
'symbol-placement': 'line',
|
||||||
|
'symbol-spacing': 20,
|
||||||
|
},
|
||||||
|
paint: {
|
||||||
|
'text-color': 'white',
|
||||||
|
'text-opacity': 0.7,
|
||||||
|
'text-halo-width': 0.2,
|
||||||
|
'text-halo-color': 'white',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ANCHOR_LAYER_KEY.directionMarkers
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_map.setFilter(this.fileId + '-direction', segmentFilter, { validate: false });
|
||||||
|
} else {
|
||||||
|
if (_map.getLayer(this.fileId + '-direction')) {
|
||||||
|
_map.removeLayer(this.fileId + '-direction');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let waypointSource = _map.getSource(this.fileId + '-waypoints') as
|
let waypointSource = _map.getSource(this.fileId + '-waypoints') as
|
||||||
| GeoJSONSource
|
| GeoJSONSource
|
||||||
| undefined;
|
| undefined;
|
||||||
@@ -284,57 +334,6 @@ export class GPXLayer {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get(directionMarkers)) {
|
|
||||||
if (!_map.getLayer(this.fileId + '-direction')) {
|
|
||||||
_map.addLayer(
|
|
||||||
{
|
|
||||||
id: this.fileId + '-direction',
|
|
||||||
type: 'symbol',
|
|
||||||
source: this.fileId,
|
|
||||||
layout: {
|
|
||||||
'text-field': '»',
|
|
||||||
'text-offset': [0, -0.1],
|
|
||||||
'text-keep-upright': false,
|
|
||||||
'text-max-angle': 361,
|
|
||||||
'text-allow-overlap': true,
|
|
||||||
'text-font': ['Open Sans Bold'],
|
|
||||||
'symbol-placement': 'line',
|
|
||||||
'symbol-spacing': 20,
|
|
||||||
},
|
|
||||||
paint: {
|
|
||||||
'text-color': 'white',
|
|
||||||
'text-opacity': 0.7,
|
|
||||||
'text-halo-width': 0.2,
|
|
||||||
'text-halo-color': 'white',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
ANCHOR_LAYER_KEY.directionMarkers
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (_map.getLayer(this.fileId + '-direction')) {
|
|
||||||
_map.removeLayer(this.fileId + '-direction');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 (_map.getLayer(this.fileId + '-direction')) {
|
|
||||||
_map.setFilter(this.fileId + '-direction', segmentFilter, { validate: false });
|
|
||||||
}
|
|
||||||
|
|
||||||
let visibleWaypoints: number[] = [];
|
let visibleWaypoints: number[] = [];
|
||||||
file.wpt.forEach((waypoint, waypointIndex) => {
|
file.wpt.forEach((waypoint, waypointIndex) => {
|
||||||
if (!waypoint._data.hidden) {
|
if (!waypoint._data.hidden) {
|
||||||
@@ -784,20 +783,7 @@ export class GPXLayer {
|
|||||||
|
|
||||||
symbols.forEach((symbol) => {
|
symbols.forEach((symbol) => {
|
||||||
const iconId = `waypoint-${symbol ?? 'default'}-${this.layerColor}`;
|
const iconId = `waypoint-${symbol ?? 'default'}-${this.layerColor}`;
|
||||||
if (!_map.hasImage(iconId)) {
|
loadSVGIcon(_map, iconId, getSvgForSymbol(symbol, this.layerColor));
|
||||||
let icon = new Image(100, 100);
|
|
||||||
icon.onload = () => {
|
|
||||||
if (!_map.hasImage(iconId)) {
|
|
||||||
_map.addImage(iconId, 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(getSvgForSymbol(symbol, this.layerColor));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +1,40 @@
|
|||||||
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 maplibregl from 'maplibre-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 { 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: maplibregl.Marker;
|
|
||||||
end: maplibregl.Marker;
|
|
||||||
updateBinded: () => void = this.update.bind(this);
|
updateBinded: () => void = this.update.bind(this);
|
||||||
unsubscribes: (() => void)[] = [];
|
unsubscribes: (() => void)[] = [];
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
let startElement = document.createElement('div');
|
|
||||||
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 maplibregl.Marker({ element: startElement });
|
|
||||||
this.end = new maplibregl.Marker({ element: endElement });
|
|
||||||
|
|
||||||
map.onLoad(() => this.update());
|
map.onLoad(() => this.update());
|
||||||
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));
|
this.unsubscribes.push(allHidden.subscribe(this.updateBinded));
|
||||||
}
|
}
|
||||||
@@ -33,33 +43,113 @@ export class StartEndMarkers {
|
|||||||
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(gpxStatistics);
|
const statistics = get(gpxStatistics);
|
||||||
const slicedStatistics = get(slicedGPXStatistics);
|
const slicedStatistics = get(slicedGPXStatistics);
|
||||||
|
const hovered = get(hoveredPoint);
|
||||||
const hidden = get(allHidden);
|
const hidden = get(allHidden);
|
||||||
if (statistics.global.length > 0 && tool !== Tool.ROUTING && !hidden) {
|
if (statistics.global.length > 0 && tool !== Tool.ROUTING && !hidden) {
|
||||||
this.start
|
const start = statistics
|
||||||
.setLngLat(
|
.getTrackPoint(slicedStatistics?.[1] ?? 0)!
|
||||||
statistics.getTrackPoint(slicedStatistics?.[1] ?? 0)!.trkpt.getCoordinates()
|
.trkpt.getCoordinates();
|
||||||
)
|
const end = statistics
|
||||||
.addTo(map_);
|
|
||||||
this.end
|
|
||||||
.setLngLat(
|
|
||||||
statistics
|
|
||||||
.getTrackPoint(slicedStatistics?.[2] ?? statistics.global.length - 1)!
|
.getTrackPoint(slicedStatistics?.[2] ?? statistics.global.length - 1)!
|
||||||
.trkpt.getCoordinates()
|
.trkpt.getCoordinates();
|
||||||
)
|
const data: GeoJSON.FeatureCollection = {
|
||||||
.addTo(map_);
|
type: 'FeatureCollection',
|
||||||
|
features: [
|
||||||
|
{
|
||||||
|
type: 'Feature',
|
||||||
|
geometry: {
|
||||||
|
type: 'Point',
|
||||||
|
coordinates: [start.lon, start.lat],
|
||||||
|
},
|
||||||
|
properties: {
|
||||||
|
icon: 'start-marker',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,9 +20,8 @@
|
|||||||
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 { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { customBasemapUpdate, isSelected, remove } from './utils';
|
import { remove } 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';
|
import { dndzone } from 'svelte-dnd-action';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -129,8 +128,8 @@
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
$customLayers[layerId] = layer;
|
|
||||||
addLayer(layerId);
|
addLayer(layerId);
|
||||||
|
$customLayers[layerId] = layer;
|
||||||
selectedLayerId = undefined;
|
selectedLayerId = undefined;
|
||||||
setDataFromSelectedLayer();
|
setDataFromSelectedLayer();
|
||||||
}
|
}
|
||||||
@@ -153,9 +152,7 @@
|
|||||||
return $tree;
|
return $tree;
|
||||||
});
|
});
|
||||||
|
|
||||||
if ($currentBasemap === layerId) {
|
if ($currentBasemap !== layerId) {
|
||||||
$customBasemapUpdate++;
|
|
||||||
} else {
|
|
||||||
$currentBasemap = layerId;
|
$currentBasemap = layerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,14 +168,6 @@
|
|||||||
return $tree;
|
return $tree;
|
||||||
});
|
});
|
||||||
|
|
||||||
if ($map && $currentOverlays && isSelected($currentOverlays, layerId)) {
|
|
||||||
try {
|
|
||||||
$map.removeImport(layerId);
|
|
||||||
} catch (e) {
|
|
||||||
// No reliable way to check if the map is ready to remove sources and layers
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
currentOverlays.update(($overlays) => {
|
currentOverlays.update(($overlays) => {
|
||||||
if (!$overlays.overlays.hasOwnProperty('custom')) {
|
if (!$overlays.overlays.hasOwnProperty('custom')) {
|
||||||
$overlays.overlays['custom'] = {};
|
$overlays.overlays['custom'] = {};
|
||||||
|
|||||||
@@ -167,11 +167,11 @@
|
|||||||
{#if isSelected($selectedOverlayTree, selectedOverlay)}
|
{#if isSelected($selectedOverlayTree, selectedOverlay)}
|
||||||
{#if $isLayerFromExtension(selectedOverlay)}
|
{#if $isLayerFromExtension(selectedOverlay)}
|
||||||
{$getLayerName(selectedOverlay)}
|
{$getLayerName(selectedOverlay)}
|
||||||
|
{:else if $customLayers.hasOwnProperty(selectedOverlay)}
|
||||||
|
{$customLayers[selectedOverlay].name}
|
||||||
{:else}
|
{:else}
|
||||||
{i18n._(`layers.label.${selectedOverlay}`)}
|
{i18n._(`layers.label.${selectedOverlay}`)}
|
||||||
{/if}
|
{/if}
|
||||||
{:else if $customLayers.hasOwnProperty(selectedOverlay)}
|
|
||||||
{$customLayers[selectedOverlay].name}
|
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
</Select.Trigger>
|
</Select.Trigger>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { db } from '$lib/db';
|
|||||||
import type { GeoJSONSource } from 'maplibre-gl';
|
import type { GeoJSONSource } from 'maplibre-gl';
|
||||||
import { ANCHOR_LAYER_KEY } from '../style';
|
import { ANCHOR_LAYER_KEY } from '../style';
|
||||||
import type { MapLayerEventManager } from '$lib/components/map/map-layer-event-manager';
|
import type { MapLayerEventManager } from '$lib/components/map/map-layer-event-manager';
|
||||||
|
import { loadSVGIcon } from '$lib/utils';
|
||||||
|
|
||||||
const { currentOverpassQueries } = settings;
|
const { currentOverpassQueries } = settings;
|
||||||
|
|
||||||
@@ -76,7 +77,14 @@ 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') as GeoJSONSource | undefined;
|
let source = this.map.getSource('overpass') as GeoJSONSource | undefined;
|
||||||
@@ -108,10 +116,6 @@ export class OverpassLayer {
|
|||||||
this.layerEventManager.on('mouseenter', 'overpass', this.onHoverBinded);
|
this.layerEventManager.on('mouseenter', 'overpass', this.onHoverBinded);
|
||||||
this.layerEventManager.on('click', 'overpass', this.onHoverBinded);
|
this.layerEventManager.on('click', 'overpass', this.onHoverBinded);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.map.setFilter('overpass', ['in', 'query', ...getCurrentQueries()], {
|
|
||||||
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
|
||||||
}
|
}
|
||||||
@@ -254,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>`
|
||||||
`);
|
);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,5 +76,3 @@ export function removeAll(node: LayerTreeType, ids: string[]) {
|
|||||||
});
|
});
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const customBasemapUpdate = writable(0);
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { fileStateCollection } from '$lib/logic/file-state';
|
||||||
import maplibregl from 'maplibre-gl';
|
import maplibregl from 'maplibre-gl';
|
||||||
|
|
||||||
type MapLayerMouseEventListener = (e: maplibregl.MapLayerMouseEvent) => void;
|
type MapLayerMouseEventListener = (e: maplibregl.MapLayerMouseEvent) => void;
|
||||||
@@ -141,7 +142,10 @@ export class MapLayerEventManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _handleMouseMove(e: maplibregl.MapMouseEvent) {
|
private _handleMouseMove(e: maplibregl.MapMouseEvent) {
|
||||||
const layerIds = Object.keys(this._listeners);
|
const layerIds = this._filterLayersContainingCoordinate(
|
||||||
|
Object.keys(this._listeners),
|
||||||
|
e.lngLat
|
||||||
|
);
|
||||||
const features =
|
const features =
|
||||||
layerIds.length > 0
|
layerIds.length > 0
|
||||||
? this._map.queryRenderedFeatures(e.point, { layers: layerIds })
|
? this._map.queryRenderedFeatures(e.point, { layers: layerIds })
|
||||||
@@ -224,8 +228,11 @@ export class MapLayerEventManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _handleTouchStart(e: maplibregl.MapTouchEvent) {
|
private _handleTouchStart(e: maplibregl.MapTouchEvent) {
|
||||||
const layerIds = Object.keys(this._listeners).filter(
|
const layerIds = this._filterLayersContainingCoordinate(
|
||||||
|
Object.keys(this._listeners).filter(
|
||||||
(layerId) => this._listeners[layerId].touchstarts.length > 0
|
(layerId) => this._listeners[layerId].touchstarts.length > 0
|
||||||
|
),
|
||||||
|
e.lngLat
|
||||||
);
|
);
|
||||||
if (layerIds.length === 0) return;
|
if (layerIds.length === 0) return;
|
||||||
const features = this._map.queryRenderedFeatures(e.points[0], { layers: layerIds });
|
const features = this._map.queryRenderedFeatures(e.points[0], { layers: layerIds });
|
||||||
@@ -250,4 +257,20 @@ export class MapLayerEventManager {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _filterLayersContainingCoordinate(
|
||||||
|
layerIds: string[],
|
||||||
|
lngLat: maplibregl.LngLat
|
||||||
|
): 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)?.inBBox(lngLat) ?? true;
|
||||||
|
} else {
|
||||||
|
return fileStateCollection.getStatistics(fileId)?.inWaypointBBox(lngLat) ?? true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
overlays,
|
overlays,
|
||||||
terrainSources,
|
terrainSources,
|
||||||
} from '$lib/assets/layers';
|
} from '$lib/assets/layers';
|
||||||
import { customBasemapUpdate, getLayers } from '$lib/components/map/layer-control/utils';
|
import { getLayers } from '$lib/components/map/layer-control/utils';
|
||||||
import { i18n } from '$lib/i18n.svelte';
|
import { i18n } from '$lib/i18n.svelte';
|
||||||
|
|
||||||
const { currentBasemap, currentOverlays, customLayers, opacities, terrainSource } = settings;
|
const { currentBasemap, currentOverlays, customLayers, opacities, terrainSource } = settings;
|
||||||
@@ -25,6 +25,7 @@ export const ANCHOR_LAYER_KEY = {
|
|||||||
tracks: 'tracks-end',
|
tracks: 'tracks-end',
|
||||||
directionMarkers: 'direction-markers-end',
|
directionMarkers: 'direction-markers-end',
|
||||||
distanceMarkers: 'distance-markers-end',
|
distanceMarkers: 'distance-markers-end',
|
||||||
|
startEndMarkers: 'start-end-markers-end',
|
||||||
interactions: 'interactions-end',
|
interactions: 'interactions-end',
|
||||||
overpass: 'overpass-end',
|
overpass: 'overpass-end',
|
||||||
waypoints: 'waypoints-end',
|
waypoints: 'waypoints-end',
|
||||||
@@ -51,10 +52,10 @@ export class StyleManager {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
currentBasemap.subscribe(() => this.updateBasemap());
|
currentBasemap.subscribe(() => this.updateBasemap());
|
||||||
customBasemapUpdate.subscribe(() => this.updateBasemap());
|
|
||||||
currentOverlays.subscribe(() => this.updateOverlays());
|
currentOverlays.subscribe(() => this.updateOverlays());
|
||||||
opacities.subscribe(() => this.updateOverlays());
|
opacities.subscribe(() => this.updateOverlays());
|
||||||
terrainSource.subscribe(() => this.updateTerrain());
|
terrainSource.subscribe(() => this.updateTerrain());
|
||||||
|
customLayers.subscribe(() => this.updateBasemap());
|
||||||
}
|
}
|
||||||
|
|
||||||
updateBasemap() {
|
updateBasemap() {
|
||||||
@@ -157,6 +158,9 @@ export class StyleManager {
|
|||||||
const terrain = this.getCurrentTerrain();
|
const terrain = this.getCurrentTerrain();
|
||||||
if (JSON.stringify(mapTerrain) !== JSON.stringify(terrain)) {
|
if (JSON.stringify(mapTerrain) !== JSON.stringify(terrain)) {
|
||||||
if (terrain.exaggeration > 0) {
|
if (terrain.exaggeration > 0) {
|
||||||
|
if (!map_.getSource(terrain.source)) {
|
||||||
|
map_.addSource(terrain.source, terrainSources[terrain.source]);
|
||||||
|
}
|
||||||
map_.setTerrain(terrain);
|
map_.setTerrain(terrain);
|
||||||
} else {
|
} else {
|
||||||
map_.setTerrain(null);
|
map_.setTerrain(null);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
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 {
|
||||||
@@ -167,7 +167,7 @@
|
|||||||
{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}`
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { mapCursor, MapCursorState } from '$lib/logic/map-cursor';
|
|||||||
import type { GeoJSONSource } from 'maplibre-gl';
|
import type { GeoJSONSource } from 'maplibre-gl';
|
||||||
import { ANCHOR_LAYER_KEY } from '$lib/components/map/style';
|
import { ANCHOR_LAYER_KEY } from '$lib/components/map/style';
|
||||||
import type { MapLayerEventManager } from '$lib/components/map/map-layer-event-manager';
|
import type { MapLayerEventManager } from '$lib/components/map/map-layer-event-manager';
|
||||||
|
import { loadSVGIcon } from '$lib/utils';
|
||||||
|
|
||||||
export class SplitControls {
|
export class SplitControls {
|
||||||
map: maplibregl.Map;
|
map: maplibregl.Map;
|
||||||
@@ -24,28 +25,16 @@ export class SplitControls {
|
|||||||
constructor(map: maplibregl.Map, layerEventManager: MapLayerEventManager) {
|
constructor(map: maplibregl.Map, layerEventManager: MapLayerEventManager) {
|
||||||
this.map = map;
|
this.map = map;
|
||||||
this.layerEventManager = layerEventManager;
|
this.layerEventManager = layerEventManager;
|
||||||
|
loadSVGIcon(
|
||||||
if (!this.map.hasImage('split-control')) {
|
this.map,
|
||||||
let icon = new Image(100, 100);
|
'split-control',
|
||||||
icon.onload = () => {
|
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40">
|
||||||
if (!this.map.hasImage('split-control')) {
|
|
||||||
this.map.addImage('split-control', 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="white" />
|
<circle cx="20" cy="20" r="20" fill="white" />
|
||||||
<g transform="translate(8 8)">
|
<g transform="translate(8 8)">
|
||||||
${Scissors.replace('stroke="currentColor"', 'stroke="black"')}
|
${Scissors.replace('stroke="currentColor"', 'stroke="black"')}
|
||||||
</g>
|
</g>
|
||||||
</svg>
|
</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)));
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ title: Files and statistics
|
|||||||
|
|
||||||
let gpxStatistics = writable(exampleGPXFile.getStatistics());
|
let gpxStatistics = writable(exampleGPXFile.getStatistics());
|
||||||
let slicedGPXStatistics = writable(undefined);
|
let slicedGPXStatistics = writable(undefined);
|
||||||
|
let hoveredPoint = writable(null);
|
||||||
let additionalDatasets = writable(['speed', 'atemp']);
|
let additionalDatasets = writable(['speed', 'atemp']);
|
||||||
let elevationFill = writable(undefined);
|
let elevationFill = writable(undefined);
|
||||||
</script>
|
</script>
|
||||||
@@ -84,6 +85,7 @@ You can also use the mouse wheel to zoom in and out on the elevation profile, an
|
|||||||
<ElevationProfile
|
<ElevationProfile
|
||||||
{gpxStatistics}
|
{gpxStatistics}
|
||||||
{slicedGPXStatistics}
|
{slicedGPXStatistics}
|
||||||
|
{hoveredPoint}
|
||||||
{additionalDatasets}
|
{additionalDatasets}
|
||||||
{elevationFill}
|
{elevationFill}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { type Database } from '$lib/db';
|
import { type Database } from '$lib/db';
|
||||||
import { liveQuery } from 'dexie';
|
import { liveQuery } from 'dexie';
|
||||||
import {
|
import {
|
||||||
|
basemaps,
|
||||||
defaultBasemap,
|
defaultBasemap,
|
||||||
defaultBasemapTree,
|
defaultBasemapTree,
|
||||||
defaultOpacities,
|
defaultOpacities,
|
||||||
@@ -9,7 +10,10 @@ import {
|
|||||||
defaultOverpassQueries,
|
defaultOverpassQueries,
|
||||||
defaultOverpassTree,
|
defaultOverpassTree,
|
||||||
defaultTerrainSource,
|
defaultTerrainSource,
|
||||||
|
overlays,
|
||||||
|
overpassQueryData,
|
||||||
type CustomLayer,
|
type CustomLayer,
|
||||||
|
type LayerTreeType,
|
||||||
} from '$lib/assets/layers';
|
} from '$lib/assets/layers';
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
import { get, writable, type Writable } from 'svelte/store';
|
import { get, writable, type Writable } from 'svelte/store';
|
||||||
@@ -19,10 +23,12 @@ export class Setting<V> {
|
|||||||
private _subscription: { unsubscribe: () => void } | null = null;
|
private _subscription: { unsubscribe: () => void } | null = null;
|
||||||
private _key: string;
|
private _key: string;
|
||||||
private _value: Writable<V>;
|
private _value: Writable<V>;
|
||||||
|
private _validator?: (value: V) => V;
|
||||||
|
|
||||||
constructor(key: string, initial: V) {
|
constructor(key: string, initial: V, validator?: (value: V) => V) {
|
||||||
this._key = key;
|
this._key = key;
|
||||||
this._value = writable(initial);
|
this._value = writable(initial);
|
||||||
|
this._validator = validator;
|
||||||
}
|
}
|
||||||
|
|
||||||
connectToDatabase(db: Database) {
|
connectToDatabase(db: Database) {
|
||||||
@@ -36,6 +42,9 @@ export class Setting<V> {
|
|||||||
this._value.set(value);
|
this._value.set(value);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (this._validator) {
|
||||||
|
value = this._validator(value);
|
||||||
|
}
|
||||||
this._value.set(value);
|
this._value.set(value);
|
||||||
}
|
}
|
||||||
first = false;
|
first = false;
|
||||||
@@ -73,11 +82,13 @@ export class SettingInitOnFirstRead<V> {
|
|||||||
private _key: string;
|
private _key: string;
|
||||||
private _value: Writable<V | undefined>;
|
private _value: Writable<V | undefined>;
|
||||||
private _initial: V;
|
private _initial: V;
|
||||||
|
private _validator?: (value: V) => V;
|
||||||
|
|
||||||
constructor(key: string, initial: V) {
|
constructor(key: string, initial: V, validator?: (value: V) => V) {
|
||||||
this._key = key;
|
this._key = key;
|
||||||
this._value = writable(undefined);
|
this._value = writable(undefined);
|
||||||
this._initial = initial;
|
this._initial = initial;
|
||||||
|
this._validator = validator;
|
||||||
}
|
}
|
||||||
|
|
||||||
connectToDatabase(db: Database) {
|
connectToDatabase(db: Database) {
|
||||||
@@ -93,6 +104,9 @@ export class SettingInitOnFirstRead<V> {
|
|||||||
this._value.set(value);
|
this._value.set(value);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (this._validator) {
|
||||||
|
value = this._validator(value);
|
||||||
|
}
|
||||||
this._value.set(value);
|
this._value.set(value);
|
||||||
}
|
}
|
||||||
first = false;
|
first = false;
|
||||||
@@ -128,37 +142,166 @@ export class SettingInitOnFirstRead<V> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getValueValidator<V>(allowed: V[], fallback: V) {
|
||||||
|
const dict = new Set<V>(allowed);
|
||||||
|
return (value: V) => (dict.has(value) ? value : fallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getArrayValidator<V>(allowed: V[]) {
|
||||||
|
const dict = new Set<V>(allowed);
|
||||||
|
return (value: V[]) => value.filter((v) => dict.has(v));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getLayerValidator(allowed: Record<string, any>, fallback: string) {
|
||||||
|
return (layer: string) =>
|
||||||
|
allowed.hasOwnProperty(layer) ||
|
||||||
|
layer.startsWith('custom-') ||
|
||||||
|
layer.startsWith('extension-')
|
||||||
|
? layer
|
||||||
|
: fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterLayerTree(t: LayerTreeType, allowed: Record<string, any>): LayerTreeType {
|
||||||
|
const filtered: LayerTreeType = {};
|
||||||
|
Object.entries(t).forEach(([key, value]) => {
|
||||||
|
if (typeof value === 'object') {
|
||||||
|
filtered[key] = filterLayerTree(value, allowed);
|
||||||
|
} else if (
|
||||||
|
allowed.hasOwnProperty(key) ||
|
||||||
|
key.startsWith('custom-') ||
|
||||||
|
key.startsWith('extension-')
|
||||||
|
) {
|
||||||
|
filtered[key] = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return filtered;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getLayerTreeValidator(allowed: Record<string, any>) {
|
||||||
|
return (value: LayerTreeType) => filterLayerTree(value, allowed);
|
||||||
|
}
|
||||||
|
|
||||||
|
type DistanceUnits = 'metric' | 'imperial' | 'nautical';
|
||||||
|
type VelocityUnits = 'speed' | 'pace';
|
||||||
|
type TemperatureUnits = 'celsius' | 'fahrenheit';
|
||||||
|
type AdditionalDataset = 'speed' | 'hr' | 'cad' | 'atemp' | 'power';
|
||||||
|
type ElevationFill = 'slope' | 'surface' | undefined;
|
||||||
|
type RoutingProfile =
|
||||||
|
| 'bike'
|
||||||
|
| 'racing_bike'
|
||||||
|
| 'gravel_bike'
|
||||||
|
| 'mountain_bike'
|
||||||
|
| 'foot'
|
||||||
|
| 'motorcycle'
|
||||||
|
| 'water'
|
||||||
|
| 'railway';
|
||||||
|
type TerrainSource = 'maptiler-dem' | 'mapterhorn';
|
||||||
|
type StreetViewSource = 'mapillary' | 'google';
|
||||||
|
|
||||||
export const settings = {
|
export const settings = {
|
||||||
distanceUnits: new Setting<'metric' | 'imperial' | 'nautical'>('distanceUnits', 'metric'),
|
distanceUnits: new Setting<DistanceUnits>(
|
||||||
velocityUnits: new Setting<'speed' | 'pace'>('velocityUnits', 'speed'),
|
'distanceUnits',
|
||||||
temperatureUnits: new Setting<'celsius' | 'fahrenheit'>('temperatureUnits', 'celsius'),
|
'metric',
|
||||||
|
getValueValidator<DistanceUnits>(['metric', 'imperial', 'nautical'], 'metric')
|
||||||
|
),
|
||||||
|
velocityUnits: new Setting<VelocityUnits>(
|
||||||
|
'velocityUnits',
|
||||||
|
'speed',
|
||||||
|
getValueValidator<VelocityUnits>(['speed', 'pace'], 'speed')
|
||||||
|
),
|
||||||
|
temperatureUnits: new Setting<TemperatureUnits>(
|
||||||
|
'temperatureUnits',
|
||||||
|
'celsius',
|
||||||
|
getValueValidator<TemperatureUnits>(['celsius', 'fahrenheit'], 'celsius')
|
||||||
|
),
|
||||||
elevationProfile: new Setting<boolean>('elevationProfile', true),
|
elevationProfile: new Setting<boolean>('elevationProfile', true),
|
||||||
additionalDatasets: new Setting<string[]>('additionalDatasets', []),
|
additionalDatasets: new Setting<AdditionalDataset[]>(
|
||||||
elevationFill: new Setting<'slope' | 'surface' | undefined>('elevationFill', undefined),
|
'additionalDatasets',
|
||||||
|
[],
|
||||||
|
getArrayValidator<AdditionalDataset>(['speed', 'hr', 'cad', 'atemp', 'power'])
|
||||||
|
),
|
||||||
|
elevationFill: new Setting<ElevationFill>(
|
||||||
|
'elevationFill',
|
||||||
|
undefined,
|
||||||
|
getValueValidator(['slope', 'surface', undefined], undefined)
|
||||||
|
),
|
||||||
treeFileView: new Setting<boolean>('fileView', false),
|
treeFileView: new Setting<boolean>('fileView', false),
|
||||||
minimizeRoutingMenu: new Setting('minimizeRoutingMenu', false),
|
minimizeRoutingMenu: new Setting('minimizeRoutingMenu', false),
|
||||||
routing: new Setting('routing', true),
|
routing: new Setting('routing', true),
|
||||||
routingProfile: new Setting('routingProfile', 'bike'),
|
routingProfile: new Setting<RoutingProfile>(
|
||||||
|
'routingProfile',
|
||||||
|
'bike',
|
||||||
|
getValueValidator<RoutingProfile>(
|
||||||
|
[
|
||||||
|
'bike',
|
||||||
|
'racing_bike',
|
||||||
|
'gravel_bike',
|
||||||
|
'mountain_bike',
|
||||||
|
'foot',
|
||||||
|
'motorcycle',
|
||||||
|
'water',
|
||||||
|
'railway',
|
||||||
|
],
|
||||||
|
'bike'
|
||||||
|
)
|
||||||
|
),
|
||||||
privateRoads: new Setting('privateRoads', false),
|
privateRoads: new Setting('privateRoads', false),
|
||||||
currentBasemap: new Setting('currentBasemap', defaultBasemap),
|
currentBasemap: new Setting(
|
||||||
previousBasemap: new Setting('previousBasemap', defaultBasemap),
|
'currentBasemap',
|
||||||
selectedBasemapTree: new Setting('selectedBasemapTree', defaultBasemapTree),
|
defaultBasemap,
|
||||||
currentOverlays: new SettingInitOnFirstRead('currentOverlays', defaultOverlays),
|
getLayerValidator(basemaps, defaultBasemap)
|
||||||
previousOverlays: new Setting('previousOverlays', defaultOverlays),
|
),
|
||||||
selectedOverlayTree: new Setting('selectedOverlayTree', defaultOverlayTree),
|
previousBasemap: new Setting(
|
||||||
|
'previousBasemap',
|
||||||
|
defaultBasemap,
|
||||||
|
getLayerValidator(Object.keys(basemaps), defaultBasemap)
|
||||||
|
),
|
||||||
|
selectedBasemapTree: new Setting(
|
||||||
|
'selectedBasemapTree',
|
||||||
|
defaultBasemapTree,
|
||||||
|
getLayerTreeValidator(basemaps)
|
||||||
|
),
|
||||||
|
currentOverlays: new SettingInitOnFirstRead(
|
||||||
|
'currentOverlays',
|
||||||
|
defaultOverlays,
|
||||||
|
getLayerTreeValidator(overlays)
|
||||||
|
),
|
||||||
|
previousOverlays: new Setting(
|
||||||
|
'previousOverlays',
|
||||||
|
defaultOverlays,
|
||||||
|
getLayerTreeValidator(overlays)
|
||||||
|
),
|
||||||
|
selectedOverlayTree: new Setting(
|
||||||
|
'selectedOverlayTree',
|
||||||
|
defaultOverlayTree,
|
||||||
|
getLayerTreeValidator(overlays)
|
||||||
|
),
|
||||||
currentOverpassQueries: new SettingInitOnFirstRead(
|
currentOverpassQueries: new SettingInitOnFirstRead(
|
||||||
'currentOverpassQueries',
|
'currentOverpassQueries',
|
||||||
defaultOverpassQueries
|
defaultOverpassQueries,
|
||||||
|
getLayerTreeValidator(overpassQueryData)
|
||||||
|
),
|
||||||
|
selectedOverpassTree: new Setting(
|
||||||
|
'selectedOverpassTree',
|
||||||
|
defaultOverpassTree,
|
||||||
|
getLayerTreeValidator(overpassQueryData)
|
||||||
),
|
),
|
||||||
selectedOverpassTree: new Setting('selectedOverpassTree', defaultOverpassTree),
|
|
||||||
opacities: new Setting('opacities', defaultOpacities),
|
opacities: new Setting('opacities', defaultOpacities),
|
||||||
customLayers: new Setting<Record<string, CustomLayer>>('customLayers', {}),
|
customLayers: new Setting<Record<string, CustomLayer>>('customLayers', {}),
|
||||||
customBasemapOrder: new Setting<string[]>('customBasemapOrder', []),
|
customBasemapOrder: new Setting<string[]>('customBasemapOrder', []),
|
||||||
customOverlayOrder: new Setting<string[]>('customOverlayOrder', []),
|
customOverlayOrder: new Setting<string[]>('customOverlayOrder', []),
|
||||||
terrainSource: new Setting('terrainSource', defaultTerrainSource),
|
terrainSource: new Setting<TerrainSource>(
|
||||||
|
'terrainSource',
|
||||||
|
defaultTerrainSource,
|
||||||
|
getValueValidator(['maptiler-dem', 'mapterhorn'], defaultTerrainSource)
|
||||||
|
),
|
||||||
directionMarkers: new Setting('directionMarkers', false),
|
directionMarkers: new Setting('directionMarkers', false),
|
||||||
distanceMarkers: new Setting('distanceMarkers', false),
|
distanceMarkers: new Setting('distanceMarkers', false),
|
||||||
streetViewSource: new Setting('streetViewSource', 'mapillary'),
|
streetViewSource: new Setting<StreetViewSource>(
|
||||||
|
'streetViewSource',
|
||||||
|
'mapillary',
|
||||||
|
getValueValidator<StreetViewSource>(['mapillary', 'google'], 'mapillary')
|
||||||
|
),
|
||||||
fileOrder: new Setting<string[]>('fileOrder', []),
|
fileOrder: new Setting<string[]>('fileOrder', []),
|
||||||
defaultOpacity: new Setting('defaultOpacity', 0.7),
|
defaultOpacity: new Setting('defaultOpacity', 0.7),
|
||||||
defaultWidth: new Setting('defaultWidth', browser && window.innerWidth < 600 ? 8 : 5),
|
defaultWidth: new Setting('defaultWidth', browser && window.innerWidth < 600 ? 8 : 5),
|
||||||
|
|||||||
@@ -1,18 +1,24 @@
|
|||||||
import { ListItem, ListLevel } from '$lib/components/file-list/file-list';
|
import { ListItem, ListLevel } from '$lib/components/file-list/file-list';
|
||||||
import { GPXFile, GPXStatistics, GPXStatisticsGroup, type Track } from 'gpx';
|
import { GPXFile, GPXStatistics, GPXStatisticsGroup, type Track } from 'gpx';
|
||||||
|
import maplibregl from 'maplibre-gl';
|
||||||
|
|
||||||
export class GPXStatisticsTree {
|
export class GPXStatisticsTree {
|
||||||
level: ListLevel;
|
level: ListLevel;
|
||||||
statistics: {
|
statistics: {
|
||||||
[key: string]: GPXStatisticsTree | GPXStatistics;
|
[key: string]: GPXStatisticsTree | GPXStatistics;
|
||||||
} = {};
|
} = {};
|
||||||
|
wptBounds: maplibregl.LngLatBounds;
|
||||||
|
|
||||||
constructor(element: GPXFile | Track) {
|
constructor(element: GPXFile | Track) {
|
||||||
|
this.wptBounds = new maplibregl.LngLatBounds();
|
||||||
if (element instanceof GPXFile) {
|
if (element instanceof GPXFile) {
|
||||||
this.level = ListLevel.FILE;
|
this.level = ListLevel.FILE;
|
||||||
element.children.forEach((child, index) => {
|
element.children.forEach((child, index) => {
|
||||||
this.statistics[index] = new GPXStatisticsTree(child);
|
this.statistics[index] = new GPXStatisticsTree(child);
|
||||||
});
|
});
|
||||||
|
element.wpt.forEach((wpt) => {
|
||||||
|
this.wptBounds.extend(wpt.getCoordinates());
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.level = ListLevel.TRACK;
|
this.level = ListLevel.TRACK;
|
||||||
element.children.forEach((child, index) => {
|
element.children.forEach((child, index) => {
|
||||||
@@ -42,5 +48,27 @@ export class GPXStatisticsTree {
|
|||||||
}
|
}
|
||||||
return statistics;
|
return statistics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inBBox(coordinates: { lat: number; lng: number }): boolean {
|
||||||
|
for (let key in this.statistics) {
|
||||||
|
const stats = this.statistics[key];
|
||||||
|
if (stats instanceof GPXStatistics) {
|
||||||
|
const bbox = new maplibregl.LngLatBounds(
|
||||||
|
stats.global.bounds.southWest,
|
||||||
|
stats.global.bounds.northEast
|
||||||
|
);
|
||||||
|
if (!bbox.isEmpty() && bbox.contains(coordinates)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (stats.inBBox(coordinates)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
inWaypointBBox(coordinates: { lat: number; lng: number }): boolean {
|
||||||
|
return !this.wptBounds.isEmpty() && this.wptBounds.contains(coordinates);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
export type GPXFileWithStatistics = { file: GPXFile; statistics: GPXStatisticsTree };
|
export type GPXFileWithStatistics = { file: GPXFile; statistics: GPXStatisticsTree };
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { selection } from '$lib/logic/selection';
|
import { selection } from '$lib/logic/selection';
|
||||||
import { GPXGlobalStatistics, GPXStatisticsGroup } from 'gpx';
|
import { GPXGlobalStatistics, GPXStatisticsGroup, type Coordinates } from 'gpx';
|
||||||
import { fileStateCollection, GPXFileState } from '$lib/logic/file-state';
|
import { fileStateCollection, GPXFileState } from '$lib/logic/file-state';
|
||||||
import {
|
import {
|
||||||
ListFileItem,
|
ListFileItem,
|
||||||
@@ -82,6 +82,8 @@ export const gpxStatistics = new SelectedGPXStatistics();
|
|||||||
export const slicedGPXStatistics: Writable<[GPXGlobalStatistics, number, number] | undefined> =
|
export const slicedGPXStatistics: Writable<[GPXGlobalStatistics, number, number] | undefined> =
|
||||||
writable(undefined);
|
writable(undefined);
|
||||||
|
|
||||||
|
export const hoveredPoint: Writable<Coordinates | null> = writable(null);
|
||||||
|
|
||||||
gpxStatistics.subscribe(() => {
|
gpxStatistics.subscribe(() => {
|
||||||
slicedGPXStatistics.set(undefined);
|
slicedGPXStatistics.set(undefined);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -197,6 +197,18 @@ export function getElevation(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function loadSVGIcon(map: maplibregl.Map, id: string, svg: string) {
|
||||||
|
if (!map.hasImage(id)) {
|
||||||
|
let icon = new Image(100, 100);
|
||||||
|
icon.onload = () => {
|
||||||
|
if (!map.hasImage(id)) {
|
||||||
|
map.addImage(id, icon);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
icon.src = 'data:image/svg+xml,' + encodeURIComponent(svg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function isMac() {
|
export function isMac() {
|
||||||
return navigator.userAgent.toUpperCase().indexOf('MAC') >= 0;
|
return navigator.userAgent.toUpperCase().indexOf('MAC') >= 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
let gpxStatistics = writable(exampleGPXFile.getStatistics());
|
let gpxStatistics = writable(exampleGPXFile.getStatistics());
|
||||||
let slicedGPXStatistics = writable(undefined);
|
let slicedGPXStatistics = writable(undefined);
|
||||||
|
let hoveredPoint = writable(null);
|
||||||
let additionalDatasets = writable(['speed', 'atemp']);
|
let additionalDatasets = writable(['speed', 'atemp']);
|
||||||
let elevationFill = writable(undefined);
|
let elevationFill = writable(undefined);
|
||||||
|
|
||||||
@@ -197,6 +198,7 @@
|
|||||||
<ElevationProfile
|
<ElevationProfile
|
||||||
{gpxStatistics}
|
{gpxStatistics}
|
||||||
{slicedGPXStatistics}
|
{slicedGPXStatistics}
|
||||||
|
{hoveredPoint}
|
||||||
{additionalDatasets}
|
{additionalDatasets}
|
||||||
{elevationFill}
|
{elevationFill}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
import { loadFiles } from '$lib/logic/file-actions';
|
import { loadFiles } from '$lib/logic/file-actions';
|
||||||
import { onDestroy, onMount } from 'svelte';
|
import { onDestroy, onMount } from 'svelte';
|
||||||
import { page } from '$app/state';
|
import { page } from '$app/state';
|
||||||
import { gpxStatistics, slicedGPXStatistics } from '$lib/logic/statistics';
|
import { gpxStatistics, hoveredPoint, slicedGPXStatistics } from '$lib/logic/statistics';
|
||||||
import { getURLForGoogleDriveFile } from '$lib/components/embedding/embedding';
|
import { getURLForGoogleDriveFile } from '$lib/components/embedding/embedding';
|
||||||
import { db } from '$lib/db';
|
import { db } from '$lib/db';
|
||||||
import { fileStateCollection } from '$lib/logic/file-state';
|
import { fileStateCollection } from '$lib/logic/file-state';
|
||||||
@@ -140,6 +140,7 @@
|
|||||||
<ElevationProfile
|
<ElevationProfile
|
||||||
{gpxStatistics}
|
{gpxStatistics}
|
||||||
{slicedGPXStatistics}
|
{slicedGPXStatistics}
|
||||||
|
{hoveredPoint}
|
||||||
{additionalDatasets}
|
{additionalDatasets}
|
||||||
{elevationFill}
|
{elevationFill}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user