veilmap/sync.js
2026-04-20 05:56:05 -04:00

33 lines
736 B
JavaScript

export class MapSync {
constructor(primary, secondary) {
this.primary = primary;
this.secondary = secondary;
this._syncing = false;
this._onMove = () => {
if (this._syncing) return;
this._syncing = true;
this.secondary.jumpTo({
center: this.primary.getCenter(),
zoom: this.primary.getZoom(),
bearing: this.primary.getBearing(),
pitch: this.primary.getPitch(),
});
this._syncing = false;
};
this._enabled = false;
}
enable() {
if (this._enabled) return;
this._enabled = true;
this.primary.on('move', this._onMove);
this._onMove();
}
disable() {
this._enabled = false;
this.primary.off('move', this._onMove);
}
}