forked from MapComplete/MapComplete
Further refactoring fullscreenelement: removal of hash handling from showDataLayer
This commit is contained in:
parent
e2e48344d6
commit
593ac5381a
7 changed files with 125 additions and 114 deletions
|
@ -1,19 +0,0 @@
|
|||
import {UIEventSource} from "../UIEventSource";
|
||||
import {UIElement} from "../../UI/UIElement";
|
||||
|
||||
export default class HistoryHandling {
|
||||
|
||||
constructor(hash: UIEventSource<string>, fullscreenMessage: UIEventSource<{ content: UIElement, hashText: string }>) {
|
||||
hash.addCallback(h => {
|
||||
if (h === undefined || h === "") {
|
||||
fullscreenMessage.setData(undefined);
|
||||
}
|
||||
})
|
||||
|
||||
fullscreenMessage.addCallback(fs => {
|
||||
hash.setData(fs?.hashText);
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
51
Logic/Actors/SelectedFeatureHandler.ts
Normal file
51
Logic/Actors/SelectedFeatureHandler.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
import {UIEventSource} from "../UIEventSource";
|
||||
import {UIElement} from "../../UI/UIElement";
|
||||
import FeatureSource from "../FeatureSource/FeatureSource";
|
||||
|
||||
/**
|
||||
* Makes sure the hash shows the selected element and vice-versa
|
||||
*/
|
||||
export default class SelectedFeatureHandler {
|
||||
private readonly _featureSource: FeatureSource;
|
||||
private readonly _hash: UIEventSource<string>;
|
||||
private readonly _selectedFeature: UIEventSource<any>;
|
||||
|
||||
constructor(hash: UIEventSource<string>,
|
||||
selectedFeature: UIEventSource<any>,
|
||||
featureSource: FeatureSource) {
|
||||
this._hash = hash;
|
||||
this._selectedFeature = selectedFeature;
|
||||
this._featureSource = featureSource;
|
||||
const self = this;
|
||||
hash.addCallback(h => {
|
||||
if (h === undefined || h === "") {
|
||||
selectedFeature.setData(undefined);
|
||||
}else{
|
||||
self.selectFeature();
|
||||
}
|
||||
})
|
||||
|
||||
featureSource.features.addCallback(_ => self.selectFeature());
|
||||
|
||||
selectedFeature.addCallback(feature => {
|
||||
hash.setData(feature?.properties?.id ?? "");
|
||||
})
|
||||
|
||||
this.selectFeature();
|
||||
|
||||
}
|
||||
|
||||
private selectFeature(){
|
||||
const features = this._featureSource?.features?.data;
|
||||
if(features === undefined){
|
||||
return;
|
||||
}
|
||||
for (const feature of features) {
|
||||
const id = feature.feature?.properties?.id;
|
||||
if(id === this._hash.data){
|
||||
this._selectedFeature.setData(feature.feature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue