From e9a511e5bd4dc956d30192bafc7d98bb51055e1f Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Wed, 15 Nov 2023 03:59:02 +0100 Subject: [PATCH] Performance: fix stuttering at low zoom --- src/Logic/FeatureSource/Sources/LayoutSource.ts | 2 +- .../TiledFeatureSource/DynamicGeoJsonTileSource.ts | 1 + .../FeatureSource/TiledFeatureSource/DynamicTileSource.ts | 7 +++++++ .../TiledFeatureSource/LocalStorageFeatureSource.ts | 5 ++++- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Logic/FeatureSource/Sources/LayoutSource.ts b/src/Logic/FeatureSource/Sources/LayoutSource.ts index c8e73d217..fa430f561 100644 --- a/src/Logic/FeatureSource/Sources/LayoutSource.ts +++ b/src/Logic/FeatureSource/Sources/LayoutSource.ts @@ -39,7 +39,7 @@ export default class LayoutSource extends FeatureSourceMerger { const osmLayers = layers.filter((layer) => layer.source.geojsonSource === undefined) const fromCache = osmLayers.map( (l) => - new LocalStorageFeatureSource(backend, l.id, 15, mapProperties, { + new LocalStorageFeatureSource(backend, l, 15, mapProperties, { isActive: isDisplayed(l.id), maxAge: l.maxAgeOfCache, }) diff --git a/src/Logic/FeatureSource/TiledFeatureSource/DynamicGeoJsonTileSource.ts b/src/Logic/FeatureSource/TiledFeatureSource/DynamicGeoJsonTileSource.ts index 9c37c0bc3..88455e9bb 100644 --- a/src/Logic/FeatureSource/TiledFeatureSource/DynamicGeoJsonTileSource.ts +++ b/src/Logic/FeatureSource/TiledFeatureSource/DynamicGeoJsonTileSource.ts @@ -66,6 +66,7 @@ export default class DynamicGeoJsonTileSource extends DynamicTileSource { const blackList = new Set() super( source.geojsonZoomLevel, + layer.minzoom, (zxy) => { if (whitelist !== undefined) { const isWhiteListed = whitelist.get(zxy[1])?.has(zxy[2]) diff --git a/src/Logic/FeatureSource/TiledFeatureSource/DynamicTileSource.ts b/src/Logic/FeatureSource/TiledFeatureSource/DynamicTileSource.ts index 024d86574..3e103c7bc 100644 --- a/src/Logic/FeatureSource/TiledFeatureSource/DynamicTileSource.ts +++ b/src/Logic/FeatureSource/TiledFeatureSource/DynamicTileSource.ts @@ -11,6 +11,7 @@ import FeatureSourceMerger from "../Sources/FeatureSourceMerger" export default class DynamicTileSource extends FeatureSourceMerger { constructor( zoomlevel: number, + minzoom: number, constructSource: (tileIndex) => FeatureSource, mapProperties: { bounds: Store @@ -26,6 +27,12 @@ export default class DynamicTileSource extends FeatureSourceMerger { mapProperties.bounds .mapD( (bounds) => { + if (options?.isActive && !options?.isActive.data) { + return undefined + } + if (mapProperties.zoom.data < minzoom) { + return undefined + } const tileRange = Tiles.TileRangeBetween( zoomlevel, bounds.getNorth(), diff --git a/src/Logic/FeatureSource/TiledFeatureSource/LocalStorageFeatureSource.ts b/src/Logic/FeatureSource/TiledFeatureSource/LocalStorageFeatureSource.ts index 7b23641ab..eac9d0859 100644 --- a/src/Logic/FeatureSource/TiledFeatureSource/LocalStorageFeatureSource.ts +++ b/src/Logic/FeatureSource/TiledFeatureSource/LocalStorageFeatureSource.ts @@ -4,11 +4,12 @@ import { BBox } from "../../BBox" import TileLocalStorage from "../Actors/TileLocalStorage" import { Feature } from "geojson" import StaticFeatureSource from "../Sources/StaticFeatureSource" +import LayerConfig from "../../../Models/ThemeConfig/LayerConfig" export default class LocalStorageFeatureSource extends DynamicTileSource { constructor( backend: string, - layername: string, + layer: LayerConfig, zoomlevel: number, mapProperties: { bounds: Store @@ -19,6 +20,7 @@ export default class LocalStorageFeatureSource extends DynamicTileSource { maxAge?: number // In seconds } ) { + const layername = layer.id const storage = TileLocalStorage.construct( backend, layername, @@ -26,6 +28,7 @@ export default class LocalStorageFeatureSource extends DynamicTileSource { ) super( zoomlevel, + layer.minzoom, (tileIndex) => new StaticFeatureSource( storage.getTileSource(tileIndex).mapD((features) => {