| 
									
										
										
										
											2022-11-02 14:44:06 +01:00
										 |  |  | import { UIEventSource } from "../../Logic/UIEventSource" | 
					
						
							|  |  |  | import LayerConfig from "../../Models/ThemeConfig/LayerConfig" | 
					
						
							|  |  |  | import Svg from "../../Svg" | 
					
						
							|  |  |  | import { FixedUiElement } from "../Base/FixedUiElement" | 
					
						
							| 
									
										
										
										
											2023-03-28 05:13:48 +02:00
										 |  |  | import { SpecialVisualization, SpecialVisualizationState } from "../SpecialVisualization"; | 
					
						
							| 
									
										
										
										
											2023-05-11 17:29:25 +02:00
										 |  |  | import SvelteUIElement from "../Base/SvelteUIElement"; | 
					
						
							|  |  |  | import ShareButton from "../Base/ShareButton.svelte"; | 
					
						
							| 
									
										
										
										
											2022-10-28 04:33:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | export class ShareLinkViz implements SpecialVisualization { | 
					
						
							|  |  |  |     funcName = "share_link" | 
					
						
							|  |  |  |     docs = "Creates a link that (attempts to) open the native 'share'-screen" | 
					
						
							|  |  |  |     example = | 
					
						
							|  |  |  |         "{share_link()} to share the current page, {share_link(<some_url>)} to share the given url" | 
					
						
							|  |  |  |     args = [ | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             name: "url", | 
					
						
							|  |  |  |             doc: "The url to share (default: current URL)", | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-28 05:13:48 +02:00
										 |  |  |     public constr(state: SpecialVisualizationState, tagSource: UIEventSource<Record<string, string>>, args: string[]) { | 
					
						
							| 
									
										
										
										
											2022-10-28 04:33:05 +02:00
										 |  |  |             const generateShareData = () => { | 
					
						
							| 
									
										
										
										
											2023-03-28 05:13:48 +02:00
										 |  |  |                 const title = state?.layout?.title?.txt ?? "MapComplete" | 
					
						
							| 
									
										
										
										
											2022-10-28 04:33:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-28 05:13:48 +02:00
										 |  |  |                 let matchingLayer: LayerConfig = state?.layout?.getMatchingLayer( | 
					
						
							| 
									
										
										
										
											2022-10-28 04:33:05 +02:00
										 |  |  |                     tagSource?.data | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |                 let name = | 
					
						
							|  |  |  |                     matchingLayer?.title?.GetRenderValue(tagSource.data)?.txt ?? | 
					
						
							|  |  |  |                     tagSource.data?.name ?? | 
					
						
							|  |  |  |                     "POI" | 
					
						
							|  |  |  |                 if (name) { | 
					
						
							|  |  |  |                     name = `${name} (${title})` | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     name = title | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 let url = args[0] ?? "" | 
					
						
							|  |  |  |                 if (url === "") { | 
					
						
							|  |  |  |                     url = window.location.href | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 return { | 
					
						
							|  |  |  |                     title: name, | 
					
						
							|  |  |  |                     url: url, | 
					
						
							| 
									
										
										
										
											2023-03-28 05:13:48 +02:00
										 |  |  |                     text: state?.layout?.shortDescription?.txt ?? "MapComplete", | 
					
						
							| 
									
										
										
										
											2022-10-28 04:33:05 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-11 17:29:25 +02:00
										 |  |  |             return new SvelteUIElement(ShareButton, {generateShareData}) | 
					
						
							|  |  |  |             //return new ShareButton(Svg.share_svg().SetClass("w-8 h-8"), generateShareData)
 | 
					
						
							| 
									
										
										
										
											2022-10-28 04:33:05 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } |