2024-01-22 01:42:05 +01:00
|
|
|
import { Store } from "../../UIEventSource"
|
2024-01-26 18:18:07 +01:00
|
|
|
import DynamicTileSource, { PolygonSourceMerger } from "./DynamicTileSource"
|
2024-01-22 01:42:05 +01:00
|
|
|
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"
|
2024-01-26 18:18:07 +01:00
|
|
|
import FeatureSourceMerger from "../Sources/FeatureSourceMerger"
|
2024-01-22 01:42:05 +01:00
|
|
|
|
2024-01-26 18:18:07 +01:00
|
|
|
|
|
|
|
class PolygonMvtSource extends PolygonSourceMerger{
|
|
|
|
constructor( layer: LayerConfig,
|
|
|
|
mapProperties: {
|
|
|
|
zoom: Store<number>
|
|
|
|
bounds: Store<BBox>
|
|
|
|
},
|
|
|
|
options?: {
|
|
|
|
isActive?: Store<boolean>
|
|
|
|
}) {
|
|
|
|
const roundedZoom = mapProperties.zoom.mapD(z => Math.min(Math.floor(z/2)*2, 14))
|
|
|
|
super(
|
|
|
|
roundedZoom,
|
|
|
|
layer.minzoom,
|
|
|
|
(zxy) => {
|
|
|
|
const [z, x, y] = Tiles.tile_from_index(zxy)
|
|
|
|
const url = Utils.SubstituteKeys(Constants.VectorTileServer,
|
|
|
|
{
|
|
|
|
z, x, y, layer: layer.id,
|
|
|
|
type: "polygons",
|
|
|
|
})
|
|
|
|
return new MvtSource(url, x, y, z)
|
|
|
|
},
|
|
|
|
mapProperties,
|
|
|
|
{
|
|
|
|
isActive: options?.isActive,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class PointMvtSource extends DynamicTileSource {
|
2024-01-22 01:42:05 +01:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
layer: LayerConfig,
|
|
|
|
mapProperties: {
|
|
|
|
zoom: Store<number>
|
|
|
|
bounds: Store<BBox>
|
|
|
|
},
|
|
|
|
options?: {
|
|
|
|
isActive?: Store<boolean>
|
|
|
|
},
|
|
|
|
) {
|
2024-01-26 18:18:07 +01:00
|
|
|
const roundedZoom = mapProperties.zoom.mapD(z => Math.min(Math.floor(z/2)*2, 14))
|
2024-01-22 01:42:05 +01:00
|
|
|
super(
|
2024-01-26 18:18:07 +01:00
|
|
|
roundedZoom,
|
2024-01-22 01:42:05 +01:00
|
|
|
layer.minzoom,
|
|
|
|
(zxy) => {
|
|
|
|
const [z, x, y] = Tiles.tile_from_index(zxy)
|
|
|
|
const url = Utils.SubstituteKeys(Constants.VectorTileServer,
|
|
|
|
{
|
|
|
|
z, x, y, layer: layer.id,
|
2024-01-26 18:18:07 +01:00
|
|
|
type: "pois",
|
2024-01-22 01:42:05 +01:00
|
|
|
})
|
|
|
|
return new MvtSource(url, x, y, z)
|
|
|
|
},
|
|
|
|
mapProperties,
|
|
|
|
{
|
|
|
|
isActive: options?.isActive,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2024-01-26 18:18:07 +01:00
|
|
|
|
|
|
|
export default class DynamicMvtileSource extends FeatureSourceMerger {
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
layer: LayerConfig,
|
|
|
|
mapProperties: {
|
|
|
|
zoom: Store<number>
|
|
|
|
bounds: Store<BBox>
|
|
|
|
},
|
|
|
|
options?: {
|
|
|
|
isActive?: Store<boolean>
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
const roundedZoom = mapProperties.zoom.mapD(z => Math.floor(z))
|
|
|
|
super(
|
|
|
|
new PointMvtSource(layer, mapProperties, options),
|
|
|
|
new PolygonMvtSource(layer, mapProperties, options)
|
|
|
|
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|