forked from MapComplete/MapComplete
More refactoring, move minimap behind facade
This commit is contained in:
parent
c11ff652b8
commit
d5c1ba4cd1
79 changed files with 1848 additions and 1118 deletions
|
@ -1,21 +1,49 @@
|
|||
/// Given a feature source, calculates a list of OSM-contributors who mapped the latest versions
|
||||
import FeatureSource from "./FeatureSource/FeatureSource";
|
||||
import {UIEventSource} from "./UIEventSource";
|
||||
import FeaturePipeline from "./FeatureSource/FeaturePipeline";
|
||||
import Loc from "../Models/Loc";
|
||||
import State from "../State";
|
||||
import {BBox} from "./GeoOperations";
|
||||
|
||||
export default class ContributorCount {
|
||||
|
||||
public readonly Contributors: UIEventSource<Map<string, number>>;
|
||||
public readonly Contributors: UIEventSource<Map<string, number>> = new UIEventSource<Map<string, number>>(new Map<string, number>());
|
||||
private readonly state: { featurePipeline: FeaturePipeline, currentBounds: UIEventSource<BBox>, locationControl: UIEventSource<Loc> };
|
||||
|
||||
constructor(featureSource: FeatureSource) {
|
||||
this.Contributors = featureSource.features.map(features => {
|
||||
const hist = new Map<string, number>();
|
||||
for (const feature of features) {
|
||||
const contributor = feature.feature.properties["_last_edit:contributor"]
|
||||
constructor(state: { featurePipeline: FeaturePipeline, currentBounds: UIEventSource<BBox>, locationControl: UIEventSource<Loc> }) {
|
||||
this.state = state;
|
||||
const self = this;
|
||||
state.currentBounds.map(bbox => {
|
||||
self.update(bbox)
|
||||
})
|
||||
state.featurePipeline.runningQuery.addCallbackAndRun(
|
||||
_ => self.update(state.currentBounds.data)
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
private lastUpdate: Date = undefined;
|
||||
|
||||
private update(bbox: BBox) {
|
||||
if(bbox === undefined){
|
||||
return;
|
||||
}
|
||||
const now = new Date();
|
||||
if (this.lastUpdate !== undefined && ((now.getTime() - this.lastUpdate.getTime()) < 1000 * 60)) {
|
||||
return;
|
||||
}
|
||||
console.log("Calculating contributors")
|
||||
const featuresList = this.state.featurePipeline.GetAllFeaturesWithin(bbox)
|
||||
const hist = new Map<string, number>();
|
||||
for (const list of featuresList) {
|
||||
for (const feature of list) {
|
||||
const contributor = feature.properties["_last_edit:contributor"]
|
||||
const count = hist.get(contributor) ?? 0;
|
||||
hist.set(contributor, count + 1)
|
||||
}
|
||||
return hist;
|
||||
})
|
||||
}
|
||||
this.Contributors.setData(hist)
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue