| 
									
										
										
										
											2023-12-07 21:56:32 +01:00
										 |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2023-12-19 16:35:11 +01:00
										 |  |  |   import { UIEventSource } from "../../Logic/UIEventSource" | 
					
						
							|  |  |  |   import type { MoveReason } from "./MoveWizardState" | 
					
						
							|  |  |  |   import { MoveWizardState } from "./MoveWizardState" | 
					
						
							|  |  |  |   import LayerConfig from "../../Models/ThemeConfig/LayerConfig" | 
					
						
							|  |  |  |   import ToSvelte from "../Base/ToSvelte.svelte" | 
					
						
							|  |  |  |   import Tr from "../Base/Tr.svelte" | 
					
						
							|  |  |  |   import Translations from "../i18n/Translations" | 
					
						
							|  |  |  |   import Move from "../../assets/svg/Move.svelte" | 
					
						
							|  |  |  |   import Move_not_allowed from "../../assets/svg/Move_not_allowed.svelte" | 
					
						
							|  |  |  |   import type { SpecialVisualizationState } from "../SpecialVisualization" | 
					
						
							|  |  |  |   import { XCircleIcon } from "@babeard/svelte-heroicons/solid" | 
					
						
							|  |  |  |   import type { MapProperties } from "../../Models/MapProperties" | 
					
						
							|  |  |  |   import type { Feature, Point } from "geojson" | 
					
						
							|  |  |  |   import { GeoOperations } from "../../Logic/GeoOperations" | 
					
						
							|  |  |  |   import LocationInput from "../InputElement/Helpers/LocationInput.svelte" | 
					
						
							|  |  |  |   import OpenBackgroundSelectorButton from "../BigComponents/OpenBackgroundSelectorButton.svelte" | 
					
						
							|  |  |  |   import Geosearch from "../BigComponents/Geosearch.svelte" | 
					
						
							|  |  |  |   import If from "../Base/If.svelte" | 
					
						
							|  |  |  |   import Constants from "../../Models/Constants" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   export let state: SpecialVisualizationState | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   export let layer: LayerConfig | 
					
						
							|  |  |  |   export let featureToMove: Feature<Point> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let id: string = featureToMove.properties.id | 
					
						
							|  |  |  |   let currentStep: "start" | "reason" | "pick_location" | "moved" = "start" | 
					
						
							|  |  |  |   const t = Translations.t.move | 
					
						
							|  |  |  |   const reason = new UIEventSource<MoveReason>(undefined) | 
					
						
							|  |  |  |   let [lon, lat] = GeoOperations.centerpointCoordinates(featureToMove) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let newLocation = new UIEventSource<{ lon: number; lat: number }>(undefined) | 
					
						
							| 
									
										
										
										
											2023-12-07 21:56:32 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   function initMapProperties() { | 
					
						
							|  |  |  |     return <any>{ | 
					
						
							|  |  |  |       allowMoving: new UIEventSource(true), | 
					
						
							|  |  |  |       allowRotating: new UIEventSource(false), | 
					
						
							|  |  |  |       allowZooming: new UIEventSource(true), | 
					
						
							|  |  |  |       bounds: new UIEventSource(undefined), | 
					
						
							|  |  |  |       location: new UIEventSource({ lon, lat }), | 
					
						
							|  |  |  |       minzoom: new UIEventSource($reason.minZoom), | 
					
						
							|  |  |  |       rasterLayer: state.mapProperties.rasterLayer, | 
					
						
							| 
									
										
										
										
											2023-12-19 16:35:11 +01:00
										 |  |  |       zoom: new UIEventSource($reason?.startZoom ?? 16), | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-12-07 21:56:32 +01:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-19 16:35:11 +01:00
										 |  |  |   let moveWizardState = new MoveWizardState(id, layer.allowMove, state) | 
					
						
							|  |  |  |   let notAllowed = moveWizardState.moveDisallowedReason | 
					
						
							|  |  |  |   let currentMapProperties: MapProperties = undefined | 
					
						
							| 
									
										
										
										
											2023-12-07 21:56:32 +01:00
										 |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-19 22:08:00 +01:00
										 |  |  | {#if moveWizardState.reasons.length > 0} | 
					
						
							| 
									
										
										
										
											2023-12-07 21:56:32 +01:00
										 |  |  |   {#if $notAllowed} | 
					
						
							| 
									
										
										
										
											2023-12-19 22:08:00 +01:00
										 |  |  |     <div class="m-2 flex rounded-lg bg-gray-200 p-2"> | 
					
						
							|  |  |  |       <Move_not_allowed class="m-2 h-8 w-8" /> | 
					
						
							| 
									
										
										
										
											2023-12-07 21:56:32 +01:00
										 |  |  |       <div class="flex flex-col"> | 
					
						
							|  |  |  |         <Tr t={t.cannotBeMoved} /> | 
					
						
							|  |  |  |         <Tr t={$notAllowed} /> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   {:else if currentStep === "start"} | 
					
						
							|  |  |  |     {#if moveWizardState.reasons.length === 1} | 
					
						
							| 
									
										
										
										
											2023-12-19 22:08:00 +01:00
										 |  |  |       <button | 
					
						
							|  |  |  |         class="flex" | 
					
						
							|  |  |  |         on:click={() => { | 
					
						
							|  |  |  |           reason.setData(moveWizardState.reasons[0]) | 
					
						
							|  |  |  |           currentStep = "pick_location" | 
					
						
							|  |  |  |         }} | 
					
						
							|  |  |  |       > | 
					
						
							|  |  |  |         <ToSvelte | 
					
						
							|  |  |  |           construct={moveWizardState.reasons[0].icon.SetStyle("height: 1.5rem; width: 1.5rem;")} | 
					
						
							|  |  |  |         /> | 
					
						
							| 
									
										
										
										
											2023-12-07 21:56:32 +01:00
										 |  |  |         <Tr t={Translations.T(moveWizardState.reasons[0].invitingText)} /> | 
					
						
							|  |  |  |       </button> | 
					
						
							|  |  |  |     {:else} | 
					
						
							| 
									
										
										
										
											2023-12-19 22:08:00 +01:00
										 |  |  |       <button | 
					
						
							|  |  |  |         class="flex" | 
					
						
							|  |  |  |         on:click={() => { | 
					
						
							|  |  |  |           currentStep = "reason" | 
					
						
							|  |  |  |         }} | 
					
						
							|  |  |  |       > | 
					
						
							|  |  |  |         <Move class="h-6 w-6" /> | 
					
						
							| 
									
										
										
										
											2023-12-07 21:56:32 +01:00
										 |  |  |         <Tr t={t.inviteToMove.generic} /> | 
					
						
							|  |  |  |       </button> | 
					
						
							|  |  |  |     {/if} | 
					
						
							|  |  |  |   {:else if currentStep === "reason"} | 
					
						
							| 
									
										
										
										
											2023-12-19 22:08:00 +01:00
										 |  |  |     <div class="interactive border-interactive flex flex-col p-2"> | 
					
						
							| 
									
										
										
										
											2023-12-07 21:56:32 +01:00
										 |  |  |       <Tr cls="text-lg font-bold" t={t.whyMove} /> | 
					
						
							|  |  |  |       {#each moveWizardState.reasons as reasonSpec} | 
					
						
							| 
									
										
										
										
											2023-12-19 22:08:00 +01:00
										 |  |  |         <button | 
					
						
							|  |  |  |           on:click={() => { | 
					
						
							|  |  |  |             reason.setData(reasonSpec) | 
					
						
							|  |  |  |             currentStep = "pick_location" | 
					
						
							|  |  |  |           }} | 
					
						
							|  |  |  |         > | 
					
						
							| 
									
										
										
										
											2023-12-19 16:35:11 +01:00
										 |  |  |           <ToSvelte construct={reasonSpec.icon.SetClass("w-16 h-16 pr-2")} /> | 
					
						
							|  |  |  |           <Tr t={Translations.T(reasonSpec.text)} /> | 
					
						
							| 
									
										
										
										
											2023-12-07 21:56:32 +01:00
										 |  |  |         </button> | 
					
						
							|  |  |  |       {/each} | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   {:else if currentStep === "pick_location"} | 
					
						
							| 
									
										
										
										
											2023-12-19 22:08:00 +01:00
										 |  |  |     <div class="border-interactive interactive flex flex-col p-2"> | 
					
						
							| 
									
										
										
										
											2023-12-07 21:56:32 +01:00
										 |  |  |       <Tr cls="text-lg font-bold" t={t.moveTitle} /> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-19 22:08:00 +01:00
										 |  |  |       <div class="relative h-64 w-full"> | 
					
						
							|  |  |  |         <LocationInput | 
					
						
							|  |  |  |           mapProperties={(currentMapProperties = initMapProperties())} | 
					
						
							|  |  |  |           value={newLocation} | 
					
						
							|  |  |  |           initialCoordinate={{ lon, lat }} | 
					
						
							|  |  |  |         /> | 
					
						
							| 
									
										
										
										
											2023-12-07 21:56:32 +01:00
										 |  |  |         <div class="absolute bottom-0 left-0"> | 
					
						
							|  |  |  |           <OpenBackgroundSelectorButton {state} /> | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       {#if $reason.includeSearch} | 
					
						
							| 
									
										
										
										
											2023-12-19 22:08:00 +01:00
										 |  |  |         <Geosearch bounds={currentMapProperties.bounds} clearAfterView={false} /> | 
					
						
							| 
									
										
										
										
											2023-12-07 21:56:32 +01:00
										 |  |  |       {/if} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       <div class="flex flex-wrap"> | 
					
						
							| 
									
										
										
										
											2023-12-21 01:46:18 +01:00
										 |  |  |         <If | 
					
						
							|  |  |  |           condition={currentMapProperties.zoom.mapD( | 
					
						
							|  |  |  |             (zoom) => zoom >= Constants.minZoomLevelToAddNewPoint | 
					
						
							|  |  |  |           )} | 
					
						
							|  |  |  |         > | 
					
						
							|  |  |  |           <button | 
					
						
							|  |  |  |             class="primary flex w-full" | 
					
						
							|  |  |  |             on:click={() => { | 
					
						
							|  |  |  |               moveWizardState.moveFeature(newLocation.data, reason.data, featureToMove) | 
					
						
							|  |  |  |               currentStep = "moved" | 
					
						
							|  |  |  |             }} | 
					
						
							|  |  |  |           > | 
					
						
							| 
									
										
										
										
											2023-12-19 22:08:00 +01:00
										 |  |  |             <Move class="mr-2 h-6 w-6" /> | 
					
						
							| 
									
										
										
										
											2023-12-07 21:56:32 +01:00
										 |  |  |             <Tr t={t.confirmMove} /> | 
					
						
							|  |  |  |           </button> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           <div slot="else" class="alert"> | 
					
						
							|  |  |  |             <Tr t={t.zoomInFurther} /> | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |         </If> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-19 22:08:00 +01:00
										 |  |  |         <button | 
					
						
							|  |  |  |           class="w-full" | 
					
						
							|  |  |  |           on:click={() => { | 
					
						
							|  |  |  |             currentStep = "start" | 
					
						
							|  |  |  |           }} | 
					
						
							|  |  |  |         > | 
					
						
							|  |  |  |           <XCircleIcon class="mr-2 h-6 w-6" /> | 
					
						
							| 
									
										
										
										
											2023-12-07 21:56:32 +01:00
										 |  |  |           <Tr t={t.cancel} /> | 
					
						
							|  |  |  |         </button> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   {:else if currentStep === "moved"} | 
					
						
							|  |  |  |     <div class="flex flex-col"> | 
					
						
							|  |  |  |       <Tr cls="thanks" t={t.pointIsMoved} /> | 
					
						
							| 
									
										
										
										
											2023-12-21 01:46:18 +01:00
										 |  |  |       <button | 
					
						
							|  |  |  |         on:click={() => { | 
					
						
							|  |  |  |           currentStep = "reason" | 
					
						
							|  |  |  |         }} | 
					
						
							|  |  |  |       > | 
					
						
							|  |  |  |         <Move class="h-6 w-6 pr-2" /> | 
					
						
							| 
									
										
										
										
											2023-12-07 21:56:32 +01:00
										 |  |  |         <Tr t={t.inviteToMoveAgain} /> | 
					
						
							|  |  |  |       </button> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   {/if} | 
					
						
							|  |  |  | {/if} |