mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-18 18:11:24 +01:00
refactor: draw burgs and labels separately
This commit is contained in:
parent
b0f081b3ba
commit
2c3cdad59d
12 changed files with 84 additions and 67 deletions
47
src/layers/renderers/drawLabels.ts
Normal file
47
src/layers/renderers/drawLabels.ts
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
export function drawLabels() {
|
||||
drawBurgLabels();
|
||||
// TODO: draw other labels
|
||||
|
||||
window.Zoom.invoke();
|
||||
}
|
||||
|
||||
function drawBurgLabels() {
|
||||
// remove old data
|
||||
burgLabels.selectAll("text").remove();
|
||||
|
||||
const validBurgs = pack.burgs.filter(burg => burg.i && !(burg as IBurg).removed) as IBurg[];
|
||||
|
||||
// capitals
|
||||
const capitals = validBurgs.filter(burg => burg.capital);
|
||||
const capitalSize = Number(burgIcons.select("#cities").attr("size")) || 1;
|
||||
|
||||
burgLabels
|
||||
.select("#cities")
|
||||
.selectAll("text")
|
||||
.data(capitals)
|
||||
.enter()
|
||||
.append("text")
|
||||
.attr("id", d => "burgLabel" + d.i)
|
||||
.attr("data-id", d => d.i)
|
||||
.attr("x", d => d.x)
|
||||
.attr("y", d => d.y)
|
||||
.attr("dy", `${capitalSize * -1.5}px`)
|
||||
.text(d => d.name);
|
||||
|
||||
// towns
|
||||
const towns = validBurgs.filter(burg => !burg.capital);
|
||||
const townSize = Number(burgIcons.select("#towns").attr("size")) || 0.5;
|
||||
|
||||
burgLabels
|
||||
.select("#towns")
|
||||
.selectAll("text")
|
||||
.data(towns)
|
||||
.enter()
|
||||
.append("text")
|
||||
.attr("id", d => "burgLabel" + d.i)
|
||||
.attr("data-id", d => d.i)
|
||||
.attr("x", d => d.x)
|
||||
.attr("y", d => d.y)
|
||||
.attr("dy", `${townSize * -1.5}px`)
|
||||
.text(d => d.name);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue