LayerServer: first version which can use a local MVT-server

This commit is contained in:
Pieter Vander Vennet 2024-01-22 01:42:05 +01:00
parent 35228daa8f
commit ef2f1487c6
17 changed files with 1009 additions and 82 deletions

View file

@ -0,0 +1,39 @@
import { Store } from "../../UIEventSource"
import DynamicTileSource from "./DynamicTileSource"
import { Utils } from "../../../Utils"
import { BBox } from "../../BBox"
import LayerConfig from "../../../Models/ThemeConfig/LayerConfig"
import MvtSource from "../Sources/MvtSource"
import { Tiles } from "../../../Models/TileRange"
import Constants from "../../../Models/Constants"
export default class DynamicMvtileSource extends DynamicTileSource {
constructor(
layer: LayerConfig,
mapProperties: {
zoom: Store<number>
bounds: Store<BBox>
},
options?: {
isActive?: Store<boolean>
},
) {
super(
mapProperties.zoom,
layer.minzoom,
(zxy) => {
const [z, x, y] = Tiles.tile_from_index(zxy)
const url = Utils.SubstituteKeys(Constants.VectorTileServer,
{
z, x, y, layer: layer.id,
})
return new MvtSource(url, x, y, z)
},
mapProperties,
{
isActive: options?.isActive,
},
)
}
}

View file

@ -10,9 +10,9 @@ import FeatureSourceMerger from "../Sources/FeatureSourceMerger"
*/
export default class DynamicTileSource extends FeatureSourceMerger {
constructor(
zoomlevel: number,
zoomlevel: Store<number>,
minzoom: number,
constructSource: (tileIndex) => FeatureSource,
constructSource: (tileIndex: number) => FeatureSource,
mapProperties: {
bounds: Store<BBox>
zoom: Store<number>
@ -34,8 +34,9 @@ export default class DynamicTileSource extends FeatureSourceMerger {
if (mapProperties.zoom.data < minzoom) {
return undefined
}
const z = Math.round(zoomlevel.data)
const tileRange = Tiles.TileRangeBetween(
zoomlevel,
z,
bounds.getNorth(),
bounds.getEast(),
bounds.getSouth(),
@ -49,7 +50,7 @@ export default class DynamicTileSource extends FeatureSourceMerger {
}
const needed = Tiles.MapRange(tileRange, (x, y) =>
Tiles.tile_index(zoomlevel, x, y)
Tiles.tile_index(z, x, y)
).filter((i) => !loadedTiles.has(i))
if (needed.length === 0) {
return undefined

View file

@ -1,5 +1,5 @@
import DynamicTileSource from "./DynamicTileSource"
import { Store } from "../../UIEventSource"
import { ImmutableStore, Store } from "../../UIEventSource"
import { BBox } from "../../BBox"
import TileLocalStorage from "../Actors/TileLocalStorage"
import { Feature } from "geojson"
@ -27,7 +27,7 @@ export default class LocalStorageFeatureSource extends DynamicTileSource {
options?.maxAge ?? 24 * 60 * 60
)
super(
zoomlevel,
new ImmutableStore(zoomlevel),
layer.minzoom,
(tileIndex) =>
new StaticFeatureSource(