Fix sharebutton

This commit is contained in:
Pieter Vander Vennet 2021-06-15 01:24:04 +02:00
parent afbe765ce9
commit 42d13f564c
7 changed files with 51 additions and 59 deletions

View file

@ -152,11 +152,10 @@ export default class LayoutConfig {
); );
} }
const defaultClustering = { this.clustering = {
maxZoom: 16, maxZoom: 16,
minNeededElements: 500 minNeededElements: 500
}; };
this.clustering = defaultClustering;
if (json.clustering) { if (json.clustering) {
this.clustering = { this.clustering = {
maxZoom: json.clustering.maxZoom ?? 18, maxZoom: json.clustering.maxZoom ?? 18,
@ -164,7 +163,7 @@ export default class LayoutConfig {
} }
for (const layer of this.layers) { for (const layer of this.layers) {
if (layer.wayHandling !== LayerConfig.WAYHANDLING_CENTER_ONLY) { if (layer.wayHandling !== LayerConfig.WAYHANDLING_CENTER_ONLY) {
console.error("WARNING: In order to allow clustering, every layer must be set to CENTER_ONLY. Layer", layer.id, "does not respect this for layout", this.id); console.debug("WARNING: In order to allow clustering, every layer must be set to CENTER_ONLY. Layer", layer.id, "does not respect this for layout", this.id);
} }
} }
} }

View file

@ -86,6 +86,7 @@ export default abstract class BaseUIElement {
} }
return this; return this;
} }
/** /**
* The same as 'Render', but creates a HTML element instead of the HTML representation * The same as 'Render', but creates a HTML element instead of the HTML representation
*/ */

View file

@ -2,16 +2,16 @@ import BaseUIElement from "../BaseUIElement";
export default class ShareButton extends BaseUIElement{ export default class ShareButton extends BaseUIElement{
private _embedded: BaseUIElement; private _embedded: BaseUIElement;
private _shareData: { text: string; title: string; url: string }; private _shareData: () => { text: string; title: string; url: string };
constructor(embedded: BaseUIElement, shareData: { constructor(embedded: BaseUIElement, generateShareData: () => {
text: string, text: string,
title: string, title: string,
url: string url: string
}) { }) {
super(); super();
this._embedded = embedded; this._embedded = embedded;
this._shareData = shareData; this._shareData = generateShareData;
this.SetClass("share-button") this.SetClass("share-button")
} }
@ -22,7 +22,7 @@ export default class ShareButton extends BaseUIElement{
e.addEventListener('click', () => { e.addEventListener('click', () => {
if (navigator.share) { if (navigator.share) {
navigator.share(this._shareData).then(() => { navigator.share(this._shareData()).then(() => {
console.log('Thanks for sharing!'); console.log('Thanks for sharing!');
}) })
.catch(err => { .catch(err => {

View file

@ -16,36 +16,6 @@ export class SlideShow extends BaseUIElement {
const el = document.createElement("div") const el = document.createElement("div")
el.classList.add("slic-carousel") el.classList.add("slic-carousel")
el.onchange = () => {
console.log("Parent is now ", el.parentElement)
}
const mutationObserver = new MutationObserver(mutations => {
console.log("Mutations are: ", mutations)
mutationObserver.disconnect()
require("slick-carousel")
// @ts-ignore
el.slick({
autoplay: true,
arrows: true,
dots: true,
lazyLoad: 'progressive',
variableWidth: true,
centerMode: true,
centerPadding: "60px",
adaptive: true
});
})
mutationObserver.observe(el, {
childList: true,
characterData: true,
subtree: true
})
this.embeddedElements.addCallbackAndRun(elements => { this.embeddedElements.addCallbackAndRun(elements => {
for (const element of elements ?? []) { for (const element of elements ?? []) {
element.SetClass("slick-carousel-content") element.SetClass("slick-carousel-content")

View file

@ -19,6 +19,13 @@ export default class TagRenderingAnswer extends VariableUiElement {
if(tags === undefined){ if(tags === undefined){
return undefined; return undefined;
} }
if(configuration.condition){
if(!configuration.condition.matchesProperties(tags)){
return undefined;
}
}
const trs = Utils.NoNull(configuration.GetRenderValues(tags)); const trs = Utils.NoNull(configuration.GetRenderValues(tags));
if(trs.length === 0){ if(trs.length === 0){
return undefined; return undefined;

View file

@ -17,11 +17,11 @@ import OpeningHoursVisualization from "./OpeningHours/OhVisualization";
import State from "../State"; import State from "../State";
import {ImageSearcher} from "../Logic/Actors/ImageSearcher"; import {ImageSearcher} from "../Logic/Actors/ImageSearcher";
import BaseUIElement from "./BaseUIElement"; import BaseUIElement from "./BaseUIElement";
import LayerConfig from "../Customizations/JSON/LayerConfig";
export default class SpecialVisualizations { export default class SpecialVisualizations {
public static specialVisualizations: { public static specialVisualizations: {
funcName: string, funcName: string,
constr: ((state: State, tagSource: UIEventSource<any>, argument: string[]) => BaseUIElement), constr: ((state: State, tagSource: UIEventSource<any>, argument: string[]) => BaseUIElement),
@ -38,7 +38,7 @@ export default class SpecialVisualizations {
return new VariableUiElement(tags.map(tags => { return new VariableUiElement(tags.map(tags => {
const parts = []; const parts = [];
for (const key in tags) { for (const key in tags) {
if(!tags.hasOwnProperty(key)){ if (!tags.hasOwnProperty(key)) {
continue; continue;
} }
parts.push(key + "=" + tags[key]); parts.push(key + "=" + tags[key]);
@ -160,22 +160,36 @@ export default class SpecialVisualizations {
], ],
constr: (state: State, tagSource: UIEventSource<any>, args) => { constr: (state: State, tagSource: UIEventSource<any>, args) => {
if (window.navigator.share) { if (window.navigator.share) {
const title = state?.layoutToUse?.data?.title?.txt ?? "MapComplete";
let name = tagSource.data.name; const generateShareData = () => {
if (name) {
name = `${name} (${title})`
} else { const title = state?.layoutToUse?.data?.title?.txt ?? "MapComplete";
name = title;
let matchingLayer: LayerConfig = undefined;
for (const layer of (state?.layoutToUse?.data?.layers ?? [])) {
if (layer.source.osmTags.matchesProperties(tagSource?.data)) {
matchingLayer = layer
}
}
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,
text: state?.layoutToUse?.data?.shortDescription?.txt ?? "MapComplete"
}
} }
let url = args[0] ?? ""
if (url === "") { return new ShareButton(Svg.share_ui(), generateShareData)
url = window.location.href
}
return new ShareButton(Svg.share_ui(), {
title: name,
url: url,
text: state?.layoutToUse?.data?.shortDescription?.txt ?? "MapComplete"
})
} else { } else {
return new FixedUiElement("") return new FixedUiElement("")
} }

View file

@ -13,14 +13,14 @@ export class SubstitutedTranslation extends VariableUiElement {
public constructor( public constructor(
translation: Translation, translation: Translation,
tags: UIEventSource<any>) { tagsSource: UIEventSource<any>) {
super( super(
tags.map(tags => { tagsSource.map(tags => {
const txt = Utils.SubstituteKeys(translation.txt, tags) const txt = Utils.SubstituteKeys(translation.txt, tags)
if (txt === undefined) { if (txt === undefined) {
return "no tags subs tr" return undefined
} }
return new Combine(SubstitutedTranslation.EvaluateSpecialComponents(txt, tags)) return new Combine(SubstitutedTranslation.EvaluateSpecialComponents(txt, tagsSource))
}, [Locale.language]) }, [Locale.language])
) )
@ -59,6 +59,7 @@ export class SubstitutedTranslation extends VariableUiElement {
try{ try{
element = knownSpecial.constr(State.state, tags, args); element = knownSpecial.constr(State.state, tags, args);
}catch(e){ }catch(e){
console.error("SPECIALRENDERING FAILED for", tags.data.id, e)
element = new FixedUiElement(`Could not generate special renering for ${knownSpecial}(${args.join(", ")}) ${e}`).SetClass("alert") element = new FixedUiElement(`Could not generate special renering for ${knownSpecial}(${args.join(", ")}) ${e}`).SetClass("alert")
} }