forked from MapComplete/MapComplete
Refactoring: LayoutToUse is a simple value now
This commit is contained in:
parent
41a2a79fe9
commit
a78d33112b
22 changed files with 133 additions and 153 deletions
|
@ -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!
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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]
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig";
|
||||
import FilteringFeatureSource from "./Sources/FilteringFeatureSource";
|
||||
import PerLayerFeatureSourceSplitter from "./PerLayerFeatureSourceSplitter";
|
||||
import FeatureSource, {FeatureSourceForLayer, FeatureSourceState, IndexedFeatureSource, Tiled} from "./FeatureSource";
|
||||
import FeatureSource, {FeatureSourceForLayer, IndexedFeatureSource, Tiled} from "./FeatureSource";
|
||||
import TiledFeatureSource from "./TiledFeatureSource/TiledFeatureSource";
|
||||
import {UIEventSource} from "../UIEventSource";
|
||||
import {TileHierarchyTools} from "./TiledFeatureSource/TileHierarchy";
|
||||
|
@ -48,7 +48,7 @@ export default class FeaturePipeline {
|
|||
readonly locationControl: UIEventSource<Loc>,
|
||||
readonly selectedElement: UIEventSource<any>,
|
||||
readonly changes: Changes,
|
||||
readonly layoutToUse: UIEventSource<LayoutConfig>,
|
||||
readonly layoutToUse: LayoutConfig,
|
||||
readonly leafletMap: any,
|
||||
readonly overpassUrl: UIEventSource<string>;
|
||||
readonly overpassTimeout: UIEventSource<number>;
|
||||
|
@ -86,7 +86,7 @@ export default class FeaturePipeline {
|
|||
if (location?.zoom === undefined) {
|
||||
return false;
|
||||
}
|
||||
let minzoom = Math.min(...state.layoutToUse.data.layers.map(layer => layer.minzoom ?? 18));
|
||||
let minzoom = Math.min(...state.layoutToUse.layers.map(layer => layer.minzoom ?? 18));
|
||||
return location.zoom >= minzoom;
|
||||
}
|
||||
);
|
||||
|
@ -223,8 +223,8 @@ export default class FeaturePipeline {
|
|||
layer: source.layer,
|
||||
minZoomLevel: 14,
|
||||
dontEnforceMinZoom: true,
|
||||
maxFeatureCount: state.layoutToUse.data.clustering.minNeededElements,
|
||||
maxZoomLevel: state.layoutToUse.data.clustering.maxZoom,
|
||||
maxFeatureCount: state.layoutToUse.clustering.minNeededElements,
|
||||
maxZoomLevel: state.layoutToUse.clustering.maxZoom,
|
||||
registerTile: (tile) => {
|
||||
// We save the tile data for the given layer to local storage
|
||||
new SaveTileToLocalStorageActor(tile, tile.tileIndex)
|
||||
|
|
|
@ -65,7 +65,7 @@ export default class OsmFeatureSource {
|
|||
}
|
||||
|
||||
private async LoadTile(z, x, y): Promise<void> {
|
||||
if (z > 18) {
|
||||
if (z > 20) {
|
||||
throw "This is an absurd high zoom level"
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ export default class DeleteAction {
|
|||
}
|
||||
State.state.osmConnection.changesetHandler.DeleteElement(
|
||||
obj,
|
||||
State.state.layoutToUse.data,
|
||||
State.state.layoutToUse,
|
||||
reason,
|
||||
State.state.allElements,
|
||||
() => {
|
||||
|
|
|
@ -131,7 +131,7 @@ export class Changes {
|
|||
}
|
||||
|
||||
await State.state.osmConnection.UploadChangeset(
|
||||
State.state.layoutToUse.data,
|
||||
State.state.layoutToUse,
|
||||
State.state.allElements,
|
||||
(csId) => Changes.createChangesetFor(csId, changes),
|
||||
)
|
||||
|
|
|
@ -87,7 +87,7 @@ export default class SimpleMetaTagger {
|
|||
|
||||
},
|
||||
(feature => {
|
||||
const units = Utils.NoNull([].concat(...State.state?.layoutToUse?.data?.layers?.map(layer => layer.units ?? [])));
|
||||
const units = Utils.NoNull([].concat(...State.state?.layoutToUse?.layers?.map(layer => layer.units ?? [])));
|
||||
if (units.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue