forked from MapComplete/MapComplete
Refactoring: stabilize touchingFeatureSource
This commit is contained in:
parent
7fd7a3722e
commit
06631ccd6d
5 changed files with 32 additions and 17 deletions
|
@ -1,28 +1,40 @@
|
|||
import {FeatureSource, FeatureSourceForLayer } from "../FeatureSource"
|
||||
import { FeatureSource, FeatureSourceForLayer } from "../FeatureSource"
|
||||
import StaticFeatureSource from "./StaticFeatureSource"
|
||||
import { GeoOperations } from "../../GeoOperations"
|
||||
import { BBox } from "../../BBox"
|
||||
import FilteredLayer from "../../../Models/FilteredLayer"
|
||||
import { Store } from "../../UIEventSource"
|
||||
|
||||
/**
|
||||
* Results in a feature source which has all the elements that touch the given features
|
||||
*/
|
||||
export default class BBoxFeatureSource extends StaticFeatureSource {
|
||||
constructor(features: FeatureSource, mustTouch: BBox) {
|
||||
const bbox = mustTouch.asGeoJson({})
|
||||
constructor(features: FeatureSource, mustTouch: Store<BBox>) {
|
||||
super(
|
||||
features.features.mapD((features) =>
|
||||
features.filter((feature) => GeoOperations.intersect(feature, bbox) !== undefined)
|
||||
features.features.mapD(
|
||||
(features) => {
|
||||
if (mustTouch.data === undefined) {
|
||||
return features
|
||||
}
|
||||
console.log("UPdating touching bbox")
|
||||
const box = mustTouch.data
|
||||
return features.filter((feature) => {
|
||||
if (feature.geometry.type === "Point") {
|
||||
return box.contains(<[number, number]>feature.geometry.coordinates)
|
||||
}
|
||||
return box.overlapsWith(BBox.get(feature))
|
||||
})
|
||||
},
|
||||
[mustTouch]
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export class BBoxFeatureSourceForLayer extends BBoxFeatureSource implements FeatureSourceForLayer {
|
||||
constructor(features: FeatureSourceForLayer, mustTouch: BBox) {
|
||||
readonly layer: FilteredLayer
|
||||
|
||||
constructor(features: FeatureSourceForLayer, mustTouch: Store<BBox>) {
|
||||
super(features, mustTouch)
|
||||
this.layer = features.layer
|
||||
}
|
||||
|
||||
readonly layer: FilteredLayer
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue