forked from MapComplete/MapComplete
		
	Themes(GRB): fix detection of overlapping buildings
This commit is contained in:
		
							parent
							
								
									915b732204
								
							
						
					
					
						commit
						6bdda9fb12
					
				
					 9 changed files with 34 additions and 184 deletions
				
			
		|  | @ -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 | ||||
|                 } | ||||
|  |  | |||
|  | @ -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 { | ||||
|  |  | |||
|  | @ -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[][] = [] | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue