2023-03-11 02:37:07 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< script  lang = "ts" >  
						 
					
						
							
								
									
										
										
										
											2023-07-28 01:02:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  import {  onDestroy ,  onMount  }  from "svelte"
							 
						 
					
						
							
								
									
										
										
										
											2024-03-25 04:17:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  import type {  Map ,  MapOptions  }  from "maplibre-gl"
							 
						 
					
						
							
								
									
										
										
										
											2023-12-12 13:53:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  import * as maplibre from "maplibre-gl"
							 
						 
					
						
							
								
									
										
										
										
											2024-03-25 04:17:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  import type {  Writable  }  from "svelte/store"
							 
						 
					
						
							
								
									
										
										
										
											2023-07-28 01:02:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  import {  AvailableRasterLayers  }  from "../../Models/RasterLayers"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  import {  Utils  }  from "../../Utils"
							 
						 
					
						
							
								
									
										
										
										
											2023-12-15 01:46:01 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  import {  ariaLabel  }  from "../../Utils/ariaLabel"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  import Translations from "../i18n/Translations"
							 
						 
					
						
							
								
									
										
										
										
											2024-03-25 04:17:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  import type {  MapProperties  }  from "../../Models/MapProperties"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  import type {  RasterLayerProperties  }  from "../../Models/RasterLayerProperties"
							 
						 
					
						
							
								
									
										
										
										
											2023-07-28 01:02:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   * The 'MaplibreMap' maps various event sources onto MapLibre.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   * Beware: this map will _only_ be set by this component
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   * It should thus be treated as a 'store' by external parties
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   */
							 
						 
					
						
							
								
									
										
										
										
											2024-03-25 04:17:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  export let map: Writable< Map >  = undefined
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  export let mapProperties: MapProperties = undefined
							 
						 
					
						
							
								
									
										
										
										
											2023-07-28 01:02:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-12-25 22:48:29 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  export let interactive: boolean = true
							 
						 
					
						
							
								
									
										
										
										
											2024-07-16 16:00:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   * If many maps are shown (> ~15), Chromium will drop some because of "too Much WEBGL-contexts" (see issue #2024 or https://webglfundamentals.org/webgl/lessons/webgl-multiple-views.html)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   * For important maps (e.g. the main map), we want to recover from this
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  export let autorecovery: boolean = false
							 
						 
					
						
							
								
									
										
										
										
											2023-12-25 22:48:29 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-07-28 01:02:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  let container: HTMLElement
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  let _map: Map
							 
						 
					
						
							
								
									
										
										
										
											2024-07-16 16:00:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  function initMap() { 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-25 04:17:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    const {  lon ,  lat  }  = mapProperties?.location?.data ?? {  lon : 0 ,  lat : 0  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const rasterLayer: RasterLayerProperties = mapProperties?.rasterLayer?.data?.properties
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    let styleUrl: string
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if (rasterLayer?.type === "vector") { 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-13 02:40:21 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      styleUrl =
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        rasterLayer?.style ??
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        rasterLayer?.url ??
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        AvailableRasterLayers.defaultBackgroundLayer.properties.url
							 
						 
					
						
							
								
									
										
										
										
											2023-07-28 01:02:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } else { 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-25 04:17:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      const defaultLayer = AvailableRasterLayers.defaultBackgroundLayer.properties
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      styleUrl = defaultLayer.style ?? defaultLayer.url
							 
						 
					
						
							
								
									
										
										
										
											2023-07-28 01:02:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-31 21:14:29 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    console.log("Initing mapLIbremap with style", styleUrl)
							 
						 
					
						
							
								
									
										
										
										
											2024-03-25 04:17:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const options: MapOptions = { 
							 
						 
					
						
							
								
									
										
										
										
											2023-07-28 01:02:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      container,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      style: styleUrl,
							 
						 
					
						
							
								
									
										
										
										
											2024-03-25 04:17:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      zoom: mapProperties?.zoom?.data ?? 1,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      center: {  lng : lon ,  lat  } ,
							 
						 
					
						
							
								
									
										
										
										
											2023-07-28 01:02:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      maxZoom: 24,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      interactive: true,
							 
						 
					
						
							
								
									
										
										
										
											2024-07-16 14:45:29 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      attributionControl: false
							 
						 
					
						
							
								
									
										
										
										
											2024-03-25 04:17:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    _map = new maplibre.Map(options)
							 
						 
					
						
							
								
									
										
										
										
											2023-12-12 13:53:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    window.requestAnimationFrame(() => { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      _map.resize()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    })
							 
						 
					
						
							
								
									
										
										
										
											2024-07-16 16:00:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-07-16 14:45:29 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    _map.on("load", function() { 
							 
						 
					
						
							
								
									
										
										
										
											2023-07-28 01:02:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      _map.resize()
							 
						 
					
						
							
								
									
										
										
										
											2023-12-30 15:24:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      const canvas = _map.getCanvas()
							 
						 
					
						
							
								
									
										
										
										
											2024-07-16 16:00:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      canvas.addEventListener("webglcontextlost", (e) => { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        console.warn("A MapLibreMap lost their context. Recovery is", autorecovery, e)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          _map?.remove()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }catch (e) { 
							 
						 
					
						
							
								
									
										
										
										
											2024-07-17 18:42:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								          console.debug("Could not remove map due to", e)
							 
						 
					
						
							
								
									
										
										
										
											2024-07-16 16:00:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if(autorecovery){ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          requestAnimationFrame(() => { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            console.warn("Attempting map recovery")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            _map = new maplibre.Map(options)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            initMap()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          })
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      })
							 
						 
					
						
							
								
									
										
										
										
											2023-12-25 22:48:29 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      if (interactive) { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ariaLabel(canvas, Translations.t.general.visualFeedback.navigation)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        canvas.role = "application"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        canvas.tabIndex = 0
							 
						 
					
						
							
								
									
										
										
										
											2023-12-30 15:24:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      } else { 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-25 22:48:29 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        canvas.tabIndex = -1
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        _map.getContainer().tabIndex = -1
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      }
							 
						 
					
						
							
								
									
										
										
										
											2023-07-28 01:02:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    })
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    map.set(_map)
							 
						 
					
						
							
								
									
										
										
										
											2024-07-16 16:00:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  onMount(() => initMap())
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-07-28 01:02:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  onDestroy(async () => { 
							 
						 
					
						
							
								
									
										
										
										
											2024-07-19 11:37:20 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< < < < < < <  HEAD  
						 
					
						
							
								
									
										
										
										
											2024-07-16 14:45:29 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    await Utils.waitFor(100)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    requestAnimationFrame(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      () => { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          _map?.remove()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          console.log("Removed map")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          map = null
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } catch (e) { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          console.error("Could not destroy map")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    )
							 
						 
					
						
							
								
									
										
										
										
											2024-07-19 11:37:20 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								=======
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    await Utils.waitFor(250)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    try { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      _map?.remove()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      map = null
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } catch (e) { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      console.error("Could not destroy map")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								>>>>>>> 6093ac3ea (Refactoring: rework image fetching code, improve nearby images UI. Fix #2026, #2027)
							 
						 
					
						
							
								
									
										
										
										
											2023-07-28 01:02:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  })
							 
						 
					
						
							
								
									
										
										
										
											2023-03-11 02:37:07 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< / script >  
						 
					
						
							
								
									
										
										
										
											2023-06-14 20:39:36 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-07-16 04:24:32 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< svelte:head >  
						 
					
						
							
								
									
										
										
										
											2023-07-28 01:02:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  < link  href = "./maplibre-gl.css"  rel = "stylesheet"  / > 
							 
						 
					
						
							
								
									
										
										
										
											2023-07-16 04:24:32 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< / svelte:head >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-12-21 01:46:18 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< div  bind:this = { container }  class="map  relative  top-0  left-0  h-full  w-full "  id = "map"  />