| 
									
										
										
										
											2020-10-02 19:00:24 +02:00
										 |  |  | import * as L from "leaflet"; | 
					
						
							| 
									
										
										
										
											2020-07-30 00:59:08 +02:00
										 |  |  | import {UIElement} from "../../UI/UIElement"; | 
					
						
							| 
									
										
										
										
											2020-10-02 19:00:24 +02:00
										 |  |  | import State from "../../State"; | 
					
						
							| 
									
										
										
										
											2020-06-29 03:12:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * The stray-click-hanlders adds a marker to the map if no feature was clicked. | 
					
						
							|  |  |  |  * Shows the given uiToShow-element in the messagebox | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | export class StrayClickHandler { | 
					
						
							|  |  |  |     private _lastMarker; | 
					
						
							|  |  |  |     private _uiToShow: (() => UIElement); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     constructor( | 
					
						
							|  |  |  |         uiToShow: (() => UIElement)) { | 
					
						
							|  |  |  |         this._uiToShow = uiToShow; | 
					
						
							|  |  |  |         const self = this; | 
					
						
							| 
									
										
										
										
											2020-07-31 01:45:54 +02:00
										 |  |  |         const map = State.state.bm.map; | 
					
						
							| 
									
										
										
										
											2020-09-17 23:53:57 +02:00
										 |  |  |         State.state.filteredLayers.data.forEach((filteredLayer) => { | 
					
						
							|  |  |  |             filteredLayer.isDisplayed.addCallback(isEnabled => { | 
					
						
							| 
									
										
										
										
											2020-10-14 12:15:09 +02:00
										 |  |  |                 if(isEnabled && self._lastMarker){ | 
					
						
							| 
									
										
										
										
											2020-09-17 23:53:57 +02:00
										 |  |  |                     // When a layer is activated, we remove the 'last click location' in order to force the user to reclick
 | 
					
						
							|  |  |  |                     // This reclick might be at a location where a feature now appeared...
 | 
					
						
							|  |  |  |                      map.removeLayer(self._lastMarker); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2020-07-31 01:45:54 +02:00
										 |  |  |         State.state.bm.LastClickLocation.addCallback(function (lastClick) { | 
					
						
							|  |  |  |             State.state.selectedElement.setData(undefined); | 
					
						
							| 
									
										
										
										
											2020-06-29 03:12:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if (self._lastMarker !== undefined) { | 
					
						
							|  |  |  |                 map.removeLayer(self._lastMarker); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-07-25 18:00:08 +02:00
										 |  |  |             self._lastMarker = L.marker([lastClick.lat, lastClick.lon], { | 
					
						
							|  |  |  |                 icon: L.icon({ | 
					
						
							|  |  |  |                     iconUrl: "./assets/add.svg", | 
					
						
							| 
									
										
										
										
											2020-07-31 01:45:54 +02:00
										 |  |  |                     iconSize: [50, 50], | 
					
						
							|  |  |  |                     iconAnchor: [25, 50], | 
					
						
							|  |  |  |                     popupAnchor: [0, -45] | 
					
						
							| 
									
										
										
										
											2020-07-25 18:00:08 +02:00
										 |  |  |                 }) | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2020-06-29 16:21:36 +02:00
										 |  |  |             const uiElement = uiToShow(); | 
					
						
							|  |  |  |             const popup = L.popup().setContent(uiElement.Render()); | 
					
						
							| 
									
										
										
										
											2020-06-29 03:12:44 +02:00
										 |  |  |             self._lastMarker.addTo(map); | 
					
						
							| 
									
										
										
										
											2020-09-05 15:27:35 +02:00
										 |  |  |             self._lastMarker.bindPopup(popup); | 
					
						
							| 
									
										
										
										
											2020-06-29 16:21:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-01 02:12:33 +02:00
										 |  |  |             self._lastMarker.on("click", () => { | 
					
						
							| 
									
										
										
										
											2020-07-31 01:45:54 +02:00
										 |  |  |                 State.state.fullScreenMessage.setData(self._uiToShow()); | 
					
						
							| 
									
										
										
										
											2020-09-15 14:00:31 +02:00
										 |  |  |                 uiElement.Update(); | 
					
						
							| 
									
										
										
										
											2020-07-01 02:12:33 +02:00
										 |  |  |             }); | 
					
						
							| 
									
										
										
										
											2020-06-29 03:12:44 +02:00
										 |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-31 01:45:54 +02:00
										 |  |  |         State.state.selectedElement.addCallback(() => { | 
					
						
							| 
									
										
										
										
											2020-06-29 03:12:44 +02:00
										 |  |  |             if (self._lastMarker !== undefined) { | 
					
						
							|  |  |  |                 map.removeLayer(self._lastMarker); | 
					
						
							|  |  |  |                 this._lastMarker = undefined; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |