2024-03-04 15:31:09 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								< script  lang = "ts" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  import {  UIEventSource  }  from "../../Logic/UIEventSource"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  import type {  Feature ,  Point  }  from "geojson"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  import type {  SpecialVisualizationState  }  from "../SpecialVisualization"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  import LoginToggle from "../Base/LoginToggle.svelte"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  import Tr from "../Base/Tr.svelte"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  import WaySplitMap from "../BigComponents/WaySplitMap.svelte"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  import BackButton from "../Base/BackButton.svelte"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  import SplitAction from "../../Logic/Osm/Actions/SplitAction"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  import Translations from "../i18n/Translations"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  import NextButton from "../Base/NextButton.svelte"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  import Loading from "../Base/Loading.svelte"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  import {  OsmWay  }  from "../../Logic/Osm/OsmObject"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  import type {  WayId  }  from "../../Models/OsmFeature"
							 
						 
					
						
							
								
									
										
										
										
											2024-06-17 04:27:08 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  import Scissors from "@babeard/svelte-heroicons/solid/Scissors"
							 
						 
					
						
							
								
									
										
										
										
											2024-03-04 15:31:09 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  export let state: SpecialVisualizationState
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  export let id: WayId
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  const t = Translations.t.split
							 
						 
					
						
							
								
									
										
										
										
											2024-11-19 16:42:53 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  let snapTolerance = 5 // meter
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 02:40:21 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  let step:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    | "initial"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    | "loading_way"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    | "splitting"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    | "applying_split"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    | "has_been_split"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    | "deleted" = "initial"
							 
						 
					
						
							
								
									
										
										
										
											2024-03-04 15:31:09 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								  // Contains the points on the road that are selected to split on - contains geojson points with extra properties such as 'location' with the distance along the linestring
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 02:40:21 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  let splitPoints = new UIEventSource< 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    Feature< 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      Point,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        id: number
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        index: number
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        dist: number
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        location: number
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    >[]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  >([])
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  let splitpointsNotEmpty = splitPoints.map((sp) => sp.length > 0)
							 
						 
					
						
							
								
									
										
										
										
											2024-03-04 15:31:09 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  let osmWay: OsmWay
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  async function downloadWay() { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    step = "loading_way"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    const dloaded = await state.osmObjectDownloader.DownloadObjectAsync(id)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if (dloaded === "deleted") { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      step = "deleted"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      return
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    osmWay = dloaded
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    step = "splitting"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  async function doSplit() { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    step = "applying_split"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    const splitAction = new SplitAction(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      id,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      splitPoints.data.map((ff) => < [number, number]>(< Point > ff.geometry).coordinates),
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      { 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-17 04:06:03 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        theme: state?.theme?.id,
							 
						 
					
						
							
								
									
										
										
										
											2024-03-04 15:31:09 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								      },
							 
						 
					
						
							
								
									
										
										
										
											2024-11-19 16:42:53 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      snapTolerance
							 
						 
					
						
							
								
									
										
										
										
											2024-03-04 15:31:09 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    await state.changes?.applyAction(splitAction)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // We throw away the old map and splitpoints, and create a new map from scratch
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    splitPoints.setData([])
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // Close the popup. The contributor has to select a segment again to make sure they continue editing the correct segment; see #1219
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    state.selectedElement?.setData(undefined)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    step = "has_been_split"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								< / script > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								< LoginToggle  ignoreLoading = { true }  { state } > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  < Tr  slot = "not-logged-in"  t = { t . loginToSplit }  / > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  { #if  step  ===  "deleted" } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    <!--  Empty  --> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  { :else  if  step  ===  "initial" } 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-17 04:27:08 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    < button  class = "w-full"  on:click = {()  =>  downloadWay ()} > 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 02:40:21 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      < Scissors  class = "h-6 w-6 shrink-0"  / > 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-04 15:31:09 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								      < Tr  t = { t . inviteToSplit }  / > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    < / button > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  { :else  if  step  ===  "loading_way" } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    < Loading  / > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  { :else  if  step  ===  "splitting" } 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 02:40:21 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    < div  class = "interactive border-interactive flex flex-col p-2" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      < div  class = "h-80 w-full" > 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-19 16:42:53 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        < WaySplitMap  { state }  { splitPoints }  { osmWay }  { snapTolerance }  mapProperties = {{ rasterLayer : state.mapProperties.rasterLayer }} / > 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-04 15:31:09 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								      < / div > 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 02:40:21 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      < div  class = "flex w-full flex-wrap-reverse md:flex-nowrap" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        < BackButton 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          clss="w-full"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          on:click={()  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            splitPoints.set([])
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            step = "initial"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          }}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        >
							 
						 
					
						
							
								
									
										
										
										
											2024-03-04 15:31:09 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								          < Tr  t = { Translations . t . general . cancel }  / > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        < / BackButton > 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 02:40:21 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        < NextButton 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          clss={( $splitpointsNotEmpty  ?  ""  :  "disabled " )  +  "w-full primary" } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          on:click={()  =>  doSplit ()} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        >
							 
						 
					
						
							
								
									
										
										
										
											2024-03-04 15:31:09 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								          < Tr  t = { t . split }  / > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        < / NextButton > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      < / div > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    < / div > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  { :else  if  step  ===  "has_been_split" } 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-05 00:16:20 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    < Tr  cls = "thanks "  t = { t . hasBeenSplit }  / > 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-04 15:31:09 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    < button  on:click = {()  =>  downloadWay ()} > 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 02:40:21 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      < Scissors  class = "h-6 w-6"  / > 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-04 15:31:09 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								      < Tr  t = { t . splitAgain }  / > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    < / button > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  { /if } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								< / LoginToggle >