Skip to content

Commit

Permalink
Refactoring: add 'anchor'-field instead of using the iconSize to dete…
Browse files Browse the repository at this point in the history
…rmine the anchor
  • Loading branch information
pietervdvn committed Jun 20, 2023
1 parent f4b7e7e commit 36cdcf0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Models/ThemeConfig/Conversion/CreateNoteImportLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L
},
],
},
iconSize: "40,40,center",
iconSize: "40,40",
anchor: "center",
},
],
}
Expand Down
2 changes: 1 addition & 1 deletion Models/ThemeConfig/Json/PointRenderingConfigJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
*/
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.
Expand Down
11 changes: 10 additions & 1 deletion Models/ThemeConfig/PointRenderingConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ export default class PointRenderingConfig extends WithContextLoader {
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.anchor = this.tr("anchor", "center")
this.label = this.tr("label", undefined)
Expand Down Expand Up @@ -239,7 +249,6 @@ export default class PointRenderingConfig extends WithContextLoader {

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
Expand Down

0 comments on commit 36cdcf0

Please sign in to comment.