More work on the custom theme generator, add aed template, move bookcases to json template

This commit is contained in:
Pieter Vander Vennet 2020-08-22 02:12:46 +02:00
parent 146552e62c
commit 560c8e1567
34 changed files with 1048 additions and 590 deletions

View file

@ -19,12 +19,9 @@ export class Changes {
public readonly pendingChangesES = new UIEventSource<number>(this._pendingChanges.length);
public readonly isSaving = new UIEventSource(false);
private readonly _changesetComment: string;
constructor(
changesetComment: string,
state: State) {
this._changesetComment = changesetComment;
this.SetupAutoSave(state);
this.LastEffortSave();
@ -74,6 +71,9 @@ export class Changes {
const eventSource = State.state.allElements.getElement(elementId);
eventSource.data[key] = value;
if(value === undefined || value === ""){
delete eventSource.data[key];
}
eventSource.ping();
// We get the id from the event source, as that ID might be rewritten
this._pendingChanges.push({elementId: eventSource.data.id, key: key, value: value});
@ -223,7 +223,7 @@ export class Changes {
console.log("Beginning upload...");
// At last, we build the changeset and upload
State.state.osmConnection.UploadChangeset(self._changesetComment,
State.state.osmConnection.UploadChangeset(
function (csId) {
let modifications = "";

View file

@ -2,6 +2,7 @@
import osmAuth from "osm-auth";
import {UIEventSource} from "../UIEventSource";
import {CustomLayersState} from "../CustomLayersState";
import {State} from "../../State";
export class UserDetails {
@ -262,16 +263,16 @@ export class OsmConnection {
const newId = parseInt(node.attributes.new_id.value);
if (oldId !== undefined && newId !== undefined &&
!isNaN(oldId) && !isNaN(newId)) {
mapping["node/"+oldId] = "node/"+newId;
mapping["node/" + oldId] = "node/" + newId;
}
}
return mapping;
}
public UploadChangeset(comment: string, generateChangeXML: ((csid: string) => string),
handleMapping: ((idMapping: any) => void),
continuation: (() => void)) {
public UploadChangeset(generateChangeXML: (csid: string) => string,
handleMapping: (idMapping: any) => void,
continuation: () => void) {
if (this._dryRun) {
console.log("NOT UPLOADING as dryrun is true");
@ -282,7 +283,7 @@ export class OsmConnection {
}
const self = this;
this.OpenChangeset(comment,
this.OpenChangeset(
function (csId) {
var changesetXML = generateChangeXML(csId);
self.AddChange(csId, changesetXML,
@ -300,17 +301,20 @@ export class OsmConnection {
}
private OpenChangeset(comment: string, continuation: ((changesetId: string) => void)) {
private OpenChangeset(continuation: (changesetId: string) => void) {
const layout = State.state.layoutToUse.data;
this.auth.xhr({
method: 'PUT',
path: '/api/0.6/changeset/create',
options: { header: { 'Content-Type': 'text/xml' } },
content: '<osm><changeset>' +
'<tag k="created_by" v="MapComplete 0.0.0" />' +
'<tag k="comment" v="' + comment + '"/>' +
'</changeset></osm>'
options: {header: {'Content-Type': 'text/xml'}},
content: [`<osm><changeset>`,
`<tag k="created_by" v="MapComplete ${State.vNumber}" />`,
`<tag k="comment" v="Adding data with #MapComplete"/>`,
`<tag k="theme" v="${layout.name}">`,
layout.maintainer !== undefined ? `<tag k="theme-creator" v="${layout.maintainer}">` : "",
`</changeset></osm>`].join("")
}, function (err, response) {
if (response === undefined) {
console.log("err", err);

View file

@ -83,6 +83,9 @@ export abstract class OsmObject {
console.log("WARNING: overwriting ",oldV, " with ", v," for key ",k)
}
this.tags[k] = v;
if(v === undefined || v === ""){
delete this.tags[k];
}
this.changed = true;
}