forked from MapComplete/MapComplete
refactoring: more state splitting, basic layoutFeatureSource
This commit is contained in:
parent
8e2f04c0d0
commit
b94a8f5745
54 changed files with 1067 additions and 1969 deletions
|
@ -1,23 +1,24 @@
|
|||
import FilteredLayer from "../../../Models/FilteredLayer"
|
||||
import { FeatureSourceForLayer, Tiled } from "../FeatureSource"
|
||||
import { UIEventSource } from "../../UIEventSource"
|
||||
import { Store } from "../../UIEventSource"
|
||||
import DynamicTileSource from "./DynamicTileSource"
|
||||
import { Utils } from "../../../Utils"
|
||||
import GeoJsonSource from "../Sources/GeoJsonSource"
|
||||
import { BBox } from "../../BBox"
|
||||
import LayerConfig from "../../../Models/ThemeConfig/LayerConfig"
|
||||
|
||||
export default class DynamicGeoJsonTileSource extends DynamicTileSource {
|
||||
private static whitelistCache = new Map<string, any>()
|
||||
|
||||
constructor(
|
||||
layer: FilteredLayer,
|
||||
registerLayer: (layer: FeatureSourceForLayer & Tiled) => void,
|
||||
state: {
|
||||
locationControl?: UIEventSource<{ zoom?: number }>
|
||||
currentBounds: UIEventSource<BBox>
|
||||
layer: LayerConfig,
|
||||
mapProperties: {
|
||||
zoom: Store<number>
|
||||
bounds: Store<BBox>
|
||||
},
|
||||
options?: {
|
||||
isActive?: Store<boolean>
|
||||
}
|
||||
) {
|
||||
const source = layer.layerDef.source
|
||||
const source = layer.source
|
||||
if (source.geojsonZoomLevel === undefined) {
|
||||
throw "Invalid layer: geojsonZoomLevel expected"
|
||||
}
|
||||
|
@ -30,7 +31,7 @@ export default class DynamicGeoJsonTileSource extends DynamicTileSource {
|
|||
const whitelistUrl = source.geojsonSource
|
||||
.replace("{z}", "" + source.geojsonZoomLevel)
|
||||
.replace("{x}_{y}.geojson", "overview.json")
|
||||
.replace("{layer}", layer.layerDef.id)
|
||||
.replace("{layer}", layer.id)
|
||||
|
||||
if (DynamicGeoJsonTileSource.whitelistCache.has(whitelistUrl)) {
|
||||
whitelist = DynamicGeoJsonTileSource.whitelistCache.get(whitelistUrl)
|
||||
|
@ -56,14 +57,13 @@ export default class DynamicGeoJsonTileSource extends DynamicTileSource {
|
|||
DynamicGeoJsonTileSource.whitelistCache.set(whitelistUrl, whitelist)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.warn("No whitelist found for ", layer.layerDef.id, err)
|
||||
console.warn("No whitelist found for ", layer.id, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const blackList = new Set<string>()
|
||||
super(
|
||||
layer,
|
||||
source.geojsonZoomLevel,
|
||||
(zxy) => {
|
||||
if (whitelist !== undefined) {
|
||||
|
@ -78,25 +78,13 @@ export default class DynamicGeoJsonTileSource extends DynamicTileSource {
|
|||
}
|
||||
}
|
||||
|
||||
const src = new GeoJsonSource(layer, zxy, {
|
||||
return new GeoJsonSource(layer, {
|
||||
zxy,
|
||||
featureIdBlacklist: blackList,
|
||||
})
|
||||
|
||||
registerLayer(src)
|
||||
return src
|
||||
},
|
||||
state
|
||||
mapProperties,
|
||||
{ isActive: options.isActive }
|
||||
)
|
||||
}
|
||||
|
||||
public static RegisterWhitelist(url: string, json: any) {
|
||||
const data = new Map<number, Set<number>>()
|
||||
for (const x in json) {
|
||||
if (x === "zoom") {
|
||||
continue
|
||||
}
|
||||
data.set(Number(x), new Set(json[x]))
|
||||
}
|
||||
DynamicGeoJsonTileSource.whitelistCache.set(url, data)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue