Reformat all files with prettier
This commit is contained in:
parent
e22d189376
commit
b541d3eab4
382 changed files with 50893 additions and 35566 deletions
|
@ -1,42 +1,51 @@
|
|||
import {LayoutConfigJson} from "../Json/LayoutConfigJson";
|
||||
import {Utils} from "../../../Utils";
|
||||
import LineRenderingConfigJson from "../Json/LineRenderingConfigJson";
|
||||
import {LayerConfigJson} from "../Json/LayerConfigJson";
|
||||
import {DesugaringStep, Each, Fuse, On} from "./Conversion";
|
||||
|
||||
export class UpdateLegacyLayer extends DesugaringStep<LayerConfigJson | string | { builtin, override }> {
|
||||
import { LayoutConfigJson } from "../Json/LayoutConfigJson"
|
||||
import { Utils } from "../../../Utils"
|
||||
import LineRenderingConfigJson from "../Json/LineRenderingConfigJson"
|
||||
import { LayerConfigJson } from "../Json/LayerConfigJson"
|
||||
import { DesugaringStep, Each, Fuse, On } from "./Conversion"
|
||||
|
||||
export class UpdateLegacyLayer extends DesugaringStep<
|
||||
LayerConfigJson | string | { builtin; override }
|
||||
> {
|
||||
constructor() {
|
||||
super("Updates various attributes from the old data format to the new to provide backwards compatibility with the formats",
|
||||
super(
|
||||
"Updates various attributes from the old data format to the new to provide backwards compatibility with the formats",
|
||||
["overpassTags", "source.osmtags", "tagRenderings[*].id", "mapRendering"],
|
||||
"UpdateLegacyLayer");
|
||||
"UpdateLegacyLayer"
|
||||
)
|
||||
}
|
||||
|
||||
convert(json: LayerConfigJson, context: string): { result: LayerConfigJson; errors: string[]; warnings: string[] } {
|
||||
convert(
|
||||
json: LayerConfigJson,
|
||||
context: string
|
||||
): { result: LayerConfigJson; errors: string[]; warnings: string[] } {
|
||||
const warnings = []
|
||||
if (typeof json === "string" || json["builtin"] !== undefined) {
|
||||
// Reuse of an already existing layer; return as-is
|
||||
return {result: json, errors: [], warnings: []}
|
||||
return { result: json, errors: [], warnings: [] }
|
||||
}
|
||||
let config = {...json};
|
||||
let config = { ...json }
|
||||
|
||||
if (config["overpassTags"]) {
|
||||
config.source = config.source ?? {
|
||||
osmTags: config["overpassTags"]
|
||||
osmTags: config["overpassTags"],
|
||||
}
|
||||
config.source.osmTags = config["overpassTags"]
|
||||
delete config["overpassTags"]
|
||||
}
|
||||
|
||||
if (config.tagRenderings !== undefined) {
|
||||
let i = 0;
|
||||
let i = 0
|
||||
for (const tagRendering of config.tagRenderings) {
|
||||
i++;
|
||||
if (typeof tagRendering === "string" || tagRendering["builtin"] !== undefined || tagRendering["rewrite"] !== undefined) {
|
||||
i++
|
||||
if (
|
||||
typeof tagRendering === "string" ||
|
||||
tagRendering["builtin"] !== undefined ||
|
||||
tagRendering["rewrite"] !== undefined
|
||||
) {
|
||||
continue
|
||||
}
|
||||
if (tagRendering["id"] === undefined) {
|
||||
|
||||
if (tagRendering["#"] !== undefined) {
|
||||
tagRendering["id"] = tagRendering["#"]
|
||||
delete tagRendering["#"]
|
||||
|
@ -49,7 +58,6 @@ export class UpdateLegacyLayer extends DesugaringStep<LayerConfigJson | string |
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (config.mapRendering === undefined) {
|
||||
config.mapRendering = []
|
||||
// This is a legacy format, lets create a pointRendering
|
||||
|
@ -59,14 +67,13 @@ export class UpdateLegacyLayer extends DesugaringStep<LayerConfigJson | string |
|
|||
location = ["point", "centroid"]
|
||||
}
|
||||
if (config["icon"] ?? config["label"] !== undefined) {
|
||||
|
||||
const pointConfig = {
|
||||
icon: config["icon"],
|
||||
iconBadges: config["iconOverlays"],
|
||||
label: config["label"],
|
||||
iconSize: config["iconSize"],
|
||||
location,
|
||||
rotation: config["rotation"]
|
||||
rotation: config["rotation"],
|
||||
}
|
||||
config.mapRendering.push(pointConfig)
|
||||
}
|
||||
|
@ -75,19 +82,20 @@ export class UpdateLegacyLayer extends DesugaringStep<LayerConfigJson | string |
|
|||
const lineRenderConfig = <LineRenderingConfigJson>{
|
||||
color: config["color"],
|
||||
width: config["width"],
|
||||
dashArray: config["dashArray"]
|
||||
dashArray: config["dashArray"],
|
||||
}
|
||||
if (Object.keys(lineRenderConfig).length > 0) {
|
||||
config.mapRendering.push(lineRenderConfig)
|
||||
}
|
||||
}
|
||||
if (config.mapRendering.length === 0) {
|
||||
throw "Could not convert the legacy theme into a new theme: no renderings defined for layer " + config.id
|
||||
throw (
|
||||
"Could not convert the legacy theme into a new theme: no renderings defined for layer " +
|
||||
config.id
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
delete config["color"]
|
||||
delete config["width"]
|
||||
delete config["dashArray"]
|
||||
|
@ -100,7 +108,7 @@ export class UpdateLegacyLayer extends DesugaringStep<LayerConfigJson | string |
|
|||
delete config["wayHandling"]
|
||||
delete config["hideUnderlayingFeaturesMinPercentage"]
|
||||
|
||||
for (const mapRenderingElement of (config.mapRendering ?? [])) {
|
||||
for (const mapRenderingElement of config.mapRendering ?? []) {
|
||||
if (mapRenderingElement["iconOverlays"] !== undefined) {
|
||||
mapRenderingElement["iconBadges"] = mapRenderingElement["iconOverlays"]
|
||||
}
|
||||
|
@ -115,34 +123,37 @@ export class UpdateLegacyLayer extends DesugaringStep<LayerConfigJson | string |
|
|||
return {
|
||||
result: config,
|
||||
errors: [],
|
||||
warnings
|
||||
};
|
||||
warnings,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class UpdateLegacyTheme extends DesugaringStep<LayoutConfigJson> {
|
||||
constructor() {
|
||||
super("Small fixes in the theme config", ["roamingRenderings"], "UpdateLegacyTheme");
|
||||
super("Small fixes in the theme config", ["roamingRenderings"], "UpdateLegacyTheme")
|
||||
}
|
||||
|
||||
convert(json: LayoutConfigJson, context: string): { result: LayoutConfigJson; errors: string[]; warnings: string[] } {
|
||||
const oldThemeConfig = {...json}
|
||||
convert(
|
||||
json: LayoutConfigJson,
|
||||
context: string
|
||||
): { result: LayoutConfigJson; errors: string[]; warnings: string[] } {
|
||||
const oldThemeConfig = { ...json }
|
||||
|
||||
if (oldThemeConfig.socialImage === "") {
|
||||
delete oldThemeConfig.socialImage
|
||||
}
|
||||
|
||||
|
||||
if (oldThemeConfig["roamingRenderings"] !== undefined) {
|
||||
|
||||
if (oldThemeConfig["roamingRenderings"].length == 0) {
|
||||
delete oldThemeConfig["roamingRenderings"]
|
||||
} else {
|
||||
return {
|
||||
result: null,
|
||||
errors: [context + ": The theme contains roamingRenderings. These are not supported anymore"],
|
||||
warnings: []
|
||||
errors: [
|
||||
context +
|
||||
": The theme contains roamingRenderings. These are not supported anymore",
|
||||
],
|
||||
warnings: [],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -152,8 +163,12 @@ class UpdateLegacyTheme extends DesugaringStep<LayoutConfigJson> {
|
|||
delete oldThemeConfig["version"]
|
||||
|
||||
if (oldThemeConfig["maintainer"] !== undefined) {
|
||||
|
||||
console.log("Maintainer: ", oldThemeConfig["maintainer"], "credits: ", oldThemeConfig["credits"])
|
||||
console.log(
|
||||
"Maintainer: ",
|
||||
oldThemeConfig["maintainer"],
|
||||
"credits: ",
|
||||
oldThemeConfig["credits"]
|
||||
)
|
||||
if (oldThemeConfig.credits === undefined) {
|
||||
oldThemeConfig["credits"] = oldThemeConfig["maintainer"]
|
||||
delete oldThemeConfig["maintainer"]
|
||||
|
@ -167,7 +182,7 @@ class UpdateLegacyTheme extends DesugaringStep<LayoutConfigJson> {
|
|||
return {
|
||||
errors: [],
|
||||
warnings: [],
|
||||
result: oldThemeConfig
|
||||
result: oldThemeConfig,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -178,8 +193,6 @@ export class FixLegacyTheme extends Fuse<LayoutConfigJson> {
|
|||
"Fixes a legacy theme to the modern JSON format geared to humans. Syntactic sugars are kept (i.e. no tagRenderings are expandend, no dependencies are automatically gathered)",
|
||||
new UpdateLegacyTheme(),
|
||||
new On("layers", new Each(new UpdateLegacyLayer()))
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue