This commit is contained in:
Azgaar 2020-12-05 19:55:08 +03:00
parent 4920ccccb4
commit 554f51e463
10 changed files with 154 additions and 133 deletions

View file

@ -516,26 +516,15 @@ function getNextId(core, i = 1) {
return core + i;
}
// from https://davidwalsh.name/javascript-debounce-function
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
}
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
}
}
function debounce(f, ms) {
let isCooldown = false;
// pause/block JS execution for a while
function sleep(delay) {
const start = new Date().getTime();
while (new Date().getTime() < start + delay);
return function() {
if (isCooldown) return;
f.apply(this, arguments);
isCooldown = true;
setTimeout(() => isCooldown = false, ms);
};
}
// parse error to get the readable string in Chrome and Firefox
@ -597,6 +586,12 @@ function generateDate(from = 100, to = 1000) {
return new Date(rand(from, to),rand(12),rand(31)).toLocaleDateString("en", {year:'numeric', month:'long', day:'numeric'});
}
function getQGIScoordinates(x, y) {
const cx = mapCoordinates.lonW + (x / graphWidth) * mapCoordinates.lonT;
const cy = mapCoordinates.latN - (y / graphHeight) * mapCoordinates.latT; // this is inverted in QGIS otherwise
return [cx, cy];
}
// prompt replacer (prompt does not work in Electron)
void function() {
const prompt = document.getElementById("prompt");