More refactoring of the featurepipeline, introduction of fetching data from the OSM-API directly per tile, personal theme refactoring

This commit is contained in:
Pieter Vander Vennet 2021-09-28 17:30:48 +02:00
parent 0a9e7c0b36
commit 41a2a79fe9
48 changed files with 746 additions and 590 deletions

View file

@ -62,26 +62,26 @@ export class OsmConnection {
};
private isChecking = false;
constructor(dryRun: boolean,
fakeUser: boolean,
constructor(options:{dryRun?: false | boolean,
fakeUser?: false | boolean,
allElements: ElementStorage,
changes: Changes,
oauth_token: UIEventSource<string>,
oauth_token?: UIEventSource<string>,
// Used to keep multiple changesets open and to write to the correct changeset
layoutName: string,
singlePage: boolean = true,
osmConfiguration: "osm" | "osm-test" = 'osm'
singlePage?: boolean,
osmConfiguration?: "osm" | "osm-test" }
) {
this.fakeUser = fakeUser;
this._singlePage = singlePage;
this._oauth_config = OsmConnection.oauth_configs[osmConfiguration] ?? OsmConnection.oauth_configs.osm;
this.fakeUser = options.fakeUser ?? false;
this._singlePage = options.singlePage ?? true;
this._oauth_config = OsmConnection.oauth_configs[options.osmConfiguration ?? 'osm'] ?? OsmConnection.oauth_configs.osm;
console.debug("Using backend", this._oauth_config.url)
OsmObject.SetBackendUrl(this._oauth_config.url + "/")
this._iframeMode = Utils.runningFromConsole ? false : window !== window.top;
this.userDetails = new UIEventSource<UserDetails>(new UserDetails(this._oauth_config.url), "userDetails");
this.userDetails.data.dryRun = dryRun || fakeUser;
if (fakeUser) {
this.userDetails.data.dryRun = (options.dryRun ?? false) || (options.fakeUser ?? false) ;
if (options.fakeUser) {
const ud = this.userDetails.data;
ud.csCount = 5678
ud.loggedIn = true;
@ -98,23 +98,23 @@ export class OsmConnection {
}
});
this.isLoggedIn.addCallbackAndRunD(li => console.log("User is logged in!", li))
this._dryRun = dryRun;
this._dryRun = options.dryRun;
this.updateAuthObject();
this.preferencesHandler = new OsmPreferences(this.auth, this);
this.changesetHandler = new ChangesetHandler(layoutName, dryRun, this, allElements, changes, this.auth);
if (oauth_token.data !== undefined) {
console.log(oauth_token.data)
this.changesetHandler = new ChangesetHandler(options.layoutName, options.dryRun, this, options.allElements, options.changes, this.auth);
if (options.oauth_token?.data !== undefined) {
console.log(options.oauth_token.data)
const self = this;
this.auth.bootstrapToken(oauth_token.data,
this.auth.bootstrapToken(options.oauth_token.data,
(x) => {
console.log("Called back: ", x)
self.AttemptLogin();
}, this.auth);
oauth_token.setData(undefined);
options. oauth_token.setData(undefined);
}
if (this.auth.authenticated()) {

View file

@ -1,7 +1,7 @@
import {Utils} from "../../Utils";
import * as polygon_features from "../../assets/polygon-features.json";
import {UIEventSource} from "../UIEventSource";
import {BBox} from "../GeoOperations";
import {BBox} from "../BBox";
export abstract class OsmObject {

View file

@ -16,8 +16,8 @@ export class Overpass {
private readonly _extraScripts: string[];
private _includeMeta: boolean;
private _relationTracker: RelationsTracker;
constructor(filter: TagsFilter, extraScripts: string[],
interpreterUrl: UIEventSource<string>,
timeout: UIEventSource<number>,
@ -41,10 +41,13 @@ export class Overpass {
}
const self = this;
const json = await Utils.downloadJson(query)
if (json.elements === [] && ((json.remarks ?? json.remark).indexOf("runtime error") >= 0)) {
console.log("Timeout or other runtime error");
throw("Runtime error (timeout)")
console.log("Got json!", json)
if (json.elements.length === 0 && json.remark !== undefined) {
console.warn("Timeout or other runtime error while querying overpass", json.remark);
throw `Runtime error (timeout or similar)${json.remark}`
}
if(json.elements.length === 0){
console.warn("No features for" ,json)
}
self._relationTracker.RegisterRelations(json)