mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-09-02 00:32:33 +00:00
dexie progress
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { Tool, filestore } from '$lib/stores';
|
||||
import { Tool } from '$lib/stores';
|
||||
import { dbUtils } from '$lib/db';
|
||||
import Routing from '$lib/components/toolbar/tools/routing/Routing.svelte';
|
||||
import Waypoint from '$lib/components/toolbar/tools/waypoint/Waypoint.svelte';
|
||||
import ToolbarItem from './ToolbarItem.svelte';
|
||||
@@ -34,7 +35,7 @@
|
||||
</ToolbarItem>
|
||||
<ToolbarItem
|
||||
tool={Tool.REVERSE}
|
||||
on:click={() => filestore.applyToSelectedFiles((file) => file.reverse())}
|
||||
on:click={() => dbUtils.applyToSelectedFiles((file) => file.reverse())}
|
||||
>
|
||||
<ArrowRightLeft slot="icon" size="18" />
|
||||
<span slot="tooltip">{$_('toolbar.reverse_tooltip')}</span>
|
||||
|
@@ -6,7 +6,7 @@
|
||||
import * as Alert from '$lib/components/ui/alert';
|
||||
import { CircleHelp } from 'lucide-svelte';
|
||||
|
||||
import { filestore, map, selectedFiles, Tool } from '$lib/stores';
|
||||
import { map, selectedFiles, Tool } from '$lib/stores';
|
||||
import { brouterProfiles, privateRoads, routing, routingProfile } from './Routing';
|
||||
|
||||
import { _ } from 'svelte-i18n';
|
||||
@@ -15,6 +15,7 @@
|
||||
import RoutingControlPopup from './RoutingControlPopup.svelte';
|
||||
import { onMount } from 'svelte';
|
||||
import mapboxgl from 'mapbox-gl';
|
||||
import { fileObservers } from '$lib/db';
|
||||
|
||||
let routingControls: Map<string, RoutingControls> = new Map();
|
||||
let popupElement: HTMLElement;
|
||||
@@ -22,10 +23,10 @@
|
||||
let selectedId: string | null = null;
|
||||
let active = false;
|
||||
|
||||
$: if ($map && $filestore) {
|
||||
$: if ($map) {
|
||||
// remove controls for deleted files
|
||||
routingControls.forEach((controls, fileId) => {
|
||||
if (!get(filestore).find((file) => file._data.id === fileId)) {
|
||||
if (!$fileObservers.has(fileId)) {
|
||||
controls.remove();
|
||||
routingControls.delete(fileId);
|
||||
|
||||
@@ -56,11 +57,11 @@
|
||||
|
||||
$: if ($map && selectedId) {
|
||||
if (!routingControls.has(selectedId)) {
|
||||
let selectedFileStore = filestore.getFileStore(selectedId);
|
||||
if (selectedFileStore) {
|
||||
let selectedFileObserver = get(fileObservers).get(selectedId);
|
||||
if (selectedFileObserver) {
|
||||
routingControls.set(
|
||||
selectedId,
|
||||
new RoutingControls(get(map), selectedFileStore, popup, popupElement)
|
||||
new RoutingControls(get(map), selectedFileObserver, popup, popupElement)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
@@ -7,7 +7,7 @@ import { route } from "./Routing";
|
||||
import { toast } from "svelte-sonner";
|
||||
|
||||
import { _ } from "svelte-i18n";
|
||||
import { filestore } from "$lib/stores";
|
||||
import { dbUtils } from "$lib/db";
|
||||
|
||||
export class RoutingControls {
|
||||
map: mapboxgl.Map;
|
||||
@@ -290,17 +290,17 @@ export class RoutingControls {
|
||||
let [previousAnchor, nextAnchor] = this.getNeighbouringAnchors(anchor);
|
||||
|
||||
if (previousAnchor === null && nextAnchor === null) { // Only one point, remove it
|
||||
filestore.applyToFile(get(this.file)._data.id, (file) => {
|
||||
dbUtils.applyToFile(get(this.file)._data.id, (file) => {
|
||||
let segment = file.getSegments()[anchor.segmentIndex];
|
||||
segment.replace(0, 0, []);
|
||||
});
|
||||
} else if (previousAnchor === null) { // First point, remove trackpoints until nextAnchor
|
||||
filestore.applyToFile(get(this.file)._data.id, (file) => {
|
||||
dbUtils.applyToFile(get(this.file)._data.id, (file) => {
|
||||
let segment = file.getSegments()[anchor.segmentIndex];
|
||||
segment.replace(0, nextAnchor.point._data.index - 1, []);
|
||||
});
|
||||
} else if (nextAnchor === null) { // Last point, remove trackpoints from previousAnchor
|
||||
filestore.applyToFile(get(this.file)._data.id, (file) => {
|
||||
dbUtils.applyToFile(get(this.file)._data.id, (file) => {
|
||||
let segment = file.getSegments()[anchor.segmentIndex];
|
||||
segment.replace(previousAnchor.point._data.index + 1, segment.trkpt.length - 1, []);
|
||||
});
|
||||
@@ -323,7 +323,7 @@ export class RoutingControls {
|
||||
|
||||
if (!lastAnchor) {
|
||||
// TODO, create segment if it does not exist
|
||||
filestore.applyToFile(get(this.file)._data.id, (file) => {
|
||||
dbUtils.applyToFile(get(this.file)._data.id, (file) => {
|
||||
let segment = file.getSegments()[0];
|
||||
segment.replace(0, 0, [newPoint]);
|
||||
});
|
||||
@@ -365,7 +365,7 @@ export class RoutingControls {
|
||||
let segment = anchors[0].segment;
|
||||
|
||||
if (anchors.length === 1) { // Only one anchor, update the point in the segment
|
||||
filestore.applyToFile(get(this.file)._data.id, (file) => {
|
||||
dbUtils.applyToFile(get(this.file)._data.id, (file) => {
|
||||
let segment = file.getSegments()[anchors[0].segmentIndex];
|
||||
segment.replace(0, 0, [new TrackPoint({
|
||||
attributes: targetCoordinates[0],
|
||||
@@ -425,7 +425,7 @@ export class RoutingControls {
|
||||
anchor.point._data.zoom = 0; // Make these anchors permanent
|
||||
});
|
||||
|
||||
filestore.applyToFile(get(this.file)._data.id, (file) => {
|
||||
dbUtils.applyToFile(get(this.file)._data.id, (file) => {
|
||||
let segment = file.getSegments()[anchors[0].segmentIndex];
|
||||
segment.replace(start, end, response);
|
||||
});
|
||||
|
Reference in New Issue
Block a user