2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  {  SpecialVisualization ,  SpecialVisualizationState  }  from  "../../SpecialVisualization"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  {  AutoAction  }  from  "../AutoApplyButton"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  {  Feature ,  LineString ,  Polygon  }  from  "geojson"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  {  UIEventSource  }  from  "../../../Logic/UIEventSource"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  BaseUIElement  from  "../../BaseUIElement"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  {  ImportFlowUtils  }  from  "./ImportFlow"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  LayerConfig  from  "../../../Models/ThemeConfig/LayerConfig"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  SvelteUIElement  from  "../../Base/SvelteUIElement"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  {  FixedUiElement  }  from  "../../Base/FixedUiElement"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  WayImportFlow  from  "./WayImportFlow.svelte"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  WayImportFlowState ,  {  WayImportFlowArguments  }  from  "./WayImportFlowState"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  {  Utils  }  from  "../../../Utils"  
						 
					
						
							
								
									
										
										
										
											2024-10-17 04:06:03 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  ThemeConfig  from  "../../../Models/ThemeConfig/ThemeConfig"  
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  {  Changes  }  from  "../../../Logic/Osm/Changes"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  {  IndexedFeatureSource  }  from  "../../../Logic/FeatureSource/FeatureSource"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  FullNodeDatabaseSource  from  "../../../Logic/FeatureSource/TiledFeatureSource/FullNodeDatabaseSource"  
						 
					
						
							
								
									
										
										
										
											2023-05-30 02:52:22 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/ * *  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  Wrapper  around  'WayImportFlow'  to  make  it  a  special  visualisation 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								export  default  class  WayImportButtonViz  implements  AutoAction ,  SpecialVisualization  {  
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    public  readonly  funcName : string  =  "import_way_button" 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-27 22:21:35 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    needsUrls  =  [ ] 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    public  readonly  docs : string  = 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        "This button will copy the data from an external dataset into OpenStreetMap, copying the geometry and adding it as a 'line'"  + 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ImportFlowUtils . documentationGeneral 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    public  readonly  args :  {  name : string ;  defaultValue? : string ;  doc : string  } [ ]  =  [ 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-01 02:52:21 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        . . . ImportFlowUtils . generalArguments , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            name :  "snap_to_point_if" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            doc :  "Points with the given tags will be snapped to or moved" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            name :  "max_snap_distance" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            doc :  "If the imported object is a LineString or (Multi)Polygon, already existing OSM-points will be reused to construct the geometry of the newly imported way" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            defaultValue :  "0.05" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            name :  "move_osm_point_if" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            doc :  "Moves the OSM-point to the newly imported point if these conditions are met" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            name :  "max_move_distance" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            doc :  "If an OSM-point is moved, the maximum amount of meters it is moved. Capped on 20m" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            defaultValue :  "0.05" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            name :  "snap_onto_layers" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            doc :  "If no existing nearby point exists, but a line of a specified layer is closeby, snap to this layer instead" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            name :  "snap_to_layer_max_distance" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            doc :  "Distance to distort the geometry to snap to this layer" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            defaultValue :  "0.1" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ] 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-30 02:52:22 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    public  readonly  supportsAutoAction  =  true 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    public  readonly  needsNodeDatabase  =  true 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    constr ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        state : SpecialVisualizationState , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        tagSource : UIEventSource < Record < string ,  string > > , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        argument : string [ ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        feature : Feature , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        _ : LayerConfig 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) :  BaseUIElement  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-30 02:52:22 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        const  geometry  =  feature . geometry 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! ( geometry . type  ==  "LineString"  ||  geometry . type  ===  "Polygon" ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            console . error ( "Invalid type to import" ,  geometry . type ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  new  FixedUiElement ( "Invalid geometry type:"  +  geometry . type ) . SetClass ( "alert" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  args : WayImportFlowArguments  =  < any > Utils . ParseVisArgs ( this . args ,  argument ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  tagsToApply  =  ImportFlowUtils . getTagsToApply ( tagSource ,  args ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        const  importFlow  =  new  WayImportFlowState ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            state , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            < Feature < LineString  |  Polygon > > feature , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            args , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            tagsToApply , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            tagSource 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-30 02:52:22 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        return  new  SvelteUIElement ( WayImportFlow ,  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            importFlow , 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-30 02:52:22 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    public  async  applyActionOn ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        feature : Feature , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        state :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-17 04:06:03 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            theme : ThemeConfig 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            changes : Changes 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            indexedFeatures : IndexedFeatureSource 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            fullNodeDatabase : FullNodeDatabaseSource 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        tagSource : UIEventSource < any > , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        argument : string [ ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) :  Promise < void >  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-30 02:52:22 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // Small safety check to prevent duplicate imports
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            const  id  =  tagSource . data . id 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( ImportFlowUtils . importedIds . has ( id ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ImportFlowUtils . importedIds . add ( id ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( feature . geometry . type  !==  "LineString"  &&  feature . geometry . type  !==  "Polygon" )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-30 02:52:22 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  args : WayImportFlowArguments  =  < any > Utils . ParseVisArgs ( this . args ,  argument ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  tagsToApply  =  ImportFlowUtils . getTagsToApply ( tagSource ,  args ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-01 02:52:21 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        const  mergeConfigs  =  WayImportFlowState . GetMergeConfig ( args ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        const  action  =  WayImportFlowState . CreateAction ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            < Feature < LineString  |  Polygon > > feature , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            args , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            state , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            tagsToApply , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            mergeConfigs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-01 02:52:21 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        tagSource . data [ "_imported" ]  =  "yes" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        tagSource . ping ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-30 02:52:22 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        await  state . changes . applyAction ( action ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    getLayerDependencies ( args : string [ ] )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-30 02:52:22 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        return  ImportFlowUtils . getLayerDependenciesWithSnapOnto ( this . args ,  args ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}