Add test for legacy theme conversion, fix legacy theme conversion

This commit is contained in:
Pieter Vander Vennet 2021-11-14 16:57:14 +01:00
parent 04e4ba769f
commit 756106afc3
4 changed files with 182 additions and 13 deletions

View file

@ -1,4 +1,5 @@
import LineRenderingConfigJson from "./Json/LineRenderingConfigJson";
import PointRenderingConfig from "./PointRenderingConfig";
export default class LegacyJsonConvert {
@ -29,22 +30,26 @@ export default class LegacyJsonConvert {
}
if (config.mapRendering === undefined && config.id !== "sidewalks") {
config.mapRendering = []
// This is a legacy format, lets create a pointRendering
let location: ("point" | "centroid")[] = ["point"]
let wayHandling: number = config["wayHandling"] ?? 0
if (wayHandling !== 0) {
location = ["point", "centroid"]
}
config.mapRendering = [
{
icon: config["icon"],
iconBadges: config["iconOverlays"],
label: config["label"],
iconSize: config["iconSize"],
location,
rotation: config["rotation"]
}
]
if(config["icon"] ?? config["label"] !== undefined){
const pointConfig = {
icon: config["icon"],
iconBadges: config["iconOverlays"],
label: config["label"],
iconSize: config["iconSize"],
location,
rotation: config["rotation"]
}
config.mapRendering.push(pointConfig)
}
if (wayHandling !== 1) {
const lineRenderConfig = <LineRenderingConfigJson>{
@ -56,6 +61,9 @@ export default class LegacyJsonConvert {
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
}
}