mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-09-02 08:42:31 +00:00
do not compute stats on draft object
This commit is contained in:
@@ -309,14 +309,8 @@ export class TrackSegment extends GPXTreeLeaf {
|
|||||||
if (segment) {
|
if (segment) {
|
||||||
if (segment instanceof TrackSegment) {
|
if (segment instanceof TrackSegment) {
|
||||||
this.trkpt = segment.trkpt;
|
this.trkpt = segment.trkpt;
|
||||||
this.statistics = segment.statistics;
|
|
||||||
this.trkptStatistics = segment.trkptStatistics;
|
|
||||||
} else {
|
} else {
|
||||||
this.trkpt = segment.trkpt.map((point) => new TrackPoint(point));
|
this.trkpt = segment.trkpt.map((point) => new TrackPoint(point));
|
||||||
if (segment.hasOwnProperty('statistics') && segment.hasOwnProperty('trkptStatistics')) {
|
|
||||||
this.statistics = segment.statistics;
|
|
||||||
this.trkptStatistics = segment.trkptStatistics;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (segment.hasOwnProperty('_data')) {
|
if (segment.hasOwnProperty('_data')) {
|
||||||
this._data = cloneJSON(segment._data);
|
this._data = cloneJSON(segment._data);
|
||||||
@@ -325,9 +319,7 @@ export class TrackSegment extends GPXTreeLeaf {
|
|||||||
this.trkpt = [];
|
this.trkpt = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.statistics) {
|
this._computeStatistics();
|
||||||
this._computeStatistics();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_computeStatistics(): void {
|
_computeStatistics(): void {
|
||||||
@@ -431,12 +423,10 @@ export class TrackSegment extends GPXTreeLeaf {
|
|||||||
|
|
||||||
append(points: TrackPoint[]): void {
|
append(points: TrackPoint[]): void {
|
||||||
this.trkpt = this.trkpt.concat(points);
|
this.trkpt = this.trkpt.concat(points);
|
||||||
this._computeStatistics();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
replace(start: number, end: number, points: TrackPoint[]): void {
|
replace(start: number, end: number, points: TrackPoint[]): void {
|
||||||
this.trkpt.splice(start, end - start + 1, ...points);
|
this.trkpt.splice(start, end - start + 1, ...points);
|
||||||
this._computeStatistics();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reverse(originalNextTimestamp: Date | undefined, newPreviousTimestamp: Date | undefined): void {
|
reverse(originalNextTimestamp: Date | undefined, newPreviousTimestamp: Date | undefined): void {
|
||||||
@@ -456,7 +446,6 @@ export class TrackSegment extends GPXTreeLeaf {
|
|||||||
} else {
|
} else {
|
||||||
this.trkpt.reverse();
|
this.trkpt.reverse();
|
||||||
}
|
}
|
||||||
this._computeStatistics();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getStartTimestamp(): Date {
|
getStartTimestamp(): Date {
|
||||||
|
@@ -10,9 +10,8 @@
|
|||||||
|
|
||||||
import { _ } from 'svelte-i18n';
|
import { _ } from 'svelte-i18n';
|
||||||
import type { GPXFile } from 'gpx';
|
import type { GPXFile } from 'gpx';
|
||||||
import type { FreezedObject } from 'structurajs';
|
|
||||||
|
|
||||||
export let file: Readable<FreezedObject<GPXFile> | undefined>;
|
export let file: Readable<GPXFile | undefined>;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||||
|
@@ -40,7 +40,7 @@ function decrementColor(color: string) {
|
|||||||
export class GPXLayer {
|
export class GPXLayer {
|
||||||
map: mapboxgl.Map;
|
map: mapboxgl.Map;
|
||||||
fileId: string;
|
fileId: string;
|
||||||
file: Readable<FreezedObject<GPXFile> | undefined>;
|
file: Readable<GPXFile | undefined>;
|
||||||
layerColor: string;
|
layerColor: string;
|
||||||
popup: mapboxgl.Popup;
|
popup: mapboxgl.Popup;
|
||||||
popupElement: HTMLElement;
|
popupElement: HTMLElement;
|
||||||
@@ -50,7 +50,7 @@ export class GPXLayer {
|
|||||||
updateBinded: () => void = this.update.bind(this);
|
updateBinded: () => void = this.update.bind(this);
|
||||||
selectOnClickBinded: (e: any) => void = this.selectOnClick.bind(this);
|
selectOnClickBinded: (e: any) => void = this.selectOnClick.bind(this);
|
||||||
|
|
||||||
constructor(map: mapboxgl.Map, fileId: string, file: Readable<FreezedObject<GPXFile> | undefined>, popup: mapboxgl.Popup, popupElement: HTMLElement) {
|
constructor(map: mapboxgl.Map, fileId: string, file: Readable<GPXFile | undefined>, popup: mapboxgl.Popup, popupElement: HTMLElement) {
|
||||||
this.map = map;
|
this.map = map;
|
||||||
this.fileId = fileId;
|
this.fileId = fileId;
|
||||||
this.file = file
|
this.file = file
|
||||||
|
@@ -8,12 +8,11 @@ import { toast } from "svelte-sonner";
|
|||||||
|
|
||||||
import { _ } from "svelte-i18n";
|
import { _ } from "svelte-i18n";
|
||||||
import { dbUtils } from "$lib/db";
|
import { dbUtils } from "$lib/db";
|
||||||
import type { FreezedObject } from "structurajs";
|
|
||||||
|
|
||||||
export class RoutingControls {
|
export class RoutingControls {
|
||||||
map: mapboxgl.Map;
|
map: mapboxgl.Map;
|
||||||
fileId: string = '';
|
fileId: string = '';
|
||||||
file: Readable<FreezedObject<GPXFile> | undefined>;
|
file: Readable<GPXFile | undefined>;
|
||||||
anchors: AnchorWithMarker[] = [];
|
anchors: AnchorWithMarker[] = [];
|
||||||
shownAnchors: AnchorWithMarker[] = [];
|
shownAnchors: AnchorWithMarker[] = [];
|
||||||
popup: mapboxgl.Popup;
|
popup: mapboxgl.Popup;
|
||||||
@@ -26,7 +25,7 @@ export class RoutingControls {
|
|||||||
updateTemporaryAnchorBinded: (e: any) => void = this.updateTemporaryAnchor.bind(this);
|
updateTemporaryAnchorBinded: (e: any) => void = this.updateTemporaryAnchor.bind(this);
|
||||||
appendAnchorBinded: (e: mapboxgl.MapMouseEvent) => void = this.appendAnchor.bind(this);
|
appendAnchorBinded: (e: mapboxgl.MapMouseEvent) => void = this.appendAnchor.bind(this);
|
||||||
|
|
||||||
constructor(map: mapboxgl.Map, fileId: string, file: Writable<GPXFile>, popup: mapboxgl.Popup, popupElement: HTMLElement) {
|
constructor(map: mapboxgl.Map, fileId: string, file: Readable<GPXFile | undefined>, popup: mapboxgl.Popup, popupElement: HTMLElement) {
|
||||||
this.map = map;
|
this.map = map;
|
||||||
this.fileId = fileId;
|
this.fileId = fileId;
|
||||||
this.file = file;
|
this.file = file;
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import Dexie, { liveQuery } from 'dexie';
|
import Dexie, { liveQuery } from 'dexie';
|
||||||
import { GPXFile } from 'gpx';
|
import { GPXFile } from 'gpx';
|
||||||
import { type FreezedObject, type Patch, produceWithPatches, applyPatches, freeze } from 'structurajs';
|
import { type FreezedObject, type Patch, produceWithPatches, applyPatches } from 'structurajs';
|
||||||
import { writable, get, derived, type Readable, type Writable } from 'svelte/store';
|
import { writable, get, derived, type Readable, type Writable } from 'svelte/store';
|
||||||
import { fileOrder, selectedFiles } from './stores';
|
import { fileOrder, selectedFiles } from './stores';
|
||||||
|
|
||||||
@@ -27,19 +27,17 @@ class Database extends Dexie {
|
|||||||
|
|
||||||
const db = new Database();
|
const db = new Database();
|
||||||
|
|
||||||
function dexieFileStore(querier: () => FreezedObject<GPXFile> | undefined | Promise<FreezedObject<GPXFile> | undefined>): Writable<FreezedObject<GPXFile>> {
|
function dexieFileStore(querier: () => FreezedObject<GPXFile> | undefined | Promise<FreezedObject<GPXFile> | undefined>): Readable<GPXFile> {
|
||||||
let store = writable<FreezedObject<GPXFile>>(undefined);
|
let store = writable<GPXFile>(undefined);
|
||||||
liveQuery(querier).subscribe(value => {
|
liveQuery(querier).subscribe(value => {
|
||||||
if (value !== undefined) {
|
if (value !== undefined) {
|
||||||
let gpx = freeze(new GPXFile(value));
|
let gpx = new GPXFile(value);
|
||||||
fileState.set(gpx._data.id, gpx);
|
fileState.set(gpx._data.id, gpx);
|
||||||
store.set(gpx);
|
store.set(gpx);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
subscribe: store.subscribe,
|
subscribe: store.subscribe
|
||||||
update: store.update,
|
|
||||||
set: store.set
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,8 +83,8 @@ function commitFileStateChange(newFileState: ReadonlyMap<string, FreezedObject<G
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fileObservers: Writable<Map<string, Writable<FreezedObject<GPXFile> | undefined>>> = writable(new Map());
|
export const fileObservers: Writable<Map<string, Readable<GPXFile | undefined>>> = writable(new Map());
|
||||||
const fileState: Map<string, FreezedObject<GPXFile>> = new Map(); // Used to generate patches
|
const fileState: Map<string, GPXFile> = new Map(); // Used to generate patches
|
||||||
|
|
||||||
liveQuery(() => db.fileids.toArray()).subscribe(dbFileIds => {
|
liveQuery(() => db.fileids.toArray()).subscribe(dbFileIds => {
|
||||||
// Find new files to observe
|
// Find new files to observe
|
||||||
|
Reference in New Issue
Block a user