namespace for submap ui.

This commit is contained in:
Mészáros Gergely 2022-04-19 11:00:43 +02:00
parent 5e6813c52c
commit e6d499fa60
2 changed files with 185 additions and 181 deletions

View file

@ -1728,8 +1728,8 @@
<p>Click to create a new map:</p>
<div id="resamplers">
<button data-tip="Click to generate new (sub)map from the current viewport" onclick="openSubmapOptions()">Submap</button>
<button data-tip="Click to resample (transform) your map to different cellcount" onclick="openRemapOptions()">Resample</button>
<button data-tip="Click to generate new (sub)map from the current viewport" onclick="UISubmap.openSubmapOptions()">Submap</button>
<button data-tip="Click to resample (transform) your map to different cellcount" onclick="UISubmap.openRemapOptions()">Resample</button>
</div>
</div>

View file

@ -4,7 +4,8 @@
UI elements for submap generation
*/
function openSubmapOptions() {
window.UISubmap = (function () {
function openSubmapOptions() {
$("#submapOptionsDialog").dialog({
title: "Submap options",
resizable: false,
@ -20,9 +21,9 @@ function openSubmapOptions() {
}
}
});
}
}
function openRemapOptions() {
function openRemapOptions() {
resetZoom(0);
$("#remapOptionsDialog").dialog({
title: "Resampler options",
@ -39,11 +40,11 @@ function openRemapOptions() {
}
}
});
}
}
/* callbacks */
/* callbacks */
const resampleCurrentMap = debounce(function () {
const resampleCurrentMap = debounce(function () {
// Resample the whole map to different cell resolution or shape
const cellNumId = Number(document.getElementById("submapPointsInput").value);
if (!cellsDensityConstants[cellNumId]) {
@ -63,9 +64,9 @@ const resampleCurrentMap = debounce(function () {
projection: (x, y) => [x, y],
inverse: (x, y) => [x, y]
});
}, 1000);
}, 1000);
const generateSubmap = debounce(function () {
const generateSubmap = debounce(function () {
// Create submap from the current map
// submap limits defined by the current window size (canvas viewport)
@ -104,9 +105,9 @@ const generateSubmap = debounce(function () {
populationRateInput.value = populationRateOutput.value = rn((populationRate = populationRateOutput.value / scale), 2);
customization = 0;
startResample(options);
}, 1000);
}, 1000);
async function startResample(options) {
async function startResample(options) {
// Do model changes with Submap.resample then do view changes if needed.
undraw();
resetZoom(0);
@ -139,9 +140,9 @@ async function startResample(options) {
turnButtonOn("toggleMarkers");
if (ThreeD.options.isOn) ThreeD.redraw();
if ($("#worldConfigurator").is(":visible")) editWorld();
}
}
function changeStyles(scale) {
function changeStyles(scale) {
// resize burgIcons
const burgIcons = [...document.getElementById("burgIcons").querySelectorAll("g")];
for (const bi of burgIcons) {
@ -165,9 +166,9 @@ function changeStyles(scale) {
emblemsProvinceSizeInput.value = minmax(+emblemsProvinceSizeInput.value * emblemMod, 0.5, 5);
emblemsBurgSizeInput.value = minmax(+emblemsBurgSizeInput.value * emblemMod, 0.5, 5);
drawEmblems();
}
}
function showSubmapErrorHandler(error) {
function showSubmapErrorHandler(error) {
ERROR && console.error(error);
clearMainTip();
@ -185,4 +186,7 @@ function showSubmapErrorHandler(error) {
},
position: {my: "center", at: "center", of: "svg"}
});
}
}
return {openSubmapOptions, openRemapOptions}
})();