Fix some linting errors, more concise code

This commit is contained in:
Pieter Vander Vennet 2024-08-01 15:48:31 +02:00
parent c6f214b3d2
commit fcc5fb059e
3 changed files with 29 additions and 36 deletions

View file

@ -24,7 +24,7 @@ export abstract class OsmObject {
// @ts-ignore
this.type = type
this.tags = {
id: `${this.type}/${id}`,
id: `${this.type}/${id}`
}
}
@ -37,24 +37,25 @@ export abstract class OsmObject {
const idN = element.id
let osmObject: OsmObject = null
switch (type) {
case "node":
case "node": {
const node = new OsmNode(idN)
allNodes.set(idN, node)
osmObject = node
node.SaveExtraData(element)
break
case "way":
}
case "way": {
osmObject = new OsmWay(idN)
const nodes = element.nodes.map((i) => allNodes.get(i))
osmObject.SaveExtraData(element, nodes)
break
case "relation":
}
case "relation": {
osmObject = new OsmRelation(idN)
const allGeojsons = OsmToGeoJson(
{ elements },
// @ts-ignore
{
flatProperties: true,
flatProperties: true
}
)
const feature = allGeojsons.features.find(
@ -62,9 +63,10 @@ export abstract class OsmObject {
)
osmObject.SaveExtraData(element, feature)
break
}
}
if (osmObject !== undefined && OsmObject.backendURL !== OsmObject.defaultBackend) {
if (osmObject !== undefined) {
osmObject.tags["_backend"] = OsmObject.backendURL
}
@ -121,7 +123,7 @@ export abstract class OsmObject {
const blacklist = polygonFeature.polygon === "blacklist"
result.set(key, {
values: new Set<string>(polygonFeature.values),
blacklist: blacklist,
blacklist: blacklist
})
}
@ -152,23 +154,20 @@ export abstract class OsmObject {
}
const v = this.tags[key]
if (v !== "" && v !== undefined) {
tags +=
' <tag k="' +
Utils.EncodeXmlValue(key) +
'" v="' +
Utils.EncodeXmlValue(this.tags[key]) +
'"/>\n'
tags += ` <tag k="${Utils.EncodeXmlValue(key)}" v="${Utils.EncodeXmlValue(this.tags[key])}"/>
`
}
}
return tags
}
abstract ChangesetXML(changesetId: string, header?: string): string
protected VersionXML() {
if (this.version === undefined) {
return ""
}
return 'version="' + this.version + '"'
return `version="${this.version}"`
}
protected LoadData(element: any): void {
@ -214,9 +213,9 @@ export class OsmNode extends OsmObject {
* @constructor
*/
ChangesetXML(changesetId: string, header?: string): string {
let tags = this.TagsXML()
const tags = this.TagsXML()
return ` <node id="${this.id}" ${header ?? ""} ${
changesetId ? ' changeset="' + changesetId + '" ' : ""
changesetId ? " changeset=\"" + changesetId + "\" " : ""
}${this.VersionXML()} lat="${this.lat}" lon="${this.lon}">
${tags} </node>
`
@ -237,8 +236,8 @@ ${tags} </node>
properties: this.tags,
geometry: {
type: "Point",
coordinates: [this.lon, this.lat],
},
coordinates: [this.lon, this.lat]
}
}
}
}
@ -265,14 +264,14 @@ export class OsmWay extends OsmObject {
* obj.ChangesetXML("123").trim() // => '<way id="1234" changeset="123" >\n <tag k="key" v="value"/>\n </way>'
*/
ChangesetXML(changesetId: string, header?: string): string {
let tags = this.TagsXML()
const tags = this.TagsXML()
let nds = ""
for (const node in this.nodes) {
nds += ' <nd ref="' + this.nodes[node] + '"/>\n'
nds += " <nd ref=\"" + this.nodes[node] + "\"/>\n"
}
return ` <way id="${this.id}" ${header ?? ""} ${
changesetId ? 'changeset="' + changesetId + '" ' : ""
changesetId ? "changeset=\"" + changesetId + "\" " : ""
} ${this.VersionXML()}>
${nds}${tags} </way>
`
@ -317,18 +316,18 @@ ${nds}${tags} </way>
if (this.isPolygon()) {
geometry = {
type: "Polygon",
coordinates: [coordinates],
coordinates: [coordinates]
}
} else {
geometry = {
type: "LineString",
coordinates: coordinates,
coordinates: coordinates
}
}
return {
type: "Feature",
properties: <any>this.tags,
geometry,
geometry
}
}
@ -365,17 +364,11 @@ export class OsmRelation extends OsmObject {
ChangesetXML(changesetId: string, header?: string): string {
let members = ""
for (const member of this.members) {
members +=
' <member type="' +
member.type +
'" ref="' +
member.ref +
'" role="' +
member.role +
'"/>\n'
members += ` <member type="${member.type}" ref="${member.ref}" role="${member.role}"/>
`
}
let tags = this.TagsXML()
const tags = this.TagsXML()
let cs = ""
if (changesetId !== undefined) {
cs = `changeset="${changesetId}"`

View file

@ -239,7 +239,7 @@ export default class OsmObjectDownloader {
if (rawData["error"] !== undefined && rawData["statuscode"] === 410) {
return "deleted"
}
// A full query might contain more then just the requested object (e.g. nodes that are part of a way, where we only want the way)
// A full query might contain more than just the requested object (e.g. nodes that are part of a way, where we only want the way)
const parsed = OsmObject.ParseObjects(rawData["content"].elements)
// Let us fetch the object we need
for (const osmObject of parsed) {

View file

@ -243,7 +243,7 @@ class RewriteMetaInfoTags extends SimpleMetaTagger {
move("changeset", "_last_edit:changeset")
move("timestamp", "_last_edit:timestamp")
move("version", "_version_number")
feature.properties._backend = feature.properties._backend ?? "https://api.openstreetmap.org"
feature.properties._backend ??= "https://www.openstreetmap.org"
return movedSomething
}
}