mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
refactor(es modules): migrate a few more functions
This commit is contained in:
parent
63e9b9c87e
commit
865a98199f
18 changed files with 330 additions and 309 deletions
10
index.html
10
index.html
|
|
@ -437,14 +437,12 @@
|
||||||
data-tip="Click to save displayed layers as a new preset"
|
data-tip="Click to save displayed layers as a new preset"
|
||||||
class="icon-plus sideButton"
|
class="icon-plus sideButton"
|
||||||
style="display: none"
|
style="display: none"
|
||||||
onclick="savePreset()"
|
|
||||||
></button>
|
></button>
|
||||||
<button
|
<button
|
||||||
id="removePresetButton"
|
id="removePresetButton"
|
||||||
data-tip="Click to remove current custom preset"
|
data-tip="Click to remove current custom preset"
|
||||||
class="icon-minus sideButton"
|
class="icon-minus sideButton"
|
||||||
style="display: none"
|
style="display: none"
|
||||||
onclick="removePreset()"
|
|
||||||
></button>
|
></button>
|
||||||
|
|
||||||
<p data-tip="Click to toggle a layer, drag to raise or lower a layer. Ctrl + click to edit layer style">
|
<p data-tip="Click to toggle a layer, drag to raise or lower a layer. Ctrl + click to edit layer style">
|
||||||
|
|
@ -1348,7 +1346,7 @@
|
||||||
|
|
||||||
<tr data-tip="Allow system to hide emblem groups if their size in too small or too big on that scale">
|
<tr data-tip="Allow system to hide emblem groups if their size in too small or too big on that scale">
|
||||||
<td colspan="2">
|
<td colspan="2">
|
||||||
<input id="hideEmblems" class="checkbox" type="checkbox" onchange="invokeActiveZooming()" checked />
|
<input id="hideEmblems" class="checkbox" type="checkbox" onchange="Zoom.invoke()" checked />
|
||||||
<label for="hideEmblems" class="checkbox-label">Toggle visibility automatically</label>
|
<label for="hideEmblems" class="checkbox-label">Toggle visibility automatically</label>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
@ -1386,14 +1384,14 @@
|
||||||
<tbody id="styleVisibility">
|
<tbody id="styleVisibility">
|
||||||
<tr data-tip="Allow system to hide labels if their size in too small or too big on that scale">
|
<tr data-tip="Allow system to hide labels if their size in too small or too big on that scale">
|
||||||
<td colspan="2">
|
<td colspan="2">
|
||||||
<input id="hideLabels" class="checkbox" type="checkbox" onchange="invokeActiveZooming()" checked />
|
<input id="hideLabels" class="checkbox" type="checkbox" onchange="Zoom.invoke()" checked />
|
||||||
<label for="hideLabels" class="checkbox-label">Toggle visibility automatically</label>
|
<label for="hideLabels" class="checkbox-label">Toggle visibility automatically</label>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr data-tip="Allow system to rescale labels on zoom">
|
<tr data-tip="Allow system to rescale labels on zoom">
|
||||||
<td colspan="2">
|
<td colspan="2">
|
||||||
<input id="rescaleLabels" class="checkbox" type="checkbox" onchange="invokeActiveZooming()" checked />
|
<input id="rescaleLabels" class="checkbox" type="checkbox" onchange="Zoom.invoke()" checked />
|
||||||
<label for="rescaleLabels" class="checkbox-label">Rescale on zoom</label>
|
<label for="rescaleLabels" class="checkbox-label">Rescale on zoom</label>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
@ -5576,7 +5574,7 @@
|
||||||
id="showLabels"
|
id="showLabels"
|
||||||
class="checkbox"
|
class="checkbox"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
onchange="hideLabels.checked = !this.checked; invokeActiveZooming()"
|
onchange="hideLabels.checked = !this.checked; Zoom.invoke()"
|
||||||
checked
|
checked
|
||||||
/>
|
/>
|
||||||
<label for="showLabels" class="checkbox-label">Show all labels</label>
|
<label for="showLabels" class="checkbox-label">Show all labels</label>
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ console.log("Hello World");
|
||||||
import "./components";
|
import "./components";
|
||||||
import {ERROR, INFO, TIME, WARN} from "./config/logging";
|
import {ERROR, INFO, TIME, WARN} from "./config/logging";
|
||||||
import {UINT16_MAX} from "./constants";
|
import {UINT16_MAX} from "./constants";
|
||||||
import {invokeActiveZooming} from "./modules/activeZooming";
|
|
||||||
import {clearLegend} from "./modules/legend";
|
import {clearLegend} from "./modules/legend";
|
||||||
import {drawScaleBar, Ruler, Rulers} from "./modules/measurers";
|
import {drawScaleBar, Ruler, Rulers} from "./modules/measurers";
|
||||||
import {applyPreset, drawBorders, drawRivers, drawStates} from "./modules/ui/layers";
|
import {applyPreset, drawBorders, drawRivers, drawStates} from "./modules/ui/layers";
|
||||||
|
|
@ -33,6 +32,7 @@ import {minmax, normalize, rn} from "./utils/numberUtils";
|
||||||
import {gauss, generateSeed, P, ra, rand, rw} from "./utils/probabilityUtils";
|
import {gauss, generateSeed, P, ra, rand, rw} from "./utils/probabilityUtils";
|
||||||
import {byId} from "./utils/shorthands";
|
import {byId} from "./utils/shorthands";
|
||||||
import {round} from "./utils/stringUtils";
|
import {round} from "./utils/stringUtils";
|
||||||
|
import {restoreLayers} from "./modules/ui/layers";
|
||||||
|
|
||||||
addGlobalListeners();
|
addGlobalListeners();
|
||||||
|
|
||||||
|
|
@ -286,7 +286,7 @@ function findBurgForMFCG(params) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Zoom.to(b.x, b.y, 8, 1600);
|
Zoom.to(b.x, b.y, 8, 1600);
|
||||||
invokeActiveZooming();
|
Zoom.invoke();
|
||||||
tip("Here stands the glorious city of " + b.name, true, "success", 15000);
|
tip("Here stands the glorious city of " + b.name, true, "success", 15000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -357,7 +357,7 @@ async function generate(options) {
|
||||||
const timeStart = performance.now();
|
const timeStart = performance.now();
|
||||||
const {seed: precreatedSeed, graph: precreatedGraph} = options || {};
|
const {seed: precreatedSeed, graph: precreatedGraph} = options || {};
|
||||||
|
|
||||||
invokeActiveZooming();
|
Zoom.invoke();
|
||||||
setSeed(precreatedSeed);
|
setSeed(precreatedSeed);
|
||||||
INFO && console.group("Generated Map " + seed);
|
INFO && console.group("Generated Map " + seed);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import {findCell} from "/src/utils/graphUtils";
|
||||||
import {rn} from "/src/utils/numberUtils";
|
import {rn} from "/src/utils/numberUtils";
|
||||||
import {rand, P, rw} from "/src/utils/probabilityUtils";
|
import {rand, P, rw} from "/src/utils/probabilityUtils";
|
||||||
import {parseTransform} from "/src/utils/stringUtils";
|
import {parseTransform} from "/src/utils/stringUtils";
|
||||||
|
import {turnLayerButtonOn, turnLayerButtonOff} from "/src/modules/ui/layers";
|
||||||
|
|
||||||
// update old .map version to the current one
|
// update old .map version to the current one
|
||||||
export function resolveVersionConflicts(version) {
|
export function resolveVersionConflicts(version) {
|
||||||
|
|
@ -69,7 +70,7 @@ export function resolveVersionConflicts(version) {
|
||||||
addZones();
|
addZones();
|
||||||
if (!markers.selectAll("*").size()) {
|
if (!markers.selectAll("*").size()) {
|
||||||
Markers.generate();
|
Markers.generate();
|
||||||
turnButtonOn("toggleMarkers");
|
turnLayerButtonOn("toggleMarkers");
|
||||||
}
|
}
|
||||||
|
|
||||||
// v1.0 add fogging layer (state focus)
|
// v1.0 add fogging layer (state focus)
|
||||||
|
|
@ -282,7 +283,7 @@ export function resolveVersionConflicts(version) {
|
||||||
.attr("box-size", 3)
|
.attr("box-size", 3)
|
||||||
.attr("stroke", "#000")
|
.attr("stroke", "#000")
|
||||||
.attr("stroke-width", 0.3);
|
.attr("stroke-width", 0.3);
|
||||||
turnButtonOn("toggleMilitary");
|
turnLayerButtonOn("toggleMilitary");
|
||||||
Military.generate();
|
Military.generate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -443,9 +444,9 @@ export function resolveVersionConflicts(version) {
|
||||||
ruler.selectAll("*").remove();
|
ruler.selectAll("*").remove();
|
||||||
|
|
||||||
if (rulers.data.length) {
|
if (rulers.data.length) {
|
||||||
turnButtonOn("toggleRulers");
|
turnLayerButtonOn("toggleRulers");
|
||||||
rulers.draw();
|
rulers.draw();
|
||||||
} else turnButtonOff("toggleRulers");
|
} else turnLayerButtonOff("toggleRulers");
|
||||||
|
|
||||||
// 1.61 changed oceanicPattern from rect to image
|
// 1.61 changed oceanicPattern from rect to image
|
||||||
const pattern = document.getElementById("oceanic");
|
const pattern = document.getElementById("oceanic");
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import {shouldRegenerateGrid, generateGrid} from "/src/utils/graphUtils";
|
import {shouldRegenerateGrid, generateGrid} from "/src/utils/graphUtils";
|
||||||
import {byId} from "/src/utils/shorthands";
|
import {byId} from "/src/utils/shorthands";
|
||||||
import {generateSeed} from "/src/utils/probabilityUtils";
|
import {generateSeed} from "/src/utils/probabilityUtils";
|
||||||
|
import {getColorScheme} from "/src/utils/colorUtils";
|
||||||
|
|
||||||
const initialSeed = generateSeed();
|
const initialSeed = generateSeed();
|
||||||
let graph = getGraph(grid);
|
let graph = getGraph(grid);
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import {tip} from "/src/scripts/tooltips";
|
||||||
import {getCoordinates} from "/src/utils/coordinateUtils";
|
import {getCoordinates} from "/src/utils/coordinateUtils";
|
||||||
import {rn} from "/src/utils/numberUtils";
|
import {rn} from "/src/utils/numberUtils";
|
||||||
import {getBase64} from "/src/utils/functionUtils";
|
import {getBase64} from "/src/utils/functionUtils";
|
||||||
|
import {getColorScheme, getHeightColor} from "/src/utils/colorUtils";
|
||||||
|
|
||||||
// download map as SVG
|
// download map as SVG
|
||||||
async function saveSVG() {
|
async function saveSVG() {
|
||||||
|
|
@ -368,7 +369,7 @@ function updateMeshCells(clone) {
|
||||||
.join("polygon")
|
.join("polygon")
|
||||||
.attr("points", d => getGridPolygon(d))
|
.attr("points", d => getGridPolygon(d))
|
||||||
.attr("id", d => "cell" + d)
|
.attr("id", d => "cell" + d)
|
||||||
.attr("stroke", d => getColor(grid.cells.h[d], scheme));
|
.attr("stroke", d => getHeightColor(grid.cells.h[d], scheme));
|
||||||
}
|
}
|
||||||
|
|
||||||
// for each g element get inline style
|
// for each g element get inline style
|
||||||
|
|
|
||||||
|
|
@ -579,7 +579,7 @@ async function parseLoadedData(data) {
|
||||||
|
|
||||||
restoreDefaultEvents();
|
restoreDefaultEvents();
|
||||||
focusOn(); // based on searchParams focus on point, cell or burg
|
focusOn(); // based on searchParams focus on point, cell or burg
|
||||||
invokeActiveZooming();
|
Zoom.invoke();
|
||||||
|
|
||||||
WARN && console.warn(`TOTAL: ${rn((performance.now() - uploadMap.timeStart) / 1000, 2)}s`);
|
WARN && console.warn(`TOTAL: ${rn((performance.now() - uploadMap.timeStart) / 1000, 2)}s`);
|
||||||
showStatistics();
|
showStatistics();
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ window.Submap = (function () {
|
||||||
const inverse = options.inverse;
|
const inverse = options.inverse;
|
||||||
const stage = s => INFO && console.log("SUBMAP:", s);
|
const stage = s => INFO && console.log("SUBMAP:", s);
|
||||||
const timeStart = performance.now();
|
const timeStart = performance.now();
|
||||||
invokeActiveZooming();
|
Zoom.invoke();
|
||||||
|
|
||||||
// copy seed
|
// copy seed
|
||||||
seed = parentMap.seed;
|
seed = parentMap.seed;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import {findCell} from "/src/utils/graphUtils";
|
import {findCell} from "/src/utils/graphUtils";
|
||||||
import {rn} from "/src/utils/numberUtils";
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
import {getColorScheme, getHeightColor} from "/src/utils/colorUtils";
|
||||||
|
|
||||||
export function showEPForRoute(node) {
|
export function showEPForRoute(node) {
|
||||||
const points = [];
|
const points = [];
|
||||||
|
|
@ -208,18 +209,18 @@ function showElevationProfile(data, routeLen, isRiver) {
|
||||||
landdef
|
landdef
|
||||||
.append("stop")
|
.append("stop")
|
||||||
.attr("offset", "0%")
|
.attr("offset", "0%")
|
||||||
.attr("style", "stop-color:" + getColor(chartData.mih, colors) + ";stop-opacity:1");
|
.attr("style", "stop-color:" + getHeightColor(chartData.mih, colors) + ";stop-opacity:1");
|
||||||
landdef
|
landdef
|
||||||
.append("stop")
|
.append("stop")
|
||||||
.attr("offset", "100%")
|
.attr("offset", "100%")
|
||||||
.attr("style", "stop-color:" + getColor(chartData.mah, colors) + ";stop-opacity:1");
|
.attr("style", "stop-color:" + getHeightColor(chartData.mah, colors) + ";stop-opacity:1");
|
||||||
} else {
|
} else {
|
||||||
for (let k = chartData.mah; k >= chartData.mih; k--) {
|
for (let k = chartData.mah; k >= chartData.mih; k--) {
|
||||||
let perc = 1 - (k - chartData.mih) / (chartData.mah - chartData.mih);
|
let perc = 1 - (k - chartData.mih) / (chartData.mah - chartData.mih);
|
||||||
landdef
|
landdef
|
||||||
.append("stop")
|
.append("stop")
|
||||||
.attr("offset", perc * 100 + "%")
|
.attr("offset", perc * 100 + "%")
|
||||||
.attr("style", "stop-color:" + getColor(k, colors) + ";stop-opacity:1");
|
.attr("style", "stop-color:" + getHeightColor(k, colors) + ";stop-opacity:1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ import {rn, minmax, lim} from "/src/utils/numberUtils";
|
||||||
import {link} from "/src/utils/linkUtils";
|
import {link} from "/src/utils/linkUtils";
|
||||||
import {prompt} from "/src/scripts/prompt";
|
import {prompt} from "/src/scripts/prompt";
|
||||||
import {throttle} from "/src/utils/functionUtils";
|
import {throttle} from "/src/utils/functionUtils";
|
||||||
|
import {turnLayerButtonOn, turnLayerButtonOff} from "/src/modules/ui/layers";
|
||||||
|
import {getColorScheme, getHeightColor} from "/src/utils/colorUtils";
|
||||||
|
|
||||||
export function editHeightmap(options) {
|
export function editHeightmap(options) {
|
||||||
const {mode, tool} = options || {};
|
const {mode, tool} = options || {};
|
||||||
|
|
@ -115,7 +117,7 @@ export function editHeightmap(options) {
|
||||||
.style("transform", "scale(1)");
|
.style("transform", "scale(1)");
|
||||||
} else exitCustomization.style.display = "block";
|
} else exitCustomization.style.display = "block";
|
||||||
|
|
||||||
turnButtonOn("toggleHeight");
|
turnLayerButtonOn("toggleHeight");
|
||||||
layersPreset.value = "heightmap";
|
layersPreset.value = "heightmap";
|
||||||
layersPreset.disabled = true;
|
layersPreset.disabled = true;
|
||||||
mockHeightmap();
|
mockHeightmap();
|
||||||
|
|
@ -191,7 +193,7 @@ export function editHeightmap(options) {
|
||||||
// restore initial layers
|
// restore initial layers
|
||||||
//viewbox.select("#heights").remove();
|
//viewbox.select("#heights").remove();
|
||||||
byId("heights").remove();
|
byId("heights").remove();
|
||||||
turnButtonOff("toggleHeight");
|
turnLayerButtonOff("toggleHeight");
|
||||||
document
|
document
|
||||||
.getElementById("mapLayers")
|
.getElementById("mapLayers")
|
||||||
.querySelectorAll("li")
|
.querySelectorAll("li")
|
||||||
|
|
@ -492,7 +494,7 @@ export function editHeightmap(options) {
|
||||||
.join("polygon")
|
.join("polygon")
|
||||||
.attr("points", d => getGridPolygon(d))
|
.attr("points", d => getGridPolygon(d))
|
||||||
.attr("id", d => "cell" + d)
|
.attr("id", d => "cell" + d)
|
||||||
.attr("fill", d => getColor(grid.cells.h[d], scheme));
|
.attr("fill", d => getHeightColor(grid.cells.h[d], scheme));
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw or update heightmap for a selection of cells
|
// draw or update heightmap for a selection of cells
|
||||||
|
|
@ -512,7 +514,7 @@ export function editHeightmap(options) {
|
||||||
.append("polygon")
|
.append("polygon")
|
||||||
.attr("points", getGridPolygon(i))
|
.attr("points", getGridPolygon(i))
|
||||||
.attr("id", "cell" + i);
|
.attr("id", "cell" + i);
|
||||||
cell.attr("fill", getColor(grid.cells.h[i], scheme));
|
cell.attr("fill", getHeightColor(grid.cells.h[i], scheme));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1279,7 +1281,7 @@ export function editHeightmap(options) {
|
||||||
return lum | 0; // land
|
return lum | 0; // land
|
||||||
};
|
};
|
||||||
|
|
||||||
const scheme = d3.range(101).map(i => getColor(i, color()));
|
const scheme = d3.range(101).map(i => getHeightColor(i, color()));
|
||||||
const hues = scheme.map(rgb => d3.hsl(rgb).h | 0);
|
const hues = scheme.map(rgb => d3.hsl(rgb).h | 0);
|
||||||
const getHeightByScheme = function (color) {
|
const getHeightByScheme = function (color) {
|
||||||
let height = scheme.indexOf(color);
|
let height = scheme.indexOf(color);
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,49 @@
|
||||||
import {TIME} from "/src/config/logging";
|
import {TIME} from "/src/config/logging";
|
||||||
import {invokeActiveZooming} from "../activeZooming";
|
|
||||||
import {getGridPolygon} from "/src/utils/graphUtils";
|
|
||||||
import {last} from "/src/utils/arrayUtils";
|
|
||||||
import {stored, store} from "/src/utils/shorthands";
|
|
||||||
import {tip} from "/src/scripts/tooltips";
|
|
||||||
import {byId} from "/src/utils/shorthands";
|
|
||||||
import {clipPoly} from "/src/utils/lineUtils";
|
|
||||||
import {rn, minmax, normalize} from "/src/utils/numberUtils";
|
|
||||||
import {isCtrlClick} from "/src/utils/keyboardUtils";
|
|
||||||
import {prompt} from "/src/scripts/prompt";
|
import {prompt} from "/src/scripts/prompt";
|
||||||
import {rand, P} from "/src/utils/probabilityUtils";
|
import {tip} from "/src/scripts/tooltips";
|
||||||
import {convertTemperature} from "/src/utils/unitUtils";
|
import {last} from "/src/utils/arrayUtils";
|
||||||
import {getBase64} from "/src/utils/functionUtils";
|
import {getBase64} from "/src/utils/functionUtils";
|
||||||
|
import {getGridPolygon} from "/src/utils/graphUtils";
|
||||||
|
import {isCtrlClick} from "/src/utils/keyboardUtils";
|
||||||
|
import {clipPoly} from "/src/utils/lineUtils";
|
||||||
|
import {minmax, normalize, rn} from "/src/utils/numberUtils";
|
||||||
|
import {P, rand} from "/src/utils/probabilityUtils";
|
||||||
|
import {byId, store, stored} from "/src/utils/shorthands";
|
||||||
|
import {convertTemperature} from "/src/utils/unitUtils";
|
||||||
|
import {getColorScheme, getHeightColor} from "/src/utils/colorUtils";
|
||||||
|
|
||||||
let presets = {};
|
let presets = {};
|
||||||
restoreCustomPresets(); // run on-load
|
restoreCustomPresets(); // run on-load
|
||||||
addToggleLayersListener();
|
addLayerListeners();
|
||||||
|
|
||||||
function getDefaultPresets() {
|
function restoreCustomPresets() {
|
||||||
return {
|
const storedPresets = JSON.parse(stored("presets"));
|
||||||
|
if (!storedPresets) {
|
||||||
|
presets = defaultPresets.slice();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const preset in storedPresets) {
|
||||||
|
if (presets[preset]) continue;
|
||||||
|
byId("layersPreset").add(new Option(preset, preset));
|
||||||
|
}
|
||||||
|
|
||||||
|
presets = storedPresets;
|
||||||
|
}
|
||||||
|
|
||||||
|
function addLayerListeners() {
|
||||||
|
byId("mapLayers").on("click", toggleLayer);
|
||||||
|
byId("savePresetButton").on("click", savePreset);
|
||||||
|
byId("removePresetButton").on("click", removePreset);
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleLayer(event) {
|
||||||
|
const targetId = event.target.id;
|
||||||
|
if (!targetId || targetId === "mapLayers" || !layerTogglesMap[targetId]) return;
|
||||||
|
layerTogglesMap[targetId]();
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultPresets = {
|
||||||
political: [
|
political: [
|
||||||
"toggleBorders",
|
"toggleBorders",
|
||||||
"toggleIcons",
|
"toggleIcons",
|
||||||
|
|
@ -82,121 +107,9 @@ function getDefaultPresets() {
|
||||||
"toggleStates"
|
"toggleStates"
|
||||||
],
|
],
|
||||||
landmass: ["toggleScaleBar"]
|
landmass: ["toggleScaleBar"]
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
function restoreCustomPresets() {
|
const layerTogglesMap = {
|
||||||
presets = getDefaultPresets();
|
|
||||||
const storedPresets = JSON.parse(localStorage.getItem("presets"));
|
|
||||||
if (!storedPresets) return;
|
|
||||||
|
|
||||||
for (const preset in storedPresets) {
|
|
||||||
if (presets[preset]) continue;
|
|
||||||
layersPreset.add(new Option(preset, preset));
|
|
||||||
}
|
|
||||||
|
|
||||||
presets = storedPresets;
|
|
||||||
}
|
|
||||||
|
|
||||||
// run on map generation
|
|
||||||
export function applyPreset() {
|
|
||||||
const preset = stored("preset") || byId("layersPreset")?.value || "political";
|
|
||||||
changePreset(preset);
|
|
||||||
}
|
|
||||||
|
|
||||||
// toggle layers on preset change
|
|
||||||
function changePreset(preset) {
|
|
||||||
const layers = presets[preset]; // layers to be turned on
|
|
||||||
const $layerButtons = byId("mapLayers").querySelectorAll("li");
|
|
||||||
|
|
||||||
$layerButtons.forEach(function ($layerButton) {
|
|
||||||
const {id} = $layerButton;
|
|
||||||
if (layers.includes(id) && !layerIsOn(id)) $layerButton.click();
|
|
||||||
else if (!layers.includes(id) && layerIsOn(id)) $layerButton.click();
|
|
||||||
});
|
|
||||||
|
|
||||||
byId("layersPreset").value = preset;
|
|
||||||
store("preset", preset);
|
|
||||||
|
|
||||||
const isDefault = getDefaultPresets()[preset];
|
|
||||||
byId("removePresetButton").style.display = isDefault ? "none" : "inline-block";
|
|
||||||
byId("savePresetButton").style.display = "none";
|
|
||||||
if (byId("canvas3d")) setTimeout(ThreeD.update(), 400);
|
|
||||||
}
|
|
||||||
|
|
||||||
function savePreset() {
|
|
||||||
prompt("Please provide a preset name", {default: ""}, preset => {
|
|
||||||
presets[preset] = Array.from(byId("mapLayers").querySelectorAll("li:not(.buttonoff)"))
|
|
||||||
.map(node => node.id)
|
|
||||||
.sort();
|
|
||||||
layersPreset.add(new Option(preset, preset, false, true));
|
|
||||||
localStorage.setItem("presets", JSON.stringify(presets));
|
|
||||||
localStorage.setItem("preset", preset);
|
|
||||||
removePresetButton.style.display = "inline-block";
|
|
||||||
savePresetButton.style.display = "none";
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function removePreset() {
|
|
||||||
const preset = layersPreset.value;
|
|
||||||
delete presets[preset];
|
|
||||||
const index = Array.from(layersPreset.options).findIndex(o => o.value === preset);
|
|
||||||
layersPreset.options.remove(index);
|
|
||||||
layersPreset.value = "custom";
|
|
||||||
removePresetButton.style.display = "none";
|
|
||||||
savePresetButton.style.display = "inline-block";
|
|
||||||
|
|
||||||
localStorage.setItem("presets", JSON.stringify(presets));
|
|
||||||
localStorage.removeItem("preset");
|
|
||||||
}
|
|
||||||
|
|
||||||
function getCurrentPreset() {
|
|
||||||
const $toggledOnLayers = byId("mapLayers").querySelectorAll("li:not(.buttonoff)");
|
|
||||||
const currentLayers = Array.from($toggledOnLayers)
|
|
||||||
.map(node => node.id)
|
|
||||||
.sort();
|
|
||||||
|
|
||||||
const defaultPresets = getDefaultPresets();
|
|
||||||
for (const preset in presets) {
|
|
||||||
if (JSON.stringify(presets[preset].sort()) !== JSON.stringify(currentLayers)) continue;
|
|
||||||
|
|
||||||
byId("layersPreset").value = preset;
|
|
||||||
byId("removePresetButton").style.display = defaultPresets[preset] ? "none" : "inline-block";
|
|
||||||
byId("savePresetButton").style.display = "none";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
byId("layersPreset").value = "custom";
|
|
||||||
byId("removePresetButton").style.display = "none";
|
|
||||||
byId("savePresetButton").style.display = "inline-block";
|
|
||||||
}
|
|
||||||
|
|
||||||
// run on map regeneration
|
|
||||||
export function restoreLayers() {
|
|
||||||
if (layerIsOn("toggleHeight")) drawHeightmap();
|
|
||||||
if (layerIsOn("toggleCells")) drawCells();
|
|
||||||
if (layerIsOn("toggleGrid")) drawGrid();
|
|
||||||
if (layerIsOn("toggleCoordinates")) drawCoordinates();
|
|
||||||
if (layerIsOn("toggleCompass")) compass.style("display", "block");
|
|
||||||
if (layerIsOn("toggleTemp")) drawTemp();
|
|
||||||
if (layerIsOn("togglePrec")) drawPrec();
|
|
||||||
if (layerIsOn("togglePopulation")) drawPopulation();
|
|
||||||
if (layerIsOn("toggleBiomes")) drawBiomes();
|
|
||||||
if (layerIsOn("toggleRelief")) ReliefIcons();
|
|
||||||
if (layerIsOn("toggleCultures")) drawCultures();
|
|
||||||
if (layerIsOn("toggleProvinces")) drawProvinces();
|
|
||||||
if (layerIsOn("toggleReligions")) drawReligions();
|
|
||||||
if (layerIsOn("toggleIce")) drawIce();
|
|
||||||
if (layerIsOn("toggleEmblems")) drawEmblems();
|
|
||||||
if (layerIsOn("toggleMarkers")) drawMarkers();
|
|
||||||
|
|
||||||
// some layers are rendered each time, remove them if they are not on
|
|
||||||
if (!layerIsOn("toggleBorders")) borders.selectAll("path").remove();
|
|
||||||
if (!layerIsOn("toggleStates")) regions.selectAll("path").remove();
|
|
||||||
if (!layerIsOn("toggleRivers")) rivers.selectAll("*").remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
export const layerTogglesMap = {
|
|
||||||
toggleBiomes,
|
toggleBiomes,
|
||||||
toggleBorders,
|
toggleBorders,
|
||||||
toggleCells,
|
toggleCells,
|
||||||
|
|
@ -226,14 +139,116 @@ export const layerTogglesMap = {
|
||||||
toggleZones
|
toggleZones
|
||||||
};
|
};
|
||||||
|
|
||||||
function toggleLayer(event) {
|
// run on map generation
|
||||||
const targetId = event.target.id;
|
export function applyPreset() {
|
||||||
if (!targetId || targetId === "mapLayers" || !layerTogglesMap[targetId]) return;
|
const preset = stored("preset") || byId("layersPreset")?.value || "political";
|
||||||
layerTogglesMap[targetId]();
|
changePreset(preset);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addToggleLayersListener() {
|
// toggle layers on preset change
|
||||||
byId("mapLayers").on("click", toggleLayer);
|
function changePreset(preset) {
|
||||||
|
const layers = presets[preset]; // layers to be turned on
|
||||||
|
const $layerButtons = byId("mapLayers").querySelectorAll("li");
|
||||||
|
|
||||||
|
$layerButtons.forEach(function ($layerButton) {
|
||||||
|
const {id} = $layerButton;
|
||||||
|
if (layers.includes(id) && !layerIsOn(id)) $layerButton.click();
|
||||||
|
else if (!layers.includes(id) && layerIsOn(id)) $layerButton.click();
|
||||||
|
});
|
||||||
|
|
||||||
|
byId("layersPreset").value = preset;
|
||||||
|
store("preset", preset);
|
||||||
|
|
||||||
|
const isDefault = defaultPresets[preset];
|
||||||
|
byId("removePresetButton").style.display = isDefault ? "none" : "inline-block";
|
||||||
|
byId("savePresetButton").style.display = "none";
|
||||||
|
if (byId("canvas3d")) setTimeout(ThreeD.update(), 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
function savePreset() {
|
||||||
|
prompt("Please provide a preset name", {default: ""}, preset => {
|
||||||
|
presets[preset] = Array.from(byId("mapLayers").querySelectorAll("li:not(.buttonoff)"))
|
||||||
|
.map(node => node.id)
|
||||||
|
.sort();
|
||||||
|
layersPreset.add(new Option(preset, preset, false, true));
|
||||||
|
localStorage.setItem("presets", JSON.stringify(presets));
|
||||||
|
localStorage.setItem("preset", preset);
|
||||||
|
removePresetButton.style.display = "inline-block";
|
||||||
|
savePresetButton.style.display = "none";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function removePreset() {
|
||||||
|
const preset = layersPreset.value;
|
||||||
|
delete presets[preset];
|
||||||
|
const index = Array.from(layersPreset.options).findIndex(o => o.value === preset);
|
||||||
|
layersPreset.options.remove(index);
|
||||||
|
layersPreset.value = "custom";
|
||||||
|
removePresetButton.style.display = "none";
|
||||||
|
savePresetButton.style.display = "inline-block";
|
||||||
|
|
||||||
|
store("presets", JSON.stringify(presets));
|
||||||
|
localStorage.removeItem("preset");
|
||||||
|
}
|
||||||
|
|
||||||
|
// run on map regeneration
|
||||||
|
export function restoreLayers() {
|
||||||
|
if (layerIsOn("toggleHeight")) drawHeightmap();
|
||||||
|
if (layerIsOn("toggleCells")) drawCells();
|
||||||
|
if (layerIsOn("toggleGrid")) drawGrid();
|
||||||
|
if (layerIsOn("toggleCoordinates")) drawCoordinates();
|
||||||
|
if (layerIsOn("toggleCompass")) compass.style("display", "block");
|
||||||
|
if (layerIsOn("toggleTemp")) drawTemp();
|
||||||
|
if (layerIsOn("togglePrec")) drawPrec();
|
||||||
|
if (layerIsOn("togglePopulation")) drawPopulation();
|
||||||
|
if (layerIsOn("toggleBiomes")) drawBiomes();
|
||||||
|
if (layerIsOn("toggleRelief")) ReliefIcons();
|
||||||
|
if (layerIsOn("toggleCultures")) drawCultures();
|
||||||
|
if (layerIsOn("toggleProvinces")) drawProvinces();
|
||||||
|
if (layerIsOn("toggleReligions")) drawReligions();
|
||||||
|
if (layerIsOn("toggleIce")) drawIce();
|
||||||
|
if (layerIsOn("toggleEmblems")) drawEmblems();
|
||||||
|
if (layerIsOn("toggleMarkers")) drawMarkers();
|
||||||
|
|
||||||
|
// some layers are rendered each time, remove them if they are not on
|
||||||
|
if (!layerIsOn("toggleBorders")) borders.selectAll("path").remove();
|
||||||
|
if (!layerIsOn("toggleStates")) regions.selectAll("path").remove();
|
||||||
|
if (!layerIsOn("toggleRivers")) rivers.selectAll("*").remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function layerIsOn(el) {
|
||||||
|
const buttonoff = byId(el).classList.contains("buttonoff");
|
||||||
|
return !buttonoff;
|
||||||
|
}
|
||||||
|
|
||||||
|
function turnLayerButtonOn(el) {
|
||||||
|
byId(el).classList.remove("buttonoff");
|
||||||
|
updatePresetInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
function turnLayerButtonOff(el) {
|
||||||
|
byId(el).classList.add("buttonoff");
|
||||||
|
updatePresetInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
function updatePresetInput() {
|
||||||
|
const $toggledOnLayers = byId("mapLayers").querySelectorAll("li:not(.buttonoff)");
|
||||||
|
const currentLayers = Array.from($toggledOnLayers)
|
||||||
|
.map(node => node.id)
|
||||||
|
.sort();
|
||||||
|
|
||||||
|
for (const preset in presets) {
|
||||||
|
if (JSON.stringify(presets[preset].sort()) !== JSON.stringify(currentLayers)) continue;
|
||||||
|
|
||||||
|
byId("layersPreset").value = preset;
|
||||||
|
byId("removePresetButton").style.display = defaultPresets[preset] ? "none" : "inline-block";
|
||||||
|
byId("savePresetButton").style.display = "none";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
byId("layersPreset").value = "custom";
|
||||||
|
byId("removePresetButton").style.display = "none";
|
||||||
|
byId("savePresetButton").style.display = "inline-block";
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleHeight(event) {
|
function toggleHeight(event) {
|
||||||
|
|
@ -243,7 +258,7 @@ function toggleHeight(event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!terrs.selectAll("*").size()) {
|
if (!terrs.selectAll("*").size()) {
|
||||||
turnButtonOn("toggleHeight");
|
turnLayerButtonOn("toggleHeight");
|
||||||
drawHeightmap();
|
drawHeightmap();
|
||||||
if (event && isCtrlClick(event)) editStyle("terrs");
|
if (event && isCtrlClick(event)) editStyle("terrs");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -251,7 +266,7 @@ function toggleHeight(event) {
|
||||||
editStyle("terrs");
|
editStyle("terrs");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
turnButtonOff("toggleHeight");
|
turnLayerButtonOff("toggleHeight");
|
||||||
terrs.selectAll("*").remove();
|
terrs.selectAll("*").remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -309,9 +324,10 @@ function drawHeightmap() {
|
||||||
.attr("width", graphWidth)
|
.attr("width", graphWidth)
|
||||||
.attr("height", graphHeight)
|
.attr("height", graphHeight)
|
||||||
.attr("fill", scheme(0.8)); // draw base layer
|
.attr("fill", scheme(0.8)); // draw base layer
|
||||||
|
|
||||||
for (const i of d3.range(20, 101)) {
|
for (const i of d3.range(20, 101)) {
|
||||||
if (paths[i].length < 10) continue;
|
if (paths[i].length < 10) continue;
|
||||||
const color = getColor(i, scheme);
|
const color = getHeightColor(i, scheme);
|
||||||
if (terracing)
|
if (terracing)
|
||||||
terrs
|
terrs
|
||||||
.append("path")
|
.append("path")
|
||||||
|
|
@ -354,21 +370,9 @@ function drawHeightmap() {
|
||||||
TIME && console.timeEnd("drawHeightmap");
|
TIME && console.timeEnd("drawHeightmap");
|
||||||
}
|
}
|
||||||
|
|
||||||
function getColorScheme(scheme) {
|
|
||||||
if (scheme === "bright") return d3.scaleSequential(d3.interpolateSpectral);
|
|
||||||
if (scheme === "light") return d3.scaleSequential(d3.interpolateRdYlGn);
|
|
||||||
if (scheme === "green") return d3.scaleSequential(d3.interpolateGreens);
|
|
||||||
if (scheme === "monochrome") return d3.scaleSequential(d3.interpolateGreys);
|
|
||||||
return d3.scaleSequential(d3.interpolateSpectral);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getColor(value, scheme = getColorScheme()) {
|
|
||||||
return scheme(1 - (value < 20 ? value - 5 : value) / 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleTemp(event) {
|
function toggleTemp(event) {
|
||||||
if (!temperature.selectAll("*").size()) {
|
if (!temperature.selectAll("*").size()) {
|
||||||
turnButtonOn("toggleTemp");
|
turnLayerButtonOn("toggleTemp");
|
||||||
drawTemp();
|
drawTemp();
|
||||||
if (event && isCtrlClick(event)) editStyle("temperature");
|
if (event && isCtrlClick(event)) editStyle("temperature");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -376,7 +380,7 @@ function toggleTemp(event) {
|
||||||
editStyle("temperature");
|
editStyle("temperature");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
turnButtonOff("toggleTemp");
|
turnLayerButtonOff("toggleTemp");
|
||||||
temperature.selectAll("*").remove();
|
temperature.selectAll("*").remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -500,7 +504,7 @@ function drawTemp() {
|
||||||
|
|
||||||
function toggleBiomes(event) {
|
function toggleBiomes(event) {
|
||||||
if (!biomes.selectAll("path").size()) {
|
if (!biomes.selectAll("path").size()) {
|
||||||
turnButtonOn("toggleBiomes");
|
turnLayerButtonOn("toggleBiomes");
|
||||||
drawBiomes();
|
drawBiomes();
|
||||||
if (event && isCtrlClick(event)) editStyle("biomes");
|
if (event && isCtrlClick(event)) editStyle("biomes");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -509,7 +513,7 @@ function toggleBiomes(event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
biomes.selectAll("path").remove();
|
biomes.selectAll("path").remove();
|
||||||
turnButtonOff("toggleBiomes");
|
turnLayerButtonOff("toggleBiomes");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -573,7 +577,7 @@ function drawBiomes() {
|
||||||
|
|
||||||
function togglePrec(event) {
|
function togglePrec(event) {
|
||||||
if (!prec.selectAll("circle").size()) {
|
if (!prec.selectAll("circle").size()) {
|
||||||
turnButtonOn("togglePrec");
|
turnLayerButtonOn("togglePrec");
|
||||||
drawPrec();
|
drawPrec();
|
||||||
if (event && isCtrlClick(event)) editStyle("prec");
|
if (event && isCtrlClick(event)) editStyle("prec");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -581,7 +585,7 @@ function togglePrec(event) {
|
||||||
editStyle("prec");
|
editStyle("prec");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
turnButtonOff("togglePrec");
|
turnLayerButtonOff("togglePrec");
|
||||||
const hide = d3.transition().duration(1000).ease(d3.easeSinIn);
|
const hide = d3.transition().duration(1000).ease(d3.easeSinIn);
|
||||||
prec.selectAll("text").attr("opacity", 1).transition(hide).attr("opacity", 0);
|
prec.selectAll("text").attr("opacity", 1).transition(hide).attr("opacity", 0);
|
||||||
prec.selectAll("circle").transition(hide).attr("r", 0).remove();
|
prec.selectAll("circle").transition(hide).attr("r", 0).remove();
|
||||||
|
|
@ -615,7 +619,7 @@ function drawPrec() {
|
||||||
|
|
||||||
function togglePopulation(event) {
|
function togglePopulation(event) {
|
||||||
if (!population.selectAll("line").size()) {
|
if (!population.selectAll("line").size()) {
|
||||||
turnButtonOn("togglePopulation");
|
turnLayerButtonOn("togglePopulation");
|
||||||
drawPopulation();
|
drawPopulation();
|
||||||
if (event && isCtrlClick(event)) editStyle("population");
|
if (event && isCtrlClick(event)) editStyle("population");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -623,7 +627,7 @@ function togglePopulation(event) {
|
||||||
editStyle("population");
|
editStyle("population");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
turnButtonOff("togglePopulation");
|
turnLayerButtonOff("togglePopulation");
|
||||||
const isD3data = population.select("line").datum();
|
const isD3data = population.select("line").datum();
|
||||||
if (!isD3data) {
|
if (!isD3data) {
|
||||||
// just remove
|
// just remove
|
||||||
|
|
@ -690,7 +694,7 @@ function drawPopulation(event) {
|
||||||
|
|
||||||
function toggleCells(event) {
|
function toggleCells(event) {
|
||||||
if (!cells.selectAll("path").size()) {
|
if (!cells.selectAll("path").size()) {
|
||||||
turnButtonOn("toggleCells");
|
turnLayerButtonOn("toggleCells");
|
||||||
drawCells();
|
drawCells();
|
||||||
if (event && isCtrlClick(event)) editStyle("cells");
|
if (event && isCtrlClick(event)) editStyle("cells");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -699,7 +703,7 @@ function toggleCells(event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cells.selectAll("path").remove();
|
cells.selectAll("path").remove();
|
||||||
turnButtonOff("toggleCells");
|
turnLayerButtonOff("toggleCells");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -714,7 +718,7 @@ function drawCells() {
|
||||||
|
|
||||||
function toggleIce(event) {
|
function toggleIce(event) {
|
||||||
if (!layerIsOn("toggleIce")) {
|
if (!layerIsOn("toggleIce")) {
|
||||||
turnButtonOn("toggleIce");
|
turnLayerButtonOn("toggleIce");
|
||||||
$("#ice").fadeIn();
|
$("#ice").fadeIn();
|
||||||
if (!ice.selectAll("*").size()) drawIce();
|
if (!ice.selectAll("*").size()) drawIce();
|
||||||
if (event && isCtrlClick(event)) editStyle("ice");
|
if (event && isCtrlClick(event)) editStyle("ice");
|
||||||
|
|
@ -724,7 +728,7 @@ function toggleIce(event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$("#ice").fadeOut();
|
$("#ice").fadeOut();
|
||||||
turnButtonOff("toggleIce");
|
turnLayerButtonOff("toggleIce");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -805,7 +809,7 @@ function toggleCultures(event) {
|
||||||
const cultures = pack.cultures.filter(c => c.i && !c.removed);
|
const cultures = pack.cultures.filter(c => c.i && !c.removed);
|
||||||
const empty = !cults.selectAll("path").size();
|
const empty = !cults.selectAll("path").size();
|
||||||
if (empty && cultures.length) {
|
if (empty && cultures.length) {
|
||||||
turnButtonOn("toggleCultures");
|
turnLayerButtonOn("toggleCultures");
|
||||||
drawCultures();
|
drawCultures();
|
||||||
if (event && isCtrlClick(event)) editStyle("cults");
|
if (event && isCtrlClick(event)) editStyle("cults");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -814,7 +818,7 @@ function toggleCultures(event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cults.selectAll("path").remove();
|
cults.selectAll("path").remove();
|
||||||
turnButtonOff("toggleCultures");
|
turnLayerButtonOff("toggleCultures");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -879,7 +883,7 @@ function drawCultures() {
|
||||||
function toggleReligions(event) {
|
function toggleReligions(event) {
|
||||||
const religions = pack.religions.filter(r => r.i && !r.removed);
|
const religions = pack.religions.filter(r => r.i && !r.removed);
|
||||||
if (!relig.selectAll("path").size() && religions.length) {
|
if (!relig.selectAll("path").size() && religions.length) {
|
||||||
turnButtonOn("toggleReligions");
|
turnLayerButtonOn("toggleReligions");
|
||||||
drawReligions();
|
drawReligions();
|
||||||
if (event && isCtrlClick(event)) editStyle("relig");
|
if (event && isCtrlClick(event)) editStyle("relig");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -888,7 +892,7 @@ function toggleReligions(event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
relig.selectAll("path").remove();
|
relig.selectAll("path").remove();
|
||||||
turnButtonOff("toggleReligions");
|
turnLayerButtonOff("toggleReligions");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -990,7 +994,7 @@ function drawReligions() {
|
||||||
|
|
||||||
function toggleStates(event) {
|
function toggleStates(event) {
|
||||||
if (!layerIsOn("toggleStates")) {
|
if (!layerIsOn("toggleStates")) {
|
||||||
turnButtonOn("toggleStates");
|
turnLayerButtonOn("toggleStates");
|
||||||
regions.style("display", null);
|
regions.style("display", null);
|
||||||
drawStates();
|
drawStates();
|
||||||
if (event && isCtrlClick(event)) editStyle("regions");
|
if (event && isCtrlClick(event)) editStyle("regions");
|
||||||
|
|
@ -1000,7 +1004,7 @@ function toggleStates(event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
regions.style("display", "none").selectAll("path").remove();
|
regions.style("display", "none").selectAll("path").remove();
|
||||||
turnButtonOff("toggleStates");
|
turnLayerButtonOff("toggleStates");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1148,13 +1152,13 @@ export function drawStates() {
|
||||||
return chain;
|
return chain;
|
||||||
}
|
}
|
||||||
|
|
||||||
invokeActiveZooming();
|
Zoom.invoke();
|
||||||
TIME && console.timeEnd("drawStates");
|
TIME && console.timeEnd("drawStates");
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleBorders(event) {
|
function toggleBorders(event) {
|
||||||
if (!layerIsOn("toggleBorders")) {
|
if (!layerIsOn("toggleBorders")) {
|
||||||
turnButtonOn("toggleBorders");
|
turnLayerButtonOn("toggleBorders");
|
||||||
drawBorders();
|
drawBorders();
|
||||||
if (event && isCtrlClick(event)) editStyle("borders");
|
if (event && isCtrlClick(event)) editStyle("borders");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1162,7 +1166,7 @@ function toggleBorders(event) {
|
||||||
editStyle("borders");
|
editStyle("borders");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
turnButtonOff("toggleBorders");
|
turnLayerButtonOff("toggleBorders");
|
||||||
borders.selectAll("path").remove();
|
borders.selectAll("path").remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1276,7 +1280,7 @@ export function drawBorders() {
|
||||||
|
|
||||||
function toggleProvinces(event) {
|
function toggleProvinces(event) {
|
||||||
if (!layerIsOn("toggleProvinces")) {
|
if (!layerIsOn("toggleProvinces")) {
|
||||||
turnButtonOn("toggleProvinces");
|
turnLayerButtonOn("toggleProvinces");
|
||||||
drawProvinces();
|
drawProvinces();
|
||||||
if (event && isCtrlClick(event)) editStyle("provs");
|
if (event && isCtrlClick(event)) editStyle("provs");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1285,7 +1289,7 @@ function toggleProvinces(event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
provs.selectAll("*").remove();
|
provs.selectAll("*").remove();
|
||||||
turnButtonOff("toggleProvinces");
|
turnLayerButtonOff("toggleProvinces");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1415,7 +1419,7 @@ function getProvincesVertices() {
|
||||||
|
|
||||||
function toggleGrid(event) {
|
function toggleGrid(event) {
|
||||||
if (!gridOverlay.selectAll("*").size()) {
|
if (!gridOverlay.selectAll("*").size()) {
|
||||||
turnButtonOn("toggleGrid");
|
turnLayerButtonOn("toggleGrid");
|
||||||
drawGrid();
|
drawGrid();
|
||||||
calculateFriendlyGridSize();
|
calculateFriendlyGridSize();
|
||||||
|
|
||||||
|
|
@ -1425,7 +1429,7 @@ function toggleGrid(event) {
|
||||||
editStyle("gridOverlay");
|
editStyle("gridOverlay");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
turnButtonOff("toggleGrid");
|
turnLayerButtonOff("toggleGrid");
|
||||||
gridOverlay.selectAll("*").remove();
|
gridOverlay.selectAll("*").remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1461,7 +1465,7 @@ function drawGrid() {
|
||||||
|
|
||||||
function toggleCoordinates(event) {
|
function toggleCoordinates(event) {
|
||||||
if (!coordinates.selectAll("*").size()) {
|
if (!coordinates.selectAll("*").size()) {
|
||||||
turnButtonOn("toggleCoordinates");
|
turnLayerButtonOn("toggleCoordinates");
|
||||||
drawCoordinates();
|
drawCoordinates();
|
||||||
if (event && isCtrlClick(event)) editStyle("coordinates");
|
if (event && isCtrlClick(event)) editStyle("coordinates");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1469,7 +1473,7 @@ function toggleCoordinates(event) {
|
||||||
editStyle("coordinates");
|
editStyle("coordinates");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
turnButtonOff("toggleCoordinates");
|
turnLayerButtonOff("toggleCoordinates");
|
||||||
coordinates.selectAll("*").remove();
|
coordinates.selectAll("*").remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1540,7 +1544,7 @@ function getViewPoint(x, y) {
|
||||||
|
|
||||||
function toggleCompass(event) {
|
function toggleCompass(event) {
|
||||||
if (!layerIsOn("toggleCompass")) {
|
if (!layerIsOn("toggleCompass")) {
|
||||||
turnButtonOn("toggleCompass");
|
turnLayerButtonOn("toggleCompass");
|
||||||
$("#compass").fadeIn();
|
$("#compass").fadeIn();
|
||||||
if (!compass.selectAll("*").size()) {
|
if (!compass.selectAll("*").size()) {
|
||||||
compass.append("use").attr("xlink:href", "#rose");
|
compass.append("use").attr("xlink:href", "#rose");
|
||||||
|
|
@ -1553,13 +1557,13 @@ function toggleCompass(event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$("#compass").fadeOut();
|
$("#compass").fadeOut();
|
||||||
turnButtonOff("toggleCompass");
|
turnLayerButtonOff("toggleCompass");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleRelief(event) {
|
function toggleRelief(event) {
|
||||||
if (!layerIsOn("toggleRelief")) {
|
if (!layerIsOn("toggleRelief")) {
|
||||||
turnButtonOn("toggleRelief");
|
turnLayerButtonOn("toggleRelief");
|
||||||
if (!terrain.selectAll("*").size()) ReliefIcons();
|
if (!terrain.selectAll("*").size()) ReliefIcons();
|
||||||
$("#terrain").fadeIn();
|
$("#terrain").fadeIn();
|
||||||
if (event && isCtrlClick(event)) editStyle("terrain");
|
if (event && isCtrlClick(event)) editStyle("terrain");
|
||||||
|
|
@ -1569,13 +1573,13 @@ function toggleRelief(event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$("#terrain").fadeOut();
|
$("#terrain").fadeOut();
|
||||||
turnButtonOff("toggleRelief");
|
turnLayerButtonOff("toggleRelief");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleTexture(event) {
|
function toggleTexture(event) {
|
||||||
if (!layerIsOn("toggleTexture")) {
|
if (!layerIsOn("toggleTexture")) {
|
||||||
turnButtonOn("toggleTexture");
|
turnLayerButtonOn("toggleTexture");
|
||||||
// append default texture image selected by default. Don't append on load to not harm performance
|
// append default texture image selected by default. Don't append on load to not harm performance
|
||||||
if (!texture.selectAll("*").size()) {
|
if (!texture.selectAll("*").size()) {
|
||||||
const x = +styleTextureShiftX.value;
|
const x = +styleTextureShiftX.value;
|
||||||
|
|
@ -1596,19 +1600,19 @@ function toggleTexture(event) {
|
||||||
} else {
|
} else {
|
||||||
if (event && isCtrlClick(event)) return editStyle("texture");
|
if (event && isCtrlClick(event)) return editStyle("texture");
|
||||||
$("#texture").fadeOut();
|
$("#texture").fadeOut();
|
||||||
turnButtonOff("toggleTexture");
|
turnLayerButtonOff("toggleTexture");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleRivers(event) {
|
function toggleRivers(event) {
|
||||||
if (!layerIsOn("toggleRivers")) {
|
if (!layerIsOn("toggleRivers")) {
|
||||||
turnButtonOn("toggleRivers");
|
turnLayerButtonOn("toggleRivers");
|
||||||
drawRivers();
|
drawRivers();
|
||||||
if (event && isCtrlClick(event)) editStyle("rivers");
|
if (event && isCtrlClick(event)) editStyle("rivers");
|
||||||
} else {
|
} else {
|
||||||
if (event && isCtrlClick(event)) return editStyle("rivers");
|
if (event && isCtrlClick(event)) return editStyle("rivers");
|
||||||
rivers.selectAll("*").remove();
|
rivers.selectAll("*").remove();
|
||||||
turnButtonOff("toggleRivers");
|
turnLayerButtonOff("toggleRivers");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1639,7 +1643,7 @@ export function drawRivers() {
|
||||||
|
|
||||||
function toggleRoutes(event) {
|
function toggleRoutes(event) {
|
||||||
if (!layerIsOn("toggleRoutes")) {
|
if (!layerIsOn("toggleRoutes")) {
|
||||||
turnButtonOn("toggleRoutes");
|
turnLayerButtonOn("toggleRoutes");
|
||||||
$("#routes").fadeIn();
|
$("#routes").fadeIn();
|
||||||
if (event && isCtrlClick(event)) editStyle("routes");
|
if (event && isCtrlClick(event)) editStyle("routes");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1648,13 +1652,13 @@ function toggleRoutes(event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$("#routes").fadeOut();
|
$("#routes").fadeOut();
|
||||||
turnButtonOff("toggleRoutes");
|
turnLayerButtonOff("toggleRoutes");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleMilitary(event) {
|
function toggleMilitary(event) {
|
||||||
if (!layerIsOn("toggleMilitary")) {
|
if (!layerIsOn("toggleMilitary")) {
|
||||||
turnButtonOn("toggleMilitary");
|
turnLayerButtonOn("toggleMilitary");
|
||||||
$("#armies").fadeIn();
|
$("#armies").fadeIn();
|
||||||
if (event && isCtrlClick(event)) editStyle("armies");
|
if (event && isCtrlClick(event)) editStyle("armies");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1663,19 +1667,19 @@ function toggleMilitary(event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$("#armies").fadeOut();
|
$("#armies").fadeOut();
|
||||||
turnButtonOff("toggleMilitary");
|
turnLayerButtonOff("toggleMilitary");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleMarkers(event) {
|
function toggleMarkers(event) {
|
||||||
if (!layerIsOn("toggleMarkers")) {
|
if (!layerIsOn("toggleMarkers")) {
|
||||||
turnButtonOn("toggleMarkers");
|
turnLayerButtonOn("toggleMarkers");
|
||||||
drawMarkers();
|
drawMarkers();
|
||||||
if (event && isCtrlClick(event)) editStyle("markers");
|
if (event && isCtrlClick(event)) editStyle("markers");
|
||||||
} else {
|
} else {
|
||||||
if (event && isCtrlClick(event)) return editStyle("markers");
|
if (event && isCtrlClick(event)) return editStyle("markers");
|
||||||
markers.selectAll("*").remove();
|
markers.selectAll("*").remove();
|
||||||
turnButtonOff("toggleMarkers");
|
turnLayerButtonOff("toggleMarkers");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1724,23 +1728,23 @@ function drawMarker(marker, rescale = 1) {
|
||||||
|
|
||||||
function toggleLabels(event) {
|
function toggleLabels(event) {
|
||||||
if (!layerIsOn("toggleLabels")) {
|
if (!layerIsOn("toggleLabels")) {
|
||||||
turnButtonOn("toggleLabels");
|
turnLayerButtonOn("toggleLabels");
|
||||||
labels.style("display", null);
|
labels.style("display", null);
|
||||||
invokeActiveZooming();
|
Zoom.invoke();
|
||||||
if (event && isCtrlClick(event)) editStyle("labels");
|
if (event && isCtrlClick(event)) editStyle("labels");
|
||||||
} else {
|
} else {
|
||||||
if (event && isCtrlClick(event)) {
|
if (event && isCtrlClick(event)) {
|
||||||
editStyle("labels");
|
editStyle("labels");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
turnButtonOff("toggleLabels");
|
turnLayerButtonOff("toggleLabels");
|
||||||
labels.style("display", "none");
|
labels.style("display", "none");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleIcons(event) {
|
function toggleIcons(event) {
|
||||||
if (!layerIsOn("toggleIcons")) {
|
if (!layerIsOn("toggleIcons")) {
|
||||||
turnButtonOn("toggleIcons");
|
turnLayerButtonOn("toggleIcons");
|
||||||
$("#icons").fadeIn();
|
$("#icons").fadeIn();
|
||||||
if (event && isCtrlClick(event)) editStyle("burgIcons");
|
if (event && isCtrlClick(event)) editStyle("burgIcons");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1748,14 +1752,14 @@ function toggleIcons(event) {
|
||||||
editStyle("burgIcons");
|
editStyle("burgIcons");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
turnButtonOff("toggleIcons");
|
turnLayerButtonOff("toggleIcons");
|
||||||
$("#icons").fadeOut();
|
$("#icons").fadeOut();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleRulers(event) {
|
function toggleRulers(event) {
|
||||||
if (!layerIsOn("toggleRulers")) {
|
if (!layerIsOn("toggleRulers")) {
|
||||||
turnButtonOn("toggleRulers");
|
turnLayerButtonOn("toggleRulers");
|
||||||
if (event && isCtrlClick(event)) editStyle("ruler");
|
if (event && isCtrlClick(event)) editStyle("ruler");
|
||||||
rulers.draw();
|
rulers.draw();
|
||||||
ruler.style("display", null);
|
ruler.style("display", null);
|
||||||
|
|
@ -1764,7 +1768,7 @@ function toggleRulers(event) {
|
||||||
editStyle("ruler");
|
editStyle("ruler");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
turnButtonOff("toggleRulers");
|
turnLayerButtonOff("toggleRulers");
|
||||||
ruler.selectAll("*").remove();
|
ruler.selectAll("*").remove();
|
||||||
ruler.style("display", "none");
|
ruler.style("display", "none");
|
||||||
}
|
}
|
||||||
|
|
@ -1772,7 +1776,7 @@ function toggleRulers(event) {
|
||||||
|
|
||||||
function toggleScaleBar(event) {
|
function toggleScaleBar(event) {
|
||||||
if (!layerIsOn("toggleScaleBar")) {
|
if (!layerIsOn("toggleScaleBar")) {
|
||||||
turnButtonOn("toggleScaleBar");
|
turnLayerButtonOn("toggleScaleBar");
|
||||||
$("#scaleBar").fadeIn();
|
$("#scaleBar").fadeIn();
|
||||||
if (event && isCtrlClick(event)) editUnits();
|
if (event && isCtrlClick(event)) editUnits();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1781,13 +1785,13 @@ function toggleScaleBar(event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$("#scaleBar").fadeOut();
|
$("#scaleBar").fadeOut();
|
||||||
turnButtonOff("toggleScaleBar");
|
turnLayerButtonOff("toggleScaleBar");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleZones(event) {
|
function toggleZones(event) {
|
||||||
if (!layerIsOn("toggleZones")) {
|
if (!layerIsOn("toggleZones")) {
|
||||||
turnButtonOn("toggleZones");
|
turnLayerButtonOn("toggleZones");
|
||||||
$("#zones").fadeIn();
|
$("#zones").fadeIn();
|
||||||
if (event && isCtrlClick(event)) editStyle("zones");
|
if (event && isCtrlClick(event)) editStyle("zones");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1795,14 +1799,14 @@ function toggleZones(event) {
|
||||||
editStyle("zones");
|
editStyle("zones");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
turnButtonOff("toggleZones");
|
turnLayerButtonOff("toggleZones");
|
||||||
$("#zones").fadeOut();
|
$("#zones").fadeOut();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleEmblems(event) {
|
function toggleEmblems(event) {
|
||||||
if (!layerIsOn("toggleEmblems")) {
|
if (!layerIsOn("toggleEmblems")) {
|
||||||
turnButtonOn("toggleEmblems");
|
turnLayerButtonOn("toggleEmblems");
|
||||||
if (!emblems.selectAll("use").size()) drawEmblems();
|
if (!emblems.selectAll("use").size()) drawEmblems();
|
||||||
$("#emblems").fadeIn();
|
$("#emblems").fadeIn();
|
||||||
if (event && isCtrlClick(event)) editStyle("emblems");
|
if (event && isCtrlClick(event)) editStyle("emblems");
|
||||||
|
|
@ -1812,7 +1816,7 @@ function toggleEmblems(event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$("#emblems").fadeOut();
|
$("#emblems").fadeOut();
|
||||||
turnButtonOff("toggleEmblems");
|
turnLayerButtonOff("toggleEmblems");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1914,34 +1918,18 @@ function drawEmblems() {
|
||||||
const stateString = stateNodes
|
const stateString = stateNodes
|
||||||
.map(
|
.map(
|
||||||
d =>
|
d =>
|
||||||
`<use data-i="${d.i}" x="${rn(d.x - d.shift)}" y="${rn(d.y - d.shift)}" width="${d.size}em" height="${
|
`<use data-i="${d.i}" x="${rn(d.x - d.shift)}" y="${rn(d.y - d.shift)}"
|
||||||
d.size
|
width="${d.size}em" height="${d.size}em"/>`
|
||||||
}em"/>`
|
|
||||||
)
|
)
|
||||||
.join("");
|
.join("");
|
||||||
emblems.select("#stateEmblems").attr("font-size", sizeStates).html(stateString);
|
emblems.select("#stateEmblems").attr("font-size", sizeStates).html(stateString);
|
||||||
|
|
||||||
invokeActiveZooming();
|
Zoom.invoke();
|
||||||
});
|
});
|
||||||
|
|
||||||
TIME && console.timeEnd("drawEmblems");
|
TIME && console.timeEnd("drawEmblems");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function layerIsOn(el) {
|
|
||||||
const buttonoff = byId(el).classList.contains("buttonoff");
|
|
||||||
return !buttonoff;
|
|
||||||
}
|
|
||||||
|
|
||||||
function turnButtonOff(el) {
|
|
||||||
byId(el).classList.add("buttonoff");
|
|
||||||
getCurrentPreset();
|
|
||||||
}
|
|
||||||
|
|
||||||
function turnButtonOn(el) {
|
|
||||||
byId(el).classList.remove("buttonoff");
|
|
||||||
getCurrentPreset();
|
|
||||||
}
|
|
||||||
|
|
||||||
// move layers on mapLayers dragging (jquery sortable)
|
// move layers on mapLayers dragging (jquery sortable)
|
||||||
$("#mapLayers").sortable({items: "li:not(.solid)", containment: "parent", cancel: ".solid", update: moveLayer});
|
$("#mapLayers").sortable({items: "li:not(.solid)", containment: "parent", cancel: ".solid", update: moveLayer});
|
||||||
function moveLayer(event, ui) {
|
function moveLayer(event, ui) {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import {rn} from "/src/utils/numberUtils";
|
||||||
import {rand, P} from "/src/utils/probabilityUtils";
|
import {rand, P} from "/src/utils/probabilityUtils";
|
||||||
import {parseTransform} from "/src/utils/stringUtils";
|
import {parseTransform} from "/src/utils/stringUtils";
|
||||||
import {si} from "/src/utils/unitUtils";
|
import {si} from "/src/utils/unitUtils";
|
||||||
|
import {turnLayerButtonOff} from "/src/modules/ui/layers";
|
||||||
|
|
||||||
export function editProvinces() {
|
export function editProvinces() {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
@ -1118,7 +1119,7 @@ export function editProvinces() {
|
||||||
if (!layerIsOn("toggleBorders")) toggleBorders();
|
if (!layerIsOn("toggleBorders")) toggleBorders();
|
||||||
else drawBorders();
|
else drawBorders();
|
||||||
provs.select("#provincesBody").remove();
|
provs.select("#provincesBody").remove();
|
||||||
turnButtonOff("toggleProvinces");
|
turnLayerButtonOff("toggleProvinces");
|
||||||
|
|
||||||
provincesEditorAddLines();
|
provincesEditorAddLines();
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -430,13 +430,13 @@ function shiftElement() {
|
||||||
|
|
||||||
styleRescaleMarkers.addEventListener("change", function () {
|
styleRescaleMarkers.addEventListener("change", function () {
|
||||||
markers.attr("rescale", +this.checked);
|
markers.attr("rescale", +this.checked);
|
||||||
invokeActiveZooming();
|
Zoom.invoke();
|
||||||
});
|
});
|
||||||
|
|
||||||
styleCoastlineAuto.addEventListener("change", function () {
|
styleCoastlineAuto.addEventListener("change", function () {
|
||||||
coastline.select("#sea_island").attr("auto-filter", +this.checked);
|
coastline.select("#sea_island").attr("auto-filter", +this.checked);
|
||||||
styleFilter.style.display = this.checked ? "none" : "block";
|
styleFilter.style.display = this.checked ? "none" : "block";
|
||||||
invokeActiveZooming();
|
Zoom.invoke();
|
||||||
});
|
});
|
||||||
|
|
||||||
styleOceanFill.addEventListener("input", function () {
|
styleOceanFill.addEventListener("input", function () {
|
||||||
|
|
@ -834,7 +834,7 @@ function updateElements() {
|
||||||
if (legend.selectAll("*").size() && window.redrawLegend) redrawLegend();
|
if (legend.selectAll("*").size() && window.redrawLegend) redrawLegend();
|
||||||
oceanLayers.selectAll("path").remove();
|
oceanLayers.selectAll("path").remove();
|
||||||
OceanLayers();
|
OceanLayers();
|
||||||
invokeActiveZooming();
|
Zoom.invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
// GLOBAL FILTERS
|
// GLOBAL FILTERS
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ function applyStyleWithUiRefresh(style) {
|
||||||
updateMapFilter();
|
updateMapFilter();
|
||||||
stylePreset.dataset.old = stylePreset.value;
|
stylePreset.dataset.old = stylePreset.value;
|
||||||
|
|
||||||
invokeActiveZooming();
|
Zoom.invoke();
|
||||||
setPresetRemoveButtonVisibiliy();
|
setPresetRemoveButtonVisibiliy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import {clearMainTip} from "/src/scripts/tooltips";
|
||||||
import {parseError} from "/src/utils/errorUtils";
|
import {parseError} from "/src/utils/errorUtils";
|
||||||
import {rn, minmax} from "/src/utils/numberUtils";
|
import {rn, minmax} from "/src/utils/numberUtils";
|
||||||
import {debounce} from "/src/utils/functionUtils";
|
import {debounce} from "/src/utils/functionUtils";
|
||||||
|
import {restoreLayers} from "/src/modules/ui/layers";
|
||||||
|
|
||||||
window.UISubmap = (function () {
|
window.UISubmap = (function () {
|
||||||
byId("submapPointsInput").addEventListener("input", function () {
|
byId("submapPointsInput").addEventListener("input", function () {
|
||||||
|
|
@ -298,7 +299,7 @@ window.UISubmap = (function () {
|
||||||
moveAllBurgsToGroup("towns", groupName);
|
moveAllBurgsToGroup("towns", groupName);
|
||||||
changeRadius(rn(oldScale * 0.8, 2), groupName);
|
changeRadius(rn(oldScale * 0.8, 2), groupName);
|
||||||
changeFontSize(svg.select(`#labels #${groupName}`), rn(oldScale * 2, 2));
|
changeFontSize(svg.select(`#labels #${groupName}`), rn(oldScale * 2, 2));
|
||||||
invokeActiveZooming();
|
Zoom.invoke();
|
||||||
}
|
}
|
||||||
if (options.rescaleStyles) changeStyles(oldScale);
|
if (options.rescaleStyles) changeStyles(oldScale);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import {isCtrlClick} from "/src/utils/keyboardUtils";
|
||||||
import {prompt} from "/src/scripts/prompt";
|
import {prompt} from "/src/scripts/prompt";
|
||||||
import {getNextId} from "/src/utils/nodeUtils";
|
import {getNextId} from "/src/utils/nodeUtils";
|
||||||
import {P, generateSeed} from "/src/utils/probabilityUtils";
|
import {P, generateSeed} from "/src/utils/probabilityUtils";
|
||||||
|
import {turnLayerButtonOn} from "/src/modules/ui/layers";
|
||||||
|
|
||||||
toolsContent.addEventListener("click", function (event) {
|
toolsContent.addEventListener("click", function (event) {
|
||||||
if (customization) return tip("Please exit the customization mode first", false, "warning");
|
if (customization) return tip("Please exit the customization mode first", false, "warning");
|
||||||
|
|
@ -436,7 +437,7 @@ function regenerateIce() {
|
||||||
|
|
||||||
function regenerateMarkers() {
|
function regenerateMarkers() {
|
||||||
Markers.regenerate();
|
Markers.regenerate();
|
||||||
turnButtonOn("toggleMarkers");
|
turnLayerButtonOn("toggleMarkers");
|
||||||
drawMarkers();
|
drawMarkers();
|
||||||
if (document.getElementById("markersOverviewRefresh").offsetParent) markersOverviewRefresh.click();
|
if (document.getElementById("markersOverviewRefresh").offsetParent) markersOverviewRefresh.click();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
import {debounce} from "/src/utils/functionUtils";
|
import {debounce} from "/src/utils/functionUtils";
|
||||||
import {handleZoom} from "/src/modules/activeZooming";
|
import {handleZoom, invokeActiveZooming} from "/src/modules/activeZooming";
|
||||||
|
|
||||||
// temporary expose to global
|
// temporary expose to window
|
||||||
window.scale = 1;
|
window.scale = 1;
|
||||||
window.viewX = 0;
|
window.viewX = 0;
|
||||||
window.viewY = 0;
|
window.viewY = 0;
|
||||||
|
|
||||||
window.Zoom = (function () {
|
window.Zoom = (function () {
|
||||||
|
const onZoomDebouced = debounce(onZoom, 50);
|
||||||
|
const zoom = d3.zoom().scaleExtent([1, 20]).on("zoom", onZoomDebouced);
|
||||||
|
|
||||||
function onZoom() {
|
function onZoom() {
|
||||||
if (!d3.event?.transform) return;
|
if (!d3.event?.transform) return;
|
||||||
const {k, x, y} = d3.event.transform;
|
const {k, x, y} = d3.event.transform;
|
||||||
|
|
@ -21,13 +24,15 @@ window.Zoom = (function () {
|
||||||
|
|
||||||
handleZoom(isScaleChanged, isPositionChanged);
|
handleZoom(isScaleChanged, isPositionChanged);
|
||||||
}
|
}
|
||||||
const onZoomDebouced = debounce(onZoom, 50);
|
|
||||||
const zoom = d3.zoom().scaleExtent([1, 20]).on("zoom", onZoomDebouced);
|
|
||||||
|
|
||||||
function setZoomBehavior() {
|
function setZoomBehavior() {
|
||||||
svg.call(zoom);
|
svg.call(zoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function invoke() {
|
||||||
|
invokeActiveZooming();
|
||||||
|
}
|
||||||
|
|
||||||
// zoom to a specific point
|
// zoom to a specific point
|
||||||
function to(x, y, z = 8, d = 2000) {
|
function to(x, y, z = 8, d = 2000) {
|
||||||
const transform = d3.zoomIdentity.translate(x * -z + graphWidth / 2, y * -z + graphHeight / 2).scale(z);
|
const transform = d3.zoomIdentity.translate(x * -z + graphWidth / 2, y * -z + graphHeight / 2).scale(z);
|
||||||
|
|
@ -54,5 +59,5 @@ window.Zoom = (function () {
|
||||||
zoom.scaleTo(element, scale);
|
zoom.scaleTo(element, scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {setZoomBehavior, to, reset, scaleExtent, translateExtent, scaleTo};
|
return {setZoomBehavior, invoke, to, reset, scaleExtent, translateExtent, scaleTo};
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
3
src/types/common.d.ts
vendored
3
src/types/common.d.ts
vendored
|
|
@ -3,3 +3,6 @@ type UnknownObject = {[key: string]: unknown};
|
||||||
interface Dict<T> {
|
interface Dict<T> {
|
||||||
[key: string]: T;
|
[key: string]: T;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RGB = `rgb(${number}, ${number}, ${number})`;
|
||||||
|
type Hex = `#${string}`;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
const d3 = window.d3;
|
const d3 = window.d3;
|
||||||
|
|
||||||
const c12 = [
|
const c12: Hex[] = [
|
||||||
"#dababf",
|
"#dababf",
|
||||||
"#fb8072",
|
"#fb8072",
|
||||||
"#80b1d3",
|
"#80b1d3",
|
||||||
|
|
@ -38,3 +38,21 @@ export function getMixedColor(hexColor: string, mixation = 0.2, bright = 0.3) {
|
||||||
|
|
||||||
return d3.color(mixedColor).brighter(bright).hex();
|
return d3.color(mixedColor).brighter(bright).hex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getColorScheme(schemeName: string) {
|
||||||
|
return colorSchemeMap[schemeName] || colorSchemeMap.default;
|
||||||
|
}
|
||||||
|
|
||||||
|
type ColorScheme = (n: number) => RGB;
|
||||||
|
const colorSchemeMap: Dict<ColorScheme> = {
|
||||||
|
default: d3.scaleSequential(d3.interpolateSpectral),
|
||||||
|
bright: d3.scaleSequential(d3.interpolateSpectral),
|
||||||
|
light: d3.scaleSequential(d3.interpolateRdYlGn),
|
||||||
|
green: d3.scaleSequential(d3.interpolateGreens),
|
||||||
|
monochrome: d3.scaleSequential(d3.interpolateGreys)
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getHeightColor(height: number, scheme = getColorScheme("default")) {
|
||||||
|
const fittedValue = height < 20 ? height - 5 : height;
|
||||||
|
return scheme(1 - fittedValue / 100);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue