diff --git a/InitUiElements.ts b/InitUiElements.ts index 066baa2..fbaa371 100644 --- a/InitUiElements.ts +++ b/InitUiElements.ts @@ -46,6 +46,8 @@ import FilteringFeatureSource from "./Logic/FeatureSource/FilteringFeatureSource import WayHandlingApplyingFeatureSource from "./Logic/FeatureSource/WayHandlingApplyingFeatureSource"; import FeatureSource from "./Logic/FeatureSource/FeatureSource"; import NoOverlapSource from "./Logic/FeatureSource/NoOverlapSource"; +import AvailableBaseLayers from "./Logic/Actors/AvailableBaseLayers"; +import LayerResetter from "./Logic/Actors/LayerResetter"; 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") } } + + + + + + InitUiElements.InitBaseMap(); new FixedUiElement("").AttachTo("decoration-desktop"); // Remove the decoration @@ -348,6 +356,28 @@ export class InitUiElements { 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 bm = new Basemap("leafletDiv", State.state.locationControl, @@ -364,6 +394,10 @@ export class InitUiElements { } static InitLayers() { + + + + const state = State.state; const flayers: FilteredLayer[] = [] for (const layer of state.layoutToUse.data.layers) { diff --git a/Logic/Actors/AvailableBaseLayers.ts b/Logic/Actors/AvailableBaseLayers.ts index 59130bc..b5eabd3 100644 --- a/Logic/Actors/AvailableBaseLayers.ts +++ b/Logic/Actors/AvailableBaseLayers.ts @@ -1,3 +1,4 @@ +console.log("AVAILABLE LAYERS") import * as editorlayerindex from "../../assets/editor-layer-index.json" import {BaseLayer} from "../../Models/BaseLayer"; import * as L from "leaflet"; diff --git a/Logic/Osm/ChangesetHandler.ts b/Logic/Osm/ChangesetHandler.ts index eacd9d5..3cae888 100644 --- a/Logic/Osm/ChangesetHandler.ts +++ b/Logic/Osm/ChangesetHandler.ts @@ -6,7 +6,6 @@ import State from "../../State"; import Locale from "../../UI/i18n/Locale"; import LayoutConfig from "../../Customizations/JSON/LayoutConfig"; import Constants from "../../Models/Constants"; -import {Basemap} from "../Leaflet/Basemap"; export class ChangesetHandler { diff --git a/Models/Constants.ts b/Models/Constants.ts index c45285b..80c5136 100644 --- a/Models/Constants.ts +++ b/Models/Constants.ts @@ -16,4 +16,5 @@ export default class Constants { addNewPointWithUnreadMessagesUnlock: 500, minZoomLevelToAddNewPoints: (Utils.isRetina() ? 18 : 19) }; + } \ No newline at end of file diff --git a/Models/LeafletMap.ts b/Models/LeafletMap.ts new file mode 100644 index 0000000..76ff1e3 --- /dev/null +++ b/Models/LeafletMap.ts @@ -0,0 +1,4 @@ +export default interface LeafletMap { + + getBounds(): [[number, number], [number, number]]; +} \ No newline at end of file diff --git a/State.ts b/State.ts index 0ca0ded..4b1c513 100644 --- a/State.ts +++ b/State.ts @@ -15,9 +15,7 @@ import InstalledThemes from "./Logic/Actors/InstalledThemes"; import {BaseLayer} from "./Models/BaseLayer"; import Loc from "./Models/Loc"; 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 LayerConfig from "./Customizations/JSON/LayerConfig"; @@ -101,7 +99,7 @@ export default class State { * The map location: currently centered lat, lon and zoom */ public readonly locationControl = new UIEventSource(undefined); - public readonly backgroundLayer; + public backgroundLayer; /* Last location where a click was registered */ 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 { diff --git a/UI/Misc/Attribution.ts b/UI/Misc/Attribution.ts index ccf0e3c..43f2c8b 100644 --- a/UI/Misc/Attribution.ts +++ b/UI/Misc/Attribution.ts @@ -7,14 +7,14 @@ import {UserDetails} from "../../Logic/Osm/OsmConnection"; import Constants from "../../Models/Constants"; import LayoutConfig from "../../Customizations/JSON/LayoutConfig"; import Loc from "../../Models/Loc"; -import * as L from "leaflet" +import LeafletMap from "../../Models/LeafletMap"; export default class Attribution extends UIElement { private readonly _location: UIEventSource; private readonly _layoutToUse: UIEventSource; private readonly _userDetails: UIEventSource; - private readonly _leafletMap: UIEventSource; + private readonly _leafletMap: UIEventSource; constructor(location: UIEventSource, userDetails: UIEventSource, diff --git a/UI/OpeningHours/OhVisualization.ts b/UI/OpeningHours/OhVisualization.ts index 2b604af..e58e70c 100644 --- a/UI/OpeningHours/OhVisualization.ts +++ b/UI/OpeningHours/OhVisualization.ts @@ -6,6 +6,7 @@ import {FixedUiElement} from "../Base/FixedUiElement"; import {OH} from "./OpeningHours"; import Translations from "../i18n/Translations"; import Constants from "../../Models/Constants"; +import opening_hours from "opening_hours"; export default class OpeningHoursVisualization extends UIElement { private readonly _key: string; diff --git a/UI/SpecialVisualizations.ts b/UI/SpecialVisualizations.ts index d1d626b..d973a85 100644 --- a/UI/SpecialVisualizations.ts +++ b/UI/SpecialVisualizations.ts @@ -8,7 +8,7 @@ import {FixedUiElement} from "./Base/FixedUiElement"; import Locale from "../UI/i18n/Locale"; import {ImageUploadFlow} from "./Image/ImageUploadFlow"; import {Translation} from "./i18n/Translation"; -import State from "../State"; + import ShareButton from "./ShareButton"; import Svg from "../Svg"; import ReviewElement from "./Reviews/ReviewElement"; @@ -17,6 +17,8 @@ import Translations from "./i18n/Translations"; import ReviewForm from "./Reviews/ReviewForm"; import OpeningHoursVisualization from "./OpeningHours/OhVisualization"; +import State from "../State"; + export class SubstitutedTranslation extends UIElement { private readonly tags: UIEventSource; 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] } catch (e) { console.error(e); @@ -108,7 +110,7 @@ export default class SpecialVisualizations { public static specialVisualizations: { funcName: string, - constr: ((tagSource: UIEventSource, argument: string[]) => UIElement), + constr: ((state: State,tagSource: UIEventSource, argument: string[]) => UIElement), docs: string, example?: string, args: { name: string, defaultValue?: string, doc: string }[] @@ -118,7 +120,7 @@ export default class SpecialVisualizations { funcName: "all_tags", docs: "Prints all key-value pairs of the object - used for debugging", args: [], - constr: ((tags: UIEventSource) => { + constr: ((state: State,tags: UIEventSource) => { return new VariableUiElement(tags.map(tags => { const parts = []; for (const key in tags) { @@ -142,7 +144,7 @@ export default class SpecialVisualizations { defaultValue: "true", 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"); } }, @@ -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)", defaultValue: "image" }], - constr: (tags, args) => { + constr: (state: State,tags, args) => { return new ImageUploadFlow(tags, args[0]) } }, @@ -167,7 +169,7 @@ export default class SpecialVisualizations { name: "subject", 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; console.log("Args[0]", args[0]) let subject = tgs.name ?? ""; @@ -179,10 +181,10 @@ export default class SpecialVisualizations { } const mangrove = MangroveReviews.Get(Number(tgs._lon), Number(tgs._lat), encodeURIComponent(subject), - State.state.mangroveIdentity, - State.state.osmConnection._dryRun + state.mangroveIdentity, + 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); } }, @@ -194,7 +196,7 @@ export default class SpecialVisualizations { defaultValue: "opening_hours", doc: "The tagkey from which the table is constructed." }], - constr: (tagSource: UIEventSource, args) => { + constr: (state: State,tagSource: UIEventSource, args) => { let keyname = args[0]; if (keyname === undefined || keyname === "") { keyname = keyname ?? "opening_hours" @@ -215,7 +217,7 @@ export default class SpecialVisualizations { }, { name: "path", doc: "The path (or shorthand) that should be returned" }], - constr: (tagSource: UIEventSource, args) => { + constr: (state: State,tagSource: UIEventSource, args) => { const url = args[0]; const shorthands = args[1]; const neededValue = args[2]; @@ -233,9 +235,9 @@ export default class SpecialVisualizations { doc: "The url to share (defualt: current URL)", } ], - constr: (tagSource: UIEventSource, args) => { + constr: (state: State,tagSource: UIEventSource, args) => { if (window.navigator.share) { - const title = State.state.layoutToUse.data.title.txt; + const title = state.layoutToUse.data.title.txt; let name = tagSource.data.name; if (name) { name = `${name} (${title})` @@ -249,7 +251,7 @@ export default class SpecialVisualizations { return new ShareButton(Svg.share_svg(), { title: name, url: url, - text: State.state.layoutToUse.data.shortDescription.txt + text: state.layoutToUse.data.shortDescription.txt }) } else { return new FixedUiElement("") diff --git a/scripts/createLayouts.ts b/scripts/createLayouts.ts index adb6d6b..38d3970 100644 --- a/scripts/createLayouts.ts +++ b/scripts/createLayouts.ts @@ -12,7 +12,6 @@ import Translations from "../UI/i18n/Translations"; import {Translation} from "../UI/i18n/Translation"; import LayoutConfig from "../Customizations/JSON/LayoutConfig"; - function enc(str: string): string { return encodeURIComponent(str.toLowerCase()); }