Refactoring: LayoutToUse is a simple value now

This commit is contained in:
Pieter Vander Vennet 2021-09-28 18:00:44 +02:00
parent 41a2a79fe9
commit a78d33112b
22 changed files with 133 additions and 153 deletions

View file

@ -11,8 +11,8 @@ export default class BackgroundLayerResetter {
constructor(currentBackgroundLayer: UIEventSource<BaseLayer>,
location: UIEventSource<Loc>,
availableLayers: UIEventSource<BaseLayer[]>,
defaultLayerId: UIEventSource<string> = undefined) {
defaultLayerId = defaultLayerId ?? new UIEventSource<string>(AvailableBaseLayers.osmCarto.id);
defaultLayerId: string = undefined) {
defaultLayerId = defaultLayerId ?? AvailableBaseLayers.osmCarto.id;
// Change the baselayer back to OSM if we go out of the current range of the layer
availableLayers.addCallbackAndRun(availableLayers => {
@ -28,7 +28,7 @@ export default class BackgroundLayerResetter {
if (availableLayer.min_zoom > location.data.zoom) {
break;
}
if (availableLayer.id === defaultLayerId.data) {
if (availableLayer.id === defaultLayerId) {
defaultLayer = availableLayer;
}
return; // All good - the current layer still works!

View file

@ -3,7 +3,7 @@ import Loc from "../../Models/Loc";
import {Or} from "../Tags/Or";
import {Overpass} from "../Osm/Overpass";
import Bounds from "../../Models/Bounds";
import FeatureSource, {FeatureSourceState} from "../FeatureSource/FeatureSource";
import FeatureSource from "../FeatureSource/FeatureSource";
import {Utils} from "../../Utils";
import {TagsFilter} from "../Tags/TagsFilter";
import SimpleMetaTagger from "../SimpleMetaTagger";
@ -39,7 +39,7 @@ export default class OverpassFeatureSource implements FeatureSource {
private readonly _previousBounds: Map<number, Bounds[]> = new Map<number, Bounds[]>();
private readonly state: {
readonly locationControl: UIEventSource<Loc>,
readonly layoutToUse: UIEventSource<LayoutConfig>,
readonly layoutToUse: LayoutConfig,
readonly overpassUrl: UIEventSource<string>;
readonly overpassTimeout: UIEventSource<number>;
readonly currentBounds :UIEventSource<BBox>
@ -52,7 +52,7 @@ export default class OverpassFeatureSource implements FeatureSource {
constructor(
state: {
readonly locationControl: UIEventSource<Loc>,
readonly layoutToUse: UIEventSource<LayoutConfig>,
readonly layoutToUse: LayoutConfig,
readonly overpassUrl: UIEventSource<string>;
readonly overpassTimeout: UIEventSource<number>;
readonly overpassMaxZoom: UIEventSource<number>,
@ -76,9 +76,6 @@ export default class OverpassFeatureSource implements FeatureSource {
this._previousBounds.set(i, []);
}
state.layoutToUse.addCallback(() => {
self.update()
});
location.addCallback(() => {
self.update()
});
@ -92,7 +89,7 @@ export default class OverpassFeatureSource implements FeatureSource {
private GetFilter(): Overpass {
let filters: TagsFilter[] = [];
let extraScripts: string[] = [];
for (const layer of this.state.layoutToUse.data.layers) {
for (const layer of this.state.layoutToUse.layers) {
if (typeof (layer) === "string") {
throw "A layer was not expanded!"
}
@ -164,7 +161,7 @@ export default class OverpassFeatureSource implements FeatureSource {
return undefined;
}
const bounds = this.state.currentBounds.data?.pad(this.state.layoutToUse.data.widenFactor)?.expandToTileBounds(14);
const bounds = this.state.currentBounds.data?.pad(this.state.layoutToUse.widenFactor)?.expandToTileBounds(14);
if (bounds === undefined) {
return undefined;

View file

@ -3,12 +3,18 @@ import Translations from "../../UI/i18n/Translations";
import Locale from "../../UI/i18n/Locale";
import TagRenderingAnswer from "../../UI/Popup/TagRenderingAnswer";
import Combine from "../../UI/Base/Combine";
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig";
import {ElementStorage} from "../ElementStorage";
export default class TitleHandler {
constructor(state) {
constructor(state : {
selectedElement: UIEventSource<any>,
layoutToUse: LayoutConfig,
allElements: ElementStorage
}) {
const currentTitle: UIEventSource<string> = state.selectedElement.map(
selected => {
const layout = state.layoutToUse.data
const layout = state.layoutToUse
const defaultTitle = Translations.WT(layout?.title)?.txt ?? "MapComplete"
if (selected === undefined) {
@ -27,7 +33,7 @@ export default class TitleHandler {
}
}
return defaultTitle
}, [Locale.language, state.layoutToUse]
}, [Locale.language]
)