Chore: cleanup typings and linting errors

This commit is contained in:
Pieter Vander Vennet 2025-04-17 02:25:51 +02:00
parent 15cbadc4e0
commit fffc959c0d
6 changed files with 21 additions and 41 deletions

View file

@ -11,15 +11,14 @@ import ChangeTagAction from "./ChangeTagAction"
import { And } from "../../Tags/And"
import { Utils } from "../../../Utils"
import { OsmConnection } from "../OsmConnection"
import { Feature } from "@turf/turf"
import { Geometry, LineString, Point } from "geojson"
import { Feature, Geometry, LineString, Point } from "geojson"
import FullNodeDatabaseSource from "../../FeatureSource/TiledFeatureSource/FullNodeDatabaseSource"
export default class ReplaceGeometryAction extends OsmChangeAction implements PreviewableAction {
/**
* The target feature - mostly used for the metadata
*/
private readonly feature: any
private readonly feature: Feature
private readonly state: {
osmConnection: OsmConnection
fullNodeDatabase?: FullNodeDatabaseSource
@ -48,7 +47,7 @@ export default class ReplaceGeometryAction extends OsmChangeAction implements Pr
osmConnection: OsmConnection
fullNodeDatabase?: FullNodeDatabaseSource
},
feature: any,
feature: Feature,
wayToReplaceId: string,
options: {
theme: string
@ -65,13 +64,13 @@ export default class ReplaceGeometryAction extends OsmChangeAction implements Pr
const geom = this.feature.geometry
let coordinates: [number, number][]
if (geom.type === "LineString") {
coordinates = geom.coordinates
coordinates = <[number, number][]>geom.coordinates
} else if (geom.type === "Polygon") {
coordinates = geom.coordinates[0]
coordinates = <[number, number][]>geom.coordinates[0]
}
this.targetCoordinates = coordinates
this.identicalTo = coordinates.map((_) => undefined)
this.identicalTo = coordinates.map(() => undefined)
for (let i = 0; i < coordinates.length; i++) {
if (this.identicalTo[i] !== undefined) {
@ -204,7 +203,6 @@ export default class ReplaceGeometryAction extends OsmChangeAction implements Pr
if (nodeDb === undefined) {
throw "PANIC: replaceGeometryAction needs the FullNodeDatabase, which is undefined. This should be initialized by having the 'type_node'-layer enabled in your theme. (NB: the replacebutton has type_node as dependency)"
}
const self = this
let parsed: OsmObject[]
{
// Gather the needed OsmObjects
@ -214,6 +212,7 @@ export default class ReplaceGeometryAction extends OsmChangeAction implements Pr
if (idN < 0 || type !== "way") {
throw "Invalid ID to conflate: " + this.wayToReplaceId
}
const url = `${
this.state.osmConnection?._oauth_config?.url ?? "https://api.openstreetmap.org"
}/api/0.6/${this.wayToReplaceId}/full`
@ -270,7 +269,7 @@ export default class ReplaceGeometryAction extends OsmChangeAction implements Pr
const partOfSomeWay = parentWayIds.length > 0
const hasTags = Object.keys(node.tags).length > 1
const nodeDistances = this.targetCoordinates.map((_) => undefined)
const nodeDistances = this.targetCoordinates.map(() => undefined)
for (let i = 0; i < this.targetCoordinates.length; i++) {
if (this.identicalTo[i] !== undefined) {
continue
@ -295,7 +294,7 @@ export default class ReplaceGeometryAction extends OsmChangeAction implements Pr
})
}
const closestIds = this.targetCoordinates.map((_) => undefined)
const closestIds = this.targetCoordinates.map(() => undefined)
const unusedIds = new Map<
number,
{
@ -330,7 +329,7 @@ export default class ReplaceGeometryAction extends OsmChangeAction implements Pr
// We found a candidate... Search the corresponding target id:
let targetId: number = undefined
let lowestDistance = Number.MAX_VALUE
let nodeDistances = distances.get(candidate)
const nodeDistances = distances.get(candidate)
for (let i = 0; i < nodeDistances.length; i++) {
const d = nodeDistances[i]
if (d !== undefined && d < lowestDistance) {
@ -400,7 +399,7 @@ export default class ReplaceGeometryAction extends OsmChangeAction implements Pr
properties: {},
geometry: {
type: "LineString",
coordinates: self.targetCoordinates,
coordinates: this.targetCoordinates
},
}
const projected = GeoOperations.nearestPoint(way, [node.lon, node.lat])
@ -528,7 +527,7 @@ export default class ReplaceGeometryAction extends OsmChangeAction implements Pr
// Some nodes might need to be deleted
if (detachedNodes.size > 0) {
detachedNodes.forEach(({ hasTags, reason }, nodeId) => {
detachedNodes.forEach(({ hasTags }, nodeId) => {
const parentWays = nodeDb.GetParentWays(nodeId)
const index = parentWays.data.map((w) => w.id).indexOf(osmWay.id)
if (index < 0) {