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,
minNeededElements: 500
};
this.clustering = defaultClustering;
if (json.clustering) {
this.clustering = {
maxZoom: json.clustering.maxZoom ?? 18,
@ -164,7 +163,7 @@ export default class LayoutConfig {
}
for (const layer of this.layers) {
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;
}
/**
* 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{
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,
title: string,
url: string
}) {
super();
this._embedded = embedded;
this._shareData = shareData;
this._shareData = generateShareData;
this.SetClass("share-button")
}
@ -22,7 +22,7 @@ export default class ShareButton extends BaseUIElement{
e.addEventListener('click', () => {
if (navigator.share) {
navigator.share(this._shareData).then(() => {
navigator.share(this._shareData()).then(() => {
console.log('Thanks for sharing!');
})
.catch(err => {

View file

@ -16,36 +16,6 @@ export class SlideShow extends BaseUIElement {
const el = document.createElement("div")
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 => {
for (const element of elements ?? []) {
element.SetClass("slick-carousel-content")

View file

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

View file

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

View file

@ -13,14 +13,14 @@ export class SubstitutedTranslation extends VariableUiElement {
public constructor(
translation: Translation,
tags: UIEventSource<any>) {
tagsSource: UIEventSource<any>) {
super(
tags.map(tags => {
tagsSource.map(tags => {
const txt = Utils.SubstituteKeys(translation.txt, tags)
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])
)
@ -59,6 +59,7 @@ export class SubstitutedTranslation extends VariableUiElement {
try{
element = knownSpecial.constr(State.state, tags, args);
}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")
}