| 
									
										
										
										
											2021-07-15 20:47:28 +02:00
										 |  |  | import { Changes } from "../Osm/Changes" | 
					
						
							| 
									
										
										
										
											2023-04-20 01:52:23 +02:00
										 |  |  | import FeaturePropertiesStore from "../FeatureSource/Actors/FeaturePropertiesStore" | 
					
						
							| 
									
										
										
										
											2021-07-15 20:47:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-20 01:52:23 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Applies tag changes onto the featureStore | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-07-15 20:47:28 +02:00
										 |  |  | export default class ChangeToElementsActor { | 
					
						
							| 
									
										
										
										
											2023-03-26 05:58:28 +02:00
										 |  |  |     constructor(changes: Changes, allElements: FeaturePropertiesStore) { | 
					
						
							| 
									
										
										
										
											2021-07-15 20:47:28 +02:00
										 |  |  |         changes.pendingChanges.addCallbackAndRun((changes) => { | 
					
						
							|  |  |  |             for (const change of changes) { | 
					
						
							|  |  |  |                 const id = change.type + "/" + change.id | 
					
						
							|  |  |  |                 if (!allElements.has(id)) { | 
					
						
							| 
									
										
										
										
											2021-07-18 14:52:09 +02:00
										 |  |  |                     continue // Ignored as the geometryFixer will introduce this
 | 
					
						
							| 
									
										
										
										
											2021-07-15 20:47:28 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2023-03-26 05:58:28 +02:00
										 |  |  |                 const src = allElements.getStore(id) | 
					
						
							| 
									
										
										
										
											2021-07-15 20:47:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 let changed = false | 
					
						
							|  |  |  |                 for (const kv of change.tags ?? []) { | 
					
						
							|  |  |  |                     // Apply tag changes and ping the consumers
 | 
					
						
							|  |  |  |                     const k = kv.k | 
					
						
							|  |  |  |                     let v = kv.v | 
					
						
							|  |  |  |                     if (v === "") { | 
					
						
							|  |  |  |                         v = undefined | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     if (src.data[k] === v) { | 
					
						
							|  |  |  |                         continue | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     changed = true | 
					
						
							|  |  |  |                     src.data[k] = v | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 if (changed) { | 
					
						
							|  |  |  |                     src.ping() | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |