71 lines
2.0 KiB
JavaScript
71 lines
2.0 KiB
JavaScript
|
|
|
|
import * as wasm from "./wasm/nexrad_browser.js";
|
|
await wasm.default();
|
|
let abi_proxy = await wasm.__nxrd_browser_init(window.innerWidth, window.innerHeight);
|
|
|
|
window.loadar2 = (s) => {
|
|
const file = document.getElementById("file").files[0];
|
|
document.getElementById("file").value = null;
|
|
const reader = new FileReader();
|
|
reader.addEventListener('load', (event) => {
|
|
let data = event.target.result;
|
|
wasm.load_ar2(data, abi_proxy);
|
|
});
|
|
reader.readAsArrayBuffer(file);
|
|
console.log(s);
|
|
}
|
|
|
|
document.getElementsByTagName("canvas")[0].focus();
|
|
|
|
window.onresize = async () => {
|
|
console.log("window resized!");
|
|
await wasm.resize_abi(window.innerWidth, window.innerHeight, abi_proxy);
|
|
}
|
|
|
|
document.getElementById("file").onchange = () => {
|
|
wasm.new_file_available(abi_proxy);
|
|
}
|
|
|
|
/*
|
|
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;
|
|
|
|
window.loadar2 = (s) => {
|
|
const file = document.getElementById("file").files[0];
|
|
document.getElementById("file").value = null;
|
|
const reader = new FileReader();
|
|
reader.addEventListener('load', (event) => {
|
|
let data = event.target.result;
|
|
wasm.load_ar2(data, global_context);
|
|
});
|
|
reader.readAsArrayBuffer(file);
|
|
console.log(s);
|
|
}
|
|
|
|
// END GLOBAL FUNCTION DEFS
|
|
|
|
window.onkeydown = (e) => {
|
|
wasm.keydown(global_context, e.key);
|
|
}
|
|
|
|
document.getElementById("file").onchange = () => {
|
|
wasm.new_file_available(global_context);
|
|
}
|
|
|
|
let render = () => { wasm.render_abi(global_context); requestAnimationFrame(render); }
|
|
|
|
requestAnimationFrame(render);
|
|
|
|
*/ |