forked from MapComplete/MapComplete
Fix contributor count
This commit is contained in:
parent
43601987dc
commit
466dd16568
2 changed files with 21 additions and 3 deletions
|
@ -225,10 +225,17 @@ export class BBox {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
public asGeoJson<T>(properties: T): Feature<Polygon, T> {
|
public asGeojsonCached() {
|
||||||
|
if (this["geojsonCache"] === undefined) {
|
||||||
|
this["geojsonCache"] = this.asGeoJson({})
|
||||||
|
}
|
||||||
|
return this["geojsonCache"]
|
||||||
|
}
|
||||||
|
|
||||||
|
public asGeoJson<T = {}>(properties?: T): Feature<Polygon, T> {
|
||||||
return {
|
return {
|
||||||
type: "Feature",
|
type: "Feature",
|
||||||
properties,
|
properties: properties,
|
||||||
geometry: this.asGeometry(),
|
geometry: this.asGeometry(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,11 +25,22 @@ export default class GeoIndexedStore implements FeatureSource {
|
||||||
*/
|
*/
|
||||||
public GetFeaturesWithin(bbox: BBox): Feature[] {
|
public GetFeaturesWithin(bbox: BBox): Feature[] {
|
||||||
// TODO optimize
|
// TODO optimize
|
||||||
const bboxFeature = bbox.asGeoJson({})
|
const bboxFeature = bbox.asGeojsonCached()
|
||||||
return this.features.data.filter((f) => {
|
return this.features.data.filter((f) => {
|
||||||
if (f.geometry.type === "Point") {
|
if (f.geometry.type === "Point") {
|
||||||
return bbox.contains(<[number, number]>f.geometry.coordinates)
|
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
|
return GeoOperations.intersect(f, bboxFeature) !== undefined
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue