| 
									
										
										
										
											2021-07-15 20:47:28 +02:00
										 |  |  | import {Tag} from "../../Tags/Tag"; | 
					
						
							|  |  |  | import OsmChangeAction from "./OsmChangeAction"; | 
					
						
							|  |  |  | import {Changes} from "../Changes"; | 
					
						
							|  |  |  | import {ChangeDescription} from "./ChangeDescription"; | 
					
						
							|  |  |  | import {And} from "../../Tags/And"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-18 14:52:09 +02:00
										 |  |  | export default class CreateNewNodeAction extends OsmChangeAction { | 
					
						
							| 
									
										
										
										
											2021-07-15 20:47:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     private readonly _basicTags: Tag[]; | 
					
						
							|  |  |  |     private readonly _lat: number; | 
					
						
							|  |  |  |     private readonly _lon: number; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-18 14:52:09 +02:00
										 |  |  |     public newElementId : string = undefined | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2021-07-15 20:47:28 +02:00
										 |  |  |     constructor(basicTags: Tag[], lat: number, lon: number) { | 
					
						
							| 
									
										
										
										
											2021-07-18 14:52:09 +02:00
										 |  |  |         super() | 
					
						
							| 
									
										
										
										
											2021-07-15 20:47:28 +02:00
										 |  |  |         this._basicTags = basicTags; | 
					
						
							|  |  |  |         this._lat = lat; | 
					
						
							|  |  |  |         this._lon = lon; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-18 14:52:09 +02:00
										 |  |  |     CreateChangeDescriptions(changes: Changes): ChangeDescription[] { | 
					
						
							| 
									
										
										
										
											2021-07-15 20:47:28 +02:00
										 |  |  |         const id = changes.getNewID() | 
					
						
							|  |  |  |         const properties = { | 
					
						
							|  |  |  |             id: "node/" + id | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-07-18 14:52:09 +02:00
										 |  |  |         this.newElementId = "node/"+id | 
					
						
							| 
									
										
										
										
											2021-07-15 20:47:28 +02:00
										 |  |  |         for (const kv of this._basicTags) { | 
					
						
							|  |  |  |             if (typeof kv.value !== "string") { | 
					
						
							|  |  |  |                 throw "Invalid value: don't use a regex in a preset" | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             properties[kv.key] = kv.value; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return [{ | 
					
						
							|  |  |  |             tags: new And(this._basicTags).asChange(properties), | 
					
						
							|  |  |  |             type: "node", | 
					
						
							|  |  |  |             id: id, | 
					
						
							|  |  |  |             changes:{ | 
					
						
							|  |  |  |                 lat: this._lat, | 
					
						
							|  |  |  |                 lon: this._lon | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |