clean up missing images in radar parsing

This commit is contained in:
Matt Walsh 2020-09-08 15:21:11 -05:00
parent 560d3a8cb2
commit 32d2b5d1cd
3 changed files with 25 additions and 7 deletions

View file

@ -183,6 +183,14 @@ const navigation = (() => {
// navigate to next or previous
const navTo = (direction) => {
// test for a current display
const current = currentDisplay();
if (!current) {
// special case for no active displays (typically on progress screen)
progress.hideCanvas();
displays[0].navNext(msg.command.firstFrame);
return;
}
if (direction === msg.command.nextFrame) currentDisplay().navNext();
if (direction === msg.command.previousFrame) currentDisplay().navPrev();
};
@ -208,8 +216,6 @@ const navigation = (() => {
// get the current display index or value
const currentDisplayIndex = () => {
let index = displays.findIndex(display=>display.isActive());
// if there is no active display, default to the first one
if (index === -1) index = displays.length-1;
return index;
};
const currentDisplay = () => {
@ -235,6 +241,11 @@ const navigation = (() => {
setPlaying(false);
navTo(msg.command.previousFrame);
break;
case 'menu':
setPlaying(false);
progress.showCanvas();
hideAllCanvases();
break;
default:
console.error(`Unknown navButton ${button}`);
}

View file

@ -49,15 +49,20 @@ class Radar extends WeatherDisplay {
}
// convert to an array of gif urls
const $list = $(radarHtml);
const gifs = $list.find('a[href]').map((i,elem) => elem.innerHTML).get();
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(radarHtml, 'text/html');
const anchors = xmlDoc.getElementsByTagName('a');
const gifs = [];
for (let idx in anchors) {
gifs.push(anchors[idx].innerHTML);
}
// filter for selected urls
let filter = /^Conus_\d/;
let filter = /Conus_\d/;
if (weatherParameters.State === 'HI') filter = /hawaii_\d/;
// get the last few images
const urlsFull = gifs.filter(gif => gif.match(filter));
const urlsFull = gifs.filter(gif => gif && gif.match(filter));
const urls = urlsFull.slice(-this.dopplerRadarImageMax);
// calculate offsets and sizes

View file

@ -232,7 +232,7 @@ class WeatherDisplay {
// if there was a command the canvas has already been drawn
if (navCmd) return;
// refresh the canvas (incase the screen index changed)
// refresh the canvas (in case the screen index changed)
if (navCmd) this.drawCanvas();
}
hideCanvas() {
@ -304,6 +304,7 @@ class WeatherDisplay {
} else {
this.screenIndexChange(this.screenIndex);
}
this.showCanvas();
}
// navigate to previous screen
@ -329,6 +330,7 @@ class WeatherDisplay {
} else {
this.screenIndexChange(this.screenIndex);
}
this.showCanvas();
}
// calculate a baseCount from the screen index for the array timings