rtwx/nexrad-browser/www/index.js

45 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-11-03 20:33:22 +00:00
import * as wasm from "./wasm/nexrad_browser.js";
await wasm.default();
2023-11-07 19:15:47 +00:00
let global_context = wasm.__nxrd_browser_init(window.innerWidth, window.innerHeight);
2023-11-07 02:56:19 +00:00
/*
2023-11-04 05:23:23 +00:00
function rescaleCanvas(canvas, ctx) {
var dpr = window.devicePixelRatio || 1;
// Get the size of the canvas in CSS pixels.
var rect = canvas.getBoundingClientRect();
// Give the canvas pixel dimensions of their CSS
// size * the device pixel ratio.
canvas.width = rect.width * dpr;
canvas.height = rect.height * dpr;
// Scale all drawing operations by the dpr, so you
// don't have to worry about the difference.
ctx.scale(dpr, dpr);
}
window.rescaleCanvas = rescaleCanvas;
2023-11-04 05:23:23 +00:00
window.loadar2 = (s) => {
2023-11-04 21:38:51 +00:00
const file = document.getElementById("file").files[0];
2023-11-05 02:38:49 +00:00
document.getElementById("file").value = null;
2023-11-04 21:38:51 +00:00
const reader = new FileReader();
reader.addEventListener('load', (event) => {
let data = event.target.result;
wasm.load_ar2(data, global_context);
2023-11-04 21:38:51 +00:00
});
reader.readAsArrayBuffer(file);
console.log(s);
2023-11-04 21:38:51 +00:00
}
// END GLOBAL FUNCTION DEFS
2023-11-04 21:38:51 +00:00
window.onkeydown = (e) => {
wasm.keydown(global_context, e.key);
2023-11-04 21:38:51 +00:00
}
document.getElementById("file").onchange = () => {
wasm.new_file_available(global_context);
2023-11-04 21:38:51 +00:00
}
let render = () => { wasm.render_abi(global_context); requestAnimationFrame(render); }
2023-11-04 05:23:23 +00:00
2023-11-07 02:56:19 +00:00
requestAnimationFrame(render);
*/