Skip to content

Commit bbd37de

Browse files
committed
feat: add zoom-based route visibility by type tier
Add data-type attributes to route SVG paths and toggle visibility in invokeActiveZooming based on route tier: royal/main/major at zoom 1, market/town/local at zoom 4, trail at zoom 7, footpath at zoom 10. Also adjust label zoom thresholds (states always visible, skyburg at 4).
1 parent e2833fa commit bbd37de

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

public/main.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,8 @@ function invokeActiveZooming() {
499499
// rescale labels on zoom
500500
if (labels.style("display") !== "none") {
501501
const MIN_ZOOM_DEFAULTS = {
502-
states: 2,
503-
capital: 1, skyburg: 1,
502+
states: 0,
503+
capital: 1, skyburg: 4,
504504
city: 4, town: 6,
505505
fort: 7, monastery: 7, caravanserai: 7, trading_post: 7,
506506
village: 10, hamlet: 14
@@ -519,6 +519,24 @@ function invokeActiveZooming() {
519519
});
520520
}
521521

522+
// toggle route visibility by type on zoom
523+
if (routes.style("display") !== "none") {
524+
const ROUTE_MIN_ZOOM = {
525+
royal: 1, main: 1, major: 1,
526+
market: 4, town: 4, local: 4,
527+
trail: 7,
528+
footpath: 10
529+
};
530+
531+
routes.selectAll("path").each(function () {
532+
const type = this.dataset.type;
533+
if (!type) return;
534+
const minZoom = ROUTE_MIN_ZOOM[type] || 0;
535+
if (scale < minZoom) this.classList.add("hidden");
536+
else this.classList.remove("hidden");
537+
});
538+
}
539+
522540
// rescale emblems on zoom
523541
if (emblems.style("display") !== "none") {
524542
emblems.selectAll("g").each(function () {

public/modules/ui/layers.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,8 @@ function drawRoutes() {
791791
const {i, group, points} = route;
792792
if (!points || points.length < 2) continue;
793793
if (!routePaths[group]) routePaths[group] = [];
794-
routePaths[group].push(`<path id="route${i}" d="${Routes.getPath(route)}"/>`);
794+
const typeAttr = route.type ? ` data-type="${route.type}"` : "";
795+
routePaths[group].push(`<path id="route${i}"${typeAttr} d="${Routes.getPath(route)}"/>`);
795796
}
796797

797798
routes.selectAll("path").remove();
@@ -803,11 +804,12 @@ function drawRoutes() {
803804
}
804805

805806
function drawRoute(route) {
806-
routes
807+
const el = routes
807808
.select("#" + route.group)
808809
.append("path")
809810
.attr("d", Routes.getPath(route))
810811
.attr("id", "route" + route.i);
812+
if (route.type) el.attr("data-type", route.type);
811813
}
812814

813815
function toggleMilitary(event) {

0 commit comments

Comments
 (0)