mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-09-01 08:12:32 +00:00
create file when routing with no selection
This commit is contained in:
@@ -20,8 +20,8 @@
|
||||
SquareArrowOutDownRight
|
||||
} from 'lucide-svelte';
|
||||
|
||||
import { map, routingControls } from '$lib/stores';
|
||||
import { dbUtils, settings } from '$lib/db';
|
||||
import { map, newGPXFile, routingControls, selectFileWhenLoaded } from '$lib/stores';
|
||||
import { dbUtils, getFileIds, settings } from '$lib/db';
|
||||
import { brouterProfiles, routingProfileSelectItem } from './Routing';
|
||||
|
||||
import { _ } from 'svelte-i18n';
|
||||
@@ -33,6 +33,9 @@
|
||||
import { selection } from '$lib/components/file-list/Selection';
|
||||
import { ListRootItem, type ListItem } from '$lib/components/file-list/FileList';
|
||||
import { flyAndScale } from '$lib/utils';
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
import { TrackPoint } from 'gpx';
|
||||
import { produce } from 'immer';
|
||||
|
||||
export let popup: mapboxgl.Popup;
|
||||
export let popupElement: HTMLElement;
|
||||
@@ -64,6 +67,33 @@
|
||||
}
|
||||
|
||||
$: validSelection = $selection.hasAnyChildren(new ListRootItem(), true, ['waypoints']);
|
||||
|
||||
function createFileWithPoint(e: any) {
|
||||
if ($selection.size === 0) {
|
||||
let file = newGPXFile();
|
||||
file = file.replaceTrackPoints(0, 0, 0, 0, [
|
||||
new TrackPoint({
|
||||
attributes: {
|
||||
lat: e.lngLat.lat,
|
||||
lon: e.lngLat.lng
|
||||
}
|
||||
})
|
||||
]);
|
||||
file = produce(file, (draft) => {
|
||||
draft._data.id = getFileIds(1)[0];
|
||||
});
|
||||
dbUtils.add(file);
|
||||
selectFileWhenLoaded(file._data.id);
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
$map?.on('click', createFileWithPoint);
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
$map?.off('click', createFileWithPoint);
|
||||
});
|
||||
</script>
|
||||
|
||||
{#if $minimizeRoutingMenu}
|
||||
|
@@ -381,7 +381,9 @@ export function getFileIds(n: number) {
|
||||
// Helper functions for file operations
|
||||
export const dbUtils = {
|
||||
add: (file: GPXFile) => {
|
||||
file._data.id = getFileIds(1)[0];
|
||||
if (file._data.id === undefined) {
|
||||
file._data.id = getFileIds(1)[0];
|
||||
}
|
||||
return applyGlobal((draft) => {
|
||||
draft.set(file._data.id, freeze(file));
|
||||
});
|
||||
|
@@ -193,7 +193,7 @@ export async function loadFile(file: File): Promise<GPXFile | null> {
|
||||
return result;
|
||||
}
|
||||
|
||||
function selectFileWhenLoaded(fileId: string) {
|
||||
export function selectFileWhenLoaded(fileId: string) {
|
||||
const unsubscribe = fileObservers.subscribe((files) => {
|
||||
if (files.has(fileId)) {
|
||||
tick().then(() => {
|
||||
|
Reference in New Issue
Block a user