Optimize availableBaseLayers code

This commit is contained in:
pietervdvn 2022-02-11 15:11:50 +01:00
parent 41548532bf
commit 08efcbdea0

View file

@ -8,6 +8,7 @@ import {TileLayer} from "leaflet";
import * as X from "leaflet-providers"; import * as X from "leaflet-providers";
import {Utils} from "../../Utils"; import {Utils} from "../../Utils";
import {AvailableBaseLayersObj} from "./AvailableBaseLayers"; import {AvailableBaseLayersObj} from "./AvailableBaseLayers";
import {BBox} from "../BBox";
export default class AvailableBaseLayersImplementation implements AvailableBaseLayersObj { export default class AvailableBaseLayersImplementation implements AvailableBaseLayersObj {
@ -26,7 +27,9 @@ export default class AvailableBaseLayersImplementation implements AvailableBaseL
category: "osmbasedmap" 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[] { private static LoadRasterIndex(): BaseLayer[] {
const layers: BaseLayer[] = [] const layers: BaseLayer[] = []
@ -258,24 +261,27 @@ export default class AvailableBaseLayersImplementation implements AvailableBaseL
private CalculateAvailableLayersAt(lon: number, lat: number): BaseLayer[] { private CalculateAvailableLayersAt(lon: number, lat: number): BaseLayer[] {
const availableLayers = [this.osmCarto] const availableLayers = [this.osmCarto]
const globalLayers = []; if (lon === undefined || lat === undefined) {
for (const layerOverviewItem of this.layerOverview) { return availableLayers.concat(this.globalLayers);
}
const lonlat = [lon, lat];
for (const layerOverviewItem of this.localLayers) {
const layer = layerOverviewItem; const layer = layerOverviewItem;
const bbox = BBox.get(layer.feature)
if (layer.feature?.geometry === undefined || layer.feature?.geometry === null) {
globalLayers.push(layer); if(layer.name === "AIV Flanders GRB"){
continue; console.log("Y U NO LOAD?")
}
if(!bbox.contains(lonlat)){
continue
} }
if (lon === undefined || lat === undefined) { if (GeoOperations.inside(lonlat, layer.feature)) {
continue;
}
if (GeoOperations.inside([lon, lat], layer.feature)) {
availableLayers.push(layer); availableLayers.push(layer);
} }
} }
return availableLayers.concat(globalLayers); return availableLayers.concat(this.globalLayers);
} }
} }