forked from MapComplete/MapComplete
Refactoring: add 'anchor'-field instead of using the iconSize to determine the anchor
This commit is contained in:
parent
f4b7e7eb88
commit
36cdcf0648
3 changed files with 13 additions and 3 deletions
|
@ -198,7 +198,8 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
iconSize: "40,40,center",
|
iconSize: "40,40",
|
||||||
|
anchor: "center",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ export default interface PointRenderingConfigJson {
|
||||||
* 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.
|
* 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
|
anchor?: "center" | "top" | "bottom" | "left" | "right" | string | TagRenderingConfigJson
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The rotation of an icon, useful for e.g. directions.
|
* The rotation of an icon, useful for e.g. directions.
|
||||||
|
|
|
@ -92,6 +92,16 @@ export default class PointRenderingConfig extends WithContextLoader {
|
||||||
throw context + ": builtin SVG asset not found: " + iconPath
|
throw context + ": builtin SVG asset not found: " + iconPath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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.iconSize = this.tr("iconSize", "40,40")
|
||||||
this.anchor = this.tr("anchor", "center")
|
this.anchor = this.tr("anchor", "center")
|
||||||
this.label = this.tr("label", undefined)
|
this.label = this.tr("label", undefined)
|
||||||
|
@ -239,7 +249,6 @@ export default class PointRenderingConfig extends WithContextLoader {
|
||||||
|
|
||||||
const anchor = render(this.anchor, "center")
|
const anchor = render(this.anchor, "center")
|
||||||
const mode = anchor?.trim()?.toLowerCase() ?? "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]
|
// in MapLibre, the offset is relative to the _center_ of the object, with left = [-x, 0] and up = [0,-y]
|
||||||
let anchorW = 0
|
let anchorW = 0
|
||||||
let anchorH = 0
|
let anchorH = 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue