v1.5.04 - Emblems auto-hide and hightlighting

This commit is contained in:
Azgaar 2021-01-30 18:47:43 +03:00
parent 56b6eb2a13
commit 32c4566aa7
9 changed files with 125 additions and 54 deletions

35
main.js
View file

@ -61,7 +61,7 @@ let coastline = viewbox.append("g").attr("id", "coastline");
let ice = viewbox.append("g").attr("id", "ice").style("display", "none");
let prec = viewbox.append("g").attr("id", "prec").style("display", "none");
let population = viewbox.append("g").attr("id", "population");
let emblems = viewbox.append("g").attr("id", "emblems");
let emblems = viewbox.append("g").attr("id", "emblems").style("display", "none");
let labels = viewbox.append("g").attr("id", "labels");
let icons = viewbox.append("g").attr("id", "icons");
let burgIcons = icons.append("g").attr("id", "burgIcons");
@ -98,6 +98,11 @@ anchors.append("g").attr("id", "towns");
population.append("g").attr("id", "rural");
population.append("g").attr("id", "urban");
// emblem groups
emblems.append("g").attr("id", "burgEmblems");
emblems.append("g").attr("id", "provinceEmblems");
emblems.append("g").attr("id", "stateEmblems");
// fogging
fogging.append("rect").attr("x", 0).attr("y", 0).attr("width", "100%").attr("height", "100%");
fogging.append("rect").attr("x", 0).attr("y", 0).attr("width", "100%").attr("height", "100%").attr("fill", "#e8f0f6").attr("filter", "url(#splotch)");
@ -444,16 +449,12 @@ function invokeActiveZooming() {
// rescale emblems on zoom
if (emblems.style("display") !== "none") {
const fontSize = rn(1 / scale ** .1, 4);
emblems.attr("font-size", fontSize);
// const realSize = fontSize * scale;
// emblems.selectAll("use").each(function(d) {
// const hidden = realSize < 20 || realSize > 350;
// if (hidden) this.classList.add("hidden");
// else this.classList.remove("hidden");
// });
emblems.selectAll("g").each(function() {
const size = this.getAttribute("font-size") * scale;
const hidden = size < 25 || size > 300;
if (hidden) this.classList.add("hidden"); else this.classList.remove("hidden");
if (!hidden && this.children.length && !this.children[0].getAttribute("href")) renderGroupCOAs(this);
});
}
// turn off ocean pattern if scale is big (improves performance)
@ -484,6 +485,18 @@ function invokeActiveZooming() {
}
}
async function renderGroupCOAs(g) {
const [group, type] = g.id === "burgEmblems" ? [pack.burgs, "burg"] :
g.id === "provinceEmblems" ? [pack.provinces, "province"] :
[pack.states, "state"];
for (let use of g.children) {
const i = +use.dataset.i;
const id = type+"COA"+i;
COArenderer.trigger(id, group[i].coa);
use.setAttribute("href", "#"+id);
}
}
// add drag to upload logic, pull request from @evyatron
void function addDragToUpload() {
document.addEventListener("dragover", function(e) {