mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-22 03:51:23 +01:00
Added check on zoom/move to hide any burg labels that are not on the screen. Results in noticable FPS increase on maps with high burg count (tested with 800+ burgs)
This commit is contained in:
parent
bf1ff2db63
commit
a685ad3bef
1 changed files with 34 additions and 1 deletions
35
main.js
35
main.js
|
|
@ -429,7 +429,11 @@ function findBurgForMFCG(params) {
|
|||
function handleZoom(isScaleChanged, isPositionChanged) {
|
||||
viewbox.attr("transform", `translate(${viewX} ${viewY}) scale(${scale})`);
|
||||
|
||||
if (isPositionChanged) drawCoordinates();
|
||||
if (isPositionChanged) {
|
||||
drawCoordinates();
|
||||
hideOutOfViewLabels();
|
||||
}
|
||||
|
||||
|
||||
if (isScaleChanged) {
|
||||
invokeActiveZooming();
|
||||
|
|
@ -452,6 +456,35 @@ function handleZoom(isScaleChanged, isPositionChanged) {
|
|||
}
|
||||
}
|
||||
|
||||
function hideOutOfViewLabels() {
|
||||
const towns = pack.burgs.filter(b => b.i && !b.capital && !b.removed);
|
||||
const townLabels = burgLabels.select("#towns");
|
||||
|
||||
|
||||
const bounds = getViewBoxExtent()
|
||||
|
||||
const minX = bounds[0][0];
|
||||
const maxX = bounds[1][0];
|
||||
|
||||
const minY = bounds[0][1];
|
||||
const maxY = bounds[1][1];
|
||||
|
||||
console.log("TownLabels:", townLabels.selectAll("text"));
|
||||
|
||||
townLabels.selectAll("text").each(function (burg, i, z) {
|
||||
burg = towns[i];
|
||||
if(!burg) return;
|
||||
|
||||
if(burg.x < minX || burg.x > maxX || burg.y < minY || burg.y > maxY) {
|
||||
d3.select(this).classed("hidden", true);
|
||||
}
|
||||
else {
|
||||
d3.select(this).classed("hidden", false);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// Zoom to a specific point
|
||||
function zoomTo(x, y, z = 8, d = 2000) {
|
||||
const transform = d3.zoomIdentity.translate(x * -z + graphWidth / 2, y * -z + graphHeight / 2).scale(z);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue