forked from MapComplete/MapComplete
57 lines
1.9 KiB
TypeScript
57 lines
1.9 KiB
TypeScript
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
|
|
import { SpecialVisualisationParams, SpecialVisualizationSvelte } from "../SpecialVisualization"
|
|
import SvelteUIElement from "../Base/SvelteUIElement"
|
|
import ShareButton from "../Base/ShareButton.svelte"
|
|
|
|
export class ShareLinkViz extends SpecialVisualizationSvelte {
|
|
funcName = "share_link"
|
|
group = "default"
|
|
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)",
|
|
},
|
|
{
|
|
name: "text",
|
|
type:"translation",
|
|
doc: "The text to show on the button. If none is given, will act as a titleIcon",
|
|
},
|
|
]
|
|
needsUrls = []
|
|
|
|
public constr({
|
|
state,
|
|
tags,
|
|
args}:SpecialVisualisationParams
|
|
) {
|
|
const text = args[1]
|
|
|
|
const generateShareData = () => {
|
|
const title = state?.theme?.title?.txt ?? "MapComplete"
|
|
const matchingLayer: LayerConfig = state?.theme?.getMatchingLayer(tags?.data)
|
|
let name =
|
|
matchingLayer?.title?.GetRenderValue(tags.data)?.Subs(tags.data)?.txt ??
|
|
tags.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,
|
|
text: state?.theme?.shortDescription?.txt ?? "MapComplete",
|
|
}
|
|
}
|
|
|
|
return new SvelteUIElement(ShareButton, { generateShareData, text })
|
|
}
|
|
}
|