Merge master

This commit is contained in:
pietervdvn 2022-01-26 21:12:25 +01:00
commit 99edba4c73
12 changed files with 129 additions and 72 deletions

View file

@ -157,19 +157,10 @@ export default class DetermineLayout {
try { try {
let parsed = await Utils.downloadJson(link) let parsed = await Utils.downloadJson(link)
console.log("Got ", parsed)
parsed = new FixLegacyTheme().convertStrict({
tagRenderings: SharedTagRenderings.SharedTagRenderingJson,
sharedLayers: new Map<string, LayerConfigJson>() // FIXME: actually add the layers
}, parsed, "While loading a dynamic theme")
parsed.id = link;
try { try {
parsed.id = link;
const layoutToUse = DetermineLayout.prepCustomTheme(parsed) const layoutToUse = DetermineLayout.prepCustomTheme(parsed)
return new LayoutConfig(layoutToUse,false).patchImages(link, JSON.stringify(layoutToUse)); return new LayoutConfig(layoutToUse,false)
} catch (e) { } catch (e) {
console.error(e) console.error(e)
DetermineLayout.ShowErrorOnCustomTheme( DetermineLayout.ShowErrorOnCustomTheme(

View file

@ -82,15 +82,12 @@ export default class FilteringFeatureSource implements FeatureSourceForLayer, Ti
} }
} }
const appliedFilters = layer.appliedFilters?.data const tagsFilter = Array.from(layer.appliedFilters?.data?.values() ?? [])
if(appliedFilters !== undefined){ for (const filter of tagsFilter) {
const tagsFilter = Array.from(appliedFilters.values()); const neededTags: TagsFilter = filter?.currentFilter
for (const filter of tagsFilter ?? []) { if (neededTags !== undefined && !neededTags.matchesProperties(f.feature.properties)) {
const neededTags : TagsFilter = filter?.currentFilter // Hidden by the filter on the layer itself - we want to hide it no matter wat
if (neededTags !== undefined && !neededTags.matchesProperties(f.feature.properties)) { return false;
// Hidden by the filter on the layer itself - we want to hide it no matter wat
return false;
}
} }
} }

View file

@ -178,12 +178,40 @@ export class OsmPreferences {
content: v content: v
}, function (error) { }, function (error) {
if (error) { if (error) {
console.log(`Could not set preference "${k}"'`, error); console.warn(`Could not set preference "${k}"'`, error);
return; return;
} }
console.log(`Preference ${k} written!`); console.debug(`Preference ${k} written!`);
}); });
} }
public ClearPreferences(){
let isRunning = false;
const self = this;
this.preferences.addCallbackAndRun(prefs => {
if(Object.keys(prefs).length == 0){
return;
}
if (isRunning) {
return
}
isRunning = true
const prefixes = ["mapcomplete-installed-theme","mapcomplete-installed-themes-","mapcomplete-current-open-changeset","mapcomplete-personal-theme-layer"]
for (const key in prefs) {
for (const prefix of prefixes) {
// console.log(key)
if (key.startsWith(prefix)) {
console.log("Clearing ", key)
self.GetPreference(key, "").setData("")
}
}
}
isRunning = false;
return true;
})
}
} }

View file

@ -32,13 +32,15 @@ export default class UserRelatedState extends ElementsState {
/** /**
* WHich other themes the user previously visited * WHich other themes the user previously visited
*/ */
public installedThemes: UIEventSource<{ id: string, // The id doubles as the URL public installedThemes: UIEventSource<{
id: string, // The id doubles as the URL
icon: string, icon: string,
title: any, title: any,
shortDescription: any}[]>; shortDescription: any
}[]>;
constructor(layoutToUse: LayoutConfig, options?:{attemptLogin : true | boolean}) { constructor(layoutToUse: LayoutConfig, options?: { attemptLogin: true | boolean }) {
super(layoutToUse); super(layoutToUse);
this.osmConnection = new OsmConnection({ this.osmConnection = new OsmConnection({
@ -73,46 +75,53 @@ export default class UserRelatedState extends ElementsState {
this.installedThemes = this.osmConnection.GetLongPreference("installed-themes").map( this.installedThemes = this.osmConnection.GetLongPreference("installed-themes").map(
str => { str => {
if(str === undefined || str === ""){ if (str === undefined || str === "") {
return [] return []
} }
try{ try {
return JSON.parse(str) return JSON.parse(str);
}catch(e){ } catch (e) {
console.warn("Could not parse preference with installed themes due to ", e,"\nThe offending string is",str) console.warn("Could not parse preference with installed themes due to ", e, "\nThe offending string is", str)
return [] return []
} }
}, [],(installed => JSON.stringify(installed)) }, [], (installed) => JSON.stringify(installed)
) )
const self = this; const self = this;
this.osmConnection.isLoggedIn.addCallbackAndRunD(loggedIn => {
if(!loggedIn){
return
}
if(this.layoutToUse?.id?.startsWith("http")){ if (this.layoutToUse?.id?.startsWith("http")) {
if(!this.installedThemes.data.some(installed => installed.id === this.layoutToUse.id)){ this.installedThemes.addCallbackAndRun(currentThemes => {
if (currentThemes === undefined) {
this.installedThemes.data.push({ // We wait till we are logged in
id: this.layoutToUse.id, return
icon: this.layoutToUse.icon,
title: this.layoutToUse.title.translations,
shortDescription: this.layoutToUse.shortDescription.translations
})
} }
this.installedThemes.ping()
console.log("Registered "+this.layoutToUse.id+" as installed themes") if(self.osmConnection.isLoggedIn.data == false){
} return;
}
if (currentThemes.some(installed => installed.id === this.layoutToUse.id)) {
// Already added to the 'installed theme' list
return;
}
console.log("Current installed themes are", this.installedThemes.data)
currentThemes.push({
id: self.layoutToUse.id,
icon: self.layoutToUse.icon,
title: self.layoutToUse.title.translations,
shortDescription: self.layoutToUse.shortDescription.translations
})
self.installedThemes.ping()
console.log("Registered " + self.layoutToUse.id + " as installed themes")
})
}
return true;
})
// Important: the favourite layers are initialized _after_ the installed themes, as these might contain an installedTheme // Important: the favourite layers are initialized _after_ the installed themes, as these might contain an installedTheme
this.favouriteLayers = LocalStorageSource.Get("favouriteLayers") this.favouriteLayers = LocalStorageSource.Get("favouriteLayers")
.syncWith(this.osmConnection.GetLongPreference("favouriteLayers")) .syncWith(this.osmConnection.GetLongPreference("favouriteLayers"))
@ -121,7 +130,7 @@ export default class UserRelatedState extends ElementsState {
[], [],
(layers) => Utils.Dedup(layers)?.join(";") (layers) => Utils.Dedup(layers)?.join(";")
); );
this.InitializeLanguage(); this.InitializeLanguage();
new SelectedElementTagsUpdater(this) new SelectedElementTagsUpdater(this)

View file

@ -2,7 +2,8 @@ import {Utils} from "../Utils";
export default class Constants { export default class Constants {
public static vNumber = "0.15.0-alpha-2"; public static vNumber = "0.15.0-rc-1";
public static ImgurApiKey = '7070e7167f0a25a' public static ImgurApiKey = '7070e7167f0a25a'
public static readonly mapillary_client_token_v4 = "MLY|4441509239301885|b40ad2d3ea105435bd40c7e76993ae85" public static readonly mapillary_client_token_v4 = "MLY|4441509239301885|b40ad2d3ea105435bd40c7e76993ae85"

View file

@ -8,7 +8,6 @@ import {LayerConfigJson} from "../Json/LayerConfigJson";
import Constants from "../../Constants"; import Constants from "../../Constants";
import {DesugaringContext, DesugaringStep, Fuse, OnEvery} from "./Conversion"; import {DesugaringContext, DesugaringStep, Fuse, OnEvery} from "./Conversion";
export class UpdateLegacyLayer extends DesugaringStep<LayerConfigJson | string | { builtin, override }> { export class UpdateLegacyLayer extends DesugaringStep<LayerConfigJson | string | { builtin, override }> {
constructor() { constructor() {
@ -21,9 +20,13 @@ export class UpdateLegacyLayer extends DesugaringStep<LayerConfigJson | string |
if (typeof json === "string") { if (typeof json === "string") {
return json return json
} }
console.log("Updating legacy layer", json)
if (json["builtin"] !== undefined) { if (json["builtin"] !== undefined) {
// @ts-ignore return {
return json; result: json,
errors: [],
warnings: []
};
} }
let config: any = {...json}; let config: any = {...json};
@ -145,6 +148,9 @@ class UpdateLegacyTheme extends DesugaringStep<LayoutConfigJson> {
} }
} }
} }
oldThemeConfig.layers = Utils.NoNull(oldThemeConfig.layers)
return { return {
errors: [], errors: [],
warnings: [], warnings: [],
@ -393,4 +399,4 @@ export class ValidateThemeAndLayers extends Fuse<LayoutConfigJson> {
new OnEvery("layers", new ValidateLayer(knownImagePaths, undefined, false)) new OnEvery("layers", new ValidateLayer(knownImagePaths, undefined, false))
); );
} }
} }

View file

@ -11,7 +11,6 @@ import {TagRenderingConfigJson} from "../Json/TagRenderingConfigJson";
import {Translation} from "../../../UI/i18n/Translation"; import {Translation} from "../../../UI/i18n/Translation";
import {SubstitutedTranslation} from "../../../UI/SubstitutedTranslation"; import {SubstitutedTranslation} from "../../../UI/SubstitutedTranslation";
import DependencyCalculator from "../DependencyCalculator"; import DependencyCalculator from "../DependencyCalculator";
import Translations from "../../../UI/i18n/Translations";
class SubstituteLayer extends Conversion<(string | LayerConfigJson), LayerConfigJson[]> { class SubstituteLayer extends Conversion<(string | LayerConfigJson), LayerConfigJson[]> {
constructor() { constructor() {
@ -179,7 +178,8 @@ class AddImportLayers extends DesugaringStep<LayoutConfigJson> {
} }
} }
export class AddMiniMap extends DesugaringStep<LayerConfigJson> {
class AddMiniMap extends DesugaringStep<LayerConfigJson> {
constructor() { constructor() {
super("Adds a default 'minimap'-element to the tagrenderings if none of the elements define such a minimap", ["tagRenderings"]); super("Adds a default 'minimap'-element to the tagrenderings if none of the elements define such a minimap", ["tagRenderings"]);
} }
@ -188,9 +188,8 @@ export class AddMiniMap extends DesugaringStep<LayerConfigJson> {
* Returns true if this tag rendering has a minimap in some language. * Returns true if this tag rendering has a minimap in some language.
* Note: this minimap can be hidden by conditions * Note: this minimap can be hidden by conditions
*/ */
public static hasMinimap(renderingConfig: TagRenderingConfigJson): boolean { private static hasMinimap(renderingConfig: TagRenderingConfigJson): boolean {
const translations: Translation[] = Utils.NoNull([renderingConfig.render, ...(renderingConfig.mappings ?? []).map(m => m.then)]) const translations: Translation[] = Utils.NoNull([renderingConfig.render, ...(renderingConfig.mappings ?? []).map(m => m.then)]);
.map(Translations.T);
for (const translation of translations) { for (const translation of translations) {
for (const key in translation.translations) { for (const key in translation.translations) {
if (!translation.translations.hasOwnProperty(key)) { if (!translation.translations.hasOwnProperty(key)) {

View file

@ -495,7 +495,10 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
} }
const data = await Utils.download(url, Utils.Merge({"accept": "application/json"}, headers ?? {})) const data = await Utils.download(url, Utils.Merge({"accept": "application/json"}, headers ?? {}))
try { try {
return JSON.parse(data) if(typeof data === "string"){
return JSON.parse(data)
}
return data
} catch (e) { } catch (e) {
console.error("Could not parse ", data, "due to", e, "\n", e.stack) console.error("Could not parse ", data, "due to", e, "\n", e.stack)
throw e; throw e;

View file

@ -13,9 +13,10 @@
"and": [ "and": [
{ {
"or": [ "or": [
"route=hiking", "route~.*foot.*",
"route=bycicle", "route~.*hiking.*",
"route=horse" "route~.*bycicle.*",
"route~.*horse.*"
] ]
} }
] ]

View file

@ -29,6 +29,7 @@
"generate:cache:speelplekken:mini": "ts-node scripts/generateCache.ts speelplekken 14 ../MapComplete-data/speelplekken_cache_mini/ 51.181710380278176 4.423413276672363 51.193007664772495 4.444141387939452", "generate:cache:speelplekken:mini": "ts-node scripts/generateCache.ts speelplekken 14 ../MapComplete-data/speelplekken_cache_mini/ 51.181710380278176 4.423413276672363 51.193007664772495 4.444141387939452",
"generate:cache:speelplekken": "npm run generate:layeroverview && ts-node scripts/generateCache.ts speelplekken 14 ../MapComplete-data/speelplekken_cache/ 51.20 4.35 51.09 4.56", "generate:cache:speelplekken": "npm run generate:layeroverview && ts-node scripts/generateCache.ts speelplekken 14 ../MapComplete-data/speelplekken_cache/ 51.20 4.35 51.09 4.56",
"generate:cache:natuurpunt": "npm run generate:layeroverview && ts-node scripts/generateCache.ts natuurpunt 12 ../MapComplete-data/natuurpunt_cache/ 50.40 2.1 51.54 6.4 --generate-point-overview nature_reserve,visitor_information_centre", "generate:cache:natuurpunt": "npm run generate:layeroverview && ts-node scripts/generateCache.ts natuurpunt 12 ../MapComplete-data/natuurpunt_cache/ 50.40 2.1 51.54 6.4 --generate-point-overview nature_reserve,visitor_information_centre",
"generate:cache:natuurpunt:mini": "ts-node scripts/generateCache.ts natuurpunt 12 ../../git/MapComplete-data/natuurpunt_cache_mini/ 51.00792239979105 4.497699737548828 51.0353492224462554 4.539070129394531 --generate-point-overview nature_reserve,visitor_information_centre",
"generate:layeroverview": "ts-node scripts/generateLayerOverview.ts --no-fail", "generate:layeroverview": "ts-node scripts/generateLayerOverview.ts --no-fail",
"generate:licenses": "ts-node scripts/generateLicenseInfo.ts --no-fail", "generate:licenses": "ts-node scripts/generateLicenseInfo.ts --no-fail",
"query:licenses": "ts-node scripts/generateLicenseInfo.ts --query", "query:licenses": "ts-node scripts/generateLicenseInfo.ts --query",

View file

@ -376,9 +376,29 @@ async function main(args: string[]) {
const lat1 = Number(args[5]) const lat1 = Number(args[5])
const lon1 = Number(args[6]) const lon1 = Number(args[6])
if(isNaN(lat0)){
throw "The first number (a latitude) is not a valid number"
}
if(isNaN(lon0)){
throw "The second number (a longitude) is not a valid number"
}
if(isNaN(lat1)){
throw "The third number (a latitude) is not a valid number"
}
if(isNaN(lon1)){
throw "The first number (a longitude) is not a valid number"
}
const tileRange = Tiles.TileRangeBetween(zoomlevel, lat0, lon0, lat1, lon1) const tileRange = Tiles.TileRangeBetween(zoomlevel, lat0, lon0, lat1, lon1)
if(isNaN(tileRange.total)){
throw "Something has gone wrong: tilerange is NAN"
}
if (tileRange.total === 0) { if (tileRange.total === 0) {
console.log("Tilerange has zero tiles - this is probably an error") console.log("Tilerange has zero tiles - this is probably an error")
return return
@ -440,8 +460,9 @@ async function main(args: string[]) {
let args = [...process.argv] let args = [...process.argv]
args.splice(0, 2) args.splice(0, 2)
try { try {
main(args).catch(e => console.error("Error building cache:", e)); main(args)
.then(() => console.log("All done!"))
.catch(e => console.error("Error building cache:", e));
} catch (e) { } catch (e) {
console.error("Error building cache:", e) console.error("Error building cache:", e)
} }
console.log("All done!")

View file

@ -4,4 +4,4 @@ import Link from "./UI/Base/Link";
import {FixedUiElement} from "./UI/Base/FixedUiElement"; import {FixedUiElement} from "./UI/Base/FixedUiElement";
const allHidden = AllKnownLayouts.layoutsList.filter(l => l.hideFromOverview) const allHidden = AllKnownLayouts.layoutsList.filter(l => l.hideFromOverview)
new List(allHidden.map(th => new Link(new FixedUiElement(th.id), "theme.html?layout="+th.id))).AttachTo("maindiv") new List(allHidden.map(th => new Link(new FixedUiElement(th.id), "theme.html?layout="+th.id))).AttachTo("maindiv")