Themes(GRB): fix detection of overlapping buildings

This commit is contained in:
Pieter Vander Vennet 2025-05-04 03:56:38 +02:00
parent 915b732204
commit 6bdda9fb12
9 changed files with 34 additions and 184 deletions

View file

@ -1,6 +1,5 @@
import { GeoOperations } from "./GeoOperations"
import Combine from "../UI/Base/Combine"
import BaseUIElement from "../UI/BaseUIElement"
import List from "../UI/Base/List"
import Title from "../UI/Base/Title"
import { BBox } from "./BBox"
@ -17,6 +16,10 @@ export interface ExtraFuncParams {
layerId: string,
bbox: BBox
) => Feature<Geometry, Record<string, string>>[][]
getProbablyOverlapsWith: (
layerId: string,
bbox: BBox
) => Feature<Geometry, Record<string, string>>[][]
getFeatureById: (id: string) => Feature<Geometry, Record<string, string>>
}
@ -102,13 +105,13 @@ class OverlapFunc implements ExtraFunction {
"...layerIds - one or more layer ids of the layer from which every feature is checked for overlap)",
]
_f(params, feat) {
_f(params: ExtraFuncParams, feat: Feature) {
return (...layerIds: string[]) => {
const result: { feat: any; overlap: number }[] = []
const seenIds = new Set<string>()
const bbox = BBox.get(feat)
for (const layerId of layerIds) {
const otherFeaturess = params.getFeaturesWithin(layerId, bbox)
const otherFeaturess = params.getProbablyOverlapsWith(layerId, bbox)
if (otherFeaturess === undefined) {
continue
}

View file

@ -27,6 +27,19 @@ export default class GeoIndexedStore implements FeatureSource {
const bboxFeature = bbox.asGeojsonCached()
return this.features.data.filter((f) => GeoOperations.completelyWithin(f, bboxFeature))
}
/**
* Gets the current features within the given bbox.
*
* @param bbox
* @constructor
*/
public GetFeaturesProbablyOverlappingWith(bbox: BBox): Feature[] {
return this.features.data.filter((f) => {
const fBbox = BBox.get(f)
return fBbox.overlapsWith(bbox)
})
}
}
export class GeoIndexedStoreForLayer extends GeoIndexedStore implements FeatureSourceForLayer {

View file

@ -290,8 +290,22 @@ export default class MetaTagging {
indexedFeatures: IndexedFeatureSource
perLayer: ReadonlyMap<string, GeoIndexedStoreForLayer>
}) {
return {
return <ExtraFuncParams>{
getFeatureById: (id) => state.indexedFeatures.featuresById.data.get(id),
getProbablyOverlapsWith: (layerId, bbox) => {
if (layerId === "*" || layerId === null || layerId === undefined) {
const feats: Feature[][] = []
state.perLayer.forEach((layer) => {
feats.push(layer.GetFeaturesWithin(bbox))
})
return feats
}
if (!state.perLayer.get(layerId)) {
// This layer is not loaded
return []
}
return [state.perLayer.get(layerId).GetFeaturesProbablyOverlappingWith(bbox)]
},
getFeaturesWithin: (layerId, bbox) => {
if (layerId === "*" || layerId === null || layerId === undefined) {
const feats: Feature[][] = []

View file

@ -278,7 +278,6 @@ class LineRenderingLayer {
}
})
features.features.addCallbackAndRunD(async (feats) => {
console.log("New features!", this._layername, feats)
updateNeededSrc.set(true)
this.update(feats)
})