| 
									
										
										
										
											2021-09-22 05:02:09 +02:00
										 |  |  | import {OsmNode, OsmRelation, OsmWay} from "../OsmObject"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-21 02:10:42 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Represents a single change to an object | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-07-15 20:47:28 +02:00
										 |  |  | export interface ChangeDescription { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-04 03:12:42 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Metadata to be included in the changeset | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     meta: { | 
					
						
							|  |  |  |         /* | 
					
						
							|  |  |  |         * The theme with which this changeset was made | 
					
						
							|  |  |  |         */ | 
					
						
							|  |  |  |         theme: string, | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * The type of the change | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         changeType:  "answer" | "create" | "split" | "delete" | string | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * THe motivation for the change, e.g. 'deleted because does not exist anymore' | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         specialMotivation?: string | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2021-09-21 02:10:42 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Identifier of the object | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-07-15 20:47:28 +02:00
										 |  |  |     type: "node" | "way" | "relation", | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2021-09-21 02:10:42 +02:00
										 |  |  |      * Identifier of the object | 
					
						
							|  |  |  |      * Negative for new objects | 
					
						
							| 
									
										
										
										
											2021-07-15 20:47:28 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     id: number, | 
					
						
							| 
									
										
										
										
											2021-09-21 02:10:42 +02:00
										 |  |  |      | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * All changes to tags | 
					
						
							|  |  |  |      * v = "" or v = undefined to erase this tag | 
					
						
							| 
									
										
										
										
											2021-10-10 00:53:14 +02:00
										 |  |  |      *  | 
					
						
							|  |  |  |      * Note that this list will only contain the _changes_ to the tags, not the full set of tags | 
					
						
							| 
									
										
										
										
											2021-09-21 02:10:42 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-07-15 20:47:28 +02:00
										 |  |  |     tags?: { k: string, v: string }[], | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-21 02:10:42 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * A change to the geometry: | 
					
						
							|  |  |  |      * 1) Change of node location | 
					
						
							|  |  |  |      * 2) Change of way geometry | 
					
						
							|  |  |  |      * 3) Change of relation members (untested) | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-07-15 20:47:28 +02:00
										 |  |  |     changes?: { | 
					
						
							|  |  |  |         lat: number, | 
					
						
							|  |  |  |         lon: number | 
					
						
							|  |  |  |     } | { | 
					
						
							| 
									
										
										
										
											2021-09-22 05:02:09 +02:00
										 |  |  |         // Coordinates are only used for rendering. They should be LAT, LON
 | 
					
						
							|  |  |  |         coordinates: [number, number][] | 
					
						
							| 
									
										
										
										
											2021-07-15 20:47:28 +02:00
										 |  |  |         nodes: number[], | 
					
						
							|  |  |  |     } | { | 
					
						
							|  |  |  |         members: { type: "node" | "way" | "relation", ref: number, role: string }[] | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* | 
					
						
							|  |  |  |     Set to delete the object | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     doDelete?: boolean | 
					
						
							| 
									
										
										
										
											2021-09-22 05:02:09 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-07-15 20:47:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-22 05:02:09 +02:00
										 |  |  | export class ChangeDescriptionTools{ | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     public static getGeojsonGeometry(change: ChangeDescription): any{ | 
					
						
							|  |  |  |         switch (change.type) { | 
					
						
							|  |  |  |             case "node": | 
					
						
							|  |  |  |                 const n = new OsmNode(change.id) | 
					
						
							|  |  |  |                 n.lat = change.changes["lat"] | 
					
						
							|  |  |  |                 n.lon = change.changes["lon"] | 
					
						
							|  |  |  |                 return n.asGeoJson().geometry | 
					
						
							|  |  |  |             case "way": | 
					
						
							|  |  |  |                 const w = new OsmWay(change.id) | 
					
						
							|  |  |  |                 w.nodes = change.changes["nodes"] | 
					
						
							|  |  |  |                 w.coordinates = change.changes["coordinates"].map(coor => coor.reverse()) | 
					
						
							|  |  |  |                 return w.asGeoJson().geometry | 
					
						
							|  |  |  |             case "relation": | 
					
						
							|  |  |  |                 const r = new OsmRelation(change.id) | 
					
						
							|  |  |  |                 r.members = change.changes["members"] | 
					
						
							|  |  |  |                 return r.asGeoJson().geometry | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-07-15 20:47:28 +02:00
										 |  |  | } |