chore: automated housekeeping...

This commit is contained in:
Pieter Vander Vennet 2024-12-11 02:45:44 +01:00
parent a178de3e03
commit bb6b053429
131 changed files with 7447 additions and 5143 deletions

View file

@ -9,7 +9,7 @@ import { TagsFilter } from "../../Tags/TagsFilter"
import { BBox } from "../../BBox"
import { FeatureCollection } from "@turf/turf"
import { OsmTags } from "../../../Models/OsmFeature"
"use strict";
;("use strict")
/**
* A wrapper around the 'Overpass'-object.
@ -63,12 +63,9 @@ export default class OverpassFeatureSource implements UpdatableFeatureSource {
? new ImmutableStore(state.layers)
: state.zoom.map((zoom) => this.layersToDownload(zoom))
state.bounds.mapD(
() => {
this.updateAsyncIfNeeded()
},
[this._layersToDownload]
)
state.bounds.mapD(() => {
this.updateAsyncIfNeeded()
}, [this._layersToDownload])
}
private layersToDownload(zoom: number): LayerConfig[] {

View file

@ -117,7 +117,7 @@ export default class ThemeSource extends FeatureSourceMerger {
},
{
ignoreZoom: true,
isActive: new ImmutableStore(false)
isActive: new ImmutableStore(false),
}
)

View file

@ -10,13 +10,13 @@ import {
MultiPolygon,
Point,
Polygon,
Position
Position,
} from "geojson"
import { Tiles } from "../Models/TileRange"
import { Utils } from "../Utils"
import { NearestPointOnLine } from "@turf/nearest-point-on-line"
"use strict"
;("use strict")
export class GeoOperations {
private static readonly _earthRadius = 6378137
@ -30,7 +30,7 @@ export class GeoOperations {
"behind",
"sharp_left",
"left",
"slight_left"
"slight_left",
] as const
private static reverseBearing = {
N: 0,
@ -48,17 +48,23 @@ export class GeoOperations {
W: 270,
WNW: 292.5,
NW: 315,
NNW: 337.5
NNW: 337.5,
}
/**
* Create a union between two features
*/
public static union(f0: Feature<Polygon | MultiPolygon>, f1: Feature<Polygon | MultiPolygon>): Feature<Polygon | MultiPolygon> | null {
public static union(
f0: Feature<Polygon | MultiPolygon>,
f1: Feature<Polygon | MultiPolygon>
): Feature<Polygon | MultiPolygon> | null {
return turf.union(f0, f1)
}
public static intersect(f0: Feature<Polygon | MultiPolygon>, f1: Feature<Polygon | MultiPolygon>): Feature<Polygon | MultiPolygon> | null {
public static intersect(
f0: Feature<Polygon | MultiPolygon>,
f1: Feature<Polygon | MultiPolygon>
): Feature<Polygon | MultiPolygon> | null {
return turf.intersect(f0, f1)
}
@ -83,9 +89,13 @@ export class GeoOperations {
*
* GeoOperations.centerpointCoordinates(undefined) // => undefined
*/
static centerpointCoordinates(feature: undefined | null): undefined ;
static centerpointCoordinates(feature: AllGeoJSON | GeoJSON | undefined): [number, number] | undefined;
static centerpointCoordinates(feature: NonNullable<AllGeoJSON> | NonNullable<GeoJSON>): NonNullable<[number, number]>;
static centerpointCoordinates(feature: undefined | null): undefined
static centerpointCoordinates(
feature: AllGeoJSON | GeoJSON | undefined
): [number, number] | undefined
static centerpointCoordinates(
feature: NonNullable<AllGeoJSON> | NonNullable<GeoJSON>
): NonNullable<[number, number]>
static centerpointCoordinates(feature: AllGeoJSON | GeoJSON): [number, number] {
if (feature === undefined || feature === null) {
return undefined
@ -142,12 +152,14 @@ export class GeoOperations {
* const overlap0 = GeoOperations.calculateOverlap(line0, [polygon]);
* overlap.length // => 1
*/
static calculateOverlap(feature: Feature, otherFeatures: Feature[]):
{ feat: Feature; overlap: number }[] {
static calculateOverlap(
feature: Feature,
otherFeatures: Feature[]
): { feat: Feature; overlap: number }[] {
const featureBBox = BBox.get(feature)
const result: { feat: Feature; overlap: number }[] = []
if (feature.geometry.type === "Point") {
const coor = <[number,number]> feature.geometry.coordinates
const coor = <[number, number]>feature.geometry.coordinates
for (const otherFeature of otherFeatures) {
if (
feature.properties.id !== undefined &&
@ -200,7 +212,7 @@ export class GeoOperations {
}
if (otherFeature.geometry.type === "Point") {
if (this.inside(<Feature<Point>> otherFeature, feature)) {
if (this.inside(<Feature<Point>>otherFeature, feature)) {
result.push({ feat: otherFeature, overlap: undefined })
}
continue
@ -266,7 +278,9 @@ export class GeoOperations {
const y: number = pointCoordinate[1]
if (feature.geometry.type === "MultiPolygon") {
const coordinatess: [number, number][][][] = <[number, number][][][]>feature.geometry.coordinates
const coordinatess: [number, number][][][] = <[number, number][][][]>(
feature.geometry.coordinates
)
for (const coordinates of coordinatess) {
const inThisPolygon = GeoOperations.pointInPolygonCoordinates(x, y, coordinates)
if (inThisPolygon) {
@ -277,7 +291,11 @@ export class GeoOperations {
}
if (feature.geometry.type === "Polygon") {
return GeoOperations.pointInPolygonCoordinates(x, y, <[number, number][][]>feature.geometry.coordinates)
return GeoOperations.pointInPolygonCoordinates(
x,
y,
<[number, number][][]>feature.geometry.coordinates
)
}
throw "GeoOperations.inside: unsupported geometry type " + feature.geometry.type
@ -287,9 +305,12 @@ export class GeoOperations {
return turf.length(feature) * 1000
}
static buffer(feature: Feature, bufferSizeInMeter: number): Feature<Polygon | MultiPolygon> | FeatureCollection<Polygon | MultiPolygon> {
static buffer(
feature: Feature,
bufferSizeInMeter: number
): Feature<Polygon | MultiPolygon> | FeatureCollection<Polygon | MultiPolygon> {
return turf.buffer(feature, bufferSizeInMeter / 1000, {
units: "kilometers"
units: "kilometers",
})
}
@ -305,9 +326,9 @@ export class GeoOperations {
[lon0, lat],
[lon0, lat0],
[lon, lat0],
[lon, lat]
]
}
[lon, lat],
],
},
}
}
@ -347,25 +368,25 @@ export class GeoOperations {
return <Feature<LineString>>{
geometry: {
type: "LineString",
coordinates: way.geometry.coordinates[0]
coordinates: way.geometry.coordinates[0],
},
properties: way.properties
properties: way.properties,
}
}
if (way.geometry.type === "MultiPolygon") {
return <Feature<MultiLineString>>{
geometry: {
type: "MultiLineString",
coordinates: way.geometry.coordinates[0]
coordinates: way.geometry.coordinates[0],
},
properties: way.properties
properties: way.properties,
}
}
if (way.geometry.type === "LineString") {
return <Feature<LineString>> way
return <Feature<LineString>>way
}
if (way.geometry.type === "MultiLineString") {
return <Feature<MultiLineString>> way
return <Feature<MultiLineString>>way
}
throw "Invalid geometry to create a way from this"
}
@ -536,8 +557,8 @@ export class GeoOperations {
properties: {},
geometry: {
type: "Point",
coordinates: p
}
coordinates: p,
},
}
)
}
@ -553,7 +574,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>" +
@ -592,7 +613,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>" +
@ -618,14 +639,14 @@ export class GeoOperations {
const copy = {
...feature,
geometry: { ...feature.geometry }
geometry: { ...feature.geometry },
}
let coordinates: [number, number][]
if (feature.geometry.type === "LineString") {
coordinates = <[number,number][]> [...feature.geometry.coordinates]
coordinates = <[number, number][]>[...feature.geometry.coordinates]
copy.geometry.coordinates = coordinates
} else {
coordinates = <[number,number][]> [...feature.geometry.coordinates[0]]
coordinates = <[number, number][]>[...feature.geometry.coordinates[0]]
copy.geometry.coordinates[0] = coordinates
}
@ -676,8 +697,8 @@ export class GeoOperations {
type: "Feature",
geometry: {
type: "LineString",
coordinates: [a, b]
}
coordinates: [a, b],
},
},
distanceMeter,
{ units: "meters" }
@ -883,8 +904,8 @@ export class GeoOperations {
properties: p.properties,
geometry: {
type: "LineString",
coordinates: p.geometry.coordinates[0]
}
coordinates: p.geometry.coordinates[0],
},
}
}
@ -912,7 +933,7 @@ export class GeoOperations {
console.debug("SPlitting way", feature.properties.id)
result.push({
...feature,
geometry: { ...feature.geometry, coordinates: coors.slice(i + 1) }
geometry: { ...feature.geometry, coordinates: coors.slice(i + 1) },
})
coors = coors.slice(0, i + 1)
break
@ -921,7 +942,7 @@ export class GeoOperations {
}
result.push({
...feature,
geometry: { ...feature.geometry, coordinates: coors }
geometry: { ...feature.geometry, coordinates: coors },
})
}
}
@ -1095,8 +1116,8 @@ export class GeoOperations {
properties: multiLineStringFeature.properties,
geometry: {
type: "LineString",
coordinates: coors[0]
}
coordinates: coors[0],
},
}
}
return {
@ -1104,8 +1125,8 @@ export class GeoOperations {
properties: multiLineStringFeature.properties,
geometry: {
type: "MultiLineString",
coordinates: coors
}
coordinates: coors,
},
}
}

View file

@ -85,7 +85,7 @@ export class ImageUploadManager {
uploadFinished: this.getCounterFor(this._uploadFinished, featureId),
retried: this.getCounterFor(this._uploadRetried, featureId),
failed: this.getCounterFor(this._uploadFailed, featureId),
retrySuccess: this.getCounterFor(this._uploadRetriedSuccess, featureId)
retrySuccess: this.getCounterFor(this._uploadRetriedSuccess, featureId),
}
}
@ -94,7 +94,7 @@ export class ImageUploadManager {
if (sizeInBytes > this._uploader.maxFileSizeInMegabytes * 1000000) {
const error = Translations.t.image.toBig.Subs({
actual_size: Math.floor(sizeInBytes / 1000000) + "MB",
max_size: this._uploader.maxFileSizeInMegabytes + "MB"
max_size: this._uploader.maxFileSizeInMegabytes + "MB",
})
return { error }
}
@ -144,7 +144,7 @@ export class ImageUploadManager {
properties,
{
theme: tags?.data?.["_orig_theme"] ?? this._theme.id,
changeType: "add-image"
changeType: "add-image",
}
)
@ -174,16 +174,19 @@ export class ImageUploadManager {
throw "ImageUploadManager: no feature given and no feature found in the indexedFeature. Cannot upload this image"
}
const featureCenterpoint = GeoOperations.centerpointCoordinates(feature)
if (location === undefined || location?.some((l) => l === undefined) ||
GeoOperations.distanceBetween(location, featureCenterpoint) > 150) {
if (
location === undefined ||
location?.some((l) => l === undefined) ||
GeoOperations.distanceBetween(location, featureCenterpoint) > 150
) {
/* GPS location is either unknown or very far away from the photographed location.
* Default to the centerpoint
*/
* Default to the centerpoint
*/
location = featureCenterpoint
}
}
try {
({ key, value, absoluteUrl } = await this._uploader.uploadImage(
;({ key, value, absoluteUrl } = await this._uploader.uploadImage(
blob,
location,
author,
@ -193,7 +196,7 @@ export class ImageUploadManager {
this.increaseCountFor(this._uploadRetried, featureId)
console.error("Could not upload image, trying again:", e)
try {
({ key, value, absoluteUrl } = await this._uploader.uploadImage(
;({ key, value, absoluteUrl } = await this._uploader.uploadImage(
blob,
location,
author,
@ -209,7 +212,7 @@ export class ImageUploadManager {
ctx: "While uploading an image in the Image Upload Manager",
featureId,
author,
targetKey
targetKey,
})
)
return undefined

View file

@ -130,7 +130,7 @@ export default class PanoramaxImageProvider extends ImageProvider {
}
public async getInfo(hash: string): Promise<ProvidedImage> {
return await this.getInfoFor(hash).then((r) => this.featureToImage(<any>r))
return await this.getInfoFor(hash).then((r) => this.featureToImage(<any>r))
}
getRelevantUrls(tags: Record<string, string>, prefixes: string[]): Store<ProvidedImage[]> {
@ -234,14 +234,19 @@ export class PanoramaxUploader implements ImageUploader {
) {
lat = exifLat
lon = exifLon
if(tags?.GPSLatitudeRef?.value?.[0] === "S"){
if (tags?.GPSLatitudeRef?.value?.[0] === "S") {
lat *= -1
}
if(tags?.GPSLongitudeRef?.value?.[0] === "W"){
if (tags?.GPSLongitudeRef?.value?.[0] === "W") {
lon *= -1
}
}
const [date, time] =( tags.DateTime.value[0] ?? tags.DateTimeOriginal.value[0] ?? tags.GPSDateStamp ?? tags["Date Created"]).split(" ")
const [date, time] = (
tags.DateTime.value[0] ??
tags.DateTimeOriginal.value[0] ??
tags.GPSDateStamp ??
tags["Date Created"]
).split(" ")
const exifDatetime = new Date(date.replaceAll(":", "-") + "T" + time)
if (exifDatetime.getFullYear() === 1970) {
// The data probably got reset to the epoch

View file

@ -6,7 +6,7 @@ import osmtogeojson from "osmtogeojson"
import { FeatureCollection } from "@turf/turf"
import { Geometry } from "geojson"
import { OsmTags } from "../../Models/OsmFeature"
"use strict";
;("use strict")
/**
* Interfaces overpass to get all the latest data
*/
@ -74,7 +74,7 @@ export class Overpass {
console.warn("No features for", json)
}
const geojson = <FeatureCollection<Geometry, OsmTags>> osmtogeojson(json)
const geojson = <FeatureCollection<Geometry, OsmTags>>osmtogeojson(json)
const osmTime = new Date(json.osm3s.timestamp_osm_base)
return [geojson, osmTime]
}

View file

@ -1,14 +1,42 @@
import { Utils } from "../../Utils"
/** This code is autogenerated - do not edit. Edit ./assets/layers/usersettings/usersettings.json instead */
export class ThemeMetaTagging {
public static readonly themeName = "usersettings"
public static readonly themeName = "usersettings"
public metaTaggging_for_usersettings(feat: {properties: Record<string, string>}) {
Utils.AddLazyProperty(feat.properties, '_mastodon_candidate_md', () => feat.properties._description.match(/\[[^\]]*\]\((.*(mastodon|en.osm.town).*)\).*/)?.at(1) )
Utils.AddLazyProperty(feat.properties, '_d', () => feat.properties._description?.replace(/&lt;/g,'<')?.replace(/&gt;/g,'>') ?? '' )
Utils.AddLazyProperty(feat.properties, '_mastodon_candidate_a', () => (feat => {const e = document.createElement('div');e.innerHTML = feat.properties._d;return Array.from(e.getElementsByTagName("a")).filter(a => a.href.match(/mastodon|en.osm.town/) !== null)[0]?.href }) (feat) )
Utils.AddLazyProperty(feat.properties, '_mastodon_link', () => (feat => {const e = document.createElement('div');e.innerHTML = feat.properties._d;return Array.from(e.getElementsByTagName("a")).filter(a => a.getAttribute("rel")?.indexOf('me') >= 0)[0]?.href})(feat) )
Utils.AddLazyProperty(feat.properties, '_mastodon_candidate', () => feat.properties._mastodon_candidate_md ?? feat.properties._mastodon_candidate_a )
feat.properties['__current_backgroun'] = 'initial_value'
}
}
public metaTaggging_for_usersettings(feat: { properties: Record<string, string> }) {
Utils.AddLazyProperty(feat.properties, "_mastodon_candidate_md", () =>
feat.properties._description
.match(/\[[^\]]*\]\((.*(mastodon|en.osm.town).*)\).*/)
?.at(1)
)
Utils.AddLazyProperty(
feat.properties,
"_d",
() => feat.properties._description?.replace(/&lt;/g, "<")?.replace(/&gt;/g, ">") ?? ""
)
Utils.AddLazyProperty(feat.properties, "_mastodon_candidate_a", () =>
((feat) => {
const e = document.createElement("div")
e.innerHTML = feat.properties._d
return Array.from(e.getElementsByTagName("a")).filter(
(a) => a.href.match(/mastodon|en.osm.town/) !== null
)[0]?.href
})(feat)
)
Utils.AddLazyProperty(feat.properties, "_mastodon_link", () =>
((feat) => {
const e = document.createElement("div")
e.innerHTML = feat.properties._d
return Array.from(e.getElementsByTagName("a")).filter(
(a) => a.getAttribute("rel")?.indexOf("me") >= 0
)[0]?.href
})(feat)
)
Utils.AddLazyProperty(
feat.properties,
"_mastodon_candidate",
() => feat.properties._mastodon_candidate_md ?? feat.properties._mastodon_candidate_a
)
feat.properties["__current_backgroun"] = "initial_value"
}
}

View file

@ -951,13 +951,12 @@ export class UIEventSource<T> extends Store<T> implements Writable<T> {
g: (j: J, t: T) => T,
allowUnregister = false
): UIEventSource<J> {
const stack = new Error().stack.split("\n")
const callee = stack[1]
const newSource = new UIEventSource<J>(f(this.data), "map(" + this.tag + ")@" + callee)
const update =() => {
const update = () => {
newSource.setData(f(this.data))
return allowUnregister && newSource._callbacks.length() === 0
}