Formatting

This commit is contained in:
Pieter Vander Vennet 2022-10-27 01:50:41 +02:00
parent 6d822b42ca
commit 61aebc61eb
32 changed files with 664 additions and 511 deletions

View file

@ -191,7 +191,7 @@ export default class OverpassFeatureSource implements FeatureSource {
const self = this
const overpassUrls = self.state.overpassUrl.data
if(overpassUrls === undefined || overpassUrls.length === 0){
if (overpassUrls === undefined || overpassUrls.length === 0) {
throw "Panic: overpassFeatureSource didn't receive any overpassUrls"
}
let bounds: BBox

View file

@ -46,9 +46,9 @@ export default class TitleHandler {
if (Utils.runningFromConsole) {
return
}
try{
document.title = title
}catch (e) {
try {
document.title = title
} catch (e) {
console.error(e)
}
})

View file

@ -84,7 +84,7 @@ export class NewGeometryFromChangesFeatureSource implements FeatureSource {
}
try {
const tags: OsmTags & {id: OsmId & string} = {
const tags: OsmTags & { id: OsmId & string } = {
id: <OsmId & string>(change.type + "/" + change.id),
}
for (const kv of change.tags) {

View file

@ -1,8 +1,8 @@
import FeatureSource, {FeatureSourceForLayer, Tiled} from "../FeatureSource"
import {ImmutableStore, Store} from "../../UIEventSource"
import FeatureSource, { FeatureSourceForLayer, Tiled } from "../FeatureSource"
import { ImmutableStore, Store } from "../../UIEventSource"
import FilteredLayer from "../../../Models/FilteredLayer"
import {BBox} from "../../BBox"
import {Feature} from "geojson";
import { BBox } from "../../BBox"
import { Feature } from "geojson"
/**
* A simple, read only feature store.

View file

@ -19,7 +19,11 @@ export default class CreateNewNodeAction extends OsmCreateAction {
private readonly _lon: number
private readonly _snapOnto: OsmWay
private readonly _reusePointDistance: number
private readonly meta: { changeType: "create" | "import"; theme: string; specialMotivation?: string }
private readonly meta: {
changeType: "create" | "import"
theme: string
specialMotivation?: string
}
private readonly _reusePreviouslyCreatedPoint: boolean
constructor(

View file

@ -3,10 +3,10 @@ import OsmChangeAction from "./OsmChangeAction"
import { Changes } from "../Changes"
import { ChangeDescription } from "./ChangeDescription"
import ChangeTagAction from "./ChangeTagAction"
import {TagsFilter} from "../../Tags/TagsFilter"
import {And} from "../../Tags/And"
import {Tag} from "../../Tags/Tag"
import {OsmId} from "../../../Models/OsmFeature";
import { TagsFilter } from "../../Tags/TagsFilter"
import { And } from "../../Tags/And"
import { Tag } from "../../Tags/Tag"
import { OsmId } from "../../../Models/OsmFeature"
import { Utils } from "../../../Utils"
export default class DeleteAction extends OsmChangeAction {
@ -19,7 +19,6 @@ export default class DeleteAction extends OsmChangeAction {
private readonly _id: OsmId
private readonly _hardDelete: boolean
constructor(
id: OsmId,
softDeletionTags: TagsFilter | undefined,
@ -39,11 +38,12 @@ export default class DeleteAction extends OsmChangeAction {
this._softDeletionTags = new And(
Utils.NoNull([
softDeletionTags,
new Tag(
"fixme",
`A mapcomplete user marked this feature to be deleted (${meta.specialMotivation})`
)
]))
new Tag(
"fixme",
`A mapcomplete user marked this feature to be deleted (${meta.specialMotivation})`
),
])
)
}
}
/**
@ -63,8 +63,11 @@ export default class DeleteAction extends OsmChangeAction {
* const descr = await da.CreateChangeDescriptions(new Changes(), obj)
* descr[0] // => {doDelete: true, meta: {theme: "test", specialMotivation: "Testcase", changeType: "deletion"}, type: "node",id: 1 }
*/
public async CreateChangeDescriptions(changes: Changes, object?: OsmObject): Promise<ChangeDescription[]> {
const osmObject = object ?? await OsmObject.DownloadObjectAsync(this._id)
public async CreateChangeDescriptions(
changes: Changes,
object?: OsmObject
): Promise<ChangeDescription[]> {
const osmObject = object ?? (await OsmObject.DownloadObjectAsync(this._id))
if (this._hardDelete) {
return [

View file

@ -13,7 +13,7 @@ import { Utils } from "../../../Utils"
import { OsmConnection } from "../OsmConnection"
import { Feature } from "@turf/turf"
import FeaturePipeline from "../../FeatureSource/FeaturePipeline"
import {Geometry, LineString, Point, Polygon} from "geojson";
import { Geometry, LineString, Point, Polygon } from "geojson"
export default class ReplaceGeometryAction extends OsmChangeAction {
/**
@ -85,7 +85,7 @@ export default class ReplaceGeometryAction extends OsmChangeAction {
public async getPreview(): Promise<FeatureSource> {
const { closestIds, allNodesById, detachedNodes, reprojectedNodes } =
await this.GetClosestIds()
const preview: Feature<Geometry> [] = closestIds.map((newId, i) => {
const preview: Feature<Geometry>[] = closestIds.map((newId, i) => {
if (this.identicalTo[i] !== undefined) {
return undefined
}
@ -390,7 +390,7 @@ export default class ReplaceGeometryAction extends OsmChangeAction {
const node = allNodesById.get(id)
// Project the node onto the target way to calculate the new coordinates
const way = <Feature<LineString>> {
const way = <Feature<LineString>>{
type: "Feature",
properties: {},
geometry: {

View file

@ -1,10 +1,10 @@
import {Utils} from "../../Utils"
import { Utils } from "../../Utils"
import * as polygon_features from "../../assets/polygon-features.json"
import {Store, UIEventSource} from "../UIEventSource"
import {BBox} from "../BBox"
import { Store, UIEventSource } from "../UIEventSource"
import { BBox } from "../BBox"
import * as OsmToGeoJson from "osmtogeojson"
import {NodeId, OsmFeature, OsmId, OsmTags, RelationId, WayId} from "../../Models/OsmFeature"
import {Feature, LineString, Polygon} from "geojson";
import { NodeId, OsmFeature, OsmId, OsmTags, RelationId, WayId } from "../../Models/OsmFeature"
import { Feature, LineString, Polygon } from "geojson"
export abstract class OsmObject {
private static defaultBackend = "https://www.openstreetmap.org/"
@ -17,7 +17,7 @@ export abstract class OsmObject {
/**
* The OSM tags as simple object
*/
tags: OsmTags & {id: OsmId}
tags: OsmTags & { id: OsmId }
version: number
public changed: boolean = false
timestamp: Date
@ -41,9 +41,9 @@ export abstract class OsmObject {
this.backendURL = url
}
public static DownloadObject(id: NodeId, forceRefresh?: boolean): Store<OsmNode> ;
public static DownloadObject(id: RelationId, forceRefresh?: boolean): Store<OsmRelation> ;
public static DownloadObject(id: WayId, forceRefresh?: boolean): Store<OsmWay> ;
public static DownloadObject(id: NodeId, forceRefresh?: boolean): Store<OsmNode>
public static DownloadObject(id: RelationId, forceRefresh?: boolean): Store<OsmRelation>
public static DownloadObject(id: WayId, forceRefresh?: boolean): Store<OsmWay>
public static DownloadObject(id: string, forceRefresh: boolean = false): Store<OsmObject> {
let src: UIEventSource<OsmObject>
if (OsmObject.objectCache.has(id)) {
@ -73,12 +73,30 @@ export abstract class OsmObject {
return rawData.elements[0].tags
}
static async DownloadObjectAsync(id: NodeId, maxCacheAgeInSecs?: number): Promise<OsmNode | undefined>
static async DownloadObjectAsync(id: WayId, maxCacheAgeInSecs?: number): Promise<OsmWay | undefined>
static async DownloadObjectAsync(id: RelationId, maxCacheAgeInSecs?: number): Promise<OsmRelation | undefined>
static async DownloadObjectAsync(id: OsmId, maxCacheAgeInSecs?: number): Promise<OsmObject | undefined>
static async DownloadObjectAsync(id: string, maxCacheAgeInSecs?: number): Promise<OsmObject | undefined>
static async DownloadObjectAsync(id: string, maxCacheAgeInSecs?: number): Promise<OsmObject | undefined> {
static async DownloadObjectAsync(
id: NodeId,
maxCacheAgeInSecs?: number
): Promise<OsmNode | undefined>
static async DownloadObjectAsync(
id: WayId,
maxCacheAgeInSecs?: number
): Promise<OsmWay | undefined>
static async DownloadObjectAsync(
id: RelationId,
maxCacheAgeInSecs?: number
): Promise<OsmRelation | undefined>
static async DownloadObjectAsync(
id: OsmId,
maxCacheAgeInSecs?: number
): Promise<OsmObject | undefined>
static async DownloadObjectAsync(
id: string,
maxCacheAgeInSecs?: number
): Promise<OsmObject | undefined>
static async DownloadObjectAsync(
id: string,
maxCacheAgeInSecs?: number
): Promise<OsmObject | undefined> {
const splitted = id.split("/")
const type = splitted[0]
const idN = Number(splitted[1])
@ -210,7 +228,7 @@ export abstract class OsmObject {
case "relation":
osmObject = new OsmRelation(idN)
const allGeojsons = OsmToGeoJson.default(
{elements},
{ elements },
// @ts-ignore
{
flatProperties: true,
@ -264,14 +282,16 @@ export abstract class OsmObject {
return false
}
private static constructPolygonFeatures(): Map<string,
{ values: Set<string>; blacklist: boolean }> {
private static constructPolygonFeatures(): Map<
string,
{ values: Set<string>; blacklist: boolean }
> {
const result = new Map<string, { values: Set<string>; blacklist: boolean }>()
for (const polygonFeature of polygon_features["default"] ?? polygon_features) {
const key = polygonFeature.key
if (polygonFeature.polygon === "all") {
result.set(key, {values: null, blacklist: false})
result.set(key, { values: null, blacklist: false })
continue
}

View file

@ -1,13 +1,13 @@
import {Tag} from "./Tag"
import {TagsFilter} from "./TagsFilter"
import {And} from "./And"
import {Utils} from "../../Utils"
import { Tag } from "./Tag"
import { TagsFilter } from "./TagsFilter"
import { And } from "./And"
import { Utils } from "../../Utils"
import ComparingTag from "./ComparingTag"
import {RegexTag} from "./RegexTag"
import { RegexTag } from "./RegexTag"
import SubstitutingTag from "./SubstitutingTag"
import {Or} from "./Or"
import {TagConfigJson} from "../../Models/ThemeConfig/Json/TagConfigJson"
import {isRegExp} from "util"
import { Or } from "./Or"
import { TagConfigJson } from "../../Models/ThemeConfig/Json/TagConfigJson"
import { isRegExp } from "util"
import * as key_counts from "../../assets/key_totals.json"
type Tags = Record<string, string>
@ -373,7 +373,7 @@ export class TagUtils {
return null
}
const [_, key, invert, modifier, value] = match
return {key, value, invert: invert == "!", modifier: modifier == "i~" ? "i" : ""}
return { key, value, invert: invert == "!", modifier: modifier == "i~" ? "i" : "" }
}
/**
@ -557,9 +557,9 @@ export class TagUtils {
if (tag.indexOf("~~") >= 0) {
const split = Utils.SplitFirst(tag, "~~")
let keyRegex: RegExp;
let keyRegex: RegExp
if (split[0] === "*") {
keyRegex = new RegExp(".+","i")
keyRegex = new RegExp(".+", "i")
} else {
keyRegex = new RegExp("^(" + split[0] + ")$")
}
@ -569,10 +569,7 @@ export class TagUtils {
} else {
valueRegex = new RegExp("^(" + split[1] + ")$", "s")
}
return new RegexTag(
keyRegex,
valueRegex
)
return new RegexTag(keyRegex, valueRegex)
}
const withRegex = TagUtils.parseRegexOperator(tag)
if (withRegex != null) {
@ -627,7 +624,7 @@ export class TagUtils {
)
}
if (split[1] === "") {
return new RegexTag(split[0], /.+/si)
return new RegexTag(split[0], /.+/is)
}
return new RegexTag(split[0], split[1], true)
}

View file

@ -6,7 +6,7 @@ import Hash from "./Hash"
import { Utils } from "../../Utils"
export class QueryParameters {
static defaults : Record<string, string> = {}
static defaults: Record<string, string> = {}
static documentation: Map<string, string> = new Map<string, string>()
private static order: string[] = ["layout", "test", "z", "lat", "lon"]
protected static readonly _wasInitialized: Set<string> = new Set()
@ -105,9 +105,9 @@ export class QueryParameters {
}
if (!Utils.runningFromConsole) {
// Don't pollute the history every time a parameter changes
try{
try {
history.replaceState(null, "", "?" + parts.join("&") + Hash.Current())
}catch(e){
} catch (e) {
console.error(e)
}
}