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()
}

View file

@ -10,12 +10,12 @@ import {
MultiPolygon,
Point,
Polygon,
Position
Position,
} from "geojson"
import { Tiles } from "../Models/TileRange"
import { Utils } from "../Utils"
("use strict")
;("use strict")
export class GeoOperations {
private static readonly _earthRadius = 6378137
@ -29,7 +29,7 @@ export class GeoOperations {
"behind",
"sharp_left",
"left",
"slight_left"
"slight_left",
] as const
private static reverseBearing = {
N: 0,
@ -47,7 +47,7 @@ export class GeoOperations {
W: 270,
WNW: 292.5,
NW: 315,
NNW: 337.5
NNW: 337.5,
}
/**
@ -309,7 +309,7 @@ export class GeoOperations {
bufferSizeInMeter: number
): Feature<Polygon | MultiPolygon> | FeatureCollection<Polygon | MultiPolygon> {
return turf.buffer(feature, bufferSizeInMeter / 1000, {
units: "kilometers"
units: "kilometers",
})
}
@ -325,9 +325,9 @@ export class GeoOperations {
[lon0, lat],
[lon0, lat0],
[lon, lat0],
[lon, lat]
]
}
[lon, lat],
],
},
}
}
@ -373,25 +373,32 @@ export class GeoOperations {
type: "Feature",
geometry: {
type: "LineString",
coordinates: linestringCoors
coordinates: linestringCoors,
},
properties: way.properties
properties: way.properties,
}
})
}
if (way.geometry.type === "MultiPolygon") {
const mpoly: Feature<MultiPolygon> = <Feature<MultiPolygon>>way
return [].concat(...mpoly.geometry.coordinates.map(linestrings =>
[].concat(...linestrings.map(linestring =>
<Feature<LineString>>{
type: "Feature",
geometry: {
type: "LineString",
coordinates: linestring
},
properties: way.properties
}))))
return [].concat(
...mpoly.geometry.coordinates.map((linestrings) =>
[].concat(
...linestrings.map(
(linestring) =>
<Feature<LineString>>{
type: "Feature",
geometry: {
type: "LineString",
coordinates: linestring,
},
properties: way.properties,
}
)
)
)
)
}
if (way.geometry.type === "LineString") {
return [<Feature<LineString>>way]
@ -568,7 +575,7 @@ export class GeoOperations {
}
const properties = {
...f.properties,
id
id,
}
intersectionPart.properties = properties
newFeatures.push(intersectionPart)
@ -600,8 +607,8 @@ export class GeoOperations {
properties: {},
geometry: {
type: "Point",
coordinates: p
}
coordinates: p,
},
}
)
}
@ -617,7 +624,7 @@ export class GeoOperations {
trackPoints.push(trkpt)
}
const header =
"<gpx version=\"1.1\" creator=\"mapcomplete.org\" xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">"
'<gpx version="1.1" creator="mapcomplete.org" xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">'
return (
header +
"\n<name>" +
@ -656,7 +663,7 @@ export class GeoOperations {
trackPoints.push(trkpt)
}
const header =
"<gpx version=\"1.1\" creator=\"mapcomplete.org\" xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">"
'<gpx version="1.1" creator="mapcomplete.org" xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">'
return (
header +
"\n<name>" +
@ -682,7 +689,7 @@ export class GeoOperations {
const copy = {
...feature,
geometry: { ...feature.geometry }
geometry: { ...feature.geometry },
}
let coordinates: [number, number][]
if (feature.geometry.type === "LineString") {
@ -740,8 +747,8 @@ export class GeoOperations {
type: "Feature",
geometry: {
type: "LineString",
coordinates: [a, b]
}
coordinates: [a, b],
},
},
distanceMeter,
{ units: "meters" }
@ -788,8 +795,8 @@ export class GeoOperations {
type: "Feature",
geometry: {
type: "Polygon",
coordinates
}
coordinates,
},
}
)
return !polygons.some((polygon) => !booleanWithin(polygon, possiblyEnclosingFeature))
@ -868,8 +875,8 @@ export class GeoOperations {
type: "Feature",
properties: { ...toSplit.properties },
geometry: boundary.geometry,
bbox: boundary.bbox
}
bbox: boundary.bbox,
},
]
}
return []
@ -967,8 +974,8 @@ export class GeoOperations {
properties: p.properties,
geometry: {
type: "LineString",
coordinates: p.geometry.coordinates[0]
}
coordinates: p.geometry.coordinates[0],
},
}
}
@ -996,7 +1003,7 @@ export class GeoOperations {
console.debug("Splitting way", feature.properties.id)
result.push(<Feature>{
...feature,
geometry: { ...feature.geometry, coordinates: coors.slice(i + 1) }
geometry: { ...feature.geometry, coordinates: coors.slice(i + 1) },
})
coors = coors.slice(0, i + 1)
break
@ -1005,7 +1012,7 @@ export class GeoOperations {
}
result.push(<Feature>{
...feature,
geometry: { ...feature.geometry, coordinates: coors }
geometry: { ...feature.geometry, coordinates: coors },
})
}
}
@ -1179,8 +1186,8 @@ export class GeoOperations {
properties: multiLineStringFeature.properties,
geometry: {
type: "LineString",
coordinates: coors[0]
}
coordinates: coors[0],
},
}
}
return {
@ -1188,8 +1195,8 @@ export class GeoOperations {
properties: multiLineStringFeature.properties,
geometry: {
type: "MultiLineString",
coordinates: coors
}
coordinates: coors,
},
}
}
@ -1342,7 +1349,7 @@ export class GeoOperations {
const intersection = turf.intersect(
turf.featureCollection([
turf.truncate(feature),
turf.truncate(otherFeature)
turf.truncate(otherFeature),
])
)
if (intersection == null) {

View file

@ -160,8 +160,8 @@ export default class FeatureReviews {
private readonly _testmode: Store<boolean>
public readonly loadingAllowed: UIEventSource<boolean | null>
private readonly _options: Readonly<{
nameKey?: "name" | string;
fallbackName?: string;
nameKey?: "name" | string
fallbackName?: string
uncertaintyRadius?: number
}>
@ -300,15 +300,21 @@ export default class FeatureReviews {
},
state?: SpecialVisualizationState
): FeatureReviews {
const key = feature.properties.id + ";" + (options?.nameKey ?? "") + ";" + (options?.fallbackName ?? "")
const key =
feature.properties.id +
";" +
(options?.nameKey ?? "") +
";" +
(options?.fallbackName ?? "")
const cached = FeatureReviews._featureReviewsCache[key]
if (cached !== undefined) {
return cached
}
const themeIsSensitive = state?.theme?.enableMorePrivacy ?? false
const settings = state?.osmConnection?.getPreference<"always" | "yes" | "ask" | "hidden">(
"reviews-allowed"
) ?? new ImmutableStore("yes");
const settings =
state?.osmConnection?.getPreference<"always" | "yes" | "ask" | "hidden">(
"reviews-allowed"
) ?? new ImmutableStore("yes")
const loadingAllowed = new UIEventSource(false)
settings.addCallbackAndRun((s) => {
if (s === "hidden") {

View file

@ -163,7 +163,7 @@
<Tr cls="subtle mt-4" t={t.tos} />
{/if}
{#if $debug || $test}
<span class="self-end subtle">{$subject}</span>
<span class="subtle self-end">{$subject}</span>
{/if}
</div>
{/if}

View file

@ -1 +1 @@
{"properties":{"name":"Bing Maps Aerial","id":"Bing","url":"https://ecn.t1.tiles.virtualearth.net/tiles/a{quadkey}.jpeg?g=15059&pr=odbl&n=f","type":"bing","category":"photo","min_zoom":1,"max_zoom":22},"type":"Feature","geometry":null}
{"properties":{"name":"Bing Maps Aerial","id":"Bing","url":"https://ecn.t3.tiles.virtualearth.net/tiles/a{quadkey}.jpeg?g=15063&pr=odbl&n=f","type":"bing","category":"photo","min_zoom":1,"max_zoom":22},"type":"Feature","geometry":null}

View file

@ -1,7 +1,7 @@
{
"contributors": [
{
"commits": 9299,
"commits": 9310,
"contributor": "Pieter Vander Vennet"
},
{

View file

@ -1,5 +1,6 @@
{
"ca": "català",
"cy": "Cymraeg",
"da": "dansk",
"de": "Deutsch",
"en": "English",

File diff suppressed because it is too large Load diff