Refactoring: split icons into proper layered icons, fix and rerun shops-thief

This commit is contained in:
Pieter Vander Vennet 2023-10-06 23:56:50 +02:00
parent d6cd0516bb
commit 19a760178b
307 changed files with 26845 additions and 116541 deletions

View file

@ -94,8 +94,8 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L
maxCacheAge: 0,
},
/* We need to set 'pass_all_features'
There are probably many note_import-layers, and we don't want the first one to gobble up all notes and then discard them...
*/
There are probably many note_import-layers, and we don't want the first one to gobble up all notes and then discard them...
*/
passAllFeatures: true,
minzoom: Math.min(12, layerJson.minzoom - 2),
title: {
@ -181,15 +181,24 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L
pointRendering: [
{
location: ["point"],
icon: {
render: "circle:white;help:black",
mappings: [
{
if: { or: ["closed_at~*", "_imported=yes"] },
then: "circle:white;checkmark:black",
marker: [
{
icon: "circle",
color: "#fff",
},
{
icon: {
render: "help",
mappings: [
{
if: { or: ["closed_at~*", "_imported=yes"] },
then: "checkmark",
},
],
},
],
},
color: "#00",
},
],
iconSize: "40,40",
anchor: "center",
},

View file

@ -81,7 +81,11 @@ export class UpdateLegacyLayer extends DesugaringStep<
}
}
if (config["mapRendering"] === undefined) {
if (
config["mapRendering"] === undefined &&
config.pointRendering === undefined &&
config.lineRendering === undefined
) {
config["mapRendering"] = []
// This is a legacy format, lets create a pointRendering
let location: ("point" | "centroid")[] = ["point"]
@ -144,6 +148,7 @@ export class UpdateLegacyLayer extends DesugaringStep<
}
if (config["mapRendering"]) {
console.log("MapRendering is", config["mapRendering"], json.id)
const pointRenderings: PointRenderingConfigJson[] = []
const lineRenderings: LineRenderingConfigJson[] = []
for (const mapRenderingElement of config["mapRendering"]) {
@ -161,6 +166,21 @@ export class UpdateLegacyLayer extends DesugaringStep<
for (const rendering of config.pointRendering ?? []) {
const pr = rendering
if (pr["icon"]) {
try {
const icon = Utils.NoEmpty(pr["icon"].split(";"))
pr.marker = icon.map((i) => {
const [iconPath, color] = i.split(":")
return { icon: iconPath, color }
})
delete pr["icon"]
} catch (e) {
console.error("Could not handle icon in", json.id)
pr.marker = [{ icon: pr["icon"] }]
delete pr["icon"]
}
}
let iconSize = pr.iconSize
if (!iconSize) {
continue
@ -178,35 +198,36 @@ export class UpdateLegacyLayer extends DesugaringStep<
}
}
for (const rendering of config.pointRendering) {
for (const key in rendering) {
if (!rendering[key]) {
continue
}
if (
typeof rendering[key]["render"] === "string" &&
Object.keys(rendering[key]).length === 1
) {
console.log("Rewrite: ", rendering[key])
rendering[key] = rendering[key]["render"]
if (config.pointRendering)
for (const rendering of config.pointRendering) {
for (const key in rendering) {
if (!rendering[key]) {
continue
}
if (
typeof rendering[key]["render"] === "string" &&
Object.keys(rendering[key]).length === 1
) {
console.log("Rewrite: ", rendering[key])
rendering[key] = rendering[key]["render"]
}
}
}
}
for (const rendering of config.lineRendering) {
for (const key in rendering) {
if (!rendering[key]) {
continue
}
if (
typeof rendering[key]["render"] === "string" &&
Object.keys(rendering[key]).length === 1
) {
console.log("Rewrite: ", rendering[key])
rendering[key] = rendering[key]["render"]
if (config.lineRendering)
for (const rendering of config.lineRendering) {
for (const key in rendering) {
if (!rendering[key]) {
continue
}
if (
typeof rendering[key]["render"] === "string" &&
Object.keys(rendering[key]).length === 1
) {
console.log("Rewrite: ", rendering[key])
rendering[key] = rendering[key]["render"]
}
}
}
}
return {
result: config,

View file

@ -21,8 +21,7 @@ import { AddContextToTranslations } from "./AddContextToTranslations"
import FilterConfigJson from "../Json/FilterConfigJson"
import predifined_filters from "../../../../assets/layers/filters/filters.json"
import { TagConfigJson } from "../Json/TagConfigJson"
import PointRenderingConfigJson from "../Json/PointRenderingConfigJson"
import LineRenderingConfigJson from "../Json/LineRenderingConfigJson"
import PointRenderingConfigJson, { IconConfigJson } from "../Json/PointRenderingConfigJson"
import ValidationUtils from "./ValidationUtils"
import { RenderingSpecification } from "../../../UI/SpecialVisualization"
import { QuestionableTagRenderingConfigJson } from "../Json/QuestionableTagRenderingConfigJson"
@ -127,6 +126,7 @@ class ExpandTagRendering extends Conversion<
> {
private readonly _state: DesugaringContext
private readonly _tagRenderingsByLabel: Map<string, TagRenderingConfigJson[]>
// Only used for self-reference
private readonly _self: LayerConfigJson
private readonly _options: {
/* If true, will copy the 'osmSource'-tags into the condition */
@ -224,7 +224,7 @@ class ExpandTagRendering extends Conversion<
const spl = name.split(".")
let layer = state.sharedLayers?.get(spl[0])
if (spl[0] === this._self.id) {
if (spl[0] === this._self?.id) {
layer = this._self
}
@ -352,7 +352,7 @@ class ExpandTagRendering extends Conversion<
if (name.indexOf(".") > 0) {
const [layerName] = name.split(".")
let layer = state.sharedLayers.get(layerName)
if (layerName === this._self.id) {
if (layerName === this._self?.id) {
layer = this._self
}
if (layer === undefined) {
@ -1116,23 +1116,19 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
}
}
class ExpandIconBadges extends DesugaringStep<PointRenderingConfigJson | LineRenderingConfigJson> {
private _state: DesugaringContext
private _layer: LayerConfigJson
class ExpandIconBadges extends DesugaringStep<PointRenderingConfigJson> {
private _expand: ExpandTagRendering
constructor(state: DesugaringContext, layer: LayerConfigJson) {
super("Expands shorthand properties on iconBadges", ["iconBadges"], "ExpandIconBadges")
this._state = state
this._layer = layer
this._expand = new ExpandTagRendering(state, layer)
}
convert(
json: PointRenderingConfigJson | LineRenderingConfigJson,
json: PointRenderingConfigJson,
context: string
): {
result: PointRenderingConfigJson | LineRenderingConfigJson
result: PointRenderingConfigJson
errors?: string[]
warnings?: string[]
information?: string[]
@ -1140,7 +1136,7 @@ class ExpandIconBadges extends DesugaringStep<PointRenderingConfigJson | LineRen
if (!json["iconBadges"]) {
return { result: json }
}
const badgesJson = (<PointRenderingConfigJson>json).iconBadges
const badgesJson = json.iconBadges
const iconBadges: { if: TagConfigJson; then: string | TagRenderingConfigJson }[] = []
@ -1176,7 +1172,7 @@ class ExpandIconBadges extends DesugaringStep<PointRenderingConfigJson | LineRen
}
}
class PreparePointRendering extends Fuse<PointRenderingConfigJson | LineRenderingConfigJson> {
class PreparePointRendering extends Fuse<PointRenderingConfigJson> {
constructor(state: DesugaringContext, layer: LayerConfigJson) {
super(
"Prepares point renderings by expanding 'icon' and 'iconBadges'",
@ -1262,6 +1258,47 @@ export class AddMiniMap extends DesugaringStep<LayerConfigJson> {
}
}
class ExpandMarkerRenderings extends DesugaringStep<IconConfigJson> {
private readonly _layer: LayerConfigJson
private readonly _state: DesugaringContext
constructor(state: DesugaringContext, layer: LayerConfigJson) {
super(
"Expands tagRenderings in the icons, if needed",
["icon", "color"],
"ExpandMarkerRenderings"
)
this._layer = layer
this._state = state
}
convert(
json: IconConfigJson,
context: string
): {
result: IconConfigJson
errors?: string[]
warnings?: string[]
information?: string[]
} {
const expander = new ExpandTagRendering(this._state, this._layer)
const result: IconConfigJson = { icon: undefined, color: undefined }
const errors: string[] = []
const warnings: string[] = []
if (json.icon && json.icon["builtin"]) {
result.icon = expander.convertJoin(<any>json.icon, context, errors, warnings)[0]
} else {
result.icon = json.icon
}
if (json.color && json.color["builtin"]) {
result.color = expander.convertJoin(<any>json.color, context, errors, warnings)[0]
} else {
result.color = json.color
}
return { result, errors, warnings }
}
}
export class PrepareLayer extends Fuse<LayerConfigJson> {
constructor(state: DesugaringContext) {
super(
@ -1274,9 +1311,13 @@ export class PrepareLayer extends Fuse<LayerConfigJson> {
new AddMiniMap(state),
new AddEditingElements(state),
new SetFullNodeDatabase(),
new On("mapRendering", new Concat(new ExpandRewrite()).andThenF(Utils.Flatten)),
new On<(PointRenderingConfigJson | LineRenderingConfigJson)[], LayerConfigJson>(
"mapRendering",
new On<PointRenderingConfigJson[], LayerConfigJson>(
"pointRendering",
(layer) =>
new Each(new On("marker", new Each(new ExpandMarkerRenderings(state, layer))))
),
new On<PointRenderingConfigJson[], LayerConfigJson>(
"pointRendering",
(layer) => new Each(new PreparePointRendering(state, layer))
),
new SetDefault("titleIcons", ["icons.defaults"]),