Merge branch 'develop' into feature/studio

This commit is contained in:
Pieter Vander Vennet 2023-06-20 22:50:47 +02:00
commit c229b92221
133 changed files with 1056 additions and 2081 deletions

View file

@ -198,7 +198,8 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L
},
],
},
iconSize: "40,40,center",
iconSize: "40,40",
anchor: "center",
},
],
}

View file

@ -3,6 +3,7 @@ import { Utils } from "../../../Utils"
import LineRenderingConfigJson from "../Json/LineRenderingConfigJson"
import { LayerConfigJson } from "../Json/LayerConfigJson"
import { DesugaringStep, Each, Fuse, On } from "./Conversion"
import PointRenderingConfigJson from "../Json/PointRenderingConfigJson"
export class UpdateLegacyLayer extends DesugaringStep<
LayerConfigJson | string | { builtin; override }
@ -139,6 +140,35 @@ export class UpdateLegacyLayer extends DesugaringStep<
}
}
for (const rendering of config.mapRendering ?? []) {
if (!rendering["iconSize"]) {
continue
}
const pr = <PointRenderingConfigJson>rendering
const iconSize = pr.iconSize
if (typeof iconSize === "string")
if (["bottom", "center", "top"].some((a) => (<string>iconSize).endsWith(a))) {
const parts = iconSize.split(",").map((parts) => parts.toLowerCase().trim())
pr.anchor = parts.pop()
pr.iconSize = parts.join(",")
}
}
for (const rendering of config.mapRendering) {
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,
errors: [],

View file

@ -586,6 +586,7 @@ class WarnForUnsubstitutedLayersInTheme extends DesugaringStep<LayoutConfigJson>
}
export class PrepareTheme extends Fuse<LayoutConfigJson> {
private state: DesugaringContext
constructor(
state: DesugaringContext,
options?: {
@ -612,6 +613,7 @@ export class PrepareTheme extends Fuse<LayoutConfigJson> {
new AddDependencyLayersToTheme(state),
new AddImportLayers()
)
this.state = state
}
convert(
@ -619,6 +621,10 @@ export class PrepareTheme extends Fuse<LayoutConfigJson> {
context: string
): { result: LayoutConfigJson; errors: string[]; warnings: string[]; information: string[] } {
const result = super.convert(json, context)
if (this.state.publicLayers.size === 0) {
// THis is a bootstrapping run, no need to already set this flag
return result
}
const needsNodeDatabase = result.result.layers?.some((l: LayerConfigJson) =>
l.tagRenderings?.some((tr: TagRenderingConfigJson) =>

View file

@ -54,6 +54,16 @@ export default interface PointRenderingConfigJson {
* Default is '40,40,center'
*/
iconSize?: string | TagRenderingConfigJson
/**
* question: What is the anchorpoint of the icon?
*
* This matches the geographical point with a location on the icon.
* For example, a feature attached to the ground can use 'bottom' as zooming in will give the appearance of being anchored to a fixed location.
*
*/
anchor?: "center" | "top" | "bottom" | "left" | "right" | string | TagRenderingConfigJson
/**
* The rotation of an icon, useful for e.g. directions.
* Usage: as if it were a css property for 'rotate', thus has to end with 'deg', e.g. `90deg`, `{direction}deg`, `calc(90deg - {camera:direction}deg)``

View file

@ -27,6 +27,8 @@ export default class PointRenderingConfig extends WithContextLoader {
public readonly icon?: TagRenderingConfig
public readonly iconBadges: { if: TagsFilter; then: TagRenderingConfig }[]
public readonly iconSize: TagRenderingConfig
public readonly anchor: TagRenderingConfig
public readonly label: TagRenderingConfig
public readonly labelCss: TagRenderingConfig
public readonly labelCssClasses: TagRenderingConfig
@ -90,7 +92,18 @@ export default class PointRenderingConfig extends WithContextLoader {
throw context + ": builtin SVG asset not found: " + iconPath
}
}
this.iconSize = this.tr("iconSize", "40,40,center")
if (typeof json.iconSize === "string") {
const s = json.iconSize
if (["bottom", "top", "center"].some((e) => s.endsWith(e))) {
throw (
"At " +
context +
" in : iconSize uses legacy ,bottom, center or top postfix. Use the field `anchor` instead."
)
}
}
this.iconSize = this.tr("iconSize", "40,40")
this.anchor = this.tr("anchor", "center")
this.label = this.tr("label", undefined)
this.rotation = this.tr("rotation", "0")
this.pitchAlignment = this.tr("pitchAlignment", "canvas")
@ -229,12 +242,13 @@ export default class PointRenderingConfig extends WithContextLoader {
return Utils.SubstituteKeys(str, tags.data).replace(/{.*}/g, "")
}
const iconSize = render(this.iconSize, "40,40,center").split(",")
const iconSize = render(this.iconSize, "40,40").split(",")
const iconW = num(iconSize[0])
let iconH = num(iconSize[1])
const mode = iconSize[2]?.trim()?.toLowerCase() ?? "center"
const anchor = render(this.anchor, "center")
const mode = anchor?.trim()?.toLowerCase() ?? "center"
// in MapLibre, the offset is relative to the _center_ of the object, with left = [-x, 0] and up = [0,-y]
let anchorW = 0
let anchorH = 0

View file

@ -32,6 +32,12 @@ export default class WithContextLoader {
return shared
}
}
if (Object.keys(v).length === 1 && typeof v["render"] === "string") {
throw `At ${
translationContext ?? "<unknown>"
}: use the content directly instead of {${key}: ${JSON.stringify(v)}}`
}
return new TagRenderingConfig(v, `${translationContext ?? this._context}.${key}`)
}