2020-09-04 22:03:03 +00:00
|
|
|
// current weather conditions display
|
2020-09-08 21:50:53 +00:00
|
|
|
/* globals WeatherDisplay, utils, STATUS, draw, luxon */
|
2020-09-04 22:03:03 +00:00
|
|
|
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
class Radar extends WeatherDisplay {
|
2020-10-29 21:44:28 +00:00
|
|
|
constructor(navId, elemId) {
|
|
|
|
super(navId, elemId, 'Local Radar');
|
2020-09-04 22:03:03 +00:00
|
|
|
|
|
|
|
// set max images
|
|
|
|
this.dopplerRadarImageMax = 6;
|
2020-09-06 01:01:13 +00:00
|
|
|
// update timing
|
|
|
|
this.timing.baseDelay = 350;
|
2020-09-09 19:29:03 +00:00
|
|
|
this.timing.delay = [
|
2020-10-29 21:44:28 +00:00
|
|
|
{ time: 4, si: 5 },
|
|
|
|
{ time: 1, si: 0 },
|
|
|
|
{ time: 1, si: 1 },
|
|
|
|
{ time: 1, si: 2 },
|
|
|
|
{ time: 1, si: 3 },
|
|
|
|
{ time: 1, si: 4 },
|
|
|
|
{ time: 4, si: 5 },
|
|
|
|
{ time: 1, si: 0 },
|
|
|
|
{ time: 1, si: 1 },
|
|
|
|
{ time: 1, si: 2 },
|
|
|
|
{ time: 1, si: 3 },
|
|
|
|
{ time: 1, si: 4 },
|
|
|
|
{ time: 4, si: 5 },
|
|
|
|
{ time: 1, si: 0 },
|
|
|
|
{ time: 1, si: 1 },
|
|
|
|
{ time: 1, si: 2 },
|
|
|
|
{ time: 1, si: 3 },
|
|
|
|
{ time: 1, si: 4 },
|
|
|
|
{ time: 12, si: 5 },
|
2020-09-09 19:29:03 +00:00
|
|
|
];
|
2020-09-04 22:03:03 +00:00
|
|
|
|
|
|
|
// pre-load background image (returns promise)
|
|
|
|
this.backgroundImage = utils.image.load('images/BackGround4_1.png');
|
|
|
|
}
|
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
async getData(_weatherParameters) {
|
|
|
|
super.getData(_weatherParameters);
|
|
|
|
const weatherParameters = _weatherParameters ?? this.weatherParameters;
|
2020-09-04 22:03:03 +00:00
|
|
|
|
|
|
|
// ALASKA ISN'T SUPPORTED!
|
|
|
|
if (weatherParameters.state === 'AK') {
|
|
|
|
this.setStatus(STATUS.noData);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-08 21:50:53 +00:00
|
|
|
// date and time parsing
|
2020-10-29 21:44:28 +00:00
|
|
|
const { DateTime } = luxon;
|
2020-09-08 21:50:53 +00:00
|
|
|
|
2020-09-04 22:03:03 +00:00
|
|
|
// get the base map
|
|
|
|
let src = 'images/4000RadarMap2.jpg';
|
2020-10-16 20:30:27 +00:00
|
|
|
if (weatherParameters.state === 'HI') src = 'images/HawaiiRadarMap2.png';
|
2020-09-04 22:03:03 +00:00
|
|
|
this.baseMap = await utils.image.load(src);
|
|
|
|
|
2020-09-25 00:51:29 +00:00
|
|
|
const baseUrl = 'https://radar.weather.gov/Conus/RadarImg/';
|
2020-09-04 22:03:03 +00:00
|
|
|
|
|
|
|
let radarHtml;
|
|
|
|
try {
|
|
|
|
// get a list of available radars
|
2020-10-29 21:44:28 +00:00
|
|
|
radarHtml = await utils.fetch.text(baseUrl, { cors: true });
|
2020-09-04 22:03:03 +00:00
|
|
|
} catch (e) {
|
2020-10-29 21:44:28 +00:00
|
|
|
console.error('Unable to get list of radars');
|
2020-10-02 02:35:49 +00:00
|
|
|
console.error(e);
|
2020-09-09 19:29:03 +00:00
|
|
|
this.setStatus(STATUS.failed);
|
2020-09-04 22:03:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// convert to an array of gif urls
|
2020-09-08 20:21:11 +00:00
|
|
|
const parser = new DOMParser();
|
|
|
|
const xmlDoc = parser.parseFromString(radarHtml, 'text/html');
|
|
|
|
const anchors = xmlDoc.getElementsByTagName('a');
|
|
|
|
const gifs = [];
|
2020-10-29 21:44:28 +00:00
|
|
|
Object.values(anchors).forEach((a) => {
|
|
|
|
gifs.push(a.innerHTML);
|
|
|
|
});
|
2020-09-04 22:03:03 +00:00
|
|
|
|
|
|
|
// filter for selected urls
|
2020-09-08 20:21:11 +00:00
|
|
|
let filter = /Conus_\d/;
|
2020-09-09 01:07:09 +00:00
|
|
|
if (weatherParameters.state === 'HI') filter = /hawaii_\d/;
|
2020-09-04 22:03:03 +00:00
|
|
|
|
|
|
|
// get the last few images
|
2020-10-29 21:44:28 +00:00
|
|
|
const urlsFull = gifs.filter((gif) => gif && gif.match(filter));
|
|
|
|
const urls = urlsFull.slice(-(this.dopplerRadarImageMax - 1));
|
2020-09-09 01:07:09 +00:00
|
|
|
|
|
|
|
// add additional 'latest.gif'
|
|
|
|
if (weatherParameters.state !== 'HI') urls.push('latest_radaronly.gif');
|
|
|
|
if (weatherParameters.state === 'HI') urls.push('hawaii_radaronly.gif');
|
2020-09-04 22:03:03 +00:00
|
|
|
|
|
|
|
// calculate offsets and sizes
|
|
|
|
let offsetX = 120;
|
|
|
|
let offsetY = 69;
|
|
|
|
let sourceXY;
|
|
|
|
let width;
|
|
|
|
let height;
|
2020-10-16 20:30:27 +00:00
|
|
|
if (weatherParameters.state === 'HI') {
|
2020-09-04 22:03:03 +00:00
|
|
|
width = 600;
|
|
|
|
height = 571;
|
2020-10-29 21:44:28 +00:00
|
|
|
sourceXY = Radar.getXYFromLatitudeLongitudeHI(weatherParameters.latitude, weatherParameters.longitude, offsetX, offsetY);
|
2020-09-04 22:03:03 +00:00
|
|
|
} else {
|
|
|
|
width = 2550;
|
|
|
|
height = 1600;
|
|
|
|
offsetX *= 2;
|
|
|
|
offsetY *= 2;
|
2020-10-29 21:44:28 +00:00
|
|
|
sourceXY = Radar.getXYFromLatitudeLongitudeDoppler(weatherParameters.latitude, weatherParameters.longitude, offsetX, offsetY);
|
2020-09-04 22:03:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// create working context for manipulation
|
|
|
|
const workingCanvas = document.createElement('canvas');
|
|
|
|
workingCanvas.width = width;
|
|
|
|
workingCanvas.height = height;
|
|
|
|
const workingContext = workingCanvas.getContext('2d');
|
|
|
|
workingContext.imageSmoothingEnabled = false;
|
|
|
|
|
|
|
|
// calculate radar offsets
|
|
|
|
let radarOffsetX = 117;
|
|
|
|
let radarOffsetY = 60;
|
2020-10-29 21:44:28 +00:00
|
|
|
let radarSourceXY = Radar.getXYFromLatitudeLongitudeDoppler(weatherParameters.latitude, weatherParameters.longitude, offsetX, offsetY);
|
2020-09-04 22:03:03 +00:00
|
|
|
let radarSourceX = radarSourceXY.x / 2;
|
|
|
|
let radarSourceY = radarSourceXY.y / 2;
|
|
|
|
|
2020-10-16 20:30:27 +00:00
|
|
|
if (weatherParameters.state === 'HI') {
|
2020-09-04 22:03:03 +00:00
|
|
|
radarOffsetX = 120;
|
|
|
|
radarOffsetY = 69;
|
|
|
|
radarSourceXY = this.getXYFromLatitudeLongitudeHI(weatherParameters.latitude, weatherParameters.longitude, offsetX, offsetY);
|
|
|
|
radarSourceX = radarSourceXY.x;
|
|
|
|
radarSourceY = radarSourceXY.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the most recent doppler radar images.
|
2020-09-09 01:07:09 +00:00
|
|
|
const radarInfo = await Promise.all(urls.map(async (url) => {
|
2020-09-04 22:03:03 +00:00
|
|
|
// create destination context
|
|
|
|
const canvas = document.createElement('canvas');
|
|
|
|
canvas.width = 640;
|
|
|
|
canvas.height = 367;
|
|
|
|
const context = canvas.getContext('2d');
|
|
|
|
context.imageSmoothingEnabled = false;
|
|
|
|
|
|
|
|
// get the image
|
2020-10-02 02:35:49 +00:00
|
|
|
const response = await fetch(utils.cors.rewriteUrl(baseUrl + url));
|
|
|
|
|
|
|
|
// test response
|
|
|
|
if (!response.ok) throw new Error(`Unable to fetch radar error ${response.status} ${response.statusText} from ${response.url}`);
|
|
|
|
|
|
|
|
// get the blob
|
|
|
|
const blob = await response.blob();
|
2020-09-09 01:07:09 +00:00
|
|
|
|
|
|
|
// store the time
|
|
|
|
const timeMatch = url.match(/_(\d{4})(\d\d)(\d\d)_(\d\d)(\d\d)_/);
|
|
|
|
let time;
|
|
|
|
if (timeMatch) {
|
|
|
|
const [, year, month, day, hour, minute] = timeMatch;
|
|
|
|
time = DateTime.fromObject({
|
|
|
|
year,
|
|
|
|
month,
|
|
|
|
day,
|
|
|
|
hour,
|
|
|
|
minute,
|
|
|
|
zone: 'UTC',
|
|
|
|
}).setZone();
|
|
|
|
} else {
|
2020-10-02 02:35:49 +00:00
|
|
|
time = DateTime.fromHTTP(response.headers.get('last-modified')).setZone();
|
2020-09-09 01:07:09 +00:00
|
|
|
}
|
2020-09-04 22:03:03 +00:00
|
|
|
|
|
|
|
// assign to an html image element
|
|
|
|
const imgBlob = await utils.image.load(blob);
|
|
|
|
|
|
|
|
// draw the entire image
|
2020-10-16 20:30:27 +00:00
|
|
|
if (weatherParameters.state === 'HI') {
|
2020-09-08 03:06:44 +00:00
|
|
|
workingContext.clearRect(0, 0, 571, 600);
|
2020-09-04 22:03:03 +00:00
|
|
|
workingContext.drawImage(imgBlob, 0, 0, 571, 600);
|
|
|
|
} else {
|
2020-09-08 03:06:44 +00:00
|
|
|
workingContext.clearRect(0, 0, 2550, 1600);
|
2020-09-04 22:03:03 +00:00
|
|
|
workingContext.drawImage(imgBlob, 0, 0, 2550, 1600);
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the base map
|
2020-10-29 21:44:28 +00:00
|
|
|
context.drawImage(await this.baseMap, sourceXY.x, sourceXY.y, offsetX * 2, offsetY * 2, 0, 0, 640, 367);
|
2020-09-04 22:03:03 +00:00
|
|
|
|
2020-09-08 03:06:44 +00:00
|
|
|
// crop the radar image
|
|
|
|
const cropCanvas = document.createElement('canvas');
|
|
|
|
cropCanvas.width = 640;
|
|
|
|
cropCanvas.height = 367;
|
|
|
|
const cropContext = cropCanvas.getContext('2d');
|
|
|
|
cropContext.imageSmoothingEnabled = false;
|
|
|
|
cropContext.drawImage(workingCanvas, radarSourceX, radarSourceY, (radarOffsetX * 2), (radarOffsetY * 2.33), 0, 0, 640, 367);
|
2020-09-08 15:05:46 +00:00
|
|
|
// clean the image
|
2020-10-29 21:44:28 +00:00
|
|
|
Radar.removeDopplerRadarImageNoise(cropContext);
|
2020-09-08 03:06:44 +00:00
|
|
|
|
|
|
|
// merge the radar and map
|
2020-10-29 21:44:28 +00:00
|
|
|
Radar.mergeDopplerRadarImage(context, cropContext);
|
2020-09-04 22:03:03 +00:00
|
|
|
|
2020-09-09 01:07:09 +00:00
|
|
|
return {
|
|
|
|
canvas,
|
|
|
|
time,
|
|
|
|
};
|
2020-09-04 22:03:03 +00:00
|
|
|
}));
|
2020-09-06 01:01:13 +00:00
|
|
|
// set max length
|
2020-09-09 01:07:09 +00:00
|
|
|
this.timing.totalScreens = radarInfo.length;
|
2020-09-06 01:01:13 +00:00
|
|
|
// store the images
|
2020-10-29 21:44:28 +00:00
|
|
|
this.data = radarInfo.map((radar) => radar.canvas);
|
2020-09-09 19:29:03 +00:00
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
this.times = radarInfo.map((radar) => radar.time);
|
2020-09-09 20:23:19 +00:00
|
|
|
this.setStatus(STATUS.loaded);
|
2020-09-04 22:03:03 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 01:01:13 +00:00
|
|
|
async drawCanvas() {
|
2020-09-04 22:03:03 +00:00
|
|
|
super.drawCanvas();
|
2020-09-09 20:23:19 +00:00
|
|
|
if (this.screenIndex === -1) return;
|
2020-09-06 01:01:13 +00:00
|
|
|
this.context.drawImage(await this.backgroundImage, 0, 0);
|
2020-10-29 21:44:28 +00:00
|
|
|
const { DateTime } = luxon;
|
2020-09-06 01:01:13 +00:00
|
|
|
// Title
|
2020-09-09 01:07:09 +00:00
|
|
|
draw.text(this.context, 'Arial', 'bold 28pt', '#ffffff', 155, 60, 'Local', 2);
|
|
|
|
draw.text(this.context, 'Arial', 'bold 28pt', '#ffffff', 155, 95, 'Radar', 2);
|
2020-09-06 01:01:13 +00:00
|
|
|
|
2020-09-09 01:07:09 +00:00
|
|
|
draw.text(this.context, 'Star4000', 'bold 18pt', '#ffffff', 438, 49, 'PRECIP', 2, 'center');
|
|
|
|
draw.text(this.context, 'Star4000', 'bold 18pt', '#ffffff', 298, 73, 'Light', 2);
|
|
|
|
draw.text(this.context, 'Star4000', 'bold 18pt', '#ffffff', 517, 73, 'Heavy', 2);
|
2020-09-06 01:01:13 +00:00
|
|
|
|
|
|
|
let x = 362;
|
|
|
|
const y = 52;
|
|
|
|
draw.box(this.context, '#000000', x - 2, y - 2, 154, 28);
|
|
|
|
draw.box(this.context, 'rgb(49, 210, 22)', x, y, 17, 24); x += 19;
|
|
|
|
draw.box(this.context, 'rgb(28, 138, 18)', x, y, 17, 24); x += 19;
|
|
|
|
draw.box(this.context, 'rgb(20, 90, 15)', x, y, 17, 24); x += 19;
|
|
|
|
draw.box(this.context, 'rgb(10, 40, 10)', x, y, 17, 24); x += 19;
|
|
|
|
draw.box(this.context, 'rgb(196, 179, 70)', x, y, 17, 24); x += 19;
|
|
|
|
draw.box(this.context, 'rgb(190, 72, 19)', x, y, 17, 24); x += 19;
|
|
|
|
draw.box(this.context, 'rgb(171, 14, 14)', x, y, 17, 24); x += 19;
|
|
|
|
draw.box(this.context, 'rgb(115, 31, 4)', x, y, 17, 24); x += 19;
|
|
|
|
|
|
|
|
this.context.drawImage(this.data[this.screenIndex], 0, 0, 640, 367, 0, 113, 640, 367);
|
2020-09-09 01:07:09 +00:00
|
|
|
draw.text(this.context, 'Star4000 Small', '24pt', '#ffffff', 438, 105, this.times[this.screenIndex].toLocaleString(DateTime.TIME_SIMPLE), 2, 'center');
|
2020-09-04 22:03:03 +00:00
|
|
|
|
|
|
|
this.finishDraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
// utility latitude/pixel conversions
|
2020-10-29 21:44:28 +00:00
|
|
|
getXYFromLatitudeLongitude(Latitude, Longitude, OffsetX, OffsetY, state) {
|
2020-09-04 22:03:03 +00:00
|
|
|
if (state === 'HI') return this.getXYFromLatitudeLongitudeHI(...arguments);
|
|
|
|
let y = 0;
|
|
|
|
let x = 0;
|
|
|
|
const ImgHeight = 1600;
|
|
|
|
const ImgWidth = 2550;
|
|
|
|
|
|
|
|
y = (50.5 - Latitude) * 55.2;
|
|
|
|
y -= OffsetY; // Centers map.
|
|
|
|
// Do not allow the map to exceed the max/min coordinates.
|
|
|
|
if (y > (ImgHeight - (OffsetY * 2))) {
|
|
|
|
y = ImgHeight - (OffsetY * 2);
|
|
|
|
} else if (y < 0) {
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = ((-127.5 - Longitude) * 41.775) * -1;
|
|
|
|
x -= OffsetX; // Centers map.
|
|
|
|
// Do not allow the map to exceed the max/min coordinates.
|
|
|
|
if (x > (ImgWidth - (OffsetX * 2))) {
|
|
|
|
x = ImgWidth - (OffsetX * 2);
|
|
|
|
} else if (x < 0) {
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return { x, y };
|
|
|
|
}
|
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
static getXYFromLatitudeLongitudeHI(Latitude, Longitude, OffsetX, OffsetY) {
|
2020-09-04 22:03:03 +00:00
|
|
|
let y = 0;
|
|
|
|
let x = 0;
|
|
|
|
const ImgHeight = 571;
|
|
|
|
const ImgWidth = 600;
|
|
|
|
|
|
|
|
y = (25 - Latitude) * 55.2;
|
|
|
|
y -= OffsetY; // Centers map.
|
|
|
|
// Do not allow the map to exceed the max/min coordinates.
|
|
|
|
if (y > (ImgHeight - (OffsetY * 2))) {
|
|
|
|
y = ImgHeight - (OffsetY * 2);
|
|
|
|
} else if (y < 0) {
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = ((-164.5 - Longitude) * 41.775) * -1;
|
|
|
|
x -= OffsetX; // Centers map.
|
|
|
|
// Do not allow the map to exceed the max/min coordinates.
|
|
|
|
if (x > (ImgWidth - (OffsetX * 2))) {
|
|
|
|
x = ImgWidth - (OffsetX * 2);
|
|
|
|
} else if (x < 0) {
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return { x, y };
|
|
|
|
}
|
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
static getXYFromLatitudeLongitudeDoppler(Latitude, Longitude, OffsetX, OffsetY) {
|
2020-09-04 22:03:03 +00:00
|
|
|
let y = 0;
|
|
|
|
let x = 0;
|
|
|
|
const ImgHeight = 3200;
|
|
|
|
const ImgWidth = 5100;
|
|
|
|
|
|
|
|
y = (51.75 - Latitude) * 55.2;
|
|
|
|
y -= OffsetY; // Centers map.
|
|
|
|
// Do not allow the map to exceed the max/min coordinates.
|
|
|
|
if (y > (ImgHeight - (OffsetY * 2))) {
|
|
|
|
y = ImgHeight - (OffsetY * 2);
|
|
|
|
} else if (y < 0) {
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = ((-130.37 - Longitude) * 41.775) * -1;
|
|
|
|
x -= OffsetX; // Centers map.
|
|
|
|
// Do not allow the map to exceed the max/min coordinates.
|
|
|
|
if (x > (ImgWidth - (OffsetX * 2))) {
|
|
|
|
x = ImgWidth - (OffsetX * 2);
|
|
|
|
} else if (x < 0) {
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return { x: x * 2, y: y * 2 };
|
|
|
|
}
|
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
static removeDopplerRadarImageNoise(RadarContext) {
|
2020-09-04 22:03:03 +00:00
|
|
|
const RadarImageData = RadarContext.getImageData(0, 0, RadarContext.canvas.width, RadarContext.canvas.height);
|
|
|
|
|
|
|
|
// examine every pixel,
|
|
|
|
// change any old rgb to the new-rgb
|
|
|
|
for (let i = 0; i < RadarImageData.data.length; i += 4) {
|
|
|
|
// i + 0 = red
|
|
|
|
// i + 1 = green
|
|
|
|
// i + 2 = blue
|
|
|
|
// i + 3 = alpha (0 = transparent, 255 = opaque)
|
2020-10-29 21:44:28 +00:00
|
|
|
let [R, G, B, A] = RadarImageData.data.slice(i, i + 4);
|
2020-09-04 22:03:03 +00:00
|
|
|
|
|
|
|
// is this pixel the old rgb?
|
|
|
|
if ((R === 1 && G === 159 && B === 244)
|
|
|
|
|| (R >= 200 && G >= 200 && B >= 200)
|
|
|
|
|| (R === 4 && G === 233 && B === 231)
|
|
|
|
|| (R === 3 && G === 0 && B === 244)) {
|
|
|
|
// Transparent
|
|
|
|
R = 0;
|
|
|
|
G = 0;
|
|
|
|
B = 0;
|
|
|
|
A = 0;
|
|
|
|
} else if (R === 2 && G === 253 && B === 2) {
|
|
|
|
// Light Green 1
|
|
|
|
R = 49;
|
|
|
|
G = 210;
|
|
|
|
B = 22;
|
|
|
|
A = 255;
|
|
|
|
} else if (R === 1 && G === 197 && B === 1) {
|
|
|
|
// Light Green 2
|
|
|
|
R = 0;
|
|
|
|
G = 142;
|
|
|
|
B = 0;
|
|
|
|
A = 255;
|
|
|
|
} else if (R === 0 && G === 142 && B === 0) {
|
|
|
|
// Dark Green 1
|
|
|
|
R = 20;
|
|
|
|
G = 90;
|
|
|
|
B = 15;
|
|
|
|
A = 255;
|
|
|
|
} else if (R === 253 && G === 248 && B === 2) {
|
|
|
|
// Dark Green 2
|
|
|
|
R = 10;
|
|
|
|
G = 40;
|
|
|
|
B = 10;
|
|
|
|
A = 255;
|
|
|
|
} else if (R === 229 && G === 188 && B === 0) {
|
|
|
|
// Yellow
|
|
|
|
R = 196;
|
|
|
|
G = 179;
|
|
|
|
B = 70;
|
|
|
|
A = 255;
|
|
|
|
} else if (R === 253 && G === 139 && B === 0) {
|
|
|
|
// Orange
|
|
|
|
R = 190;
|
|
|
|
G = 72;
|
|
|
|
B = 19;
|
|
|
|
A = 255;
|
|
|
|
} else if (R === 212 && G === 0 && B === 0) {
|
|
|
|
// Red
|
|
|
|
R = 171;
|
|
|
|
G = 14;
|
|
|
|
B = 14;
|
|
|
|
A = 255;
|
|
|
|
} else if (R === 188 && G === 0 && B === 0) {
|
|
|
|
// Brown
|
|
|
|
R = 115;
|
|
|
|
G = 31;
|
|
|
|
B = 4;
|
|
|
|
A = 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
// store new values
|
|
|
|
RadarImageData.data[i] = R;
|
|
|
|
RadarImageData.data[i + 1] = G;
|
|
|
|
RadarImageData.data[i + 2] = B;
|
|
|
|
RadarImageData.data[i + 3] = A;
|
|
|
|
}
|
|
|
|
|
|
|
|
// rewrite the image
|
|
|
|
RadarContext.putImageData(RadarImageData, 0, 0);
|
|
|
|
}
|
2020-09-08 03:06:44 +00:00
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
static mergeDopplerRadarImage(mapContext, radarContext) {
|
|
|
|
const mapImageData = mapContext.getImageData(0, 0, mapContext.canvas.width, mapContext.canvas.height);
|
|
|
|
const radarImageData = radarContext.getImageData(0, 0, radarContext.canvas.width, radarContext.canvas.height);
|
2020-09-08 03:06:44 +00:00
|
|
|
|
|
|
|
// examine every pixel,
|
|
|
|
// change any old rgb to the new-rgb
|
2020-10-29 21:44:28 +00:00
|
|
|
for (let i = 0; i < radarImageData.data.length; i += 4) {
|
2020-09-08 03:06:44 +00:00
|
|
|
// i + 0 = red
|
|
|
|
// i + 1 = green
|
|
|
|
// i + 2 = blue
|
|
|
|
// i + 3 = alpha (0 = transparent, 255 = opaque)
|
|
|
|
|
|
|
|
// is this pixel the old rgb?
|
|
|
|
if ((mapImageData.data[i] < 116 && mapImageData.data[i + 1] < 116 && mapImageData.data[i + 2] < 116)) {
|
|
|
|
// change to your new rgb
|
|
|
|
|
|
|
|
// Transparent
|
|
|
|
radarImageData.data[i] = 0;
|
|
|
|
radarImageData.data[i + 1] = 0;
|
|
|
|
radarImageData.data[i + 2] = 0;
|
|
|
|
radarImageData.data[i + 3] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
radarContext.putImageData(radarImageData, 0, 0);
|
|
|
|
|
|
|
|
mapContext.drawImage(radarContext.canvas, 0, 0);
|
|
|
|
}
|
2020-10-29 21:44:28 +00:00
|
|
|
}
|