From 08efcbdea00d95ee16f7ec82c0eca5ad0e89c8f4 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Fri, 11 Feb 2022 15:11:50 +0100 Subject: [PATCH] Optimize availableBaseLayers code --- .../AvailableBaseLayersImplementation.ts | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/Logic/Actors/AvailableBaseLayersImplementation.ts b/Logic/Actors/AvailableBaseLayersImplementation.ts index 4cea4539c..fd96d6a11 100644 --- a/Logic/Actors/AvailableBaseLayersImplementation.ts +++ b/Logic/Actors/AvailableBaseLayersImplementation.ts @@ -8,6 +8,7 @@ import {TileLayer} from "leaflet"; import * as X from "leaflet-providers"; import {Utils} from "../../Utils"; import {AvailableBaseLayersObj} from "./AvailableBaseLayers"; +import {BBox} from "../BBox"; export default class AvailableBaseLayersImplementation implements AvailableBaseLayersObj { @@ -26,7 +27,9 @@ export default class AvailableBaseLayersImplementation implements AvailableBaseL category: "osmbasedmap" } - public layerOverview = AvailableBaseLayersImplementation.LoadRasterIndex().concat(AvailableBaseLayersImplementation.LoadProviderIndex()); + public readonly layerOverview = AvailableBaseLayersImplementation.LoadRasterIndex().concat(AvailableBaseLayersImplementation.LoadProviderIndex()); + public readonly globalLayers = this.layerOverview.filter(layer => layer.feature?.geometry === undefined || layer.feature?.geometry === null) + public readonly localLayers = this.layerOverview.filter(layer => layer.feature?.geometry !== undefined && layer.featuer?.geometry !== null) private static LoadRasterIndex(): BaseLayer[] { const layers: BaseLayer[] = [] @@ -258,24 +261,27 @@ export default class AvailableBaseLayersImplementation implements AvailableBaseL private CalculateAvailableLayersAt(lon: number, lat: number): BaseLayer[] { const availableLayers = [this.osmCarto] - const globalLayers = []; - for (const layerOverviewItem of this.layerOverview) { + if (lon === undefined || lat === undefined) { + return availableLayers.concat(this.globalLayers); + } + const lonlat = [lon, lat]; + for (const layerOverviewItem of this.localLayers) { const layer = layerOverviewItem; - - if (layer.feature?.geometry === undefined || layer.feature?.geometry === null) { - globalLayers.push(layer); - continue; + const bbox = BBox.get(layer.feature) + + if(layer.name === "AIV Flanders GRB"){ + console.log("Y U NO LOAD?") + } + + if(!bbox.contains(lonlat)){ + continue } - if (lon === undefined || lat === undefined) { - continue; - } - - if (GeoOperations.inside([lon, lat], layer.feature)) { + if (GeoOperations.inside(lonlat, layer.feature)) { availableLayers.push(layer); } } - return availableLayers.concat(globalLayers); + return availableLayers.concat(this.globalLayers); } } \ No newline at end of file