Skip to content

Commit

Permalink
Common background draw; repair radars without noTransmitZones
Browse files Browse the repository at this point in the history
  • Loading branch information
keesverruijt committed Jan 13, 2025
1 parent 55d50d0 commit 21e8c0e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
7 changes: 2 additions & 5 deletions web/render_2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ import { RANGE_SCALE } from "./viewer.js";
class render_2d {
// The constructor gets two canvases, the real drawing one and one for background data
// such as range circles etc.
constructor(canvas_dom, canvas_background_dom) {
constructor(canvas_dom, canvas_background_dom, drawBackground) {
this.dom = canvas_dom;
this.background_dom = canvas_background_dom;
this.redrawCanvas();
}

setDrawBackgroundCallback(drawBackground) {
this.drawBackgroundCallback = drawBackground;
this.redrawCanvas();
}

// This is called as soon as it is clear what the number of spokes and their max length is
Expand Down
3 changes: 2 additions & 1 deletion web/render_webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { RANGE_SCALE } from "./viewer.js";
class render_webgl {
// The constructor gets two canvases, the real drawing one and one for background data
// such as range circles etc.
constructor(canvas_dom, canvas_background_dom) {
constructor(canvas_dom, canvas_background_dom, drawBackground) {
this.dom = canvas_dom;
this.background_dom = canvas_background_dom;
this.background_ctx = this.background_dom.getContext("2d");
this.drawBackgroundCallback = drawBackground;

const gl = this.dom.getContext("webgl2");
if (!gl) {
Expand Down
3 changes: 2 additions & 1 deletion web/render_webgl_alt.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { RANGE_SCALE } from "./viewer.js";
class render_webgl_alt {
// The constructor gets two canvases, the real drawing one and one for background data
// such as range circles etc.
constructor(canvas_dom, canvas_background_dom) {
constructor(canvas_dom, canvas_background_dom, drawBackground) {
this.dom = canvas_dom;
this.background_dom = canvas_background_dom;
this.background_ctx = this.background_dom.getContext("2d");
this.drawBackgroundCallback = drawBackground;

let gl = this.dom.getContext("webgl2", {
preserveDrawingBuffer: true,
Expand Down
45 changes: 24 additions & 21 deletions web/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,32 @@ window.onload = function () {
if (draw == "2d") {
renderer = new render_2d(
document.getElementById("myr_canvas"),
document.getElementById("myr_canvas_background")
document.getElementById("myr_canvas_background"),
drawBackground
);
} else if (draw == "alt") {
renderer = new render_webgl_alt(
document.getElementById("myr_canvas_webgl"),
document.getElementById("myr_canvas_background")
document.getElementById("myr_canvas_background"),
drawBackground
);
} else {
renderer = new render_webgl(
document.getElementById("myr_canvas_webgl"),
document.getElementById("myr_canvas_background")
document.getElementById("myr_canvas_background"),
drawBackground
);
}
} catch (e) {
console.log(e);
console.log("Falling back on 2d context");
renderer = new render_2d(
document.getElementById("myr_canvas"),
document.getElementById("myr_canvas_background")
document.getElementById("myr_canvas_background"),
drawBackground
);
}

renderer.setDrawBackgroundCallback(drawBackground);

loadRadar(id);

window.onresize = function () {
Expand Down Expand Up @@ -134,7 +136,7 @@ function hexToRGBA(hex) {
return a;
}

function controlUpdate(range, control, controlValue) {
function controlUpdate(control, controlValue) {
if (control.name == "Range" && control.descriptions) {
let range = parseFloat(controlValue.value);
rangeDescriptions = control.descriptions;
Expand Down Expand Up @@ -203,20 +205,21 @@ function drawBackground(obj, txt) {

obj.background_ctx.fillStyle = "lightgrey";

noTransmitAngles.forEach((e) => {
if (e && e[0]) {
obj.background_ctx.beginPath();
obj.background_ctx.arc(
obj.center_x,
obj.center_y,
obj.beam_length * 2,
(2 * Math.PI * e[0]) / obj.spokes,
(2 * Math.PI * e[1]) / obj.spokes
);
obj.background_ctx.fill();
}
});

if (typeof noTransmitAngles == "array") {
noTransmitAngles.forEach((e) => {
if (e && e[0]) {
obj.background_ctx.beginPath();
obj.background_ctx.arc(
obj.center_x,
obj.center_y,
obj.beam_length * 2,
(2 * Math.PI * e[0]) / obj.spokes,
(2 * Math.PI * e[1]) / obj.spokes
);
obj.background_ctx.fill();
}
});
}
obj.background_ctx.fillStyle = "lightblue";
this.background_ctx.fillText(txt, 5, 20);
}

0 comments on commit 21e8c0e

Please sign in to comment.