forked from MapComplete/MapComplete
Refactoring: move all code files into a src directory
This commit is contained in:
parent
de99f56ca8
commit
e75d2789d2
389 changed files with 0 additions and 12 deletions
43
src/Logic/FeatureSource/Sources/TouchesBboxFeatureSource.ts
Normal file
43
src/Logic/FeatureSource/Sources/TouchesBboxFeatureSource.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import { FeatureSource, FeatureSourceForLayer } from "../FeatureSource"
|
||||
import StaticFeatureSource from "./StaticFeatureSource"
|
||||
import { BBox } from "../../BBox"
|
||||
import FilteredLayer from "../../../Models/FilteredLayer"
|
||||
import { Store } from "../../UIEventSource"
|
||||
import { Feature } from "geojson"
|
||||
|
||||
/**
|
||||
* Results in a feature source which has all the elements that touch the given features
|
||||
*/
|
||||
export default class BBoxFeatureSource<T extends Feature = Feature> extends StaticFeatureSource<T> {
|
||||
constructor(features: FeatureSource<T>, mustTouch: Store<BBox>) {
|
||||
super(
|
||||
features.features.mapD(
|
||||
(features) => {
|
||||
if (mustTouch.data === undefined) {
|
||||
return features
|
||||
}
|
||||
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<T extends Feature = Feature>
|
||||
extends BBoxFeatureSource<T>
|
||||
implements FeatureSourceForLayer
|
||||
{
|
||||
readonly layer: FilteredLayer
|
||||
|
||||
constructor(features: FeatureSourceForLayer<T>, mustTouch: Store<BBox>) {
|
||||
super(features, mustTouch)
|
||||
this.layer = features.layer
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue