Optimize availableBaseLayers code
This commit is contained in:
parent
41548532bf
commit
08efcbdea0
1 changed files with 19 additions and 13 deletions
|
@ -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) {
|
||||
const layer = layerOverviewItem;
|
||||
|
||||
if (layer.feature?.geometry === undefined || layer.feature?.geometry === null) {
|
||||
globalLayers.push(layer);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lon === undefined || lat === undefined) {
|
||||
continue;
|
||||
return availableLayers.concat(this.globalLayers);
|
||||
}
|
||||
const lonlat = [lon, lat];
|
||||
for (const layerOverviewItem of this.localLayers) {
|
||||
const layer = layerOverviewItem;
|
||||
const bbox = BBox.get(layer.feature)
|
||||
|
||||
if(layer.name === "AIV Flanders GRB"){
|
||||
console.log("Y U NO LOAD?")
|
||||
}
|
||||
|
||||
if (GeoOperations.inside([lon, lat], layer.feature)) {
|
||||
if(!bbox.contains(lonlat)){
|
||||
continue
|
||||
}
|
||||
|
||||
if (GeoOperations.inside(lonlat, layer.feature)) {
|
||||
availableLayers.push(layer);
|
||||
}
|
||||
}
|
||||
|
||||
return availableLayers.concat(globalLayers);
|
||||
return availableLayers.concat(this.globalLayers);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue