mapcomplete/UI/BigComponents/RightControls.ts

68 lines
2.3 KiB
TypeScript
Raw Normal View History

2021-07-28 16:48:59 +02:00
import Combine from "../Base/Combine";
import Toggle from "../Input/Toggle";
import MapControlButton from "../MapControlButton";
import GeoLocationHandler from "../../Logic/Actors/GeoLocationHandler";
import Svg from "../../Svg";
import MapState from "../../Logic/State/MapState";
2022-07-21 15:54:24 +02:00
import LevelSelector from "../Input/LevelSelector";
import FeaturePipeline from "../../Logic/FeatureSource/FeaturePipeline";
import {Utils} from "../../Utils";
2021-07-28 16:48:59 +02:00
export default class RightControls extends Combine {
2022-07-21 15:54:24 +02:00
constructor(state: MapState & { featurePipeline: FeaturePipeline }) {
2021-11-07 16:34:51 +01:00
const geolocatioHandler = new GeoLocationHandler(
state
)
2021-11-07 16:34:51 +01:00
2021-07-28 16:48:59 +02:00
const geolocationButton = new Toggle(
new MapControlButton(
geolocatioHandler
, {
2021-07-28 16:48:59 +02:00
dontStyle: true
}
),
undefined,
state.featureSwitchGeolocation
2021-07-28 16:48:59 +02:00
);
const plus = new MapControlButton(
2021-08-20 00:06:44 +02:00
Svg.plus_svg()
2021-07-28 16:48:59 +02:00
).onClick(() => {
state.locationControl.data.zoom++;
state.locationControl.ping();
2021-07-28 16:48:59 +02:00
});
const min = new MapControlButton(
2021-08-20 00:06:44 +02:00
Svg.min_svg()
2021-07-28 16:48:59 +02:00
).onClick(() => {
state.locationControl.data.zoom--;
state.locationControl.ping();
2021-07-28 16:48:59 +02:00
});
2022-07-21 15:54:24 +02:00
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)))
2022-07-21 19:18:11 +02:00
allLevels.sort((a,b) => a < b ? -1 : 1)
2022-07-21 15:54:24 +02:00
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")
2021-07-28 16:48:59 +02:00
}
}