Performance: don't query for summary if the summaries are not online

This commit is contained in:
Pieter Vander Vennet 2025-07-25 19:56:54 +02:00
parent 0c1f9e8cca
commit 517540face
2 changed files with 18 additions and 5 deletions

View file

@ -1,5 +1,5 @@
import DynamicTileSource from "./DynamicTileSource" import DynamicTileSource from "./DynamicTileSource"
import { Store, UIEventSource } from "../../UIEventSource" import { ImmutableStore, Store, UIEventSource } from "../../UIEventSource"
import { BBox } from "../../BBox" import { BBox } from "../../BBox"
import StaticFeatureSource from "../Sources/StaticFeatureSource" import StaticFeatureSource from "../Sources/StaticFeatureSource"
import { Feature, Point } from "geojson" import { Feature, Point } from "geojson"
@ -20,7 +20,7 @@ export class SummaryTileSourceRewriter implements FeatureSource {
public readonly totalNumberOfFeatures: Store<number> = this._totalNumberOfFeatures public readonly totalNumberOfFeatures: Store<number> = this._totalNumberOfFeatures
constructor( constructor(
summarySource: SummaryTileSource, summarySource: SummaryTileSource,
filteredLayers: ReadonlyMap<string, FilteredLayer> filteredLayers: ReadonlyMap<string, FilteredLayer>,
) { ) {
this.filteredLayers = Array.from(filteredLayers.values()).filter( this.filteredLayers = Array.from(filteredLayers.values()).filter(
(l) => !Constants.isPriviliged(l.layerDef) (l) => !Constants.isPriviliged(l.layerDef)
@ -73,11 +73,18 @@ export class SummaryTileSource extends DynamicTileSource {
zoom: Store<number> zoom: Store<number>
}, },
options?: { options?: {
isActive?: Store<boolean> isActive?: Store<boolean>,
availableLayers?: Store<Set<string>>
} }
) { ) {
const layersSummed = layers.join("+")
const zDiff = 2 const zDiff = 2
const layersSummed = (options?.availableLayers??new ImmutableStore(undefined)).map(available => {
console.log("Determining 'layersSummed' with currently available:", available)
if(available === undefined){
return layers.join("+")
}
return layers.filter(l => available.has(l)).join("+")
})
super( super(
zoomRounded, zoomRounded,
0, // minzoom 0, // minzoom
@ -85,7 +92,7 @@ export class SummaryTileSource extends DynamicTileSource {
const features = SummaryTileSource.downloadTile( const features = SummaryTileSource.downloadTile(
tileIndex, tileIndex,
cacheserver, cacheserver,
layersSummed layersSummed.data
) )
const [z] = Tiles.tile_from_index(tileIndex) const [z] = Tiles.tile_from_index(tileIndex)
return new StaticFeatureSource( return new StaticFeatureSource(
@ -110,6 +117,9 @@ export class SummaryTileSource extends DynamicTileSource {
cacheserver: string, cacheserver: string,
layersSummed: string layersSummed: string
): Store<Feature<Point>[]> { ): Store<Feature<Point>[]> {
if(layersSummed === ""){
return new ImmutableStore([])
}
const [z, x, y] = Tiles.tile_from_index(tileIndex) const [z, x, y] = Tiles.tile_from_index(tileIndex)
let coordinates = Tiles.centerPointOf(z, x, y) let coordinates = Tiles.centerPointOf(z, x, y)
const url = `${cacheserver}/summary/${layersSummed}/${z}/${x}/${y}.json` const url = `${cacheserver}/summary/${layersSummed}/${z}/${x}/${y}.json`

View file

@ -24,6 +24,7 @@ import { ShowDataLayerOptions } from "../../UI/Map/ShowDataLayerOptions"
export class WithSpecialLayers extends WithChangesState { export class WithSpecialLayers extends WithChangesState {
readonly favourites: FavouritesFeatureSource readonly favourites: FavouritesFeatureSource
private mvtAvailableLayers: Store<Set<string>>
/** /**
* When hovering (in the popup) an image, the location of the image will be revealed on the main map. * When hovering (in the popup) an image, the location of the image will be revealed on the main map.
* This store contains those images that should be shown, probably only the currently hovered image * This store contains those images that should be shown, probably only the currently hovered image
@ -43,6 +44,7 @@ export class WithSpecialLayers extends WithChangesState {
constructor(theme: ThemeConfig, mvtAvailableLayers: Store<Set<string>>) { constructor(theme: ThemeConfig, mvtAvailableLayers: Store<Set<string>>) {
super(theme, mvtAvailableLayers) super(theme, mvtAvailableLayers)
this.mvtAvailableLayers = mvtAvailableLayers
this.favourites = new FavouritesFeatureSource(this) this.favourites = new FavouritesFeatureSource(this)
@ -111,6 +113,7 @@ export class WithSpecialLayers extends WithChangesState {
this.mapProperties, this.mapProperties,
{ {
isActive: this.mapProperties.zoom.map((z) => z < maxzoom), isActive: this.mapProperties.zoom.map((z) => z < maxzoom),
availableLayers: this.mvtAvailableLayers
} }
) )