2025-10-17 23:54:45 +02:00
|
|
|
import { GPXFileStateCollectionObserver } from '$lib/logic/file-state';
|
|
|
|
|
import { GPXLayer } from './gpx-layer';
|
|
|
|
|
|
|
|
|
|
export class GPXLayerCollection {
|
|
|
|
|
private _layers: Map<string, GPXLayer>;
|
|
|
|
|
private _fileStateCollectionObserver: GPXFileStateCollectionObserver | null = null;
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
this._layers = new Map<string, GPXLayer>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
init() {
|
|
|
|
|
if (this._fileStateCollectionObserver) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this._fileStateCollectionObserver = new GPXFileStateCollectionObserver(
|
2025-10-19 16:14:05 +02:00
|
|
|
(newFiles) => {
|
|
|
|
|
newFiles.forEach((fileState, fileId) => {
|
|
|
|
|
const layer = new GPXLayer(fileId, fileState);
|
|
|
|
|
this._layers.set(fileId, layer);
|
|
|
|
|
});
|
2025-10-17 23:54:45 +02:00
|
|
|
},
|
|
|
|
|
(fileId) => {
|
|
|
|
|
const layer = this._layers.get(fileId);
|
|
|
|
|
if (layer) {
|
|
|
|
|
layer.remove();
|
|
|
|
|
this._layers.delete(fileId);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
() => {
|
|
|
|
|
this._layers.forEach((layer) => {
|
|
|
|
|
layer.remove();
|
|
|
|
|
});
|
|
|
|
|
this._layers.clear();
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const gpxLayers = new GPXLayerCollection();
|