From dc404706c5a23d6f9dda3a64289a07042cb57a48 Mon Sep 17 00:00:00 2001 From: vcoppe Date: Sat, 28 Dec 2024 16:14:36 +0100 Subject: [PATCH] detect and ignore duplicate POIs when merging --- gpx/src/gpx.ts | 17 +++++++++++++++++ website/src/lib/db.ts | 6 +++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/gpx/src/gpx.ts b/gpx/src/gpx.ts index 3333513f..88120983 100644 --- a/gpx/src/gpx.ts +++ b/gpx/src/gpx.ts @@ -1235,6 +1235,23 @@ export class Waypoint { }); } + equals(other: Waypoint): boolean { + if (this.attributes.lat !== other.attributes.lat || this.attributes.lon !== other.attributes.lon || this.ele !== other.ele || + this.name !== other.name || this.cmt !== other.cmt || this.desc !== other.desc || this.sym !== other.sym || this.type !== other.type) { + return false; + } + + if (this.time === undefined && other.time !== undefined || this.time !== undefined && other.time === undefined || this.time !== undefined && other.time !== undefined && this.time.getTime() !== other.time.getTime()) { + return false; + } + + if (JSON.stringify(this.link) !== JSON.stringify(other.link)) { + return false; + } + + return true; + } + // Producers setHidden(hidden: boolean) { this._data.hidden = hidden; diff --git a/website/src/lib/db.ts b/website/src/lib/db.ts index 5a4888ff..e489ade4 100644 --- a/website/src/lib/db.ts +++ b/website/src/lib/db.ts @@ -593,7 +593,11 @@ export const dbUtils = { if (file && originalFile) { if (level === ListLevel.FILE) { toMerge.trk.push(...originalFile.trk.map((track) => track.clone())); - toMerge.wpt.push(...originalFile.wpt.map((wpt) => wpt.clone())); + for (const wpt of originalFile.wpt) { + if (!toMerge.wpt.some((w) => w.equals(wpt))) { + toMerge.wpt.push(wpt.clone()); + } + } if (first) { target = items[0]; targetFile = file;