From c27a7769187057154385ce8e230c403ba560e15f Mon Sep 17 00:00:00 2001 From: Candid Dauth Date: Sat, 2 Mar 2024 03:46:33 +0100 Subject: [PATCH] Reset line points in client on zoom change --- client/src/client.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/client/src/client.ts b/client/src/client.ts index e911c6ed..bed2b717 100644 --- a/client/src/client.ts +++ b/client/src/client.ts @@ -353,8 +353,32 @@ export default class Client { } async updateBbox(bbox: BboxWithZoom): Promise>> { + const isZoomChange = this.bbox && bbox.zoom !== this.bbox.zoom; + this._set(this.state, 'bbox', bbox); const obj = await this._emit("updateBbox", bbox); + + if (isZoomChange) { + // Reset line points on zoom change to prevent us from accumulating too many unneeded line points. + // On zoom change the line points are sent from the server without applying the "except" rule for the last bbox, + // so we can be sure that we will receive all line points that are relevant for the new bbox. + obj.linePoints = obj.linePoints || []; + const linePointEventsById = new Map(obj.linePoints.map((e) => [e.id, e] as const)); + for (const lineIdStr of Object.keys(this.data.lines)) { + const lineId = Number(lineIdStr); + const e = linePointEventsById.get(lineId); + if (e) { + e.reset = true; + } else { + obj.linePoints.push({ + id: lineId, + trackPoints: [], + reset: true + }); + } + } + } + this._receiveMultiple(obj); return obj; }