| 
									
										
										
										
											2023-04-02 02:59:20 +02:00
										 |  |  | import LayoutConfig from "../../../Models/ThemeConfig/LayoutConfig" | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | import { WritableFeatureSource } from "../FeatureSource" | 
					
						
							|  |  |  | import { ImmutableStore, Store, UIEventSource } from "../../UIEventSource" | 
					
						
							| 
									
										
										
										
											2023-04-02 02:59:20 +02:00
										 |  |  | import { Feature, Point } from "geojson" | 
					
						
							|  |  |  | import { TagUtils } from "../../Tags/TagUtils" | 
					
						
							|  |  |  | import BaseUIElement from "../../../UI/BaseUIElement" | 
					
						
							|  |  |  | import { Utils } from "../../../Utils" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Highly specialized feature source. | 
					
						
							|  |  |  |  * Based on a lon/lat UIEVentSource, will generate the corresponding feature with the correct properties | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | export class LastClickFeatureSource implements WritableFeatureSource { | 
					
						
							|  |  |  |     public readonly features: UIEventSource<Feature[]> = new UIEventSource<Feature[]>([]) | 
					
						
							| 
									
										
										
										
											2023-04-02 02:59:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Must be public: passed as tags into the selected view | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2023-04-02 02:59:20 +02:00
										 |  |  |     public properties: Record<string, string> | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-02 02:59:20 +02:00
										 |  |  |     constructor(location: Store<{ lon: number; lat: number }>, layout: LayoutConfig) { | 
					
						
							|  |  |  |         const allPresets: BaseUIElement[] = [] | 
					
						
							|  |  |  |         for (const layer of layout.layers) | 
					
						
							|  |  |  |             for (let i = 0; i < (layer.presets ?? []).length; i++) { | 
					
						
							|  |  |  |                 const preset = layer.presets[i] | 
					
						
							|  |  |  |                 const tags = new ImmutableStore(TagUtils.KVtoProperties(preset.tags)) | 
					
						
							|  |  |  |                 const { html } = layer.mapRendering[0].RenderIcon(tags, false, { | 
					
						
							|  |  |  |                     noSize: true, | 
					
						
							|  |  |  |                     includeBadges: false, | 
					
						
							|  |  |  |                 }) | 
					
						
							|  |  |  |                 allPresets.push(html) | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const renderings = Utils.Dedup( | 
					
						
							|  |  |  |             allPresets.map((uiElem) => uiElem.ConstructElement().innerHTML) | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const properties = { | 
					
						
							|  |  |  |             lastclick: "yes", | 
					
						
							|  |  |  |             id: "last_click", | 
					
						
							|  |  |  |             has_note_layer: layout.layers.some((l) => l.id === "note") ? "yes" : "no", | 
					
						
							|  |  |  |             has_presets: layout.layers.some((l) => l.presets?.length > 0) ? "yes" : "no", | 
					
						
							|  |  |  |             renderings: renderings.join(""), | 
					
						
							|  |  |  |             number_of_presets: "" + renderings.length, | 
					
						
							|  |  |  |             first_preset: renderings[0], | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         this.properties = properties | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |         location.addCallbackAndRunD(({ lon, lat }) => { | 
					
						
							|  |  |  |             const point = <Feature<Point>>{ | 
					
						
							| 
									
										
										
										
											2023-04-02 02:59:20 +02:00
										 |  |  |                 type: "Feature", | 
					
						
							|  |  |  |                 properties, | 
					
						
							|  |  |  |                 geometry: { | 
					
						
							|  |  |  |                     type: "Point", | 
					
						
							|  |  |  |                     coordinates: [lon, lat], | 
					
						
							|  |  |  |                 }, | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |             this.features.setData([point]) | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2023-04-02 02:59:20 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } |