forked from MapComplete/MapComplete
Merge master
This commit is contained in:
commit
cbea216d01
119 changed files with 5314 additions and 4218 deletions
|
|
@ -53,7 +53,7 @@ export class Changes {
|
|||
featureSwitches?: FeatureSwitchState
|
||||
},
|
||||
leftRightSensitive: boolean = false,
|
||||
reportError?: (string: string | Error, extramessage?: string) => void,
|
||||
reportError?: (string: string | Error, extramessage?: string) => void
|
||||
) {
|
||||
this._leftRightSensitive = leftRightSensitive
|
||||
// We keep track of all changes just as well
|
||||
|
|
@ -68,7 +68,7 @@ export class Changes {
|
|||
state.osmConnection,
|
||||
state.featurePropertiesStore,
|
||||
this,
|
||||
(e, extramessage: string) => this._reportError(e, extramessage),
|
||||
(e, extramessage: string) => this._reportError(e, extramessage)
|
||||
)
|
||||
this.historicalUserLocations = state.historicalUserLocations
|
||||
|
||||
|
|
@ -82,7 +82,7 @@ export class Changes {
|
|||
modifiedObjects: OsmObject[]
|
||||
newObjects: OsmObject[]
|
||||
deletedObjects: OsmObject[]
|
||||
},
|
||||
}
|
||||
): string {
|
||||
const changedElements = allChanges.modifiedObjects ?? []
|
||||
const newElements = allChanges.newObjects ?? []
|
||||
|
|
@ -172,7 +172,7 @@ export class Changes {
|
|||
docs: "The identifier of the used background layer, this will probably be an identifier from the [editor layer index](https://github.com/osmlab/editor-layer-index)",
|
||||
},
|
||||
],
|
||||
"default",
|
||||
"default"
|
||||
),
|
||||
...addSource(ChangeTagAction.metatags, "ChangeTag"),
|
||||
...addSource(ChangeLocationAction.metatags, "ChangeLocation"),
|
||||
|
|
@ -201,7 +201,7 @@ export class Changes {
|
|||
: "",
|
||||
].join("\n"),
|
||||
source,
|
||||
]),
|
||||
])
|
||||
),
|
||||
].join("\n\n")
|
||||
}
|
||||
|
|
@ -217,7 +217,11 @@ export class Changes {
|
|||
// See #2082. We check for previous rewritings, as a remapping might be from a previous session
|
||||
do {
|
||||
this._nextId--
|
||||
} while (this._changesetHandler._remappings.has("node/" + this._nextId) || this._changesetHandler._remappings.has("way/" + this._nextId) || this._changesetHandler._remappings.has("relation/" + this._nextId))
|
||||
} while (
|
||||
this._changesetHandler._remappings.has("node/" + this._nextId) ||
|
||||
this._changesetHandler._remappings.has("way/" + this._nextId) ||
|
||||
this._changesetHandler._remappings.has("relation/" + this._nextId)
|
||||
)
|
||||
return this._nextId
|
||||
}
|
||||
|
||||
|
|
@ -254,7 +258,7 @@ export class Changes {
|
|||
const changeDescriptions = await action.Perform(this)
|
||||
const remapped = ChangeDescriptionTools.rewriteAllIds(
|
||||
changeDescriptions,
|
||||
this._changesetHandler._remappings,
|
||||
this._changesetHandler._remappings
|
||||
)
|
||||
|
||||
remapped[0].meta.distanceToObject = this.calculateDistanceToChanges(action, remapped)
|
||||
|
|
@ -319,7 +323,7 @@ export class Changes {
|
|||
}
|
||||
if (change.changes === undefined) {
|
||||
// This object is a change to a newly created object. However, we have not seen the creation changedescription yet!
|
||||
if(ignoreNoCreate){
|
||||
if (ignoreNoCreate) {
|
||||
continue
|
||||
}
|
||||
throw "Not a creation of the object: " + JSON.stringify(change)
|
||||
|
|
@ -462,7 +466,7 @@ export class Changes {
|
|||
result.modifiedObjects.length,
|
||||
"modified;",
|
||||
result.deletedObjects.length,
|
||||
"deleted",
|
||||
"deleted"
|
||||
)
|
||||
}
|
||||
return result
|
||||
|
|
@ -470,7 +474,7 @@ export class Changes {
|
|||
|
||||
private calculateDistanceToChanges(
|
||||
change: OsmChangeAction,
|
||||
changeDescriptions: ChangeDescription[],
|
||||
changeDescriptions: ChangeDescription[]
|
||||
) {
|
||||
const locations = this.historicalUserLocations?.features?.data
|
||||
if (locations === undefined) {
|
||||
|
|
@ -490,7 +494,7 @@ export class Changes {
|
|||
.filter((feat) => feat.geometry.type === "Point")
|
||||
.filter((feat) => {
|
||||
const visitTime = new Date(
|
||||
(<GeoLocationPointProperties>(<any>feat.properties)).date,
|
||||
(<GeoLocationPointProperties>(<any>feat.properties)).date
|
||||
)
|
||||
// In seconds
|
||||
const diff = (now.getTime() - visitTime.getTime()) / 1000
|
||||
|
|
@ -537,9 +541,9 @@ export class Changes {
|
|||
...recentLocationPoints.map((gpsPoint) => {
|
||||
const otherCoor = GeoOperations.centerpointCoordinates(gpsPoint)
|
||||
return GeoOperations.distanceBetween(coor, otherCoor)
|
||||
}),
|
||||
),
|
||||
),
|
||||
})
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -575,7 +579,7 @@ export class Changes {
|
|||
|
||||
public fragmentChanges(
|
||||
pending: ChangeDescription[],
|
||||
objects: OsmObject[],
|
||||
objects: OsmObject[]
|
||||
): {
|
||||
refused: ChangeDescription[]
|
||||
toUpload: ChangeDescription[]
|
||||
|
|
@ -585,7 +589,7 @@ export class Changes {
|
|||
|
||||
// All ids which have an 'update'
|
||||
const createdIds = new Set(
|
||||
pending.filter((cd) => cd.changes !== undefined).map((cd) => cd.id),
|
||||
pending.filter((cd) => cd.changes !== undefined).map((cd) => cd.id)
|
||||
)
|
||||
pending.forEach((c) => {
|
||||
if (c.id < 0) {
|
||||
|
|
@ -594,7 +598,7 @@ export class Changes {
|
|||
} else {
|
||||
this._reportError(
|
||||
`Got an orphaned change. The 'creation'-change description for ${c.type}/${c.id} got lost. Permanently dropping this change:` +
|
||||
JSON.stringify(c),
|
||||
JSON.stringify(c)
|
||||
)
|
||||
}
|
||||
return
|
||||
|
|
@ -605,10 +609,10 @@ export class Changes {
|
|||
} else {
|
||||
console.log(
|
||||
"Refusing change about " +
|
||||
c.type +
|
||||
"/" +
|
||||
c.id +
|
||||
" as not in the objects. No internet?",
|
||||
c.type +
|
||||
"/" +
|
||||
c.id +
|
||||
" as not in the objects. No internet?"
|
||||
)
|
||||
refused.push(c)
|
||||
}
|
||||
|
|
@ -623,16 +627,18 @@ export class Changes {
|
|||
*/
|
||||
private async flushSelectChanges(
|
||||
pending: ChangeDescription[],
|
||||
openChangeset: UIEventSource<number>,
|
||||
openChangeset: UIEventSource<number>
|
||||
): Promise<ChangeDescription[]> {
|
||||
const neededIds = Changes.GetNeededIds(pending)
|
||||
/* Download the latest version of the OSM-objects
|
||||
* We _do not_ pass in the Changes object itself - we want the data from OSM directly in order to apply the changes
|
||||
*/
|
||||
* We _do not_ pass in the Changes object itself - we want the data from OSM directly in order to apply the changes
|
||||
*/
|
||||
const downloader = new OsmObjectDownloader(this.backend, undefined)
|
||||
const osmObjects = Utils.NoNull(await Promise.all<{ id: string; osmObj: OsmObject | "deleted" }>(
|
||||
neededIds.map((id) => this.getOsmObject(id, downloader)),
|
||||
))
|
||||
const osmObjects = Utils.NoNull(
|
||||
await Promise.all<{ id: string; osmObj: OsmObject | "deleted" }>(
|
||||
neededIds.map((id) => this.getOsmObject(id, downloader))
|
||||
)
|
||||
)
|
||||
|
||||
// Drop changes to deleted items
|
||||
for (const { osmObj, id } of osmObjects) {
|
||||
|
|
@ -665,7 +671,7 @@ export class Changes {
|
|||
(csId, remappings) => {
|
||||
if (remappings.size > 0) {
|
||||
toUpload = toUpload.map((ch) =>
|
||||
ChangeDescriptionTools.rewriteIds(ch, remappings),
|
||||
ChangeDescriptionTools.rewriteIds(ch, remappings)
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -678,7 +684,7 @@ export class Changes {
|
|||
return Changes.buildChangesetXML("" + csId, changes)
|
||||
},
|
||||
metatags,
|
||||
openChangeset,
|
||||
openChangeset
|
||||
)
|
||||
|
||||
console.log("Upload successful! Refused changes are", refused)
|
||||
|
|
@ -695,15 +701,15 @@ export class Changes {
|
|||
pending
|
||||
.filter(
|
||||
(descr) =>
|
||||
descr.meta.changeType !== undefined && descr.meta.changeType !== null,
|
||||
descr.meta.changeType !== undefined && descr.meta.changeType !== null
|
||||
)
|
||||
.map((descr) => descr.meta.changeType),
|
||||
.map((descr) => descr.meta.changeType)
|
||||
),
|
||||
([key, count]) => ({
|
||||
key: key,
|
||||
value: count,
|
||||
aggregate: true,
|
||||
}),
|
||||
})
|
||||
)
|
||||
const motivations = pending
|
||||
.filter((descr) => descr.meta.specialMotivation !== undefined)
|
||||
|
|
@ -742,7 +748,7 @@ export class Changes {
|
|||
value: count,
|
||||
aggregate: true,
|
||||
}
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
// This method is only called with changedescriptions for this theme
|
||||
|
|
@ -788,14 +794,14 @@ export class Changes {
|
|||
try {
|
||||
const openChangeset = UIEventSource.asInt(
|
||||
this.state.osmConnection.GetPreference(
|
||||
"current-open-changeset-" + theme,
|
||||
),
|
||||
"current-open-changeset-" + theme
|
||||
)
|
||||
)
|
||||
console.log(
|
||||
"Using current-open-changeset-" +
|
||||
theme +
|
||||
" from the preferences, got " +
|
||||
openChangeset.data,
|
||||
theme +
|
||||
" from the preferences, got " +
|
||||
openChangeset.data
|
||||
)
|
||||
|
||||
const refused = await self.flushSelectChanges(pendingChanges, openChangeset)
|
||||
|
|
@ -810,7 +816,7 @@ export class Changes {
|
|||
this.errors.ping()
|
||||
return pendingChanges
|
||||
}
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
// We keep all the refused changes to try them again
|
||||
|
|
@ -818,7 +824,7 @@ export class Changes {
|
|||
} catch (e) {
|
||||
console.error(
|
||||
"Could not handle changes - probably an old, pending changeset in localstorage with an invalid format; erasing those",
|
||||
e,
|
||||
e
|
||||
)
|
||||
this.errors.data.push(e)
|
||||
this.errors.ping()
|
||||
|
|
|
|||
|
|
@ -21,8 +21,11 @@ export type ChangesetMetadata = {
|
|||
uid: number
|
||||
user: string
|
||||
changes_count: number
|
||||
tags: Record<string, string>,
|
||||
minlat: number, minlon: number, maxlat: number, maxlon: number
|
||||
tags: Record<string, string>
|
||||
minlat: number
|
||||
minlon: number
|
||||
maxlat: number
|
||||
maxlon: number
|
||||
comments_count: number
|
||||
}
|
||||
|
||||
|
|
@ -49,7 +52,7 @@ export class ChangesetHandler {
|
|||
| { addAlias: (id0: string, id1: string) => void }
|
||||
| undefined,
|
||||
changes: Changes,
|
||||
reportError: (e: string | Error, extramessage: string) => void,
|
||||
reportError: (e: string | Error, extramessage: string) => void
|
||||
) {
|
||||
this.osmConnection = osmConnection
|
||||
this._reportError = reportError
|
||||
|
|
@ -107,27 +110,27 @@ export class ChangesetHandler {
|
|||
return hasChange
|
||||
}
|
||||
|
||||
private async UploadWithNew(generateChangeXML: (csid: number, remappings: Map<string, string>) => string, openChangeset: UIEventSource<number>, extraMetaTags: ChangesetTag[]) {
|
||||
private async UploadWithNew(
|
||||
generateChangeXML: (csid: number, remappings: Map<string, string>) => string,
|
||||
openChangeset: UIEventSource<number>,
|
||||
extraMetaTags: ChangesetTag[]
|
||||
) {
|
||||
const csId = await this.OpenChangeset(extraMetaTags)
|
||||
openChangeset.setData(csId)
|
||||
const changeset = generateChangeXML(csId, this._remappings)
|
||||
console.log(
|
||||
"Opened a new changeset (openChangeset.data is undefined):",
|
||||
changeset,
|
||||
extraMetaTags,
|
||||
extraMetaTags
|
||||
)
|
||||
const changes = await this.UploadChange(csId, changeset)
|
||||
const hasSpecialMotivationChanges = ChangesetHandler.rewriteMetaTags(
|
||||
extraMetaTags,
|
||||
changes,
|
||||
)
|
||||
const hasSpecialMotivationChanges = ChangesetHandler.rewriteMetaTags(extraMetaTags, changes)
|
||||
if (hasSpecialMotivationChanges) {
|
||||
// At this point, 'extraMetaTags' will have changed - we need to set the tags again
|
||||
await this.UpdateTags(csId, extraMetaTags)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The full logic to upload a change to one or more elements.
|
||||
*
|
||||
|
|
@ -141,7 +144,7 @@ export class ChangesetHandler {
|
|||
public async UploadChangeset(
|
||||
generateChangeXML: (csid: number, remappings: Map<string, string>) => string,
|
||||
extraMetaTags: ChangesetTag[],
|
||||
openChangeset: UIEventSource<number>,
|
||||
openChangeset: UIEventSource<number>
|
||||
): Promise<void> {
|
||||
if (
|
||||
!extraMetaTags.some((tag) => tag.key === "comment") ||
|
||||
|
|
@ -174,30 +177,30 @@ export class ChangesetHandler {
|
|||
// We can hopefully reuse the changeset
|
||||
|
||||
try {
|
||||
|
||||
const rewritings = await this.UploadChange(
|
||||
csId,
|
||||
generateChangeXML(csId, this._remappings),
|
||||
generateChangeXML(csId, this._remappings)
|
||||
)
|
||||
|
||||
const rewrittenTags = this.RewriteTagsOf(
|
||||
extraMetaTags,
|
||||
rewritings,
|
||||
oldChangesetMeta,
|
||||
oldChangesetMeta
|
||||
)
|
||||
await this.UpdateTags(csId, rewrittenTags)
|
||||
return // We are done!
|
||||
} catch (e) {
|
||||
this._reportError(e, "While reusing a changeset " + openChangeset.data)
|
||||
}
|
||||
|
||||
}
|
||||
} catch (e) {
|
||||
this._reportError(e, "While getting metadata from a changeset " + openChangeset.data)
|
||||
this._reportError(
|
||||
e,
|
||||
"While getting metadata from a changeset " + openChangeset.data
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// We have to open a new changeset
|
||||
try {
|
||||
return await this.UploadWithNew(generateChangeXML, openChangeset, extraMetaTags)
|
||||
|
|
@ -212,7 +215,7 @@ export class ChangesetHandler {
|
|||
console.warn(
|
||||
"Could not open/upload changeset due to ",
|
||||
e,
|
||||
"trying again with a another fresh changeset ",
|
||||
"trying again with a another fresh changeset "
|
||||
)
|
||||
openChangeset.setData(undefined)
|
||||
|
||||
|
|
@ -238,7 +241,7 @@ export class ChangesetHandler {
|
|||
uid: number // User ID
|
||||
changes_count: number
|
||||
tags: any
|
||||
},
|
||||
}
|
||||
): ChangesetTag[] {
|
||||
// Note: extraMetaTags is where all the tags are collected into
|
||||
|
||||
|
|
@ -375,7 +378,7 @@ export class ChangesetHandler {
|
|||
tag.key !== undefined &&
|
||||
tag.value !== undefined &&
|
||||
tag.key !== "" &&
|
||||
tag.value !== "",
|
||||
tag.value !== ""
|
||||
)
|
||||
const metadata = tags.map((kv) => `<tag k="${kv.key}" v="${escapeHtml(kv.value)}"/>`)
|
||||
const content = [`<osm><changeset>`, metadata, `</changeset></osm>`].join("")
|
||||
|
|
@ -415,7 +418,7 @@ export class ChangesetHandler {
|
|||
const csId = await this.osmConnection.put(
|
||||
"changeset/create",
|
||||
[`<osm><changeset>`, metadata, `</changeset></osm>`].join(""),
|
||||
{ "Content-Type": "text/xml" },
|
||||
{ "Content-Type": "text/xml" }
|
||||
)
|
||||
return Number(csId)
|
||||
}
|
||||
|
|
@ -425,12 +428,12 @@ export class ChangesetHandler {
|
|||
*/
|
||||
private async UploadChange(
|
||||
changesetId: number,
|
||||
changesetXML: string,
|
||||
changesetXML: string
|
||||
): Promise<Map<string, string>> {
|
||||
const response = await this.osmConnection.post<XMLDocument>(
|
||||
"changeset/" + changesetId + "/upload",
|
||||
changesetXML,
|
||||
{ "Content-Type": "text/xml" },
|
||||
{ "Content-Type": "text/xml" }
|
||||
)
|
||||
const changes = this.parseUploadChangesetResponse(response)
|
||||
console.log("Uploaded changeset ", changesetId)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue