| 
									
										
										
										
											2020-06-29 03:12:44 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Asks to add a feature at the last clicked location, at least if zoom is sufficient | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-01-04 04:06:21 +01:00
										 |  |  | import {UIEventSource} from "../../Logic/UIEventSource"; | 
					
						
							|  |  |  | import Svg from "../../Svg"; | 
					
						
							|  |  |  | import {SubtleButton} from "../Base/SubtleButton"; | 
					
						
							|  |  |  | import Combine from "../Base/Combine"; | 
					
						
							|  |  |  | import Translations from "../i18n/Translations"; | 
					
						
							|  |  |  | import Constants from "../../Models/Constants"; | 
					
						
							| 
									
										
										
										
											2021-03-29 02:04:42 +02:00
										 |  |  | import {TagUtils} from "../../Logic/Tags/TagUtils"; | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  | import BaseUIElement from "../BaseUIElement"; | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  | import {VariableUiElement} from "../Base/VariableUIElement"; | 
					
						
							|  |  |  | import Toggle from "../Input/Toggle"; | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  | import UserDetails, {OsmConnection} from "../../Logic/Osm/OsmConnection"; | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  | import LocationInput from "../Input/LocationInput"; | 
					
						
							| 
									
										
										
										
											2021-07-14 16:05:50 +02:00
										 |  |  | import AvailableBaseLayers from "../../Logic/Actors/AvailableBaseLayers"; | 
					
						
							| 
									
										
										
										
											2021-07-15 20:47:28 +02:00
										 |  |  | import CreateNewNodeAction from "../../Logic/Osm/Actions/CreateNewNodeAction"; | 
					
						
							| 
									
										
										
										
											2021-08-07 21:19:01 +02:00
										 |  |  | import {OsmObject, OsmWay} from "../../Logic/Osm/OsmObject"; | 
					
						
							| 
									
										
										
										
											2021-08-07 23:11:34 +02:00
										 |  |  | import PresetConfig from "../../Models/ThemeConfig/PresetConfig"; | 
					
						
							| 
									
										
										
										
											2021-09-07 01:49:18 +02:00
										 |  |  | import FilteredLayer from "../../Models/FilteredLayer"; | 
					
						
							| 
									
										
										
										
											2021-09-28 17:30:48 +02:00
										 |  |  | import {BBox} from "../../Logic/BBox"; | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  | 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"; | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +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-01-04 04:06:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  | /*private*/ | 
					
						
							| 
									
										
										
										
											2021-08-07 21:19:01 +02:00
										 |  |  | interface PresetInfo extends PresetConfig { | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |     name: string | BaseUIElement, | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  |     icon: () => BaseUIElement, | 
					
						
							| 
									
										
										
										
											2021-09-07 01:49:18 +02:00
										 |  |  |     layerToAddTo: FilteredLayer | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-01-08 16:49:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  | export default class SimpleAddUI extends Toggle { | 
					
						
							| 
									
										
										
										
											2020-07-29 18:35:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |     constructor(isShown: UIEventSource<boolean>, | 
					
						
							|  |  |  |                 filterViewIsOpened: UIEventSource<boolean>, | 
					
						
							|  |  |  |                 state: { | 
					
						
							|  |  |  |                     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>, | 
					
						
							|  |  |  |                 }) { | 
					
						
							| 
									
										
										
										
											2021-06-30 15:34:32 +02:00
										 |  |  |         const loginButton = new SubtleButton(Svg.osm_logo_ui(), Translations.t.general.add.pleaseLogin.Clone()) | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |             .onClick(() => state.osmConnection.AttemptLogin()); | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |         const readYourMessages = new Combine([ | 
					
						
							|  |  |  |             Translations.t.general.readYourMessages.Clone().SetClass("alert"), | 
					
						
							|  |  |  |             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
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |         const selectedPreset = new UIEventSource<PresetInfo>(undefined); | 
					
						
							|  |  |  |         isShown.addCallback(_ => selectedPreset.setData(undefined)) // Clear preset selection when the UI is closed/opened
 | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |         state.LastClickLocation.addCallback(_ => selectedPreset.setData(undefined)) | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |         const presetsOverview = SimpleAddUI.CreateAllPresetsPanel(selectedPreset, state) | 
					
						
							| 
									
										
										
										
											2021-08-07 21:19:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         async function createNewPoint(tags: any[], location: { lat: number, lon: number }, snapOntoWay?: OsmWay) { | 
					
						
							| 
									
										
										
										
											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", | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |                 snapOnto: snapOntoWay | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             await state.changes.applyAction(newElementAction) | 
					
						
							| 
									
										
										
										
											2021-08-07 21:19:01 +02:00
										 |  |  |             selectedPreset.setData(undefined) | 
					
						
							|  |  |  |             isShown.setData(false) | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |             state.selectedElement.setData(state.allElements.ContainingFeatures.get( | 
					
						
							| 
									
										
										
										
											2021-08-07 21:19:01 +02:00
										 |  |  |                 newElementAction.newElementId | 
					
						
							|  |  |  |             )) | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |         const addUi = new VariableUiElement( | 
					
						
							|  |  |  |             selectedPreset.map(preset => { | 
					
						
							|  |  |  |                     if (preset === undefined) { | 
					
						
							|  |  |  |                         return presetsOverview | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |                     return SimpleAddUI.CreateConfirmButton(state, filterViewIsOpened, preset, | 
					
						
							| 
									
										
										
										
											2021-08-07 21:19:01 +02:00
										 |  |  |                         (tags, location, snapOntoWayId?: string) => { | 
					
						
							|  |  |  |                             if (snapOntoWayId === undefined) { | 
					
						
							|  |  |  |                                 createNewPoint(tags, location, undefined) | 
					
						
							|  |  |  |                             } else { | 
					
						
							|  |  |  |                                 OsmObject.DownloadObject(snapOntoWayId).addCallbackAndRunD(way => { | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  |                                     createNewPoint(tags, location, <OsmWay>way) | 
					
						
							| 
									
										
										
										
											2021-08-07 21:19:01 +02:00
										 |  |  |                                     return true; | 
					
						
							|  |  |  |                                 }) | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                         }, | 
					
						
							|  |  |  |                         () => { | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |                             selectedPreset.setData(undefined) | 
					
						
							|  |  |  |                         }) | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             )) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         super( | 
					
						
							|  |  |  |             new Toggle( | 
					
						
							|  |  |  |                 new Toggle( | 
					
						
							|  |  |  |                     new Toggle( | 
					
						
							| 
									
										
										
										
											2021-09-22 05:02:09 +02:00
										 |  |  |                         Translations.t.general.add.stillLoading.Clone().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"), | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |                     state.locationControl.map(loc => loc.zoom >= Constants.userJourney.minZoomLevelToAddNewPoints) | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |                 ), | 
					
						
							|  |  |  |                 readYourMessages, | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |                 state.osmConnection.userDetails.map((userdetails: UserDetails) => | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |                     userdetails.csCount >= Constants.userJourney.addNewPointWithUnreadMessagesUnlock || | 
					
						
							|  |  |  |                     userdetails.unreadMessages == 0) | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |             loginButton, | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |             state.osmConnection.isLoggedIn | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-01-08 16:49:42 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |         this.SetStyle("font-size:large"); | 
					
						
							| 
									
										
										
										
											2021-01-08 16:49:42 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |     private static CreateConfirmButton( | 
					
						
							|  |  |  |         state: { | 
					
						
							|  |  |  |           LastClickLocation: UIEventSource<{ lat: number, lon: number }>, | 
					
						
							|  |  |  |           osmConnection: OsmConnection, | 
					
						
							|  |  |  |           featurePipeline: FeaturePipeline   | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |             filterViewIsOpened: UIEventSource<boolean>, | 
					
						
							|  |  |  |         preset: PresetInfo, | 
					
						
							| 
									
										
										
										
											2021-08-07 21:19:01 +02:00
										 |  |  |                                        confirm: (tags: any[], location: { lat: number, lon: number }, snapOntoWayId: string) => void, | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |                                        cancel: () => void): BaseUIElement { | 
					
						
							| 
									
										
										
										
											2021-01-08 16:49:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |         let location = state.LastClickLocation; | 
					
						
							| 
									
										
										
										
											2021-08-07 21:19:01 +02:00
										 |  |  |         let preciseInput: LocationInput = undefined | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  |         if (preset.preciseInput !== undefined) { | 
					
						
							| 
									
										
										
										
											2021-09-22 05:02:09 +02:00
										 |  |  |             // We uncouple the event source
 | 
					
						
							| 
									
										
										
										
											2021-07-14 16:05:50 +02:00
										 |  |  |             const locationSrc = new UIEventSource({ | 
					
						
							|  |  |  |                 lat: location.data.lat, | 
					
						
							|  |  |  |                 lon: location.data.lon, | 
					
						
							|  |  |  |                 zoom: 19 | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2021-07-18 14:52:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-14 16:05:50 +02:00
										 |  |  |             let backgroundLayer = undefined; | 
					
						
							| 
									
										
										
										
											2021-07-18 14:52:09 +02:00
										 |  |  |             if (preset.preciseInput.preferredBackground) { | 
					
						
							|  |  |  |                 backgroundLayer = AvailableBaseLayers.SelectBestLayerAccordingTo(locationSrc, new UIEventSource<string | string[]>(preset.preciseInput.preferredBackground)) | 
					
						
							| 
									
										
										
										
											2021-07-14 16:05:50 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-07-18 14:52:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-22 05:02:09 +02:00
										 |  |  |             let snapToFeatures: UIEventSource<{ feature: any }[]> = undefined | 
					
						
							|  |  |  |             let mapBounds: UIEventSource<BBox> = undefined | 
					
						
							| 
									
										
										
										
											2021-08-07 21:19:01 +02:00
										 |  |  |             if (preset.preciseInput.snapToLayers) { | 
					
						
							| 
									
										
										
										
											2021-09-22 05:02:09 +02:00
										 |  |  |                 snapToFeatures = new UIEventSource<{ feature: any }[]>([]) | 
					
						
							|  |  |  |                 mapBounds = new UIEventSource<BBox>(undefined) | 
					
						
							| 
									
										
										
										
											2021-08-07 21:19:01 +02:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-22 05:02:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-07 21:19:01 +02:00
										 |  |  |             const tags = TagUtils.KVtoProperties(preset.tags ?? []); | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  |             preciseInput = new LocationInput({ | 
					
						
							| 
									
										
										
										
											2021-07-14 16:05:50 +02:00
										 |  |  |                 mapBackground: backgroundLayer, | 
					
						
							| 
									
										
										
										
											2021-08-07 21:19:01 +02:00
										 |  |  |                 centerLocation: locationSrc, | 
					
						
							| 
									
										
										
										
											2021-09-22 05:02:09 +02:00
										 |  |  |                 snapTo: snapToFeatures, | 
					
						
							| 
									
										
										
										
											2021-08-07 21:19:01 +02:00
										 |  |  |                 snappedPointTags: tags, | 
					
						
							| 
									
										
										
										
											2021-09-22 05:02:09 +02:00
										 |  |  |                 maxSnapDistance: preset.preciseInput.maxSnapDistance, | 
					
						
							|  |  |  |                 bounds: mapBounds | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  |             }) | 
					
						
							| 
									
										
										
										
											2021-10-13 03:09:37 +02:00
										 |  |  |             preciseInput.installBounds(0.15, true) | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  |             preciseInput.SetClass("h-32 rounded-xl overflow-hidden border border-gray").SetStyle("height: 12rem;") | 
					
						
							| 
									
										
										
										
											2021-09-22 05:02:09 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (preset.preciseInput.snapToLayers) { | 
					
						
							|  |  |  |                 // We have to snap to certain layers.
 | 
					
						
							|  |  |  |                 // Lets fetch them
 | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 let loadedBbox: BBox = undefined | 
					
						
							| 
									
										
										
										
											2021-09-22 05:02:09 +02:00
										 |  |  |                 mapBounds?.addCallbackAndRunD(bbox => { | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |                     if (loadedBbox !== undefined && bbox.isContainedIn(loadedBbox)) { | 
					
						
							| 
									
										
										
										
											2021-09-22 05:02:09 +02:00
										 |  |  |                         // All is already there
 | 
					
						
							|  |  |  |                         // return;
 | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     bbox = bbox.pad(2); | 
					
						
							|  |  |  |                     loadedBbox = bbox; | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |                     const allFeatures: { feature: any }[] = [] | 
					
						
							| 
									
										
										
										
											2021-09-22 05:02:09 +02:00
										 |  |  |                     preset.preciseInput.snapToLayers.forEach(layerId => { | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |                         state.featurePipeline.GetFeaturesWithin(layerId, bbox).forEach(feats => allFeatures.push(...feats.map(f => ({feature: f})))) | 
					
						
							| 
									
										
										
										
											2021-09-22 05:02:09 +02:00
										 |  |  |                     }) | 
					
						
							|  |  |  |                     snapToFeatures.setData(allFeatures) | 
					
						
							|  |  |  |                 }) | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-08 16:49:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  |         let confirmButton: BaseUIElement = new SubtleButton(preset.icon(), | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |             new Combine([ | 
					
						
							|  |  |  |                 Translations.t.general.add.addNew.Subs({category: preset.name}), | 
					
						
							|  |  |  |                 Translations.t.general.add.warnVisibleForEveryone.Clone().SetClass("alert") | 
					
						
							|  |  |  |             ]).SetClass("flex flex-col") | 
					
						
							|  |  |  |         ).SetClass("font-bold break-words") | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  |             .onClick(() => { | 
					
						
							| 
									
										
										
										
											2021-08-07 21:19:01 +02:00
										 |  |  |                 confirm(preset.tags, (preciseInput?.GetValue() ?? location).data, preciseInput?.snappedOnto?.data?.properties?.id); | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  |             }); | 
					
						
							| 
									
										
										
										
											2021-07-18 14:52:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  |         if (preciseInput !== undefined) { | 
					
						
							|  |  |  |             confirmButton = new Combine([preciseInput, confirmButton]) | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  |         const openLayerControl = | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |             new SubtleButton( | 
					
						
							|  |  |  |                 Svg.layers_ui(), | 
					
						
							|  |  |  |                 new Combine([ | 
					
						
							|  |  |  |                     Translations.t.general.add.layerNotEnabled | 
					
						
							|  |  |  |                         .Subs({layer: preset.layerToAddTo.layerDef.name}) | 
					
						
							|  |  |  |                         .SetClass("alert"), | 
					
						
							|  |  |  |                     Translations.t.general.add.openLayerControl | 
					
						
							|  |  |  |                 ]) | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |                 .onClick(() => filterViewIsOpened.setData(true)) | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |         const openLayerOrConfirm = new Toggle( | 
					
						
							|  |  |  |             confirmButton, | 
					
						
							|  |  |  |             openLayerControl, | 
					
						
							|  |  |  |             preset.layerToAddTo.isDisplayed | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-07 01:49:18 +02:00
										 |  |  |         const disableFilter = new SubtleButton( | 
					
						
							|  |  |  |             new Combine([ | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  |                 Svg.filter_ui().SetClass("absolute w-full"), | 
					
						
							| 
									
										
										
										
											2021-09-07 01:49:18 +02:00
										 |  |  |                 Svg.cross_bottom_right_svg().SetClass("absolute red-svg") | 
					
						
							|  |  |  |             ]).SetClass("relative"), | 
					
						
							|  |  |  |             new Combine( | 
					
						
							|  |  |  |                 [ | 
					
						
							|  |  |  |                     Translations.t.general.add.disableFiltersExplanation.Clone(), | 
					
						
							|  |  |  |                     Translations.t.general.add.disableFilters.Clone().SetClass("text-xl") | 
					
						
							|  |  |  |                 ] | 
					
						
							|  |  |  |             ).SetClass("flex flex-col") | 
					
						
							|  |  |  |         ).onClick(() => { | 
					
						
							| 
									
										
										
										
											2021-09-27 18:35:32 +02:00
										 |  |  |             preset.layerToAddTo.appliedFilters.setData([]) | 
					
						
							| 
									
										
										
										
											2021-09-07 01:49:18 +02:00
										 |  |  |             cancel() | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-07 01:49:18 +02:00
										 |  |  |         const disableFiltersOrConfirm = new Toggle( | 
					
						
							|  |  |  |             openLayerOrConfirm, | 
					
						
							|  |  |  |             disableFilter, | 
					
						
							| 
									
										
										
										
											2021-09-30 00:26:21 +02:00
										 |  |  |             preset.layerToAddTo.appliedFilters.map(filters => { | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |                 if (filters === undefined || filters.length === 0) { | 
					
						
							| 
									
										
										
										
											2021-09-30 00:26:21 +02:00
										 |  |  |                     return true; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 for (const filter of filters) { | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |                     if (filter.selected === 0 && filter.filter.options.length === 1) { | 
					
						
							| 
									
										
										
										
											2021-09-30 00:26:21 +02:00
										 |  |  |                         return false; | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |                     if (filter.selected !== undefined) { | 
					
						
							| 
									
										
										
										
											2021-09-30 00:26:21 +02:00
										 |  |  |                         const tags = filter.filter.options[filter.selected].osmTags | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |                         if (tags !== undefined && tags["and"]?.length !== 0) { | 
					
						
							| 
									
										
										
										
											2021-09-30 00:26:21 +02:00
										 |  |  |                             // This actually doesn't filter anything at all
 | 
					
						
							|  |  |  |                             return false; | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 return true | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-30 00:26:21 +02:00
										 |  |  |             }) | 
					
						
							| 
									
										
										
										
											2021-09-07 01:49:18 +02:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-09-09 00:05:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |         const tagInfo = SimpleAddUI.CreateTagInfoFor(preset, state.osmConnection); | 
					
						
							| 
									
										
										
										
											2021-01-08 16:49:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |         const cancelButton = new SubtleButton(Svg.close_ui(), | 
					
						
							|  |  |  |             Translations.t.general.cancel | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  |         ).onClick(cancel) | 
					
						
							| 
									
										
										
										
											2021-01-08 16:49:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |         return new Combine([ | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |             state.osmConnection.userDetails.data.dryRun ? | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  |                 Translations.t.general.testing.Clone().SetClass("alert") : undefined, | 
					
						
							| 
									
										
										
										
											2021-09-07 01:49:18 +02:00
										 |  |  |             disableFiltersOrConfirm, | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |             cancelButton, | 
					
						
							|  |  |  |             preset.description, | 
					
						
							|  |  |  |             tagInfo | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ]).SetClass("flex flex-col") | 
					
						
							| 
									
										
										
										
											2021-01-08 16:49:42 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |     private 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( | 
					
						
							| 
									
										
										
										
											2021-06-21 03:12:43 +02:00
										 |  |  |             Translations.t.general.add.presetInfo.Subs({ | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |                 tags: preset.tags.map(t => t.asHumanString(optionallyLinkToWiki && csCount > Constants.userJourney.tagsVisibleAndWikiLinked, true)).join("&"), | 
					
						
							| 
									
										
										
										
											2021-06-19 18:28:30 +02:00
										 |  |  |             }).SetStyle("word-break: break-all"), | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             undefined, | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |     private static CreateAllPresetsPanel(selectedPreset: UIEventSource<PresetInfo>, | 
					
						
							|  |  |  |                                          state: { | 
					
						
							|  |  |  |                                              filteredLayers: UIEventSource<FilteredLayer[]>, | 
					
						
							|  |  |  |                                              featureSwitchFilter: UIEventSource<boolean>, | 
					
						
							|  |  |  |                                              osmConnection: OsmConnection | 
					
						
							|  |  |  |                                          }): BaseUIElement { | 
					
						
							|  |  |  |         const presetButtons = SimpleAddUI.CreatePresetButtons(state, selectedPreset) | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  |         let intro: BaseUIElement = Translations.t.general.add.intro; | 
					
						
							| 
									
										
										
										
											2021-01-08 16:49:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  |         let testMode: BaseUIElement = undefined; | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |         if (state.osmConnection?.userDetails?.data?.dryRun) { | 
					
						
							| 
									
										
										
										
											2021-06-12 02:58:32 +02:00
										 |  |  |             testMode = Translations.t.general.testing.Clone().SetClass("alert") | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |     private static CreatePresetSelectButton(preset: PresetInfo, osmConnection: OsmConnection) { | 
					
						
							| 
									
										
										
										
											2021-01-08 16:49:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |         const tagInfo = SimpleAddUI.CreateTagInfoFor(preset, osmConnection ,false); | 
					
						
							| 
									
										
										
										
											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([ | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |                 Translations.t.general.add.addNew.Subs({ | 
					
						
							|  |  |  |                     category: preset.name | 
					
						
							|  |  |  |                 }).SetClass("font-bold"), | 
					
						
							|  |  |  |                 Translations.WT(preset.description)?.FirstSentence(), | 
					
						
							|  |  |  |                 tagInfo?.SetClass("subtle") | 
					
						
							|  |  |  |             ]).SetClass("flex flex-col") | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-01-08 16:49:42 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* | 
					
						
							|  |  |  |     * Generates the list with all the buttons.*/ | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |     private static CreatePresetButtons( | 
					
						
							|  |  |  |         state: { | 
					
						
							|  |  |  |             filteredLayers: UIEventSource<FilteredLayer[]>, | 
					
						
							|  |  |  |             featureSwitchFilter: UIEventSource<boolean>, | 
					
						
							|  |  |  |             osmConnection: OsmConnection | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         selectedPreset: UIEventSource<PresetInfo>): BaseUIElement { | 
					
						
							| 
									
										
										
										
											2021-01-08 16:49:42 +01:00
										 |  |  |         const allButtons = []; | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |         for (const layer of state.filteredLayers.data) { | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |             if (layer.isDisplayed.data === false && !state.featureSwitchFilter.data) { | 
					
						
							| 
									
										
										
										
											2021-07-28 16:48:59 +02:00
										 |  |  |                 // The layer is not displayed and we cannot enable the layer control -> we skip
 | 
					
						
							|  |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-08-07 21:19:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if (layer.layerDef.name === undefined) { | 
					
						
							| 
									
										
										
										
											2021-07-28 16:48:59 +02:00
										 |  |  |                 // this is a parlty hidden layer
 | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-30 00:56:46 +01:00
										 |  |  |             const presets = layer.layerDef.presets; | 
					
						
							|  |  |  |             for (const preset of presets) { | 
					
						
							| 
									
										
										
										
											2020-07-31 16:17:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |                 const tags = TagUtils.KVtoProperties(preset.tags ?? []); | 
					
						
							| 
									
										
										
										
											2021-07-18 14:52:09 +02:00
										 |  |  |                 let icon: () => BaseUIElement = () => layer.layerDef.GenerateLeafletStyle(new UIEventSource<any>(tags), false).icon.html | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |                     .SetClass("w-12 h-12 block relative"); | 
					
						
							|  |  |  |                 const presetInfo: PresetInfo = { | 
					
						
							|  |  |  |                     tags: preset.tags, | 
					
						
							|  |  |  |                     layerToAddTo: layer, | 
					
						
							|  |  |  |                     name: preset.title, | 
					
						
							| 
									
										
										
										
											2021-08-07 21:19:01 +02:00
										 |  |  |                     title: preset.title, | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |                     description: preset.description, | 
					
						
							| 
									
										
										
										
											2021-07-14 00:17:15 +02:00
										 |  |  |                     icon: icon, | 
					
						
							|  |  |  |                     preciseInput: preset.preciseInput | 
					
						
							| 
									
										
										
										
											2020-08-22 18:57:27 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-15 05:20:02 +02:00
										 |  |  |                 const button = SimpleAddUI.CreatePresetSelectButton(presetInfo, state.osmConnection); | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |                 button.onClick(() => { | 
					
						
							|  |  |  |                     selectedPreset.setData(presetInfo) | 
					
						
							|  |  |  |                 }) | 
					
						
							| 
									
										
										
										
											2021-01-08 16:49:42 +01:00
										 |  |  |                 allButtons.push(button); | 
					
						
							| 
									
										
										
										
											2020-07-31 16:17:16 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-06-29 03:12:44 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-06-14 02:39:23 +02:00
										 |  |  |         return new Combine(allButtons).SetClass("flex flex-col"); | 
					
						
							| 
									
										
										
										
											2020-06-29 03:12:44 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |