| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  | import {OsmNode, OsmObject} from "./OsmObject"; | 
					
						
							| 
									
										
										
										
											2020-10-02 19:00:24 +02:00
										 |  |  | import State from "../../State"; | 
					
						
							| 
									
										
										
										
											2020-07-31 04:58:58 +02:00
										 |  |  | import {Utils} from "../../Utils"; | 
					
						
							| 
									
										
										
										
											2020-10-27 01:01:34 +01:00
										 |  |  | import {UIEventSource} from "../UIEventSource"; | 
					
						
							| 
									
										
										
										
											2021-01-02 19:09:49 +01:00
										 |  |  | import Constants from "../../Models/Constants"; | 
					
						
							| 
									
										
										
										
											2021-01-03 03:09:52 +01:00
										 |  |  | import FeatureSource from "../FeatureSource/FeatureSource"; | 
					
						
							| 
									
										
										
										
											2021-03-29 00:41:53 +02:00
										 |  |  | import {TagsFilter} from "../Tags/TagsFilter"; | 
					
						
							|  |  |  | import {Tag} from "../Tags/Tag"; | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  | import {OsmConnection} from "./OsmConnection"; | 
					
						
							|  |  |  | import {LocalStorageSource} from "../Web/LocalStorageSource"; | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-03 03:09:52 +01:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Handles all changes made to OSM. | 
					
						
							|  |  |  |  * Needs an authenticator via OsmConnection | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  | export class Changes implements FeatureSource { | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     private static _nextId = -1; // Newly assigned ID's are negative
 | 
					
						
							| 
									
										
										
										
											2021-04-23 12:56:56 +02:00
										 |  |  |     public readonly name = "Newly added features" | 
					
						
							| 
									
										
										
										
											2021-02-20 22:18:42 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * The newly created points, as a FeatureSource | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  |     public features = new UIEventSource<{ feature: any, freshness: Date }[]>([]); | 
					
						
							| 
									
										
										
										
											2021-02-20 22:18:42 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * All the pending changes | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  |     public readonly pending = LocalStorageSource.GetParsed<{ elementId: string, key: string, value: string }[]>("pending-changes", []) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * All the pending new objects to upload | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private readonly newObjects = LocalStorageSource.GetParsed<{ id: number, lat: number, lon: number }[]>("newObjects", []) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private readonly isUploading = new UIEventSource(false); | 
					
						
							| 
									
										
										
										
											2021-07-13 00:40:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Adds a change to the pending changes | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  |     private static checkChange(kv: { k: string, v: string }): { k: string, v: string } { | 
					
						
							| 
									
										
										
										
											2021-03-29 02:31:08 +02:00
										 |  |  |         const key = kv.k; | 
					
						
							|  |  |  |         const value = kv.v; | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  |         if (key === undefined || key === null) { | 
					
						
							|  |  |  |             console.log("Invalid key"); | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |             return undefined; | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (value === undefined || value === null) { | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |             console.log("Invalid value for ", key); | 
					
						
							|  |  |  |             return undefined; | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (key.startsWith(" ") || value.startsWith(" ") || value.endsWith(" ") || key.endsWith(" ")) { | 
					
						
							| 
									
										
										
										
											2020-08-06 19:42:10 +02:00
										 |  |  |             console.warn("Tag starts with or ends with a space - trimming anyway") | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-08-27 11:11:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-29 02:31:08 +02:00
										 |  |  |         return {k: key.trim(), v: value.trim()}; | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-03 03:09:52 +01:00
										 |  |  |     addTag(elementId: string, tagsFilter: TagsFilter, | 
					
						
							|  |  |  |            tags?: UIEventSource<any>) { | 
					
						
							| 
									
										
										
										
											2021-03-29 02:31:08 +02:00
										 |  |  |         const eventSource = tags ?? State.state?.allElements.getEventSourceById(elementId); | 
					
						
							|  |  |  |         const elementTags = eventSource.data; | 
					
						
							|  |  |  |         const changes = tagsFilter.asChange(elementTags).map(Changes.checkChange) | 
					
						
							| 
									
										
										
										
											2021-01-03 03:09:52 +01:00
										 |  |  |         if (changes.length == 0) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-03 03:09:52 +01:00
										 |  |  |         for (const change of changes) { | 
					
						
							|  |  |  |             if (elementTags[change.k] !== change.v) { | 
					
						
							|  |  |  |                 elementTags[change.k] = change.v; | 
					
						
							| 
									
										
										
										
											2021-04-17 23:36:46 +02:00
										 |  |  |                 console.log("Applied ", change.k, "=", change.v) | 
					
						
							| 
									
										
										
										
											2021-07-01 02:26:45 +02:00
										 |  |  |                 // We use 'elementTags.id' here, as we might have retrieved with the id 'node/-1' as new point, but should use the rewritten id
 | 
					
						
							| 
									
										
										
										
											2021-02-20 22:18:42 +01:00
										 |  |  |                 this.pending.data.push({elementId: elementTags.id, key: change.k, value: change.v}); | 
					
						
							| 
									
										
										
										
											2021-01-03 03:09:52 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-02-20 22:18:42 +01:00
										 |  |  |         this.pending.ping(); | 
					
						
							| 
									
										
										
										
											2021-01-03 03:09:52 +01:00
										 |  |  |         eventSource.ping(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-20 22:18:42 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Uploads all the pending changes in one go. | 
					
						
							|  |  |  |      * Triggered by the 'PendingChangeUploader'-actor in Actors | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  |     public flushChanges(flushreason: string = undefined) { | 
					
						
							|  |  |  |         if (this.pending.data.length === 0) { | 
					
						
							| 
									
										
										
										
											2021-02-20 22:18:42 +01:00
										 |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  |         if (flushreason !== undefined) { | 
					
						
							| 
									
										
										
										
											2021-02-20 22:18:42 +01:00
										 |  |  |             console.log(flushreason) | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  |         this.uploadAll(); | 
					
						
							| 
									
										
										
										
											2021-02-20 22:18:42 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Create a new node element at the given lat/long. | 
					
						
							|  |  |  |      * An internal OsmObject is created to upload later on, a geojson represention is returned. | 
					
						
							|  |  |  |      * Note that the geojson version shares the tags (properties) by pointer, but has _no_ id in properties | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-01-03 03:09:52 +01:00
										 |  |  |     public createElement(basicTags: Tag[], lat: number, lon: number) { | 
					
						
							| 
									
										
										
										
											2020-08-06 21:06:50 +02:00
										 |  |  |         console.log("Creating a new element with ", basicTags) | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  |         const newId = Changes._nextId; | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  |         Changes._nextId--; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  |         const id = "node/" + newId; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  |         const properties = {id: id}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const geojson = { | 
					
						
							|  |  |  |             "type": "Feature", | 
					
						
							|  |  |  |             "properties": properties, | 
					
						
							|  |  |  |             "id": id, | 
					
						
							|  |  |  |             "geometry": { | 
					
						
							|  |  |  |                 "type": "Point", | 
					
						
							|  |  |  |                 "coordinates": [ | 
					
						
							|  |  |  |                     lon, | 
					
						
							|  |  |  |                     lat | 
					
						
							|  |  |  |                 ] | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // The basictags are COPIED, the id is included in the properties
 | 
					
						
							|  |  |  |         // The tags are not yet written into the OsmObject, but this is applied onto a 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 11:11:20 +02:00
										 |  |  |         const changes = []; | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  |         for (const kv of basicTags) { | 
					
						
							| 
									
										
										
										
											2020-08-27 11:11:20 +02:00
										 |  |  |             if (typeof kv.value !== "string") { | 
					
						
							|  |  |  |                 throw "Invalid value: don't use a regex in a preset" | 
					
						
							| 
									
										
										
										
											2020-08-23 01:49:19 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  |             properties[kv.key] = kv.value; | 
					
						
							| 
									
										
										
										
											2020-08-27 11:11:20 +02:00
										 |  |  |             changes.push({elementId: id, key: kv.key, value: kv.value}) | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-14 19:45:02 +01:00
										 |  |  |         console.log("New feature added and pinged") | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  |         this.features.data.push({feature: geojson, freshness: new Date()}); | 
					
						
							| 
									
										
										
										
											2021-01-04 22:14:56 +01:00
										 |  |  |         this.features.ping(); | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-14 19:45:02 +01:00
										 |  |  |         State.state.allElements.addOrGetElement(geojson).ping(); | 
					
						
							| 
									
										
										
										
											2021-01-04 22:14:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  |         if (State.state.osmConnection.userDetails.data.backend !== OsmConnection.oauth_configs.osm.url) { | 
					
						
							|  |  |  |             properties["_backend"] = State.state.osmConnection.userDetails.data.backend | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.newObjects.data.push({id: newId, lat: lat, lon: lon}) | 
					
						
							|  |  |  |         this.pending.data.push(...changes) | 
					
						
							|  |  |  |         this.pending.ping(); | 
					
						
							|  |  |  |         this.newObjects.ping(); | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  |         return geojson; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |     private uploadChangesWithLatestVersions( | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  |         knownElements: OsmObject[]) { | 
					
						
							| 
									
										
										
										
											2021-07-08 10:24:43 +02:00
										 |  |  |         const knownById = new Map<string, OsmObject>(); | 
					
						
							|  |  |  |         knownElements.forEach(knownElement => { | 
					
						
							|  |  |  |             knownById.set(knownElement.type + "/" + knownElement.id, knownElement) | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         const newElements: OsmNode [] = this.newObjects.data.map(spec => { | 
					
						
							|  |  |  |             const newElement = new OsmNode(spec.id); | 
					
						
							|  |  |  |             newElement.lat = spec.lat; | 
					
						
							|  |  |  |             newElement.lon = spec.lon; | 
					
						
							|  |  |  |             return newElement | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |         // Here, inside the continuation, we know that all 'neededIds' are loaded in 'knownElements', which maps the ids onto the elements
 | 
					
						
							|  |  |  |         // We apply the changes on them
 | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  |         for (const change of this.pending.data) { | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |             if (parseInt(change.elementId.split("/")[1]) < 0) { | 
					
						
							|  |  |  |                 // This is a new element - we should apply this on one of the new elements
 | 
					
						
							|  |  |  |                 for (const newElement of newElements) { | 
					
						
							|  |  |  |                     if (newElement.type + "/" + newElement.id === change.elementId) { | 
					
						
							|  |  |  |                         newElement.addTag(change.key, change.value); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2021-07-08 10:24:43 +02:00
										 |  |  |                 knownById.get(change.elementId).addTag(change.key, change.value); | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |         // Small sanity check for duplicate information
 | 
					
						
							|  |  |  |         let changedElements = []; | 
					
						
							|  |  |  |         for (const elementId in knownElements) { | 
					
						
							|  |  |  |             const element = knownElements[elementId]; | 
					
						
							|  |  |  |             if (element.changed) { | 
					
						
							|  |  |  |                 changedElements.push(element); | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |         if (changedElements.length == 0 && newElements.length == 0) { | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  |             console.log("No changes in any object - clearing"); | 
					
						
							|  |  |  |             this.pending.setData([]) | 
					
						
							|  |  |  |             this.newObjects.setData([]) | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  |         const self = this; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (this.isUploading.data) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         this.isUploading.setData(true) | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |         console.log("Beginning upload..."); | 
					
						
							|  |  |  |         // At last, we build the changeset and upload
 | 
					
						
							|  |  |  |         State.state.osmConnection.UploadChangeset( | 
					
						
							| 
									
										
										
										
											2020-08-30 01:13:18 +02:00
										 |  |  |             State.state.layoutToUse.data, | 
					
						
							|  |  |  |             State.state.allElements, | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |             function (csId) { | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |                 let modifications = ""; | 
					
						
							|  |  |  |                 for (const element of changedElements) { | 
					
						
							|  |  |  |                     if (!element.changed) { | 
					
						
							|  |  |  |                         continue; | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  |                     } | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |                     modifications += element.ChangesetXML(csId) + "\n"; | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 let creations = ""; | 
					
						
							|  |  |  |                 for (const newElement of newElements) { | 
					
						
							|  |  |  |                     creations += newElement.ChangesetXML(csId); | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-02 19:09:49 +01:00
										 |  |  |                 let changes = `<osmChange version='0.6' generator='Mapcomplete ${Constants.vNumber}'>`; | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |                 if (creations.length > 0) { | 
					
						
							|  |  |  |                     changes += | 
					
						
							|  |  |  |                         "<create>" + | 
					
						
							|  |  |  |                         creations + | 
					
						
							|  |  |  |                         "</create>"; | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |                 if (modifications.length > 0) { | 
					
						
							|  |  |  |                     changes += | 
					
						
							| 
									
										
										
										
											2020-08-30 01:13:18 +02:00
										 |  |  |                         "<modify>\n" + | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |                         modifications + | 
					
						
							| 
									
										
										
										
											2020-08-30 01:13:18 +02:00
										 |  |  |                         "\n</modify>"; | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |                 changes += "</osmChange>"; | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |                 return changes; | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  |             }, | 
					
						
							|  |  |  |             () => { | 
					
						
							|  |  |  |                 console.log("Upload successfull!") | 
					
						
							|  |  |  |                 self.newObjects.setData([]) | 
					
						
							|  |  |  |                 self.pending.setData([]); | 
					
						
							|  |  |  |                 self.isUploading.setData(false) | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             () => self.isUploading.setData(false) | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  |     private uploadAll() { | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |         const self = this; | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  |         const pending = this.pending.data; | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |         let neededIds: string[] = []; | 
					
						
							|  |  |  |         for (const change of pending) { | 
					
						
							|  |  |  |             const id = change.elementId; | 
					
						
							|  |  |  |             if (parseFloat(id.split("/")[1]) < 0) { | 
					
						
							|  |  |  |                 // New element - we don't have to download this
 | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 neededIds.push(id); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 18:44:16 +02:00
										 |  |  |         neededIds = Utils.Dedup(neededIds); | 
					
						
							| 
									
										
										
										
											2021-06-30 18:48:23 +02:00
										 |  |  |         OsmObject.DownloadAll(neededIds).addCallbackAndRunD(knownElements => { | 
					
						
							| 
									
										
										
										
											2021-07-26 15:39:27 +02:00
										 |  |  |             self.uploadChangesWithLatestVersions(knownElements) | 
					
						
							| 
									
										
										
										
											2021-06-30 18:48:23 +02:00
										 |  |  |         }) | 
					
						
							| 
									
										
										
										
											2020-07-31 04:58:58 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-27 11:11:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-24 00:35:19 +02:00
										 |  |  | } |