From 466dd165688739fe6900dfdb63e8e788e6ee0225 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Fri, 14 Apr 2023 00:12:15 +0200 Subject: [PATCH] Fix contributor count --- Logic/BBox.ts | 11 +++++++++-- Logic/FeatureSource/Actors/GeoIndexedStore.ts | 13 ++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Logic/BBox.ts b/Logic/BBox.ts index 3a1dc9e34..32f02acfa 100644 --- a/Logic/BBox.ts +++ b/Logic/BBox.ts @@ -225,10 +225,17 @@ export class BBox { ] } - public asGeoJson(properties: T): Feature { + public asGeojsonCached() { + if (this["geojsonCache"] === undefined) { + this["geojsonCache"] = this.asGeoJson({}) + } + return this["geojsonCache"] + } + + public asGeoJson(properties?: T): Feature { return { type: "Feature", - properties, + properties: properties, geometry: this.asGeometry(), } } diff --git a/Logic/FeatureSource/Actors/GeoIndexedStore.ts b/Logic/FeatureSource/Actors/GeoIndexedStore.ts index 39eb02f58..a4f91eb33 100644 --- a/Logic/FeatureSource/Actors/GeoIndexedStore.ts +++ b/Logic/FeatureSource/Actors/GeoIndexedStore.ts @@ -25,11 +25,22 @@ export default class GeoIndexedStore implements FeatureSource { */ public GetFeaturesWithin(bbox: BBox): Feature[] { // TODO optimize - const bboxFeature = bbox.asGeoJson({}) + const bboxFeature = bbox.asGeojsonCached() return this.features.data.filter((f) => { if (f.geometry.type === "Point") { return bbox.contains(<[number, number]>f.geometry.coordinates) } + if (f.geometry.type === "LineString") { + const intersection = GeoOperations.intersect( + BBox.get(f).asGeojsonCached(), + bboxFeature + ) + return intersection !== undefined + } + if (f.geometry.type === "Polygon" || f.geometry.type === "MultiPolygon") { + return GeoOperations.intersect(f, bboxFeature) !== undefined + } + console.log("Calculating intersection between", bboxFeature, "and", f) return GeoOperations.intersect(f, bboxFeature) !== undefined }) }