2023-04-20 01:52:23 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< script  lang = "ts" >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   * This component shows a map which focuses on a single OSM-Way (linestring) feature.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   * Clicking the map will add a new 'scissor' point, projected on the linestring (and possible snapped to an already existing node within the linestring;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   * clicking this point again will remove it.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   * The bound 'value' will contain the location of these projected points.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   * Points are not coalesced with already existing nodes within the way; it is up to the code actually splitting the way to decide to reuse an existing point or not
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   *
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   * This component is _not_ responsible for the rest of the flow, e.g. the confirm button
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   */
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  import type {  LayerConfigJson  }  from "../../Models/ThemeConfig/Json/LayerConfigJson"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  import split_point from "../../assets/layers/split_point/split_point.json"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  import split_road from "../../assets/layers/split_road/split_road.json"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  import {  UIEventSource  }  from "../../Logic/UIEventSource"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  import {  Map  as  MlMap  }  from "maplibre-gl"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  import type {  MapProperties  }  from "../../Models/MapProperties"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  import {  MapLibreAdaptor  }  from "../Map/MapLibreAdaptor"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  import MaplibreMap from "../Map/MaplibreMap.svelte"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  import {  OsmWay  }  from "../../Logic/Osm/OsmObject"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  import ShowDataLayer from "../Map/ShowDataLayer"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  import StaticFeatureSource from "../../Logic/FeatureSource/Sources/StaticFeatureSource"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  import {  GeoOperations  }  from "../../Logic/GeoOperations"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  import {  BBox  }  from "../../Logic/BBox"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  import type {  Feature ,  LineString ,  Point  }  from "geojson"
							 
						 
					
						
							
								
									
										
										
										
											2023-04-20 01:52:23 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const splitpoint_style = new LayerConfig(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < LayerConfigJson > split_point,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    "(BUILTIN) SplitRoadWizard.ts",
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    true
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  ) as const
							 
						 
					
						
							
								
									
										
										
										
											2023-04-20 01:52:23 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const splitroad_style = new LayerConfig(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < LayerConfigJson > split_road,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    "(BUILTIN) SplitRoadWizard.ts",
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    true
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  ) as const
							 
						 
					
						
							
								
									
										
										
										
											2023-04-20 01:52:23 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   * The way to focus on
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  export let osmWay: OsmWay
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   * How to render this layer.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   * A default is given
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  export let layer: LayerConfig = splitroad_style
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   * Optional: use these properties to set e.g. background layer
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  export let mapProperties: undefined | Partial< MapProperties >  = undefined
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  let map: UIEventSource< MlMap >  = new UIEventSource< MlMap > (undefined)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  let adaptor = new MapLibreAdaptor(map, mapProperties)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const wayGeojson: Feature< LineString >  = GeoOperations.forceLineString(osmWay.asGeoJson())
							 
						 
					
						
							
								
									
										
										
										
											2023-04-20 01:52:23 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  adaptor.location.setData(GeoOperations.centerpointCoordinatesObj(wayGeojson))
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  adaptor.bounds.setData(BBox.get(wayGeojson).pad(2))
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  adaptor.maxbounds.setData(BBox.get(wayGeojson).pad(2))
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-20 01:52:23 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  new ShowDataLayer(map, { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    features: new StaticFeatureSource([wayGeojson]),
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    drawMarkers: false,
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    layer: layer,
							 
						 
					
						
							
								
									
										
										
										
											2023-04-20 01:52:23 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  })
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  export let splitPoints: UIEventSource< 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Feature< 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      Point,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        id: number
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        index: number
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        dist: number
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        location: number
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    >[]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  > = new UIEventSource([])
							 
						 
					
						
							
								
									
										
										
										
											2023-04-20 01:52:23 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  const splitPointsFS = new StaticFeatureSource(splitPoints)
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-20 01:52:23 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  new ShowDataLayer(map, { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    layer: splitpoint_style,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    features: splitPointsFS,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    onClick: (clickedFeature: Feature) => { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      console.log("Clicked feature is", clickedFeature, splitPoints.data)
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      const i = splitPoints.data.findIndex((f) => f === clickedFeature)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      if (i <  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-20 01:52:23 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        return
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      splitPoints.data.splice(i, 1)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      splitPoints.ping()
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    },
							 
						 
					
						
							
								
									
										
										
										
											2023-04-20 01:52:23 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  })
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  let id = 0
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  adaptor.lastClickLocation.addCallbackD(({  lon ,  lat  } ) => { 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-20 01:52:23 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    const projected = GeoOperations.nearestPoint(wayGeojson, [lon, lat])
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-20 01:52:23 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    projected.properties["id"] = id
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    id++
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    splitPoints.data.push(< any > projected)
							 
						 
					
						
							
								
									
										
										
										
											2023-04-20 01:52:23 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    splitPoints.ping()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  })
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / script >  
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:44:01 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< div  class = "h-full w-full" >  
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  < MaplibreMap  { map }  /> 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-20 01:52:23 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< / div >