mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-02-06 16:33:09 +00:00
progress
This commit is contained in:
38
website/src/lib/components/map/gpx-layer/gpx-layers.ts
Normal file
38
website/src/lib/components/map/gpx-layer/gpx-layers.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
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(
|
||||
(fileId, fileState) => {
|
||||
const layer = new GPXLayer(fileId, fileState);
|
||||
this._layers.set(fileId, layer);
|
||||
},
|
||||
(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();
|
||||
Reference in New Issue
Block a user