fix: only transition if points have changed

This commit is contained in:
ccmdi 2025-10-15 14:26:15 -04:00
parent c7f6b4e48b
commit 8dd11fb4ce
No known key found for this signature in database

View file

@ -34,6 +34,7 @@ export class MapBasesView extends BasesView {
private markerType: 'pins' | 'dots' = 'pins';
private tileLayer: string = 'https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png';
private savedViewState: { latitude: number; longitude: number; zoom: number } | null = null;
private lastPoints: MapPoint[] = [];
constructor(controller: QueryController, scrollEl: HTMLElement, plugin: MapPlugin) {
super(controller);
@ -83,6 +84,7 @@ export class MapBasesView extends BasesView {
console.error('Error finalizing deck:', e);
}
this.deck = null;
this.lastPoints = [];
}
}
@ -239,6 +241,9 @@ export class MapBasesView extends BasesView {
}
});
// Store the initial points for future comparison
this.lastPoints = points;
this.containerEl.removeClass('is-loading');
setTimeout(() => {
@ -259,11 +264,61 @@ export class MapBasesView extends BasesView {
return false;
}
private arePointsEqual(points1: MapPoint[], points2: MapPoint[]): boolean {
if (points1.length !== points2.length) return false;
for (let i = 0; i < points1.length; i++) {
const p1 = points1[i];
const p2 = points2[i];
// Compare essential properties that affect rendering
if (p1.lat !== p2.lat ||
p1.lng !== p2.lng ||
p1.title !== p2.title ||
p1.color !== p2.color ||
p1.size !== p2.size ||
p1.cover !== p2.cover ||
p1.file?.path !== p2.file?.path) {
return false;
}
// Compare tags
const tags1 = p1.tags || [];
const tags2 = p2.tags || [];
if (tags1.length !== tags2.length || !tags1.every((tag, idx) => tag === tags2[idx])) {
return false;
}
// Compare properties
const props1 = p1.properties || [];
const props2 = p2.properties || [];
if (props1.length !== props2.length) {
return false;
}
for (let j = 0; j < props1.length; j++) {
if (props1[j].name !== props2[j].name || props1[j].value !== props2[j].value) {
return false;
}
}
}
return true;
}
private updatePointsOnly(): void {
if (!this.deck || !this.data) return;
const points = this.extractPointsFromData();
// Check if points have actually changed
if (this.arePointsEqual(points, this.lastPoints)) {
console.warn('onDataUpdated triggered but points are unchanged - skipping update');
return;
}
// Store the new points for future comparison
this.lastPoints = points;
const hasConfiguredCenter = this.center[0] !== 0 || this.center[1] !== 0;
updateMapPoints(this.deck, points, {