From edf728a12e96675fbbb32056f3407d27d4540d9a Mon Sep 17 00:00:00 2001 From: Azgaar Date: Sat, 17 Jul 2021 23:32:02 +0300 Subject: [PATCH] 3d labels - draw labels as they are --- modules/burgs-and-states.js | 23 ++++++++++------------- modules/ui/3d.js | 5 +++-- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/modules/burgs-and-states.js b/modules/burgs-and-states.js index d3c426d6..972b8784 100644 --- a/modules/burgs-and-states.js +++ b/modules/burgs-and-states.js @@ -477,9 +477,7 @@ // calculate and draw curved state labels for a list of states const drawStateLabels = function (list) { TIME && console.time("drawStateLabels"); - const cells = pack.cells, - features = pack.features, - states = pack.states; + const {cells, features, states} = pack; const paths = []; // text paths lineGen.curve(d3.curveBundle.beta(1)); @@ -572,8 +570,8 @@ } void (function drawLabels() { - const g = labels.select("#states"), - t = defs.select("#textPaths"); + const g = labels.select("#states"); + const t = defs.select("#textPaths"); const displayed = layerIsOn("toggleLabels"); if (!displayed) toggleLabels(); @@ -602,8 +600,8 @@ .attr("id", "textPath_stateLabel" + id); const pathLength = p[1].length > 1 ? textPath.node().getTotalLength() / letterLength : 0; // path length in letters - let lines = [], - ratio = 100; + let lines = []; + let ratio = 100; if (pathLength < s.name.length) { // only short name will fit @@ -622,10 +620,9 @@ // prolongate path if it's too short if (pathLength && pathLength < lines[0].length) { const points = p[1]; - const f = points[0], - l = points[points.length - 1]; - const dx = l[0] - f[0], - dy = l[1] - f[1]; + const f = points[0]; + const l = points[points.length - 1]; + const [dx, dy] = [l[0] - f[0], l[1] - f[1]]; const mod = Math.abs((letterLength * lines[0].length) / dx) / 2; points[0] = [rn(f[0] - dx * mod), rn(f[1] - dy * mod)]; points[points.length - 1] = [rn(l[0] + dx * mod), rn(l[1] + dy * mod)]; @@ -653,8 +650,8 @@ if (lines.length < 2) return; // check whether multilined label is generally inside the state. If no, replace with short name label - const cs = pack.cells.state, - b = el.parentNode.getBBox(); + const cs = pack.cells.state; + const b = el.parentNode.getBBox(); const c1 = () => +cs[findCell(b.x, b.y)] === id; const c2 = () => +cs[findCell(b.x + b.width / 2, b.y)] === id; const c3 = () => +cs[findCell(b.x + b.width, b.y)] === id; diff --git a/modules/ui/3d.js b/modules/ui/3d.js index 86d20b06..6de37a40 100644 --- a/modules/ui/3d.js +++ b/modules/ui/3d.js @@ -269,7 +269,7 @@ size: +towns.attr("data-size"), color: towns.attr("fill"), elevation: 5, - quality: 20, + quality: 30, iconSize: +town_icons.attr("size"), iconColor: "#666", line: 5 - towns.attr("data-size") / 2 @@ -326,7 +326,8 @@ if (state.removed) continue; const [x, y, z] = get3dCoords(state.pole[0], state.pole[1]); - const stateSprite = await createTextLabel({text: state.fullName, ...stateOptions}); + const text = states.select("#stateLabel" + state.i)?.text() || state.name; + const stateSprite = await createTextLabel({text, ...stateOptions}); stateSprite.position.set(x, y + stateOptions.elevation, z); stateSprite.size = stateOptions.size;