chore: automated housekeeping...

This commit is contained in:
Pieter Vander Vennet 2024-08-14 13:53:56 +02:00
parent f77570589d
commit 9b8a9337fd
111 changed files with 2911 additions and 1280 deletions

View file

@ -8,26 +8,26 @@ import { GeoOperations } from "../Logic/GeoOperations"
import { RasterLayerProperties } from "./RasterLayerProperties"
import { Utils } from "../Utils"
export type EditorLayerIndex = (Feature<Polygon, EditorLayerIndexProperties> &
RasterLayerPolygon)[]
export type EditorLayerIndex = (Feature<Polygon, EditorLayerIndexProperties> & RasterLayerPolygon)[]
export class AvailableRasterLayers {
private static _editorLayerIndex: EditorLayerIndex = undefined
private static _editorLayerIndexStore: UIEventSource<EditorLayerIndex> = new UIEventSource<EditorLayerIndex>(undefined)
private static _editorLayerIndexStore: UIEventSource<EditorLayerIndex> =
new UIEventSource<EditorLayerIndex>(undefined)
public static async editorLayerIndex(): Promise<EditorLayerIndex> {
if(AvailableRasterLayers._editorLayerIndex !== undefined){
if (AvailableRasterLayers._editorLayerIndex !== undefined) {
return AvailableRasterLayers._editorLayerIndex
}
console.debug("Downloading ELI")
const eli = await Utils.downloadJson<{ features: EditorLayerIndex }>("./assets/data/editor-layer-index.json")
this._editorLayerIndex = eli.features.filter(l => l.properties.id !== "Bing")
const eli = await Utils.downloadJson<{ features: EditorLayerIndex }>(
"./assets/data/editor-layer-index.json"
)
this._editorLayerIndex = eli.features.filter((l) => l.properties.id !== "Bing")
this._editorLayerIndexStore.set(this._editorLayerIndex)
return this._editorLayerIndex
}
public static globalLayers: RasterLayerPolygon[] = globallayers.layers
.filter(
(properties) =>
@ -41,7 +41,7 @@ export class AvailableRasterLayers {
geometry: BBox.global.asGeometry(),
}
)
public static bing = <RasterLayerPolygon> bingJson
public static bing = <RasterLayerPolygon>bingJson
public static readonly osmCartoProperties: RasterLayerProperties = {
id: "osm",
name: "OpenStreetMap",
@ -70,10 +70,14 @@ export class AvailableRasterLayers {
return l.properties.id === "protomaps.sunny"
})
public static layersAvailableAt( location: Store<{ lon: number; lat: number }>,
enableBing?: Store<boolean>): {store: Store<RasterLayerPolygon[]> } {
const store = {store: undefined}
Utils.AddLazyProperty(store, "store", () => AvailableRasterLayers._layersAvailableAt(location, enableBing))
public static layersAvailableAt(
location: Store<{ lon: number; lat: number }>,
enableBing?: Store<boolean>
): { store: Store<RasterLayerPolygon[]> } {
const store = { store: undefined }
Utils.AddLazyProperty(store, "store", () =>
AvailableRasterLayers._layersAvailableAt(location, enableBing)
)
return store
}
@ -81,19 +85,19 @@ export class AvailableRasterLayers {
location: Store<{ lon: number; lat: number }>,
enableBing?: Store<boolean>
): Store<RasterLayerPolygon[]> {
this.editorLayerIndex() // start the download
const availableLayersBboxes = Stores.ListStabilized(
location.mapD((loc) => {
const eli = AvailableRasterLayers._editorLayerIndexStore.data
if(!eli){
return []
}
const lonlat: [number, number] = [loc.lon, loc.lat]
return eli.filter((eliPolygon) =>
BBox.get(eliPolygon).contains(lonlat)
)
}, [AvailableRasterLayers._editorLayerIndexStore])
location.mapD(
(loc) => {
const eli = AvailableRasterLayers._editorLayerIndexStore.data
if (!eli) {
return []
}
const lonlat: [number, number] = [loc.lon, loc.lat]
return eli.filter((eliPolygon) => BBox.get(eliPolygon).contains(lonlat))
},
[AvailableRasterLayers._editorLayerIndexStore]
)
)
return Stores.ListStabilized(
availableLayersBboxes.map(
@ -126,7 +130,6 @@ export class AvailableRasterLayers {
)
)
}
}
export class RasterLayerUtils {