Merge branch 'develop'

This commit is contained in:
Pieter Vander Vennet 2024-07-15 10:16:07 +02:00
commit 7b47cff62e
483 changed files with 11615 additions and 16323 deletions

View file

@ -5,6 +5,7 @@ import List from "../UI/Base/List"
import Title from "../UI/Base/Title"
import { BBox } from "./BBox"
import { Feature, Geometry, MultiPolygon, Polygon } from "geojson"
import MarkdownUtils from "../Utils/MarkdownUtils"
export interface ExtraFuncParams {
/**
@ -517,16 +518,16 @@ export class ExtraFunctions {
return record
}
public static HelpText(): BaseUIElement {
const elems = []
public static HelpText(): string {
const elems: string[] = []
for (const func of ExtraFunctions.allFuncs) {
elems.push(new Title(func._name, 3), func._doc, new List(func._args ?? [], true))
elems.push("### "+func._name, func._doc, MarkdownUtils.list(func._args))
}
return new Combine([
return [
ExtraFunctions.intro,
new List(ExtraFunctions.allFuncs.map((func) => `[${func._name}](#${func._name})`)),
MarkdownUtils.list(ExtraFunctions.allFuncs.map((func) => `[${func._name}](#${func._name})`)),
...elems,
])
].join("\n")
}
}

View file

@ -78,7 +78,14 @@ export class WikimediaImageProvider extends ImageProvider {
return new SvelteUIElement(Wikimedia_commons_white).SetStyle("width:2em;height: 2em")
}
public PrepUrl(value: string): ProvidedImage {
public PrepUrl(value: NonNullable<string>): ProvidedImage
public PrepUrl(value: undefined): undefined
public PrepUrl(value: string): ProvidedImage
public PrepUrl(value: string | undefined): ProvidedImage | undefined{
if(value === undefined){
return undefined
}
value = WikimediaImageProvider.removeCommonsPrefix(value)
if (value.startsWith("File:")) {

View file

@ -13,14 +13,11 @@ import { ChangesetHandler, ChangesetTag } from "./ChangesetHandler"
import { OsmConnection } from "./OsmConnection"
import FeaturePropertiesStore from "../FeatureSource/Actors/FeaturePropertiesStore"
import OsmObjectDownloader from "./OsmObjectDownloader"
import Combine from "../../UI/Base/Combine"
import BaseUIElement from "../../UI/BaseUIElement"
import Title from "../../UI/Base/Title"
import Table from "../../UI/Base/Table"
import ChangeLocationAction from "./Actions/ChangeLocationAction"
import ChangeTagAction from "./Actions/ChangeTagAction"
import FeatureSwitchState from "../State/FeatureSwitchState"
import DeleteAction from "./Actions/DeleteAction"
import MarkdownUtils from "../../Utils/MarkdownUtils"
/**
* Handles all changes made to OSM.
@ -43,7 +40,7 @@ export class Changes {
private _nextId: number = -1 // Newly assigned ID's are negative
private readonly previouslyCreated: OsmObject[] = []
private readonly _leftRightSensitive: boolean
private readonly _changesetHandler: ChangesetHandler
public readonly _changesetHandler: ChangesetHandler
private readonly _reportError?: (string: string | Error) => void
constructor(
@ -116,7 +113,7 @@ export class Changes {
return changes
}
public static getDocs(): BaseUIElement {
public static getDocs(): string {
function addSource(items: any[], src: string) {
items.forEach((i) => {
i["source"] = src
@ -188,27 +185,27 @@ export class Changes {
...ReplaceGeometryAction.metatags,
...SplitAction.metatags,*/
]
return new Combine([
new Title("Metatags on a changeset", 1),
return [
"# Metatags on a changeset",
"You might encounter the following metatags on a changeset:",
new Table(
MarkdownUtils.table(
["key", "value", "explanation", "source"],
metatagsDocs.map(({ key, value, docs, source, changeType, specialMotivation }) => [
key ?? changeType?.join(", ") ?? "",
value,
new Combine([
[
docs,
specialMotivation
? "This might give a reason per modified node or way"
: "",
]),
].join("\n"),
source,
]),
),
])
].join("\n\n")
}
private static GetNeededIds(changes: ChangeDescription[]) {
public static GetNeededIds(changes: ChangeDescription[]) {
return Utils.Dedup(changes.filter((c) => c.id >= 0).map((c) => c.type + "/" + c.id))
}
@ -519,7 +516,7 @@ export class Changes {
const osmObj = await downloader.DownloadObjectAsync(id, 0)
return { id, osmObj }
} catch (e) {
const msg = "Could not download OSM-object" +
const msg = "Could not download OSM-object " +
id +
" trying again before dropping it from the changes (" +
e +
@ -529,7 +526,7 @@ export class Changes {
return { id, osmObj }
}
} catch (e) {
const msg = "Could not download OSM-object" +
const msg = "Could not download OSM-object " +
id +
" dropping it from the changes (" +
e +

View file

@ -25,7 +25,7 @@ export class ChangesetHandler {
* Contains previously rewritten IDs
* @private
*/
private readonly _remappings = new Map<string, string>()
public readonly _remappings = new Map<string, string>()
private readonly _reportError: (e: string | Error) => void
constructor(
@ -187,7 +187,7 @@ export class ChangesetHandler {
await this.UpdateTags(csId, rewrittenTags)
} catch (e) {
if (this._reportError) {
this._reportError("Could not reuse changeset, might be closed: " + e.stacktrace ?? "" + e)
this._reportError("Could not reuse changeset "+csId+", might be closed: " + (e.stacktrace ?? ("" + e)))
}
console.warn("Could not upload, changeset is probably closed: ", e)
openChangeset.setData(undefined)

View file

@ -766,29 +766,27 @@ export default class SimpleMetaTaggers {
return somethingChanged
}
public static HelpText(): BaseUIElement {
const subElements: (string | BaseUIElement)[] = [
new Combine([
public static HelpText(): string {
const subElements: string[] = [
[
"Metatags are extra tags available, in order to display more data or to give better questions.",
"They are calculated automatically on every feature when the data arrives in the webbrowser. This document gives an overview of the available metatags.",
"**Hint:** when using metatags, add the [query parameter](URL_Parameters.md) `debug=true` to the URL. This will include a box in the popup for features which shows all the properties of the object",
]).SetClass("flex-col"),
].join("\n"),
]
subElements.push(new Title("Metatags calculated by MapComplete", 2))
subElements.push("## Metatags calculated by MapComplete")
subElements.push(
new FixedUiElement(
"The following values are always calculated, by default, by MapComplete and are available automatically on all elements in every theme"
)
)
for (const metatag of SimpleMetaTaggers.metatags) {
subElements.push(
new Title(metatag.keys.join(", "), 3),
"### "+metatag.keys.join(", "),
metatag.doc,
metatag.isLazy ? "This is a lazy metatag and is only calculated when needed" : ""
)
}
return new Combine(subElements).SetClass("flex-col")
return subElements.join("\n\n")
}
}

View file

@ -119,6 +119,8 @@ export interface WikidataAdvancedSearchoptions extends WikidataSearchoptions {
notInstanceOf?: number[]
}
interface SparqlResult {results: { bindings: {item, label, description, num}[] }}
/**
* Utility functions around wikidata
*/
@ -202,7 +204,7 @@ export default class Wikidata {
} ORDER BY ASC(?num) LIMIT ${options?.maxCount ?? 20}`
const url = wds.sparqlQuery(sparql)
const result = await Utils.downloadJson(url)
const result = await Utils.downloadJson<SparqlResult>(url)
/*The full uri of the wikidata-item*/
return result.results.bindings.map(({ item, label, description, num }) => ({
@ -389,7 +391,7 @@ export default class Wikidata {
' SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }\n' +
"}"
const url = wds.sparqlQuery(query)
const result = await Utils.downloadJsonCached(url, 24 * 60 * 60 * 1000)
const result = await Utils.downloadJsonCached<SparqlResult>(url, 24 * 60 * 60 * 1000)
return result.results.bindings
}
@ -420,7 +422,7 @@ export default class Wikidata {
}
const url = "https://www.wikidata.org/wiki/Special:EntityData/" + id + ".json"
const entities = (await Utils.downloadJsonCached(url, 10000)).entities
const entities = (await Utils.downloadJsonCached<{entities}>(url, 10000)).entities
const firstKey = <string>Array.from(Object.keys(entities))[0] // Roundabout way to fetch the entity; it might have been a redirect
const response = entities[firstKey]

View file

@ -215,7 +215,7 @@ export default class Wikipedia {
}
private async GetArticleUncachedAsync(pageName: string): Promise<string> {
const response = await Utils.downloadJson(this.getDataUrl(pageName))
const response = await Utils.downloadJson<any>(this.getDataUrl(pageName))
if (response?.parse?.text === undefined) {
return undefined
}