Fix the build

This commit is contained in:
pietervdvn 2021-01-03 13:50:18 +01:00
parent e42a668c4a
commit 0b57042de1
10 changed files with 62 additions and 41 deletions

View file

@ -46,6 +46,8 @@ import FilteringFeatureSource from "./Logic/FeatureSource/FilteringFeatureSource
import WayHandlingApplyingFeatureSource from "./Logic/FeatureSource/WayHandlingApplyingFeatureSource"; import WayHandlingApplyingFeatureSource from "./Logic/FeatureSource/WayHandlingApplyingFeatureSource";
import FeatureSource from "./Logic/FeatureSource/FeatureSource"; import FeatureSource from "./Logic/FeatureSource/FeatureSource";
import NoOverlapSource from "./Logic/FeatureSource/NoOverlapSource"; import NoOverlapSource from "./Logic/FeatureSource/NoOverlapSource";
import AvailableBaseLayers from "./Logic/Actors/AvailableBaseLayers";
import LayerResetter from "./Logic/Actors/LayerResetter";
export class InitUiElements { export class InitUiElements {
@ -83,6 +85,12 @@ export class InitUiElements {
console.warn("NOT saving custom layout to OSM as we are tesing -> probably in an iFrame") console.warn("NOT saving custom layout to OSM as we are tesing -> probably in an iFrame")
} }
} }
InitUiElements.InitBaseMap(); InitUiElements.InitBaseMap();
new FixedUiElement("").AttachTo("decoration-desktop"); // Remove the decoration new FixedUiElement("").AttachTo("decoration-desktop"); // Remove the decoration
@ -348,6 +356,28 @@ export class InitUiElements {
static InitBaseMap() { static InitBaseMap() {
State.state.availableBackgroundLayers = new AvailableBaseLayers(State.state.locationControl).availableEditorLayers;
State.state.backgroundLayer = QueryParameters.GetQueryParameter("background",
State.state.layoutToUse.data.defaultBackgroundId ?? AvailableBaseLayers.osmCarto.id,
"The id of the background layer to start with")
.map((selectedId: string) => {
const available = State.state.availableBackgroundLayers.data;
for (const layer of available) {
if (layer.id === selectedId) {
return layer;
}
}
return AvailableBaseLayers.osmCarto;
}, [], layer => layer.id);
new LayerResetter(
State.state.backgroundLayer, State.state.locationControl,
State.state.availableBackgroundLayers, State.state.layoutToUse.map((layout: LayoutConfig) => layout.defaultBackgroundId));
const attr = new Attribution(State.state.locationControl, State.state.osmConnection.userDetails, State.state.layoutToUse, State.state.leafletMap); const attr = new Attribution(State.state.locationControl, State.state.osmConnection.userDetails, State.state.layoutToUse, State.state.leafletMap);
const bm = new Basemap("leafletDiv", const bm = new Basemap("leafletDiv",
State.state.locationControl, State.state.locationControl,
@ -364,6 +394,10 @@ export class InitUiElements {
} }
static InitLayers() { static InitLayers() {
const state = State.state; const state = State.state;
const flayers: FilteredLayer[] = [] const flayers: FilteredLayer[] = []
for (const layer of state.layoutToUse.data.layers) { for (const layer of state.layoutToUse.data.layers) {

View file

@ -1,3 +1,4 @@
console.log("AVAILABLE LAYERS")
import * as editorlayerindex from "../../assets/editor-layer-index.json" import * as editorlayerindex from "../../assets/editor-layer-index.json"
import {BaseLayer} from "../../Models/BaseLayer"; import {BaseLayer} from "../../Models/BaseLayer";
import * as L from "leaflet"; import * as L from "leaflet";

View file

@ -6,7 +6,6 @@ import State from "../../State";
import Locale from "../../UI/i18n/Locale"; import Locale from "../../UI/i18n/Locale";
import LayoutConfig from "../../Customizations/JSON/LayoutConfig"; import LayoutConfig from "../../Customizations/JSON/LayoutConfig";
import Constants from "../../Models/Constants"; import Constants from "../../Models/Constants";
import {Basemap} from "../Leaflet/Basemap";
export class ChangesetHandler { export class ChangesetHandler {

View file

@ -16,4 +16,5 @@ export default class Constants {
addNewPointWithUnreadMessagesUnlock: 500, addNewPointWithUnreadMessagesUnlock: 500,
minZoomLevelToAddNewPoints: (Utils.isRetina() ? 18 : 19) minZoomLevelToAddNewPoints: (Utils.isRetina() ? 18 : 19)
}; };
} }

4
Models/LeafletMap.ts Normal file
View file

@ -0,0 +1,4 @@
export default interface LeafletMap {
getBounds(): [[number, number], [number, number]];
}

View file

@ -15,9 +15,7 @@ import InstalledThemes from "./Logic/Actors/InstalledThemes";
import {BaseLayer} from "./Models/BaseLayer"; import {BaseLayer} from "./Models/BaseLayer";
import Loc from "./Models/Loc"; import Loc from "./Models/Loc";
import Constants from "./Models/Constants"; import Constants from "./Models/Constants";
import AvailableBaseLayers from "./Logic/Actors/AvailableBaseLayers";
import * as L from "leaflet"
import LayerResetter from "./Logic/Actors/LayerResetter";
import UpdateFromOverpass from "./Logic/Actors/UpdateFromOverpass"; import UpdateFromOverpass from "./Logic/Actors/UpdateFromOverpass";
import LayerConfig from "./Customizations/JSON/LayerConfig"; import LayerConfig from "./Customizations/JSON/LayerConfig";
@ -101,7 +99,7 @@ export default class State {
* The map location: currently centered lat, lon and zoom * The map location: currently centered lat, lon and zoom
*/ */
public readonly locationControl = new UIEventSource<Loc>(undefined); public readonly locationControl = new UIEventSource<Loc>(undefined);
public readonly backgroundLayer; public backgroundLayer;
/* Last location where a click was registered /* Last location where a click was registered
*/ */
public readonly LastClickLocation: UIEventSource<{ lat: number, lon: number }> = new UIEventSource<{ lat: number, lon: number }>(undefined) public readonly LastClickLocation: UIEventSource<{ lat: number, lon: number }> = new UIEventSource<{ lat: number, lon: number }>(undefined)
@ -155,24 +153,6 @@ export default class State {
}); });
this.availableBackgroundLayers = new AvailableBaseLayers(this.locationControl).availableEditorLayers;
this.backgroundLayer = QueryParameters.GetQueryParameter("background",
this.layoutToUse.data.defaultBackgroundId ?? AvailableBaseLayers.osmCarto.id,
"The id of the background layer to start with")
.map((selectedId: string) => {
const available = self.availableBackgroundLayers.data;
for (const layer of available) {
if (layer.id === selectedId) {
return layer;
}
}
return AvailableBaseLayers.osmCarto;
}, [], layer => layer.id);
new LayerResetter(
this.backgroundLayer, this.locationControl,
this.availableBackgroundLayers, this.layoutToUse.map((layout: LayoutConfig) => layout.defaultBackgroundId));
function featSw(key: string, deflt: (layout: LayoutConfig) => boolean, documentation: string): UIEventSource<boolean> { function featSw(key: string, deflt: (layout: LayoutConfig) => boolean, documentation: string): UIEventSource<boolean> {

View file

@ -7,14 +7,14 @@ import {UserDetails} from "../../Logic/Osm/OsmConnection";
import Constants from "../../Models/Constants"; import Constants from "../../Models/Constants";
import LayoutConfig from "../../Customizations/JSON/LayoutConfig"; import LayoutConfig from "../../Customizations/JSON/LayoutConfig";
import Loc from "../../Models/Loc"; import Loc from "../../Models/Loc";
import * as L from "leaflet" import LeafletMap from "../../Models/LeafletMap";
export default class Attribution extends UIElement { export default class Attribution extends UIElement {
private readonly _location: UIEventSource<Loc>; private readonly _location: UIEventSource<Loc>;
private readonly _layoutToUse: UIEventSource<LayoutConfig>; private readonly _layoutToUse: UIEventSource<LayoutConfig>;
private readonly _userDetails: UIEventSource<UserDetails>; private readonly _userDetails: UIEventSource<UserDetails>;
private readonly _leafletMap: UIEventSource<L.Map>; private readonly _leafletMap: UIEventSource<LeafletMap>;
constructor(location: UIEventSource<Loc>, constructor(location: UIEventSource<Loc>,
userDetails: UIEventSource<UserDetails>, userDetails: UIEventSource<UserDetails>,

View file

@ -6,6 +6,7 @@ import {FixedUiElement} from "../Base/FixedUiElement";
import {OH} from "./OpeningHours"; import {OH} from "./OpeningHours";
import Translations from "../i18n/Translations"; import Translations from "../i18n/Translations";
import Constants from "../../Models/Constants"; import Constants from "../../Models/Constants";
import opening_hours from "opening_hours";
export default class OpeningHoursVisualization extends UIElement { export default class OpeningHoursVisualization extends UIElement {
private readonly _key: string; private readonly _key: string;

View file

@ -8,7 +8,7 @@ import {FixedUiElement} from "./Base/FixedUiElement";
import Locale from "../UI/i18n/Locale"; import Locale from "../UI/i18n/Locale";
import {ImageUploadFlow} from "./Image/ImageUploadFlow"; import {ImageUploadFlow} from "./Image/ImageUploadFlow";
import {Translation} from "./i18n/Translation"; import {Translation} from "./i18n/Translation";
import State from "../State";
import ShareButton from "./ShareButton"; import ShareButton from "./ShareButton";
import Svg from "../Svg"; import Svg from "../Svg";
import ReviewElement from "./Reviews/ReviewElement"; import ReviewElement from "./Reviews/ReviewElement";
@ -17,6 +17,8 @@ import Translations from "./i18n/Translations";
import ReviewForm from "./Reviews/ReviewForm"; import ReviewForm from "./Reviews/ReviewForm";
import OpeningHoursVisualization from "./OpeningHours/OhVisualization"; import OpeningHoursVisualization from "./OpeningHours/OhVisualization";
import State from "../State";
export class SubstitutedTranslation extends UIElement { export class SubstitutedTranslation extends UIElement {
private readonly tags: UIEventSource<any>; private readonly tags: UIEventSource<any>;
private readonly translation: Translation; private readonly translation: Translation;
@ -89,7 +91,7 @@ export class SubstitutedTranslation extends UIElement {
} }
const element = knownSpecial.constr(this.tags, args); const element = knownSpecial.constr(State.state, this.tags, args);
return [...partBefore, element, ...partAfter] return [...partBefore, element, ...partAfter]
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@ -108,7 +110,7 @@ export default class SpecialVisualizations {
public static specialVisualizations: { public static specialVisualizations: {
funcName: string, funcName: string,
constr: ((tagSource: UIEventSource<any>, argument: string[]) => UIElement), constr: ((state: State,tagSource: UIEventSource<any>, argument: string[]) => UIElement),
docs: string, docs: string,
example?: string, example?: string,
args: { name: string, defaultValue?: string, doc: string }[] args: { name: string, defaultValue?: string, doc: string }[]
@ -118,7 +120,7 @@ export default class SpecialVisualizations {
funcName: "all_tags", funcName: "all_tags",
docs: "Prints all key-value pairs of the object - used for debugging", docs: "Prints all key-value pairs of the object - used for debugging",
args: [], args: [],
constr: ((tags: UIEventSource<any>) => { constr: ((state: State,tags: UIEventSource<any>) => {
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) {
@ -142,7 +144,7 @@ export default class SpecialVisualizations {
defaultValue: "true", defaultValue: "true",
doc: "Also include images given via 'Wikidata', 'wikimedia_commons' and 'mapillary" doc: "Also include images given via 'Wikidata', 'wikimedia_commons' and 'mapillary"
}], }],
constr: (tags, args) => { constr: (state: State,tags, args) => {
return new ImageCarousel(tags, args[0], args[1].toLowerCase() === "true"); return new ImageCarousel(tags, args[0], args[1].toLowerCase() === "true");
} }
}, },
@ -155,7 +157,7 @@ export default class SpecialVisualizations {
doc: "Image tag to add the URL to (or image-tag:0, image-tag:1 when multiple images are added)", doc: "Image tag to add the URL to (or image-tag:0, image-tag:1 when multiple images are added)",
defaultValue: "image" defaultValue: "image"
}], }],
constr: (tags, args) => { constr: (state: State,tags, args) => {
return new ImageUploadFlow(tags, args[0]) return new ImageUploadFlow(tags, args[0])
} }
}, },
@ -167,7 +169,7 @@ export default class SpecialVisualizations {
name: "subject", name: "subject",
doc: "The identifier used for this value; by default the name of the reviewed object" doc: "The identifier used for this value; by default the name of the reviewed object"
}], }],
constr: (tags, args) => { constr: (state: State,tags, args) => {
const tgs = tags.data; const tgs = tags.data;
console.log("Args[0]", args[0]) console.log("Args[0]", args[0])
let subject = tgs.name ?? ""; let subject = tgs.name ?? "";
@ -179,10 +181,10 @@ export default class SpecialVisualizations {
} }
const mangrove = MangroveReviews.Get(Number(tgs._lon), Number(tgs._lat), const mangrove = MangroveReviews.Get(Number(tgs._lon), Number(tgs._lat),
encodeURIComponent(subject), encodeURIComponent(subject),
State.state.mangroveIdentity, state.mangroveIdentity,
State.state.osmConnection._dryRun state.osmConnection._dryRun
); );
const form = new ReviewForm((r, whenDone) => mangrove.AddReview(r, whenDone), State.state.osmConnection.userDetails); const form = new ReviewForm((r, whenDone) => mangrove.AddReview(r, whenDone), state.osmConnection.userDetails);
return new ReviewElement(mangrove.GetSubjectUri(), mangrove.GetReviews(), form); return new ReviewElement(mangrove.GetSubjectUri(), mangrove.GetReviews(), form);
} }
}, },
@ -194,7 +196,7 @@ export default class SpecialVisualizations {
defaultValue: "opening_hours", defaultValue: "opening_hours",
doc: "The tagkey from which the table is constructed." doc: "The tagkey from which the table is constructed."
}], }],
constr: (tagSource: UIEventSource<any>, args) => { constr: (state: State,tagSource: UIEventSource<any>, args) => {
let keyname = args[0]; let keyname = args[0];
if (keyname === undefined || keyname === "") { if (keyname === undefined || keyname === "") {
keyname = keyname ?? "opening_hours" keyname = keyname ?? "opening_hours"
@ -215,7 +217,7 @@ export default class SpecialVisualizations {
}, { }, {
name: "path", doc: "The path (or shorthand) that should be returned" name: "path", doc: "The path (or shorthand) that should be returned"
}], }],
constr: (tagSource: UIEventSource<any>, args) => { constr: (state: State,tagSource: UIEventSource<any>, args) => {
const url = args[0]; const url = args[0];
const shorthands = args[1]; const shorthands = args[1];
const neededValue = args[2]; const neededValue = args[2];
@ -233,9 +235,9 @@ export default class SpecialVisualizations {
doc: "The url to share (defualt: current URL)", doc: "The url to share (defualt: current URL)",
} }
], ],
constr: (tagSource: UIEventSource<any>, args) => { constr: (state: State,tagSource: UIEventSource<any>, args) => {
if (window.navigator.share) { if (window.navigator.share) {
const title = State.state.layoutToUse.data.title.txt; const title = state.layoutToUse.data.title.txt;
let name = tagSource.data.name; let name = tagSource.data.name;
if (name) { if (name) {
name = `${name} (${title})` name = `${name} (${title})`
@ -249,7 +251,7 @@ export default class SpecialVisualizations {
return new ShareButton(Svg.share_svg(), { return new ShareButton(Svg.share_svg(), {
title: name, title: name,
url: url, url: url,
text: State.state.layoutToUse.data.shortDescription.txt text: state.layoutToUse.data.shortDescription.txt
}) })
} else { } else {
return new FixedUiElement("") return new FixedUiElement("")

View file

@ -12,7 +12,6 @@ import Translations from "../UI/i18n/Translations";
import {Translation} from "../UI/i18n/Translation"; import {Translation} from "../UI/i18n/Translation";
import LayoutConfig from "../Customizations/JSON/LayoutConfig"; import LayoutConfig from "../Customizations/JSON/LayoutConfig";
function enc(str: string): string { function enc(str: string): string {
return encodeURIComponent(str.toLowerCase()); return encodeURIComponent(str.toLowerCase());
} }