mapcomplete/Logic/FeatureSource/TiledFeatureSource/LocalStorageFeatureSource.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-03-28 05:13:48 +02:00
import DynamicTileSource from "./DynamicTileSource"
import { Store } from "../../UIEventSource"
import { BBox } from "../../BBox"
2023-03-28 05:13:48 +02:00
import TileLocalStorage from "../Actors/TileLocalStorage"
import { Feature } from "geojson"
2023-03-28 05:13:48 +02:00
import StaticFeatureSource from "../Sources/StaticFeatureSource"
export default class LocalStorageFeatureSource extends DynamicTileSource {
constructor(
backend: string,
2023-03-28 05:13:48 +02:00
layername: string,
zoomlevel: number,
mapProperties: {
bounds: Store<BBox>
zoom: Store<number>
},
options?: {
isActive?: Store<boolean>
2023-06-01 02:52:21 +02:00
maxAge?: number // In seconds
2023-03-28 05:13:48 +02:00
}
) {
const storage = TileLocalStorage.construct<Feature[]>(
backend,
layername,
options?.maxAge ?? 24 * 60 * 60
)
2023-03-28 05:13:48 +02:00
super(
zoomlevel,
2023-04-18 23:44:49 +02:00
(tileIndex) =>
new StaticFeatureSource(
storage.getTileSource(tileIndex).mapD((features) => {
if (features.length === undefined) {
console.trace("These are not features:", features)
storage.invalidate(zoomlevel, tileIndex)
return []
}
return features.filter((f) => !f.properties.id.match(/(node|way)\/-[0-9]+/))
})
2023-04-18 23:44:49 +02:00
),
2023-03-28 05:13:48 +02:00
mapProperties,
options
)
}
}