Wire in level selector

This commit is contained in:
Pieter Vander Vennet 2022-07-21 15:54:24 +02:00
parent 0d3e7f8168
commit 13e949a1cd
4 changed files with 126 additions and 26 deletions

View file

@ -4,10 +4,15 @@ import MapControlButton from "../MapControlButton";
import GeoLocationHandler from "../../Logic/Actors/GeoLocationHandler";
import Svg from "../../Svg";
import MapState from "../../Logic/State/MapState";
import {VariableUiElement} from "../Base/VariableUIElement";
import LevelSelector from "../Input/LevelSelector";
import {UIEventSource} from "../../Logic/UIEventSource";
import FeaturePipeline from "../../Logic/FeatureSource/FeaturePipeline";
import {Utils} from "../../Utils";
export default class RightControls extends Combine {
constructor(state: MapState) {
constructor(state: MapState & { featurePipeline: FeaturePipeline }) {
const geolocatioHandler = new GeoLocationHandler(
state
@ -38,7 +43,26 @@ export default class RightControls extends Combine {
state.locationControl.ping();
});
super([plus, min, geolocationButton].map(el => el.SetClass("m-0.5 md:m-1")))
const levelsInView = state.currentBounds.map(bbox => {
if(bbox === undefined){
return []
}
const allElements = state.featurePipeline.GetAllFeaturesAndMetaWithin(bbox);
const allLevelsRaw: string[] = [].concat(...allElements.map(allElements => allElements.features.map(f => <string>f.properties["level"])))
const allLevels = [].concat(...allLevelsRaw.map(l => LevelSelector.LevelsParser(l)))
return Utils.Dedup(allLevels)
})
const levelSelect = new LevelSelector(levelsInView)
levelsInView.addCallbackAndRun(levelsInView => {
if(levelsInView.length <= 1){
levelSelect.SetClass("invisible")
}else{
levelSelect.RemoveClass("invisible")
}
})
super([levelSelect, plus, min, geolocationButton].map(el => el.SetClass("m-0.5 md:m-1")))
this.SetClass("flex flex-col items-center")
}