forked from MapComplete/MapComplete
Finish importer, add applicable import layers to every theme by default
This commit is contained in:
parent
3402ac0954
commit
ca1490902c
41 changed files with 1559 additions and 898 deletions
|
@ -10,11 +10,12 @@ import {UIEventSource} from "./UIEventSource";
|
|||
import {LocalStorageSource} from "./Web/LocalStorageSource";
|
||||
import LZString from "lz-string";
|
||||
import * as personal from "../assets/themes/personal/personal.json";
|
||||
import {FixLegacyTheme, PrepareTheme} from "../Models/ThemeConfig/Conversion/LegacyJsonConvert";
|
||||
import {FixLegacyTheme} from "../Models/ThemeConfig/Conversion/LegacyJsonConvert";
|
||||
import {LayerConfigJson} from "../Models/ThemeConfig/Json/LayerConfigJson";
|
||||
import SharedTagRenderings from "../Customizations/SharedTagRenderings";
|
||||
import * as known_layers from "../assets/generated/known_layers.json"
|
||||
import {LayoutConfigJson} from "../Models/ThemeConfig/Json/LayoutConfigJson";
|
||||
import {PrepareTheme} from "../Models/ThemeConfig/Conversion/PrepareTheme";
|
||||
|
||||
export default class DetermineLayout {
|
||||
|
||||
|
|
|
@ -29,11 +29,11 @@ export default class FilteringFeatureSource implements FeatureSourceForLayer, Ti
|
|||
},
|
||||
tileIndex,
|
||||
upstream: FeatureSourceForLayer,
|
||||
metataggingUpdated: UIEventSource<any>
|
||||
metataggingUpdated?: UIEventSource<any>
|
||||
) {
|
||||
this.name = "FilteringFeatureSource(" + upstream.name + ")"
|
||||
this.tileIndex = tileIndex
|
||||
this.bbox = BBox.fromTileIndex(tileIndex)
|
||||
this.bbox = tileIndex === undefined ? undefined : BBox.fromTileIndex(tileIndex)
|
||||
this.upstream = upstream
|
||||
this.state = state
|
||||
|
||||
|
@ -55,7 +55,7 @@ export default class FilteringFeatureSource implements FeatureSourceForLayer, Ti
|
|||
}
|
||||
})
|
||||
|
||||
metataggingUpdated.addCallback(_ => {
|
||||
metataggingUpdated?.addCallback(_ => {
|
||||
self._is_dirty.setData(true)
|
||||
})
|
||||
|
||||
|
@ -63,6 +63,7 @@ export default class FilteringFeatureSource implements FeatureSourceForLayer, Ti
|
|||
}
|
||||
|
||||
private update() {
|
||||
console.log("FIltering", this.upstream.name)
|
||||
const self = this;
|
||||
const layer = this.upstream.layer;
|
||||
const features: { feature: any; freshness: Date }[] = (this.upstream.features.data ?? []);
|
||||
|
|
|
@ -28,7 +28,7 @@ export default class GeoJsonSource implements FeatureSourceForLayer, Tiled {
|
|||
private readonly featureIdBlacklist?: UIEventSource<Set<string>>
|
||||
|
||||
public constructor(flayer: FilteredLayer,
|
||||
zxy?: [number, number, number],
|
||||
zxy?: [number, number, number] | BBox,
|
||||
options?: {
|
||||
featureIdBlacklist?: UIEventSource<Set<string>>
|
||||
}) {
|
||||
|
@ -41,23 +41,32 @@ export default class GeoJsonSource implements FeatureSourceForLayer, Tiled {
|
|||
this.featureIdBlacklist = options?.featureIdBlacklist
|
||||
let url = flayer.layerDef.source.geojsonSource.replace("{layer}", flayer.layerDef.id);
|
||||
if (zxy !== undefined) {
|
||||
const [z, x, y] = zxy;
|
||||
let tile_bbox = BBox.fromTile(z, x, y)
|
||||
let tile_bbox: BBox;
|
||||
if (zxy instanceof BBox) {
|
||||
tile_bbox = zxy;
|
||||
} else {
|
||||
const [z, x, y] = zxy;
|
||||
tile_bbox = BBox.fromTile(z, x, y);
|
||||
|
||||
this.tileIndex = Tiles.tile_index(z, x, y)
|
||||
this.bbox = BBox.fromTile(z, x, y)
|
||||
url = url
|
||||
.replace('{z}', "" + z)
|
||||
.replace('{x}', "" + x)
|
||||
.replace('{y}', "" + y)
|
||||
}
|
||||
let bounds: { minLat: number, maxLat: number, minLon: number, maxLon: number } = tile_bbox
|
||||
if (this.layer.layerDef.source.mercatorCrs) {
|
||||
bounds = tile_bbox.toMercator()
|
||||
}
|
||||
|
||||
url = url
|
||||
.replace('{z}', "" + z)
|
||||
.replace('{x}', "" + x)
|
||||
.replace('{y}', "" + y)
|
||||
.replace('{y_min}', "" + bounds.minLat)
|
||||
.replace('{y_max}', "" + bounds.maxLat)
|
||||
.replace('{x_min}', "" + bounds.minLon)
|
||||
.replace('{x_max}', "" + bounds.maxLon)
|
||||
|
||||
this.tileIndex = Tiles.tile_index(z, x, y)
|
||||
this.bbox = BBox.fromTile(z, x, y)
|
||||
|
||||
} else {
|
||||
this.tileIndex = Tiles.tile_index(0, 0, 0)
|
||||
this.bbox = BBox.global;
|
||||
|
@ -83,7 +92,7 @@ export default class GeoJsonSource implements FeatureSourceForLayer, Tiled {
|
|||
if (self.layer.layerDef.source.mercatorCrs) {
|
||||
json = GeoOperations.GeoJsonToWGS84(json)
|
||||
}
|
||||
|
||||
|
||||
const time = new Date();
|
||||
const newFeatures: { feature: any, freshness: Date } [] = []
|
||||
let i = 0;
|
||||
|
|
|
@ -683,6 +683,8 @@ export class GeoOperations {
|
|||
throw "CalculateIntersection fallthrough: can not calculate an intersection between features"
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -18,13 +18,13 @@ export class ChangesetHandler {
|
|||
private readonly allElements: ElementStorage;
|
||||
private osmConnection: OsmConnection;
|
||||
private readonly changes: Changes;
|
||||
private readonly _dryRun: boolean;
|
||||
private readonly _dryRun: UIEventSource<boolean>;
|
||||
private readonly userDetails: UIEventSource<UserDetails>;
|
||||
private readonly auth: any;
|
||||
private readonly backend: string;
|
||||
|
||||
constructor(layoutName: string,
|
||||
dryRun: boolean,
|
||||
dryRun: UIEventSource<boolean>,
|
||||
osmConnection: OsmConnection,
|
||||
allElements: ElementStorage,
|
||||
changes: Changes,
|
||||
|
@ -67,7 +67,7 @@ export class ChangesetHandler {
|
|||
this.userDetails.data.csCount = 1;
|
||||
this.userDetails.ping();
|
||||
}
|
||||
if (this._dryRun) {
|
||||
if (this._dryRun.data) {
|
||||
const changesetXML = generateChangeXML(123456);
|
||||
console.log("Metatags are", extraMetaTags)
|
||||
console.log(changesetXML);
|
||||
|
|
|
@ -19,7 +19,6 @@ export default class UserDetails {
|
|||
public img: string;
|
||||
public unreadMessages = 0;
|
||||
public totalMessages = 0;
|
||||
public dryRun: boolean;
|
||||
home: { lon: number; lat: number };
|
||||
public backend: string;
|
||||
|
||||
|
@ -47,7 +46,6 @@ export class OsmConnection {
|
|||
public auth;
|
||||
public userDetails: UIEventSource<UserDetails>;
|
||||
public isLoggedIn: UIEventSource<boolean>
|
||||
_dryRun: boolean;
|
||||
public preferencesHandler: OsmPreferences;
|
||||
public changesetHandler: ChangesetHandler;
|
||||
public readonly _oauth_config: {
|
||||
|
@ -55,6 +53,7 @@ export class OsmConnection {
|
|||
oauth_secret: string,
|
||||
url: string
|
||||
};
|
||||
private readonly _dryRun: UIEventSource<boolean>;
|
||||
private fakeUser: boolean;
|
||||
private _onLoggedIn: ((userDetails: UserDetails) => void)[] = [];
|
||||
private readonly _iframeMode: Boolean | boolean;
|
||||
|
@ -62,7 +61,7 @@ export class OsmConnection {
|
|||
private isChecking = false;
|
||||
|
||||
constructor(options: {
|
||||
dryRun?: false | boolean,
|
||||
dryRun?: UIEventSource<boolean>,
|
||||
fakeUser?: false | boolean,
|
||||
allElements: ElementStorage,
|
||||
changes: Changes,
|
||||
|
@ -82,7 +81,6 @@ export class OsmConnection {
|
|||
this._iframeMode = Utils.runningFromConsole ? false : window !== window.top;
|
||||
|
||||
this.userDetails = new UIEventSource<UserDetails>(new UserDetails(this._oauth_config.url), "userDetails");
|
||||
this.userDetails.data.dryRun = (options.dryRun ?? false) || (options.fakeUser ?? false);
|
||||
if (options.fakeUser) {
|
||||
const ud = this.userDetails.data;
|
||||
ud.csCount = 5678
|
||||
|
@ -99,13 +97,13 @@ export class OsmConnection {
|
|||
self.AttemptLogin()
|
||||
}
|
||||
});
|
||||
this._dryRun = options.dryRun;
|
||||
this._dryRun = options.dryRun ?? new UIEventSource<boolean>(false);
|
||||
|
||||
this.updateAuthObject();
|
||||
|
||||
this.preferencesHandler = new OsmPreferences(this.auth, this);
|
||||
|
||||
this.changesetHandler = new ChangesetHandler(options.layoutName, options.dryRun, this, options.allElements, options.changes, this.auth);
|
||||
this.changesetHandler = new ChangesetHandler(options.layoutName, this._dryRun, this, options.allElements, options.changes, this.auth);
|
||||
if (options.oauth_token?.data !== undefined) {
|
||||
console.log(options.oauth_token.data)
|
||||
const self = this;
|
||||
|
@ -223,7 +221,7 @@ export class OsmConnection {
|
|||
if ((text ?? "") !== "") {
|
||||
textSuffix = "?text=" + encodeURIComponent(text)
|
||||
}
|
||||
if (this._dryRun) {
|
||||
if (this._dryRun.data) {
|
||||
console.warn("Dryrun enabled - not actually closing note ", id, " with text ", text)
|
||||
return new Promise((ok, error) => {
|
||||
ok()
|
||||
|
@ -246,7 +244,7 @@ export class OsmConnection {
|
|||
}
|
||||
|
||||
public reopenNote(id: number | string, text?: string): Promise<any> {
|
||||
if (this._dryRun) {
|
||||
if (this._dryRun.data) {
|
||||
console.warn("Dryrun enabled - not actually reopening note ", id, " with text ", text)
|
||||
return new Promise((ok, error) => {
|
||||
ok()
|
||||
|
@ -273,10 +271,10 @@ export class OsmConnection {
|
|||
}
|
||||
|
||||
public openNote(lat: number, lon: number, text: string): Promise<{ id: number }> {
|
||||
if (this._dryRun) {
|
||||
if (this._dryRun.data) {
|
||||
console.warn("Dryrun enabled - not actually opening note with text ", text)
|
||||
return new Promise((ok, error) => {
|
||||
ok()
|
||||
return new Promise<{ id: number }>((ok, error) => {
|
||||
window.setTimeout(() => ok({id: Math.floor(Math.random() * 1000)}), Math.random() * 5000)
|
||||
});
|
||||
}
|
||||
const auth = this.auth;
|
||||
|
@ -285,15 +283,18 @@ export class OsmConnection {
|
|||
auth.xhr({
|
||||
method: 'POST',
|
||||
path: `/api/0.6/notes.json`,
|
||||
options: {header:
|
||||
{'Content-Type': 'application/json'}},
|
||||
options: {
|
||||
header:
|
||||
{'Content-Type': 'application/json'}
|
||||
},
|
||||
content: JSON.stringify(content)
|
||||
|
||||
}, function (err, response) {
|
||||
if (err !== null) {
|
||||
error(err)
|
||||
} else {
|
||||
const id = Number(response.children[0].children[0].children.item("id").innerHTML)
|
||||
|
||||
const id = response.properties.id
|
||||
console.log("OPENED NOTE", id)
|
||||
ok({id})
|
||||
}
|
||||
|
@ -304,7 +305,7 @@ export class OsmConnection {
|
|||
}
|
||||
|
||||
public addCommentToNode(id: number | string, text: string): Promise<any> {
|
||||
if (this._dryRun) {
|
||||
if (this._dryRun.data) {
|
||||
console.warn("Dryrun enabled - not actually adding comment ", text, "to note ", id)
|
||||
return new Promise((ok, error) => {
|
||||
ok()
|
||||
|
@ -317,7 +318,7 @@ export class OsmConnection {
|
|||
return new Promise((ok, error) => {
|
||||
this.auth.xhr({
|
||||
method: 'POST',
|
||||
|
||||
|
||||
path: `/api/0.6/notes.json/${id}/comment?text=${encodeURIComponent(text)}`
|
||||
}, function (err, response) {
|
||||
if (err !== null) {
|
||||
|
|
|
@ -43,7 +43,7 @@ export default class UserRelatedState extends ElementsState {
|
|||
|
||||
this.osmConnection = new OsmConnection({
|
||||
changes: this.changes,
|
||||
dryRun: this.featureSwitchIsTesting.data,
|
||||
dryRun: this.featureSwitchIsTesting,
|
||||
fakeUser: this.featureSwitchFakeUser.data,
|
||||
allElements: this.allElements,
|
||||
oauth_token: QueryParameters.GetQueryParameter(
|
||||
|
|
|
@ -10,6 +10,13 @@ export class RegexTag extends TagsFilter {
|
|||
constructor(key: string | RegExp, value: RegExp | string, invert: boolean = false) {
|
||||
super();
|
||||
this.key = key;
|
||||
if (typeof value === "string") {
|
||||
if (value.indexOf("^") < 0 && value.indexOf("$") < 0) {
|
||||
value = "^" + value + "$"
|
||||
}
|
||||
value = new RegExp(value)
|
||||
}
|
||||
|
||||
this.value = value;
|
||||
this.invert = invert;
|
||||
this.matchesEmpty = RegexTag.doesMatch("", this.value);
|
||||
|
@ -109,7 +116,7 @@ export class RegexTag extends TagsFilter {
|
|||
console.error("Cannot export regex tag to asChange; ", this.key, this.value)
|
||||
return []
|
||||
}
|
||||
|
||||
|
||||
AsJson() {
|
||||
return this.asHumanString()
|
||||
}
|
||||
|
|
|
@ -192,16 +192,16 @@ export class TagUtils {
|
|||
}
|
||||
|
||||
const f = (value: string | undefined) => {
|
||||
if(value === undefined){
|
||||
if (value === undefined) {
|
||||
return false;
|
||||
}
|
||||
let b = Number(value?.trim() )
|
||||
let b = Number(value?.trim())
|
||||
if (isNaN(b)) {
|
||||
if(value.endsWith(" UTC")) {
|
||||
if (value.endsWith(" UTC")) {
|
||||
value = value.replace(" UTC", "+00")
|
||||
}
|
||||
b = new Date(value).getTime()
|
||||
if(isNaN(b)){
|
||||
if (isNaN(b)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ export class TagUtils {
|
|||
}
|
||||
return new RegexTag(
|
||||
split[0],
|
||||
new RegExp("^" + split[1] + "$"),
|
||||
split[1],
|
||||
true
|
||||
);
|
||||
}
|
||||
|
@ -228,8 +228,8 @@ export class TagUtils {
|
|||
split[1] = "..*"
|
||||
}
|
||||
return new RegexTag(
|
||||
new RegExp("^" + split[0] + "$"),
|
||||
new RegExp("^" + split[1] + "$")
|
||||
split[0],
|
||||
split[1]
|
||||
);
|
||||
}
|
||||
if (tag.indexOf("!:=") >= 0) {
|
||||
|
@ -248,7 +248,7 @@ export class TagUtils {
|
|||
}
|
||||
return new RegexTag(
|
||||
split[0],
|
||||
new RegExp("^" + split[1] + "$"),
|
||||
new RegExp("^" + split[1] + "$"),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ export class TagUtils {
|
|||
}
|
||||
return new RegexTag(
|
||||
split[0],
|
||||
new RegExp("^" + split[1] + "$"),
|
||||
split[1],
|
||||
true
|
||||
);
|
||||
}
|
||||
|
@ -273,7 +273,7 @@ export class TagUtils {
|
|||
}
|
||||
return new RegexTag(
|
||||
split[0],
|
||||
new RegExp("^" + split[1] + "$")
|
||||
split[1]
|
||||
);
|
||||
}
|
||||
if (tag.indexOf("=") >= 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue