forked from MapComplete/MapComplete
refactoring
This commit is contained in:
parent
b94a8f5745
commit
5d0fe31c41
114 changed files with 2412 additions and 2958 deletions
|
@ -1,39 +1,31 @@
|
|||
/// Given a feature source, calculates a list of OSM-contributors who mapped the latest versions
|
||||
import { Store, UIEventSource } from "./UIEventSource"
|
||||
import FeaturePipeline from "./FeatureSource/FeaturePipeline"
|
||||
import Loc from "../Models/Loc"
|
||||
import { BBox } from "./BBox"
|
||||
import GeoIndexedStore from "./FeatureSource/Actors/GeoIndexedStore"
|
||||
|
||||
export default class ContributorCount {
|
||||
public readonly Contributors: UIEventSource<Map<string, number>> = new UIEventSource<
|
||||
Map<string, number>
|
||||
>(new Map<string, number>())
|
||||
private readonly state: {
|
||||
featurePipeline: FeaturePipeline
|
||||
currentBounds: Store<BBox>
|
||||
locationControl: Store<Loc>
|
||||
}
|
||||
private readonly perLayer: ReadonlyMap<string, GeoIndexedStore>
|
||||
private lastUpdate: Date = undefined
|
||||
|
||||
constructor(state: {
|
||||
featurePipeline: FeaturePipeline
|
||||
currentBounds: Store<BBox>
|
||||
locationControl: Store<Loc>
|
||||
bounds: Store<BBox>
|
||||
dataIsLoading: Store<boolean>
|
||||
perLayer: ReadonlyMap<string, GeoIndexedStore>
|
||||
}) {
|
||||
this.state = state
|
||||
this.perLayer = state.perLayer
|
||||
const self = this
|
||||
state.currentBounds.map((bbox) => {
|
||||
self.update(bbox)
|
||||
})
|
||||
state.featurePipeline.runningQuery.addCallbackAndRun((_) =>
|
||||
self.update(state.currentBounds.data)
|
||||
state.bounds.mapD(
|
||||
(bbox) => {
|
||||
self.update(bbox)
|
||||
},
|
||||
[state.dataIsLoading]
|
||||
)
|
||||
}
|
||||
|
||||
private update(bbox: BBox) {
|
||||
if (bbox === undefined) {
|
||||
return
|
||||
}
|
||||
const now = new Date()
|
||||
if (
|
||||
this.lastUpdate !== undefined &&
|
||||
|
@ -42,7 +34,9 @@ export default class ContributorCount {
|
|||
return
|
||||
}
|
||||
this.lastUpdate = now
|
||||
const featuresList = this.state.featurePipeline.GetAllFeaturesWithin(bbox)
|
||||
const featuresList = [].concat(
|
||||
Array.from(this.perLayer.values()).map((fs) => fs.GetFeaturesWithin(bbox))
|
||||
)
|
||||
const hist = new Map<string, number>()
|
||||
for (const list of featuresList) {
|
||||
for (const feature of list) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue