mapcomplete/UI/BigComponents/LeftControls.ts

149 lines
6 KiB
TypeScript
Raw Normal View History

2021-07-28 16:48:59 +02:00
import Combine from "../Base/Combine";
import ScrollableFullScreen from "../Base/ScrollableFullScreen";
import Translations from "../i18n/Translations";
import Toggle from "../Input/Toggle";
import MapControlButton from "../MapControlButton";
import Svg from "../../Svg";
import AllDownloads from "./AllDownloads";
import FilterView from "./FilterView";
import {UIEventSource} from "../../Logic/UIEventSource";
import FeaturePipeline from "../../Logic/FeatureSource/FeaturePipeline";
import Loc from "../../Models/Loc";
import {BBox} from "../../Logic/BBox";
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig";
import FilteredLayer from "../../Models/FilteredLayer";
import BaseLayer from "../../Models/BaseLayer";
import {OsmConnection} from "../../Logic/Osm/OsmConnection";
import BackgroundMapSwitch from "./BackgroundMapSwitch";
2021-12-10 17:30:50 +01:00
import {FeatureSourceForLayer} from "../../Logic/FeatureSource/FeatureSource";
import Lazy from "../Base/Lazy";
import {VariableUiElement} from "../Base/VariableUIElement";
import FeatureInfoBox from "../Popup/FeatureInfoBox";
import {ElementStorage} from "../../Logic/ElementStorage";
2021-07-28 16:48:59 +02:00
export default class LeftControls extends Combine {
constructor(state: {
2021-12-10 17:30:50 +01:00
allElements: ElementStorage;
currentView: FeatureSourceForLayer;
featureSwitchBackgroundSelection: UIEventSource<boolean>;
layoutToUse: LayoutConfig,
featurePipeline: FeaturePipeline,
currentBounds: UIEventSource<BBox>,
locationControl: UIEventSource<Loc>,
overlayToggles: any,
featureSwitchEnableExport: UIEventSource<boolean>,
featureSwitchExportAsPdf: UIEventSource<boolean>,
filteredLayers: UIEventSource<FilteredLayer[]>,
featureSwitchFilter: UIEventSource<boolean>,
backgroundLayer: UIEventSource<BaseLayer>,
osmConnection: OsmConnection
},
guiState: {
2021-12-10 17:30:50 +01:00
currentViewControlIsOpened: UIEventSource<boolean>;
downloadControlIsOpened: UIEventSource<boolean>,
filterViewIsOpened: UIEventSource<boolean>,
copyrightViewIsOpened: UIEventSource<boolean>
}) {
2021-07-28 16:48:59 +02:00
2021-12-10 17:30:50 +01:00
const currentViewFL = state.currentView?.layer
const currentViewAction = new Toggle(
new Lazy(() => {
const feature : UIEventSource<any> = state.currentView.features.map(ffs => ffs[0]?.feature)
const icon = new VariableUiElement(feature.map(feature => {
const defaultIcon = Svg.checkbox_empty_svg()
if (feature === undefined) {
return defaultIcon;
}
const tags = {...feature.properties, button: "yes"}
2021-12-11 02:19:28 +01:00
const elem = currentViewFL.layerDef.mapRendering[0]?.GenerateLeafletStyle(new UIEventSource(tags), false, {
2021-12-10 17:30:50 +01:00
noSize: true
})?.html
2021-12-11 02:19:28 +01:00
console.log("Elem is ", elem, "for", tags)
2021-12-10 17:30:50 +01:00
if(elem === undefined){
return defaultIcon
}
return elem
2021-12-11 02:19:28 +01:00
})).SetClass("inline-block w-full h-full")
2021-12-10 17:30:50 +01:00
const featureBox = new VariableUiElement(feature.map(feature => {
if(feature === undefined){return undefined}
return new Lazy(() => {
const tagsSource= state.allElements.getEventSourceById(feature.properties.id)
return new FeatureInfoBox(tagsSource, currentViewFL.layerDef, "currentview", guiState.currentViewControlIsOpened)
})
}))
return new Toggle(
featureBox,
new MapControlButton(icon),
guiState.currentViewControlIsOpened
)
2021-12-11 02:19:28 +01:00
}).onClick(() => {
2021-12-10 17:30:50 +01:00
guiState.currentViewControlIsOpened.setData(true)
}),
undefined,
new UIEventSource<boolean>(currentViewFL !== undefined && currentViewFL?.layerDef?.tagRenderings !== null)
)
2021-07-28 16:48:59 +02:00
const toggledDownload = new Toggle(
new AllDownloads(
guiState.downloadControlIsOpened
2021-07-28 16:48:59 +02:00
).SetClass("block p-1 rounded-full"),
new MapControlButton(Svg.download_svg())
.onClick(() => guiState.downloadControlIsOpened.setData(true)),
guiState.downloadControlIsOpened
)
2021-07-28 16:48:59 +02:00
const downloadButtonn = new Toggle(
toggledDownload,
undefined,
state.featureSwitchEnableExport.map(downloadEnabled => downloadEnabled || state.featureSwitchExportAsPdf.data,
[state.featureSwitchExportAsPdf])
2021-07-28 16:48:59 +02:00
);
const toggledFilter = new Toggle(
new ScrollableFullScreen(
() => Translations.t.general.layerSelection.title.Clone(),
() =>
new FilterView(state.filteredLayers, state.overlayToggles).SetClass(
"block p-1"
2021-07-28 16:48:59 +02:00
),
2021-10-25 20:50:59 +02:00
"filters",
guiState.filterViewIsOpened
).SetClass("rounded-lg"),
new MapControlButton(Svg.filter_svg())
.onClick(() => guiState.filterViewIsOpened.setData(true)),
guiState.filterViewIsOpened
)
2021-07-28 16:48:59 +02:00
const filterButton = new Toggle(
toggledFilter,
undefined,
state.featureSwitchFilter
2021-07-28 16:48:59 +02:00
);
2021-12-10 17:30:50 +01:00
const mapSwitch = new Toggle(
new BackgroundMapSwitch(state, state.backgroundLayer),
undefined,
state.featureSwitchBackgroundSelection
)
2021-07-28 16:48:59 +02:00
2021-12-10 17:30:50 +01:00
super([
currentViewAction,
filterButton,
2021-07-28 16:48:59 +02:00
downloadButtonn,
2021-12-10 17:30:50 +01:00
mapSwitch
])
2021-07-28 16:48:59 +02:00
this.SetClass("flex flex-col")
}
}