| 
									
										
										
										
											2020-06-29 03:12:44 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Asks to add a feature at the last clicked location, at least if zoom is sufficient | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2023-01-06 03:37:22 +01:00
										 |  |  | import { Store, UIEventSource } from "../../Logic/UIEventSource" | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | import Svg from "../../Svg" | 
					
						
							|  |  |  | import { SubtleButton } from "../Base/SubtleButton" | 
					
						
							|  |  |  | import Combine from "../Base/Combine" | 
					
						
							|  |  |  | import Translations from "../i18n/Translations" | 
					
						
							|  |  |  | import Constants from "../../Models/Constants" | 
					
						
							|  |  |  | import { TagUtils } from "../../Logic/Tags/TagUtils" | 
					
						
							|  |  |  | import BaseUIElement from "../BaseUIElement" | 
					
						
							|  |  |  | import { VariableUiElement } from "../Base/VariableUIElement" | 
					
						
							|  |  |  | import Toggle from "../Input/Toggle" | 
					
						
							|  |  |  | import UserDetails, { OsmConnection } from "../../Logic/Osm/OsmConnection" | 
					
						
							|  |  |  | import CreateNewNodeAction from "../../Logic/Osm/Actions/CreateNewNodeAction" | 
					
						
							|  |  |  | import { OsmObject, OsmWay } from "../../Logic/Osm/OsmObject" | 
					
						
							|  |  |  | import PresetConfig from "../../Models/ThemeConfig/PresetConfig" | 
					
						
							|  |  |  | import FilteredLayer from "../../Models/FilteredLayer" | 
					
						
							|  |  |  | import Loc from "../../Models/Loc" | 
					
						
							|  |  |  | import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig" | 
					
						
							|  |  |  | import { Changes } from "../../Logic/Osm/Changes" | 
					
						
							|  |  |  | import FeaturePipeline from "../../Logic/FeatureSource/FeaturePipeline" | 
					
						
							|  |  |  | import { ElementStorage } from "../../Logic/ElementStorage" | 
					
						
							|  |  |  | import ConfirmLocationOfPoint from "../NewPoint/ConfirmLocationOfPoint" | 
					
						
							|  |  |  | import BaseLayer from "../../Models/BaseLayer" | 
					
						
							|  |  |  | import Loading from "../Base/Loading" | 
					
						
							|  |  |  | import Hash from "../../Logic/Web/Hash" | 
					
						
							|  |  |  | import { GlobalFilter } from "../../Logic/State/MapState" | 
					
						
							| 
									
										
										
										
											2022-10-27 01:50:41 +02:00
										 |  |  | import { WayId } from "../../Models/OsmFeature" | 
					
						
							| 
									
										
										
										
											2022-11-08 14:37:48 +01:00
										 |  |  | import { Tag } from "../../Logic/Tags/Tag" | 
					
						
							| 
									
										
										
										
											2023-01-06 03:37:22 +01:00
										 |  |  | import { LoginToggle } from "../Popup/LoginButton" | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |  * The SimpleAddUI is a single panel, which can have multiple states: | 
					
						
							|  |  |  |  * - A list of presets which can be added by the user | 
					
						
							|  |  |  |  * - A 'confirm-selection' button (or alternatively: please enable the layer) | 
					
						
							|  |  |  |  * - A 'something is wrong - please soom in further' | 
					
						
							|  |  |  |  * - A 'read your unread messages before adding a point' | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-01-04 04:06:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-31 02:08:39 +01:00
										 |  |  | export interface PresetInfo extends PresetConfig { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     name: string | BaseUIElement | 
					
						
							|  |  |  |     icon: () => BaseUIElement | 
					
						
							|  |  |  |     layerToAddTo: FilteredLayer | 
					
						
							| 
									
										
										
										
											2022-01-25 21:55:51 +01:00
										 |  |  |     boundsFactor?: 0.25 | number | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-01-08 16:49:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-06 03:37:22 +01:00
										 |  |  | export default class SimpleAddUI extends LoginToggle { | 
					
						
							| 
									
										
										
										
											2022-07-18 00:28:26 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-07-18 00:28:26 +02:00
										 |  |  |      * @param isShown | 
					
						
							|  |  |  |      * @param resetScrollSignal | 
					
						
							|  |  |  |      * @param filterViewIsOpened | 
					
						
							|  |  |  |      * @param state | 
					
						
							|  |  |  |      * @param takeLocationFrom: defaults to state.lastClickLocation. Take this location to add the new point around | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     constructor( | 
					
						
							|  |  |  |         isShown: UIEventSource<boolean>, | 
					
						
							|  |  |  |         resetScrollSignal: UIEventSource<void>, | 
					
						
							|  |  |  |         filterViewIsOpened: UIEventSource<boolean>, | 
					
						
							|  |  |  |         state: { | 
					
						
							|  |  |  |             featureSwitchIsTesting: UIEventSource<boolean> | 
					
						
							| 
									
										
										
										
											2023-01-06 03:37:22 +01:00
										 |  |  |             featureSwitchUserbadge: Store<boolean> | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             layoutToUse: LayoutConfig | 
					
						
							|  |  |  |             osmConnection: OsmConnection | 
					
						
							|  |  |  |             changes: Changes | 
					
						
							|  |  |  |             allElements: ElementStorage | 
					
						
							|  |  |  |             LastClickLocation: UIEventSource<{ lat: number; lon: number }> | 
					
						
							|  |  |  |             featurePipeline: FeaturePipeline | 
					
						
							|  |  |  |             selectedElement: UIEventSource<any> | 
					
						
							|  |  |  |             locationControl: UIEventSource<Loc> | 
					
						
							|  |  |  |             filteredLayers: UIEventSource<FilteredLayer[]> | 
					
						
							|  |  |  |             featureSwitchFilter: UIEventSource<boolean> | 
					
						
							|  |  |  |             backgroundLayer: UIEventSource<BaseLayer> | 
					
						
							|  |  |  |             globalFilters: UIEventSource<GlobalFilter[]> | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         takeLocationFrom?: UIEventSource<{ lat: number; lon: number }> | 
					
						
							| 
									
										
										
										
											2022-07-18 00:28:26 +02:00
										 |  |  |     ) { | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |         const readYourMessages = new Combine([ | 
					
						
							|  |  |  |             Translations.t.general.readYourMessages.Clone().SetClass("alert"), | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             new SubtleButton(Svg.envelope_ui(), Translations.t.general.goToInbox, { | 
					
						
							|  |  |  |                 url: "https://www.openstreetmap.org/messages/inbox", | 
					
						
							|  |  |  |                 newTab: false, | 
					
						
							|  |  |  |             }), | 
					
						
							|  |  |  |         ]) | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-18 00:28:26 +02:00
										 |  |  |         takeLocationFrom = takeLocationFrom ?? state.LastClickLocation | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         const selectedPreset = new UIEventSource<PresetInfo>(undefined) | 
					
						
							|  |  |  |         selectedPreset.addCallback((_) => { | 
					
						
							|  |  |  |             resetScrollSignal.ping() | 
					
						
							| 
									
										
										
										
											2022-02-09 00:35:59 +01:00
										 |  |  |         }) | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         isShown.addCallback((_) => selectedPreset.setData(undefined)) // Clear preset selection when the UI is closed/opened
 | 
					
						
							|  |  |  |         takeLocationFrom.addCallback((_) => selectedPreset.setData(undefined)) | 
					
						
							| 
									
										
										
										
											2021-08-07 21:19:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         const presetsOverview = SimpleAddUI.CreateAllPresetsPanel(selectedPreset, state) | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         async function createNewPoint( | 
					
						
							| 
									
										
										
										
											2022-11-07 23:12:31 +01:00
										 |  |  |             tags: Tag[], | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             location: { lat: number; lon: number }, | 
					
						
							|  |  |  |             snapOntoWay?: OsmWay | 
					
						
							|  |  |  |         ): Promise<void> { | 
					
						
							| 
									
										
										
										
											2023-01-09 20:56:39 +01:00
										 |  |  |             tags.push(new Tag(Tag.newlyCreated.key, new Date().toISOString())) | 
					
						
							| 
									
										
										
										
											2023-01-29 13:31:49 +01:00
										 |  |  |             if (snapOntoWay) { | 
					
						
							|  |  |  |                 tags.push(new Tag("_referencing_ways", "way/" + snapOntoWay.id)) | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-10-04 03:12:42 +02:00
										 |  |  |             const newElementAction = new CreateNewNodeAction(tags, location.lat, location.lon, { | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |                 theme: state.layoutToUse?.id ?? "unkown", | 
					
						
							| 
									
										
										
										
											2021-10-04 03:12:42 +02:00
										 |  |  |                 changeType: "create", | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 snapOnto: snapOntoWay, | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |             }) | 
					
						
							|  |  |  |             await state.changes.applyAction(newElementAction) | 
					
						
							| 
									
										
										
										
											2021-08-07 21:19:01 +02:00
										 |  |  |             selectedPreset.setData(undefined) | 
					
						
							|  |  |  |             isShown.setData(false) | 
					
						
							| 
									
										
										
										
											2022-11-08 14:37:48 +01:00
										 |  |  |             const selectedFeature = state.allElements.ContainingFeatures.get( | 
					
						
							|  |  |  |                 newElementAction.newElementId | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2022-11-07 23:12:31 +01:00
										 |  |  |             state.selectedElement.setData(selectedFeature) | 
					
						
							| 
									
										
										
										
											2022-03-23 12:42:47 +01:00
										 |  |  |             Hash.hash.setData(newElementAction.newElementId) | 
					
						
							| 
									
										
										
										
											2021-08-07 21:19:01 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |         const addUi = new VariableUiElement( | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             selectedPreset.map((preset) => { | 
					
						
							|  |  |  |                 if (preset === undefined) { | 
					
						
							|  |  |  |                     return presetsOverview | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-10-31 02:08:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 function confirm( | 
					
						
							|  |  |  |                     tags: any[], | 
					
						
							|  |  |  |                     location: { lat: number; lon: number }, | 
					
						
							| 
									
										
										
										
											2022-09-21 02:21:20 +02:00
										 |  |  |                     snapOntoWayId?: WayId | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 ) { | 
					
						
							|  |  |  |                     if (snapOntoWayId === undefined) { | 
					
						
							|  |  |  |                         createNewPoint(tags, location, undefined) | 
					
						
							|  |  |  |                     } else { | 
					
						
							|  |  |  |                         OsmObject.DownloadObject(snapOntoWayId).addCallbackAndRunD((way) => { | 
					
						
							| 
									
										
										
										
											2022-09-21 02:21:20 +02:00
										 |  |  |                             createNewPoint(tags, location, way) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                             return true | 
					
						
							|  |  |  |                         }) | 
					
						
							| 
									
										
										
										
											2021-10-31 02:08:39 +01:00
										 |  |  |                     } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-10-31 02:08:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 function cancel() { | 
					
						
							|  |  |  |                     selectedPreset.setData(undefined) | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 const message = Translations.t.general.add.addNew.Subs( | 
					
						
							|  |  |  |                     { category: preset.name }, | 
					
						
							|  |  |  |                     preset.name["context"] | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |                 return new ConfirmLocationOfPoint( | 
					
						
							|  |  |  |                     state, | 
					
						
							|  |  |  |                     filterViewIsOpened, | 
					
						
							|  |  |  |                     preset, | 
					
						
							|  |  |  |                     message, | 
					
						
							|  |  |  |                     takeLocationFrom.data, | 
					
						
							|  |  |  |                     confirm, | 
					
						
							|  |  |  |                     cancel, | 
					
						
							|  |  |  |                     () => { | 
					
						
							|  |  |  |                         isShown.setData(false) | 
					
						
							| 
									
										
										
										
											2022-11-14 01:22:38 +01:00
										 |  |  |                     }, | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         cancelIcon: Svg.back_svg(), | 
					
						
							| 
									
										
										
										
											2022-11-14 01:29:22 +01:00
										 |  |  |                         cancelText: Translations.t.general.add.backToSelect, | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                     } | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         super( | 
					
						
							|  |  |  |             new Toggle( | 
					
						
							|  |  |  |                 new Toggle( | 
					
						
							|  |  |  |                     new Toggle( | 
					
						
							| 
									
										
										
										
											2022-01-25 21:55:51 +01:00
										 |  |  |                         new Loading(Translations.t.general.add.stillLoading).SetClass("alert"), | 
					
						
							| 
									
										
										
										
											2021-10-20 19:12:28 +02:00
										 |  |  |                         addUi, | 
					
						
							|  |  |  |                         state.featurePipeline.runningQuery | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |                     ), | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  |                     Translations.t.general.add.zoomInFurther.Clone().SetClass("alert"), | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                     state.locationControl.map( | 
					
						
							|  |  |  |                         (loc) => loc.zoom >= Constants.userJourney.minZoomLevelToAddNewPoints | 
					
						
							|  |  |  |                     ) | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |                 ), | 
					
						
							|  |  |  |                 readYourMessages, | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 state.osmConnection.userDetails.map( | 
					
						
							|  |  |  |                     (userdetails: UserDetails) => | 
					
						
							|  |  |  |                         userdetails.csCount >= | 
					
						
							|  |  |  |                             Constants.userJourney.addNewPointWithUnreadMessagesUnlock || | 
					
						
							|  |  |  |                         userdetails.unreadMessages == 0 | 
					
						
							|  |  |  |                 ) | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |             ), | 
					
						
							| 
									
										
										
										
											2023-01-06 03:37:22 +01:00
										 |  |  |             Translations.t.general.add.pleaseLogin, | 
					
						
							|  |  |  |             state | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-01-08 16:49:42 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     public static CreateTagInfoFor( | 
					
						
							|  |  |  |         preset: PresetInfo, | 
					
						
							|  |  |  |         osmConnection: OsmConnection, | 
					
						
							|  |  |  |         optionallyLinkToWiki = true | 
					
						
							|  |  |  |     ) { | 
					
						
							|  |  |  |         const csCount = osmConnection.userDetails.data.csCount | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |         return new Toggle( | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             Translations.t.general.add.presetInfo | 
					
						
							|  |  |  |                 .Subs({ | 
					
						
							|  |  |  |                     tags: preset.tags | 
					
						
							|  |  |  |                         .map((t) => | 
					
						
							|  |  |  |                             t.asHumanString( | 
					
						
							|  |  |  |                                 optionallyLinkToWiki && | 
					
						
							|  |  |  |                                     csCount > Constants.userJourney.tagsVisibleAndWikiLinked, | 
					
						
							|  |  |  |                                 true | 
					
						
							|  |  |  |                             ) | 
					
						
							|  |  |  |                         ) | 
					
						
							|  |  |  |                         .join("&"), | 
					
						
							|  |  |  |                 }) | 
					
						
							|  |  |  |                 .SetStyle("word-break: break-all"), | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             undefined, | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             osmConnection.userDetails.map( | 
					
						
							|  |  |  |                 (userdetails) => userdetails.csCount >= Constants.userJourney.tagsVisibleAt | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-01-08 16:49:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     private static CreateAllPresetsPanel( | 
					
						
							|  |  |  |         selectedPreset: UIEventSource<PresetInfo>, | 
					
						
							|  |  |  |         state: { | 
					
						
							|  |  |  |             featureSwitchIsTesting: UIEventSource<boolean> | 
					
						
							|  |  |  |             filteredLayers: UIEventSource<FilteredLayer[]> | 
					
						
							|  |  |  |             featureSwitchFilter: UIEventSource<boolean> | 
					
						
							|  |  |  |             osmConnection: OsmConnection | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     ): BaseUIElement { | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |         const presetButtons = SimpleAddUI.CreatePresetButtons(state, selectedPreset) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         let intro: BaseUIElement = Translations.t.general.add.intro | 
					
						
							| 
									
										
										
										
											2021-01-08 16:49:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         let testMode: BaseUIElement = new Toggle( | 
					
						
							|  |  |  |             Translations.t.general.testing.SetClass("alert"), | 
					
						
							| 
									
										
										
										
											2022-01-21 01:57:16 +01:00
										 |  |  |             undefined, | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             state.featureSwitchIsTesting | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-01-08 16:49:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |         return new Combine([intro, testMode, presetButtons]).SetClass("flex flex-col") | 
					
						
							| 
									
										
										
										
											2021-01-08 16:49:42 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-09 03:38:40 +01:00
										 |  |  |     private static CreatePresetSelectButton(preset: PresetInfo) { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         const title = Translations.t.general.add.addNew.Subs( | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 category: preset.name, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             preset.name["context"] | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |         return new SubtleButton( | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  |             preset.icon(), | 
					
						
							| 
									
										
										
										
											2021-01-08 16:49:42 +01:00
										 |  |  |             new Combine([ | 
					
						
							| 
									
										
										
										
											2022-04-01 12:51:55 +02:00
										 |  |  |                 title.SetClass("font-bold"), | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 preset.description?.FirstSentence(), | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |             ]).SetClass("flex flex-col") | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-01-08 16:49:42 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |      * Generates the list with all the buttons.*/ | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |     private static CreatePresetButtons( | 
					
						
							|  |  |  |         state: { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             filteredLayers: UIEventSource<FilteredLayer[]> | 
					
						
							|  |  |  |             featureSwitchFilter: UIEventSource<boolean> | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |             osmConnection: OsmConnection | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         selectedPreset: UIEventSource<PresetInfo> | 
					
						
							|  |  |  |     ): BaseUIElement { | 
					
						
							|  |  |  |         const allButtons = [] | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |         for (const layer of state.filteredLayers.data) { | 
					
						
							| 
									
										
										
										
											2022-04-19 00:57:36 +02:00
										 |  |  |             if (layer.isDisplayed.data === false) { | 
					
						
							|  |  |  |                 // The layer is not displayed...
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 if (!state.featureSwitchFilter.data) { | 
					
						
							| 
									
										
										
										
											2022-04-19 00:57:36 +02:00
										 |  |  |                     // ...and we cannot enable the layer control -> we skip, as these presets can never be shown anyway
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                     continue | 
					
						
							| 
									
										
										
										
											2022-04-19 00:57:36 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-08-07 21:19:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-19 00:57:36 +02:00
										 |  |  |                 if (layer.layerDef.name === undefined) { | 
					
						
							|  |  |  |                     // this layer can never be toggled on in any case, so we skip the presets
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                     continue | 
					
						
							| 
									
										
										
										
											2022-04-19 00:57:36 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |             const presets = layer.layerDef.presets | 
					
						
							| 
									
										
										
										
											2020-10-30 00:56:46 +01:00
										 |  |  |             for (const preset of presets) { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 const tags = TagUtils.KVtoProperties(preset.tags ?? []) | 
					
						
							|  |  |  |                 let icon: () => BaseUIElement = () => | 
					
						
							|  |  |  |                     layer.layerDef.mapRendering[0] | 
					
						
							|  |  |  |                         .GenerateLeafletStyle(new UIEventSource<any>(tags), false) | 
					
						
							|  |  |  |                         .html.SetClass("w-12 h-12 block relative") | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |                 const presetInfo: PresetInfo = { | 
					
						
							|  |  |  |                     layerToAddTo: layer, | 
					
						
							|  |  |  |                     name: preset.title, | 
					
						
							| 
									
										
										
										
											2021-08-07 21:19:01 +02:00
										 |  |  |                     title: preset.title, | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  |                     icon: icon, | 
					
						
							| 
									
										
										
										
											2022-02-09 03:38:40 +01:00
										 |  |  |                     preciseInput: preset.preciseInput, | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                     ...preset, | 
					
						
							| 
									
										
										
										
											2020-08-22 18:57:27 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 const button = SimpleAddUI.CreatePresetSelectButton(presetInfo) | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |                 button.onClick(() => { | 
					
						
							|  |  |  |                     selectedPreset.setData(presetInfo) | 
					
						
							|  |  |  |                 }) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 allButtons.push(button) | 
					
						
							| 
									
										
										
										
											2020-07-31 16:17:16 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-06-29 03:12:44 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         return new Combine(allButtons).SetClass("flex flex-col") | 
					
						
							| 
									
										
										
										
											2020-06-29 03:12:44 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | } |