| 
									
										
										
										
											2023-09-16 18:52:42 +02:00
										 |  |  | <script lang="ts"> | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * A screen showing: | 
					
						
							|  |  |  |    * - A link to share the current view | 
					
						
							|  |  |  |    * - Some query parameters that can be enabled/disabled | 
					
						
							|  |  |  |    * - The code to embed MC as IFrame | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   import ThemeViewState from "../../Models/ThemeViewState" | 
					
						
							|  |  |  |   import { QueryParameters } from "../../Logic/Web/QueryParameters" | 
					
						
							|  |  |  |   import Tr from "../Base/Tr.svelte" | 
					
						
							|  |  |  |   import Translations from "../i18n/Translations" | 
					
						
							|  |  |  |   import { Utils } from "../../Utils" | 
					
						
							| 
									
										
										
										
											2024-03-01 00:30:21 +01:00
										 |  |  |   import Qr from "../../Utils/Qr" | 
					
						
							| 
									
										
										
										
											2024-06-27 17:37:34 +02:00
										 |  |  |   import AccordionSingle from "../Flowbite/AccordionSingle.svelte" | 
					
						
							|  |  |  |   import Constants from "../../Models/Constants" | 
					
						
							|  |  |  |   import Copyable from "../Base/Copyable.svelte" | 
					
						
							| 
									
										
										
										
											2023-09-16 18:52:42 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   export let state: ThemeViewState | 
					
						
							|  |  |  |   const tr = Translations.t.general.sharescreen | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let url = window.location | 
					
						
							|  |  |  |   let linkToShare: string = undefined | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * In some cases (local deploys, custom themes), we need to set the URL to `/theme.html?layout=xyz` instead of `/xyz?...` | 
					
						
							| 
									
										
										
										
											2024-06-27 17:37:34 +02:00
										 |  |  |    * Note that the 'layout='-param will be included automatically | 
					
						
							| 
									
										
										
										
											2023-09-16 18:52:42 +02:00
										 |  |  |    */ | 
					
						
							|  |  |  |   let needsThemeRedirect = url.port !== "" || url.hostname.match(/^[0-9]/) || !state.layout.official | 
					
						
							|  |  |  |   let layoutId = state.layout.id | 
					
						
							| 
									
										
										
										
											2024-07-09 13:42:08 +02:00
										 |  |  |   let baseLink = `${url.protocol}//${url.host}/${needsThemeRedirect ? "theme.html" : layoutId}?` | 
					
						
							| 
									
										
										
										
											2023-09-16 18:52:42 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   let showWelcomeMessage = true | 
					
						
							|  |  |  |   let enableLogin = true | 
					
						
							| 
									
										
										
										
											2024-06-27 17:37:34 +02:00
										 |  |  |   let enableFilters = true | 
					
						
							|  |  |  |   let enableBackground = true | 
					
						
							|  |  |  |   let enableGeolocation = true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-02 11:47:26 +02:00
										 |  |  |   let location = state.mapProperties.location | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-27 17:37:34 +02:00
										 |  |  |   function calculateLinkToShare( | 
					
						
							|  |  |  |     showWelcomeMessage: boolean, | 
					
						
							|  |  |  |     enableLogin: boolean, | 
					
						
							|  |  |  |     enableFilters: boolean, | 
					
						
							|  |  |  |     enableBackground: boolean, | 
					
						
							| 
									
										
										
										
											2024-07-09 13:42:08 +02:00
										 |  |  |     enableGeolocation: boolean | 
					
						
							|  |  |  |   ) { | 
					
						
							| 
									
										
										
										
											2023-09-16 18:52:42 +02:00
										 |  |  |     const layout = state.layout | 
					
						
							|  |  |  |     let excluded = Utils.NoNull([ | 
					
						
							|  |  |  |       showWelcomeMessage ? undefined : "fs-welcome-message", | 
					
						
							|  |  |  |       enableLogin ? undefined : "fs-enable-login", | 
					
						
							| 
									
										
										
										
											2024-06-27 17:37:34 +02:00
										 |  |  |       enableFilters ? undefined : "fs-filter", | 
					
						
							|  |  |  |       enableBackground ? undefined : "fs-background", | 
					
						
							|  |  |  |       enableGeolocation ? undefined : "fs-geolocation", | 
					
						
							| 
									
										
										
										
											2023-09-16 18:52:42 +02:00
										 |  |  |     ]) | 
					
						
							| 
									
										
										
										
											2024-06-27 17:37:34 +02:00
										 |  |  |     const layerParamsWhitelist: string[] = ["fs-layers-enabled=false"] | 
					
						
							|  |  |  |     const layerParamsBlacklist: string[] = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (const flayer of state.layerState.filteredLayers.values()) { | 
					
						
							|  |  |  |       const id = flayer.layerDef.id | 
					
						
							|  |  |  |       if (flayer.layerDef.filterIsSameAs) { | 
					
						
							|  |  |  |         continue | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (id.indexOf("note_import") >= 0) { | 
					
						
							|  |  |  |         continue | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (Constants.added_by_default.indexOf(<any>id) >= 0) { | 
					
						
							|  |  |  |         continue | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       const enabled = flayer.isDisplayed.data | 
					
						
							|  |  |  |       if (enabled) { | 
					
						
							|  |  |  |         layerParamsWhitelist.push("layer-" + id + "=true") | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         layerParamsBlacklist.push("layer-" + id + "=false") | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const layersBlack = layerParamsBlacklist.join("&") | 
					
						
							|  |  |  |     const layersWhite = layerParamsWhitelist.join("&") | 
					
						
							| 
									
										
										
										
											2024-07-09 13:42:08 +02:00
										 |  |  |     const layers = | 
					
						
							|  |  |  |       layersBlack.length < layersWhite.length ? layerParamsBlacklist : layerParamsWhitelist | 
					
						
							| 
									
										
										
										
											2024-06-27 17:37:34 +02:00
										 |  |  |     const params = QueryParameters.GetParts(new Set(excluded)) | 
					
						
							| 
									
										
										
										
											2024-07-09 13:42:08 +02:00
										 |  |  |       .filter((part) => !part.startsWith("layer-")) | 
					
						
							| 
									
										
										
										
											2024-06-27 17:37:34 +02:00
										 |  |  |       .concat(...layers) | 
					
						
							|  |  |  |       .concat(excluded.map((k) => k + "=" + false)) | 
					
						
							|  |  |  |     linkToShare = baseLink + Utils.Dedup(params).join("&") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-16 18:52:42 +02:00
										 |  |  |     if (layout.definitionRaw !== undefined) { | 
					
						
							|  |  |  |       linkToShare += "&userlayout=" + (layout.definedAtUrl ?? layout.id) | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-08-10 15:37:44 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-09 13:42:08 +02:00
										 |  |  |   $: calculateLinkToShare( | 
					
						
							|  |  |  |     showWelcomeMessage, | 
					
						
							|  |  |  |     enableLogin, | 
					
						
							|  |  |  |     enableFilters, | 
					
						
							|  |  |  |     enableBackground, | 
					
						
							|  |  |  |     enableGeolocation | 
					
						
							|  |  |  |   ) | 
					
						
							| 
									
										
										
										
											2023-08-10 15:37:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-27 17:37:34 +02:00
										 |  |  |   let iframeCode: string | 
					
						
							|  |  |  |   $: iframeCode = `<iframe src="${linkToShare}" | 
					
						
							| 
									
										
										
										
											2024-07-09 13:42:08 +02:00
										 |  |  |     ${ | 
					
						
							|  |  |  |       enableGeolocation ? 'allow="geolocation"' : "" | 
					
						
							|  |  |  |     } width="100%" height="100%" style="min-width: 250px; min-height: 250px" | 
					
						
							| 
									
										
										
										
											2024-06-27 17:37:34 +02:00
										 |  |  |     title="${state.layout.title?.txt ?? "MapComplete"} with MapComplete"> | 
					
						
							|  |  |  |     </iframe>` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-09 13:42:08 +02:00
										 |  |  |   Array.from(state.layerState.filteredLayers.values()).forEach((flayer) => | 
					
						
							|  |  |  |     flayer.isDisplayed.addCallbackAndRunD((_) => { | 
					
						
							|  |  |  |       calculateLinkToShare( | 
					
						
							|  |  |  |         showWelcomeMessage, | 
					
						
							|  |  |  |         enableLogin, | 
					
						
							|  |  |  |         enableFilters, | 
					
						
							|  |  |  |         enableBackground, | 
					
						
							|  |  |  |         enableGeolocation | 
					
						
							|  |  |  |       ) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   ) | 
					
						
							| 
									
										
										
										
											2023-08-10 15:37:44 +02:00
										 |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-02 11:47:26 +02:00
										 |  |  | <div class="flex flex-col link-underline"> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   <a href="geo:{$location.lat},{$location.lon}">Open the current location in other applications</a> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-27 17:37:34 +02:00
										 |  |  |   <div class="flex flex-col"> | 
					
						
							|  |  |  |     <Tr t={tr.intro} /> | 
					
						
							| 
									
										
										
										
											2024-07-09 13:42:08 +02:00
										 |  |  |     <Copyable {state} text={linkToShare} /> | 
					
						
							| 
									
										
										
										
											2024-06-27 17:37:34 +02:00
										 |  |  |   </div> | 
					
						
							|  |  |  |   <div class="flex justify-center"> | 
					
						
							| 
									
										
										
										
											2024-08-14 13:53:56 +02:00
										 |  |  |     <img src={new Qr(linkToShare).toImageElement(125)} style="width: 125px" /> | 
					
						
							| 
									
										
										
										
											2023-08-10 15:37:44 +02:00
										 |  |  |   </div> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-16 18:52:42 +02:00
										 |  |  |   <Tr t={tr.embedIntro} /> | 
					
						
							| 
									
										
										
										
											2023-08-10 15:37:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-09 13:42:08 +02:00
										 |  |  |   <Copyable text={iframeCode} /> | 
					
						
							| 
									
										
										
										
											2024-06-27 17:37:34 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   <AccordionSingle> | 
					
						
							|  |  |  |     <div slot="header"> | 
					
						
							| 
									
										
										
										
											2024-07-09 13:42:08 +02:00
										 |  |  |       <Tr t={tr.options} /> | 
					
						
							| 
									
										
										
										
											2024-03-01 00:30:21 +01:00
										 |  |  |     </div> | 
					
						
							|  |  |  |     <div class="link-underline my-1 flex flex-col"> | 
					
						
							|  |  |  |       <label> | 
					
						
							|  |  |  |         <input bind:checked={showWelcomeMessage} type="checkbox" id="share_show_welcome" /> | 
					
						
							|  |  |  |         <Tr t={tr.fsWelcomeMessage} /> | 
					
						
							|  |  |  |       </label> | 
					
						
							| 
									
										
										
										
											2023-08-10 15:37:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-01 00:30:21 +01:00
										 |  |  |       <label> | 
					
						
							| 
									
										
										
										
											2024-04-13 02:40:21 +02:00
										 |  |  |         <input bind:checked={enableLogin} type="checkbox" id="share_enable_login" /> | 
					
						
							| 
									
										
										
										
											2024-03-01 00:30:21 +01:00
										 |  |  |         <Tr t={tr.fsUserbadge} /> | 
					
						
							|  |  |  |       </label> | 
					
						
							| 
									
										
										
										
											2024-06-27 17:37:34 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       <label> | 
					
						
							|  |  |  |         <input bind:checked={enableFilters} type="checkbox" id="share_enable_filter" /> | 
					
						
							|  |  |  |         <Tr t={tr.fsFilter} /> | 
					
						
							|  |  |  |       </label> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       <label> | 
					
						
							|  |  |  |         <input bind:checked={enableBackground} type="checkbox" id="share_enable_background" /> | 
					
						
							|  |  |  |         <Tr t={tr.fsBackground} /> | 
					
						
							|  |  |  |       </label> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       <label> | 
					
						
							|  |  |  |         <input bind:checked={enableGeolocation} type="checkbox" id="share_enable_geolocation" /> | 
					
						
							|  |  |  |         <Tr t={tr.fsGeolocation} /> | 
					
						
							|  |  |  |       </label> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       <span> | 
					
						
							| 
									
										
										
										
											2024-07-09 13:42:08 +02:00
										 |  |  |         <Tr t={tr.stateIsIncluded} /> | 
					
						
							|  |  |  |         <a | 
					
						
							|  |  |  |           class="inline-block w-fit cursor-pointer" | 
					
						
							|  |  |  |           on:click={() => state.guistate.filtersPanelIsOpened.set(true)} | 
					
						
							|  |  |  |         > | 
					
						
							|  |  |  |           <Tr t={tr.openLayers} /> | 
					
						
							|  |  |  |         </a> | 
					
						
							| 
									
										
										
										
											2024-06-27 17:37:34 +02:00
										 |  |  |       </span> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       <Tr cls="link-underline" t={tr.documentation} /> | 
					
						
							| 
									
										
										
										
											2024-03-01 00:30:21 +01:00
										 |  |  |     </div> | 
					
						
							| 
									
										
										
										
											2024-06-27 17:37:34 +02:00
										 |  |  |   </AccordionSingle> | 
					
						
							| 
									
										
										
										
											2023-08-10 15:37:44 +02:00
										 |  |  | </div> |