chore: automated housekeeping...

This commit is contained in:
Pieter Vander Vennet 2025-03-07 21:53:42 +01:00
parent c1a2126b32
commit 4c93f023dd
32 changed files with 1551 additions and 76 deletions

View file

@ -35,14 +35,17 @@ export interface SnappingOptions {
}
export default class SnappingFeatureSource
implements FeatureSource<Feature<Point, { "snapped-to": string; dist: number }>> {
implements FeatureSource<Feature<Point, { "snapped-to": string; dist: number }>>
{
public readonly features: Store<[Feature<Point, { "snapped-to": string; dist: number }>]>
/*Contains the id of the way it snapped to*/
public readonly snappedTo: Store<string>
private readonly _snappedTo: UIEventSource<string>
// private static readonly downloadedRelations: UIEventSource<Map<RelationId, OsmRelation>> = new UIEventSource(new Map())
private static readonly downloadedRelationMembers: UIEventSource<Feature[]> = new UIEventSource([])
private static readonly downloadedRelationMembers: UIEventSource<Feature[]> = new UIEventSource(
[]
)
constructor(
snapTo: FeatureSource,
@ -54,9 +57,11 @@ export default class SnappingFeatureSource
this.snappedTo = this._snappedTo
const simplifiedFeatures = snapTo.features
.mapD((features) =>
[].concat(...features
.filter((feature) => feature.geometry.type !== "Point")
.map((f) => GeoOperations.forceLineString(<any>f)))
[].concat(
...features
.filter((feature) => feature.geometry.type !== "Point")
.map((f) => GeoOperations.forceLineString(<any>f))
)
)
.map(
(features) => {
@ -67,10 +72,11 @@ export default class SnappingFeatureSource
[location]
)
this.features = location.mapD(
({ lon, lat }) => {
const features = simplifiedFeatures.data.concat(...SnappingFeatureSource.downloadedRelationMembers.data)
const features = simplifiedFeatures.data.concat(
...SnappingFeatureSource.downloadedRelationMembers.data
)
const loc: [number, number] = [lon, lat]
const maxDistance = (options?.maxDistance ?? 1000) / 1000
let bestSnap: Feature<Point, { "snapped-to": string; dist: number }> = undefined
@ -79,12 +85,15 @@ export default class SnappingFeatureSource
// TODO handle Polygons with holes
continue
}
const snapped: Feature<Point, {
dist: number;
index: number;
multiFeatureIndex: number;
location: number
}> = GeoOperations.nearestPoint(feature, loc)
const snapped: Feature<
Point,
{
dist: number
index: number
multiFeatureIndex: number
location: number
}
> = GeoOperations.nearestPoint(feature, loc)
if (snapped.properties.dist > maxDistance) {
continue
}
@ -104,7 +113,7 @@ export default class SnappingFeatureSource
}
bestSnap = {
...snapped,
properties: { ...snapped.properties, "snapped-to": id }
properties: { ...snapped.properties, "snapped-to": id },
}
}
}
@ -114,12 +123,12 @@ export default class SnappingFeatureSource
type: "Feature",
geometry: {
type: "Point",
coordinates: [lon, lat]
coordinates: [lon, lat],
},
properties: {
"snapped-to": undefined,
dist: -1
}
dist: -1,
},
}
}
const c = bestSnap.geometry.coordinates
@ -149,11 +158,15 @@ export default class SnappingFeatureSource
if (member.role !== "outer" && member.role !== "inner") {
continue
}
const way = await SnappingFeatureSource._downloader.DownloadObjectAsync(member.type + "/" + member.ref)
const way = await SnappingFeatureSource._downloader.DownloadObjectAsync(
member.type + "/" + member.ref
)
if (way === "deleted") {
continue
}
SnappingFeatureSource.downloadedRelationMembers.data.push(...GeoOperations.forceLineString(way.asGeoJson()))
SnappingFeatureSource.downloadedRelationMembers.data.push(
...GeoOperations.forceLineString(way.asGeoJson())
)
}
SnappingFeatureSource.downloadedRelationMembers.ping()
}