Refactoring: tweak some featuresources to allow them to run in the tests

This commit is contained in:
Pieter Vander Vennet 2023-05-17 13:19:43 +02:00
parent ad1178df6c
commit 39aff86c76
3 changed files with 15 additions and 4 deletions

View file

@ -14,6 +14,7 @@ export default class TileLocalStorage<T> {
private readonly inUse = new UIEventSource(false)
private readonly cachedSources: Record<number, UIEventSource<T> & { flush: () => void }> = {}
private static readonly useIndexedDb = typeof indexedDB !== "undefined"
private constructor(layername: string) {
this._layername = layername
}
@ -49,6 +50,9 @@ export default class TileLocalStorage<T> {
}
private async SetIdb(tileIndex: number, data: any): Promise<void> {
if(!TileLocalStorage.useIndexedDb){
return
}
try {
await this.inUse.AsPromise((inUse) => !inUse)
this.inUse.setData(true)
@ -69,6 +73,9 @@ export default class TileLocalStorage<T> {
}
private GetIdb(tileIndex: number): Promise<any> {
if(!TileLocalStorage.useIndexedDb){
return undefined
}
return IdbLocalStorage.GetDirectly(this._layername + "_" + tileIndex)
}
}

View file

@ -1,8 +1,8 @@
import { FeatureSource, IndexedFeatureSource } from "./FeatureSource"
import {FeatureSource} from "./FeatureSource"
import FilteredLayer from "../../Models/FilteredLayer"
import SimpleFeatureSource from "./Sources/SimpleFeatureSource"
import { Feature } from "geojson"
import { UIEventSource } from "../UIEventSource"
import {Feature} from "geojson"
import {UIEventSource} from "../UIEventSource"
/**
* In some rare cases, some elements are shown on multiple layers (when 'passthrough' is enabled)
@ -59,6 +59,10 @@ export default class PerLayerFeatureSourceSplitter<T extends FeatureSource = Fea
let foundALayer = false
for (let i = 0; i < layers.length; i++) {
const layer = layers[i]
if(!layer.layerDef?.source){
console.error("PerLayerFeatureSourceSplitter got a layer without a source:", layer.layerDef.id)
continue
}
if (layer.layerDef.source.osmTags.matchesProperties(f.properties)) {
const id = f.properties.id
// We have found our matching layer!

View file

@ -32,7 +32,7 @@ export class LastClickFeatureSource implements WritableFeatureSource {
}
const renderings = Utils.Dedup(
allPresets.map((uiElem) => uiElem.ConstructElement().innerHTML)
allPresets.map((uiElem) => Utils.runningFromConsole ? "" : uiElem.ConstructElement().innerHTML)
)
const properties = {