forked from MapComplete/MapComplete
Chore: reformat all files with prettier
This commit is contained in:
parent
5757ae5dea
commit
d008dcb54d
214 changed files with 8926 additions and 8196 deletions
|
@ -1,5 +1,5 @@
|
|||
import {FeatureSource} from "../FeatureSource"
|
||||
import {UIEventSource} from "../../UIEventSource"
|
||||
import { FeatureSource } from "../FeatureSource"
|
||||
import { UIEventSource } from "../../UIEventSource"
|
||||
|
||||
/**
|
||||
* Constructs a UIEventStore for the properties of every Feature, indexed by id
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import {IdbLocalStorage} from "../../Web/IdbLocalStorage"
|
||||
import {UIEventSource} from "../../UIEventSource"
|
||||
import { IdbLocalStorage } from "../../Web/IdbLocalStorage"
|
||||
import { UIEventSource } from "../../UIEventSource"
|
||||
|
||||
/**
|
||||
* A class which allows to read/write a tile to local storage.
|
||||
|
@ -14,14 +14,18 @@ export default class TileLocalStorage<T> {
|
|||
private readonly _layername: string
|
||||
private readonly inUse = new UIEventSource(false)
|
||||
private readonly cachedSources: Record<number, UIEventSource<T> & { flush: () => void }> = {}
|
||||
private readonly _maxAgeSeconds: number;
|
||||
private readonly _maxAgeSeconds: number
|
||||
|
||||
private constructor(layername: string, maxAgeSeconds: number) {
|
||||
this._layername = layername
|
||||
this._maxAgeSeconds = maxAgeSeconds;
|
||||
this._maxAgeSeconds = maxAgeSeconds
|
||||
}
|
||||
|
||||
public static construct<T>(backend: string, layername: string, maxAgeS: number): TileLocalStorage<T> {
|
||||
public static construct<T>(
|
||||
backend: string,
|
||||
layername: string,
|
||||
maxAgeS: number
|
||||
): TileLocalStorage<T> {
|
||||
const key = backend + "_" + layername
|
||||
const cached = TileLocalStorage.perLayer[key]
|
||||
if (cached) {
|
||||
|
@ -59,7 +63,10 @@ export default class TileLocalStorage<T> {
|
|||
await this.inUse.AsPromise((inUse) => !inUse)
|
||||
this.inUse.setData(true)
|
||||
await IdbLocalStorage.SetDirectly(this._layername + "_" + tileIndex, data)
|
||||
await IdbLocalStorage.SetDirectly(this._layername + "_" + tileIndex + "_date", Date.now())
|
||||
await IdbLocalStorage.SetDirectly(
|
||||
this._layername + "_" + tileIndex + "_date",
|
||||
Date.now()
|
||||
)
|
||||
|
||||
this.inUse.setData(false)
|
||||
} catch (e) {
|
||||
|
@ -80,7 +87,9 @@ export default class TileLocalStorage<T> {
|
|||
if (!TileLocalStorage.useIndexedDb) {
|
||||
return undefined
|
||||
}
|
||||
const date = <any>await IdbLocalStorage.GetDirectly(this._layername + "_" + tileIndex + "_date")
|
||||
const date = <any>(
|
||||
await IdbLocalStorage.GetDirectly(this._layername + "_" + tileIndex + "_date")
|
||||
)
|
||||
const maxAge = this._maxAgeSeconds
|
||||
const timeDiff = Date.now() - date
|
||||
if (timeDiff >= maxAge) {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import {FeatureSource} from "./FeatureSource"
|
||||
import { FeatureSource } from "./FeatureSource"
|
||||
import FilteredLayer from "../../Models/FilteredLayer"
|
||||
import SimpleFeatureSource from "./Sources/SimpleFeatureSource"
|
||||
import {Feature} from "geojson"
|
||||
import {UIEventSource} from "../UIEventSource"
|
||||
import { Feature } from "geojson"
|
||||
import { UIEventSource } from "../UIEventSource"
|
||||
|
||||
/**
|
||||
* In some rare cases, some elements are shown on multiple layers (when 'passthrough' is enabled)
|
||||
|
@ -59,8 +59,11 @@ export default class PerLayerFeatureSourceSplitter<T extends FeatureSource = Fea
|
|||
let foundALayer = false
|
||||
for (let i = 0; i < layers.length; i++) {
|
||||
const layer = layers[i]
|
||||
if(!layer.layerDef?.source){
|
||||
console.error("PerLayerFeatureSourceSplitter got a layer without a source:", layer.layerDef.id)
|
||||
if (!layer.layerDef?.source) {
|
||||
console.error(
|
||||
"PerLayerFeatureSourceSplitter got a layer without a source:",
|
||||
layer.layerDef.id
|
||||
)
|
||||
continue
|
||||
}
|
||||
if (layer.layerDef.source.osmTags.matchesProperties(f.properties)) {
|
||||
|
|
|
@ -6,7 +6,7 @@ import { UIEventSource } from "../../UIEventSource"
|
|||
import { FeatureSource, IndexedFeatureSource } from "../FeatureSource"
|
||||
import { ChangeDescription, ChangeDescriptionTools } from "../../Osm/Actions/ChangeDescription"
|
||||
import { Feature } from "geojson"
|
||||
import {Utils} from "../../../Utils";
|
||||
import { Utils } from "../../../Utils"
|
||||
|
||||
export default class ChangeGeometryApplicator implements FeatureSource {
|
||||
public readonly features: UIEventSource<Feature[]> = new UIEventSource<Feature[]>([])
|
||||
|
@ -70,7 +70,7 @@ export default class ChangeGeometryApplicator implements FeatureSource {
|
|||
// We only apply the last change as that one'll have the latest geometry
|
||||
const change = changesForFeature[changesForFeature.length - 1]
|
||||
copy.geometry = ChangeDescriptionTools.getGeojsonGeometry(change)
|
||||
if(Utils.SameObject(copy.geometry, feature.geometry)){
|
||||
if (Utils.SameObject(copy.geometry, feature.geometry)) {
|
||||
// No actual changes: pass along the original
|
||||
newFeatures.push(feature)
|
||||
continue
|
||||
|
|
|
@ -30,7 +30,7 @@ export default class FeatureSourceMerger implements IndexedFeatureSource {
|
|||
}
|
||||
|
||||
public addSource(source: FeatureSource) {
|
||||
if(!source){
|
||||
if (!source) {
|
||||
return
|
||||
}
|
||||
this._sources.push(source)
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
/**
|
||||
* Fetches a geojson file somewhere and passes it along
|
||||
*/
|
||||
import {Store, UIEventSource} from "../../UIEventSource"
|
||||
import {Utils} from "../../../Utils"
|
||||
import {FeatureSource} from "../FeatureSource"
|
||||
import {BBox} from "../../BBox"
|
||||
import {GeoOperations} from "../../GeoOperations"
|
||||
import {Feature} from "geojson"
|
||||
import { Store, UIEventSource } from "../../UIEventSource"
|
||||
import { Utils } from "../../../Utils"
|
||||
import { FeatureSource } from "../FeatureSource"
|
||||
import { BBox } from "../../BBox"
|
||||
import { GeoOperations } from "../../GeoOperations"
|
||||
import { Feature } from "geojson"
|
||||
import LayerConfig from "../../../Models/ThemeConfig/LayerConfig"
|
||||
import {Tiles} from "../../../Models/TileRange"
|
||||
import { Tiles } from "../../../Models/TileRange"
|
||||
|
||||
export default class GeoJsonSource implements FeatureSource {
|
||||
public readonly features: Store<Feature[]>
|
||||
|
@ -65,13 +65,13 @@ export default class GeoJsonSource implements FeatureSource {
|
|||
return
|
||||
}
|
||||
this.LoadJSONFrom(url, eventsource, layer)
|
||||
.then((fs) => console.debug("Loaded",fs.length, "features from", url))
|
||||
.then((fs) => console.debug("Loaded", fs.length, "features from", url))
|
||||
.catch((err) => console.warn("Could not load ", url, "due to", err))
|
||||
return true // data is loaded, we can safely unregister
|
||||
})
|
||||
} else {
|
||||
this.LoadJSONFrom(url, eventsource, layer)
|
||||
.then((fs) => console.debug("Loaded",fs.length, "features from", url))
|
||||
.then((fs) => console.debug("Loaded", fs.length, "features from", url))
|
||||
.catch((err) => console.warn("Could not load ", url, "due to", err))
|
||||
}
|
||||
this.features = eventsource
|
||||
|
@ -105,7 +105,7 @@ export default class GeoJsonSource implements FeatureSource {
|
|||
let i = 0
|
||||
let skipped = 0
|
||||
for (const feature of json.features) {
|
||||
if(feature.geometry.type === "Point"){
|
||||
if (feature.geometry.type === "Point") {
|
||||
// See https://github.com/maproulette/maproulette-backend/issues/242
|
||||
feature.geometry.coordinates = feature.geometry.coordinates.map(Number)
|
||||
}
|
||||
|
|
|
@ -32,7 +32,9 @@ export class LastClickFeatureSource implements WritableFeatureSource {
|
|||
}
|
||||
|
||||
const renderings = Utils.Dedup(
|
||||
allPresets.map((uiElem) => Utils.runningFromConsole ? "" : uiElem.ConstructElement().innerHTML)
|
||||
allPresets.map((uiElem) =>
|
||||
Utils.runningFromConsole ? "" : uiElem.ConstructElement().innerHTML
|
||||
)
|
||||
)
|
||||
|
||||
const properties = {
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
import GeoJsonSource from "./GeoJsonSource"
|
||||
import LayerConfig from "../../../Models/ThemeConfig/LayerConfig"
|
||||
import {FeatureSource} from "../FeatureSource"
|
||||
import {Or} from "../../Tags/Or"
|
||||
import { FeatureSource } from "../FeatureSource"
|
||||
import { Or } from "../../Tags/Or"
|
||||
import FeatureSwitchState from "../../State/FeatureSwitchState"
|
||||
import OverpassFeatureSource from "./OverpassFeatureSource"
|
||||
import {Store, UIEventSource} from "../../UIEventSource"
|
||||
import { Store, UIEventSource } from "../../UIEventSource"
|
||||
import OsmFeatureSource from "./OsmFeatureSource"
|
||||
import FeatureSourceMerger from "./FeatureSourceMerger"
|
||||
import DynamicGeoJsonTileSource from "../TiledFeatureSource/DynamicGeoJsonTileSource"
|
||||
import {BBox} from "../../BBox"
|
||||
import { BBox } from "../../BBox"
|
||||
import LocalStorageFeatureSource from "../TiledFeatureSource/LocalStorageFeatureSource"
|
||||
import FullNodeDatabaseSource from "../TiledFeatureSource/FullNodeDatabaseSource";
|
||||
import FullNodeDatabaseSource from "../TiledFeatureSource/FullNodeDatabaseSource"
|
||||
|
||||
/**
|
||||
* This source will fetch the needed data from various sources for the given layout.
|
||||
|
@ -41,7 +41,7 @@ export default class LayoutSource extends FeatureSourceMerger {
|
|||
(l) =>
|
||||
new LocalStorageFeatureSource(backend, l.id, 15, mapProperties, {
|
||||
isActive: isDisplayed(l.id),
|
||||
maxAge: l.maxAgeOfCache
|
||||
maxAge: l.maxAgeOfCache,
|
||||
})
|
||||
)
|
||||
|
||||
|
@ -127,7 +127,7 @@ export default class LayoutSource extends FeatureSourceMerger {
|
|||
backend,
|
||||
isActive,
|
||||
patchRelations: true,
|
||||
fullNodeDatabase
|
||||
fullNodeDatabase,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import { TagsFilter } from "../../Tags/TagsFilter"
|
|||
import { Feature } from "geojson"
|
||||
import FeatureSourceMerger from "../Sources/FeatureSourceMerger"
|
||||
import OsmObjectDownloader from "../../Osm/OsmObjectDownloader"
|
||||
import FullNodeDatabaseSource from "../TiledFeatureSource/FullNodeDatabaseSource";
|
||||
import FullNodeDatabaseSource from "../TiledFeatureSource/FullNodeDatabaseSource"
|
||||
|
||||
/**
|
||||
* If a tile is needed (requested via the UIEventSource in the constructor), will download the appropriate tile and pass it via 'handleTile'
|
||||
|
@ -24,16 +24,16 @@ export default class OsmFeatureSource extends FeatureSourceMerger {
|
|||
/**
|
||||
* If given: this featureSwitch will not update if the store contains 'false'
|
||||
*/
|
||||
isActive?: Store<boolean>,
|
||||
patchRelations?: true | boolean,
|
||||
isActive?: Store<boolean>
|
||||
patchRelations?: true | boolean
|
||||
fullNodeDatabase?: FullNodeDatabaseSource
|
||||
};
|
||||
}
|
||||
|
||||
public readonly isRunning: UIEventSource<boolean> = new UIEventSource<boolean>(false)
|
||||
|
||||
private readonly _downloadedTiles: Set<number> = new Set<number>()
|
||||
private readonly _downloadedData: Feature[][] = []
|
||||
private readonly _patchRelations: boolean;
|
||||
private readonly _patchRelations: boolean
|
||||
/**
|
||||
* Downloads data directly from the OSM-api within the given bounds.
|
||||
* All features which match the TagsFilter 'allowedFeatures' are kept and converted into geojson
|
||||
|
@ -45,12 +45,12 @@ export default class OsmFeatureSource extends FeatureSourceMerger {
|
|||
/**
|
||||
* If given: this featureSwitch will not update if the store contains 'false'
|
||||
*/
|
||||
isActive?: Store<boolean>,
|
||||
patchRelations?: true | boolean,
|
||||
isActive?: Store<boolean>
|
||||
patchRelations?: true | boolean
|
||||
fullNodeDatabase?: FullNodeDatabaseSource
|
||||
}) {
|
||||
super()
|
||||
this.options = options;
|
||||
this.options = options
|
||||
this._bounds = options.bounds
|
||||
this.allowedTags = options.allowedFeatures
|
||||
this.isActive = options.isActive ?? new ImmutableStore(true)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {FeatureSource} from "../FeatureSource"
|
||||
import {ImmutableStore, Store} from "../../UIEventSource"
|
||||
import {Feature} from "geojson"
|
||||
import { FeatureSource } from "../FeatureSource"
|
||||
import { ImmutableStore, Store } from "../../UIEventSource"
|
||||
import { Feature } from "geojson"
|
||||
|
||||
/**
|
||||
* A simple, read only feature store.
|
||||
|
@ -8,13 +8,7 @@ import {Feature} from "geojson"
|
|||
export default class StaticFeatureSource<T extends Feature = Feature> implements FeatureSource<T> {
|
||||
public readonly features: Store<T[]>
|
||||
|
||||
constructor(
|
||||
features:
|
||||
| Store<T[]>
|
||||
| T[]
|
||||
| { features: T[] }
|
||||
| { features: Store<T[]> }
|
||||
) {
|
||||
constructor(features: Store<T[]> | T[] | { features: T[] } | { features: Store<T[]> }) {
|
||||
if (features === undefined) {
|
||||
throw "Static feature source received undefined as source"
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import {FeatureSource, FeatureSourceForLayer} from "../FeatureSource"
|
||||
import { FeatureSource, FeatureSourceForLayer } from "../FeatureSource"
|
||||
import StaticFeatureSource from "./StaticFeatureSource"
|
||||
import {BBox} from "../../BBox"
|
||||
import { BBox } from "../../BBox"
|
||||
import FilteredLayer from "../../../Models/FilteredLayer"
|
||||
import {Store} from "../../UIEventSource"
|
||||
import {Feature} from "geojson";
|
||||
import { Store } from "../../UIEventSource"
|
||||
import { Feature } from "geojson"
|
||||
|
||||
/**
|
||||
* Results in a feature source which has all the elements that touch the given features
|
||||
|
@ -30,7 +30,10 @@ export default class BBoxFeatureSource<T extends Feature = Feature> extends Stat
|
|||
}
|
||||
}
|
||||
|
||||
export class BBoxFeatureSourceForLayer<T extends Feature = Feature> extends BBoxFeatureSource<T> implements FeatureSourceForLayer {
|
||||
export class BBoxFeatureSourceForLayer<T extends Feature = Feature>
|
||||
extends BBoxFeatureSource<T>
|
||||
implements FeatureSourceForLayer
|
||||
{
|
||||
readonly layer: FilteredLayer
|
||||
|
||||
constructor(features: FeatureSourceForLayer<T>, mustTouch: Store<BBox>) {
|
||||
|
|
|
@ -72,7 +72,9 @@ export default class DynamicGeoJsonTileSource extends DynamicTileSource {
|
|||
if (!isWhiteListed) {
|
||||
console.debug(
|
||||
"Not downloading tile",
|
||||
zxy,"for layer",layer.id,
|
||||
zxy,
|
||||
"for layer",
|
||||
layer.id,
|
||||
"as it is not on the whitelist"
|
||||
)
|
||||
return undefined
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
import {OsmNode, OsmObject, OsmWay} from "../../Osm/OsmObject"
|
||||
import {UIEventSource} from "../../UIEventSource"
|
||||
import {BBox} from "../../BBox";
|
||||
import StaticFeatureSource from "../Sources/StaticFeatureSource";
|
||||
import {Tiles} from "../../../Models/TileRange";
|
||||
import { OsmNode, OsmObject, OsmWay } from "../../Osm/OsmObject"
|
||||
import { UIEventSource } from "../../UIEventSource"
|
||||
import { BBox } from "../../BBox"
|
||||
import StaticFeatureSource from "../Sources/StaticFeatureSource"
|
||||
import { Tiles } from "../../../Models/TileRange"
|
||||
|
||||
export default class FullNodeDatabaseSource {
|
||||
|
||||
private readonly loadedTiles = new Map<number, Map<number, OsmNode>>()
|
||||
private readonly nodeByIds = new Map<number, OsmNode>()
|
||||
private readonly parentWays = new Map<number, UIEventSource<OsmWay[]>>()
|
||||
|
@ -13,7 +12,7 @@ export default class FullNodeDatabaseSource {
|
|||
private smallestZoom = 99
|
||||
private largestZoom = 0
|
||||
|
||||
public handleOsmJson(osmJson: any, z: number, x: number, y: number) : void {
|
||||
public handleOsmJson(osmJson: any, z: number, x: number, y: number): void {
|
||||
const allObjects = OsmObject.ParseObjects(osmJson.elements)
|
||||
const nodesById = new Map<number, OsmNode>()
|
||||
|
||||
|
@ -81,14 +80,14 @@ export default class FullNodeDatabaseSource {
|
|||
* Gets (at least) all nodes which are part of this BBOX; might also return some nodes that fall outside of the bbox but are closeby
|
||||
* @param bbox
|
||||
*/
|
||||
getNodesWithin(bbox: BBox) : Map<number, OsmNode>{
|
||||
getNodesWithin(bbox: BBox): Map<number, OsmNode> {
|
||||
const allById = new Map<number, OsmNode>()
|
||||
for (let z = this.smallestZoom; z < this.largestZoom; z++) {
|
||||
const range = Tiles.tileRangeFrom(bbox, z)
|
||||
Tiles.MapRange(range, (x, y ) => {
|
||||
Tiles.MapRange(range, (x, y) => {
|
||||
const tileId = Tiles.tile_index(z, x, y)
|
||||
const nodesById = this.loadedTiles.get(tileId)
|
||||
nodesById?.forEach((v,k) => allById.set(k,v))
|
||||
nodesById?.forEach((v, k) => allById.set(k, v))
|
||||
})
|
||||
}
|
||||
return allById
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import DynamicTileSource from "./DynamicTileSource"
|
||||
import {Store} from "../../UIEventSource"
|
||||
import {BBox} from "../../BBox"
|
||||
import { Store } from "../../UIEventSource"
|
||||
import { BBox } from "../../BBox"
|
||||
import TileLocalStorage from "../Actors/TileLocalStorage"
|
||||
import {Feature} from "geojson"
|
||||
import { Feature } from "geojson"
|
||||
import StaticFeatureSource from "../Sources/StaticFeatureSource"
|
||||
|
||||
export default class LocalStorageFeatureSource extends DynamicTileSource {
|
||||
|
@ -15,26 +15,27 @@ export default class LocalStorageFeatureSource extends DynamicTileSource {
|
|||
zoom: Store<number>
|
||||
},
|
||||
options?: {
|
||||
isActive?: Store<boolean>,
|
||||
isActive?: Store<boolean>
|
||||
maxAge?: number // In seconds
|
||||
}
|
||||
) {
|
||||
const storage = TileLocalStorage.construct<Feature[]>(backend, layername, options?.maxAge ?? 24 * 60 * 60)
|
||||
const storage = TileLocalStorage.construct<Feature[]>(
|
||||
backend,
|
||||
layername,
|
||||
options?.maxAge ?? 24 * 60 * 60
|
||||
)
|
||||
super(
|
||||
zoomlevel,
|
||||
(tileIndex) =>
|
||||
new StaticFeatureSource(
|
||||
storage
|
||||
.getTileSource(tileIndex)
|
||||
.mapD((features) => {
|
||||
if (features.length === undefined) {
|
||||
console.trace("These are not features:", features)
|
||||
storage.invalidate(zoomlevel, tileIndex)
|
||||
return []
|
||||
}
|
||||
return features.filter((f) => !f.properties.id.match(/(node|way)\/-[0-9]+/));
|
||||
}
|
||||
)
|
||||
storage.getTileSource(tileIndex).mapD((features) => {
|
||||
if (features.length === undefined) {
|
||||
console.trace("These are not features:", features)
|
||||
storage.invalidate(zoomlevel, tileIndex)
|
||||
return []
|
||||
}
|
||||
return features.filter((f) => !f.properties.id.match(/(node|way)\/-[0-9]+/))
|
||||
})
|
||||
),
|
||||
mapProperties,
|
||||
options
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue