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 // navigate to next or previous
const navTo = (direction) => { 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.nextFrame) currentDisplay().navNext();
if (direction === msg.command.previousFrame) currentDisplay().navPrev(); if (direction === msg.command.previousFrame) currentDisplay().navPrev();
}; };
@ -208,8 +216,6 @@ const navigation = (() => {
// get the current display index or value // get the current display index or value
const currentDisplayIndex = () => { const currentDisplayIndex = () => {
let index = displays.findIndex(display=>display.isActive()); 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; return index;
}; };
const currentDisplay = () => { const currentDisplay = () => {
@ -235,6 +241,11 @@ const navigation = (() => {
setPlaying(false); setPlaying(false);
navTo(msg.command.previousFrame); navTo(msg.command.previousFrame);
break; break;
case 'menu':
setPlaying(false);
progress.showCanvas();
hideAllCanvases();
break;
default: default:
console.error(`Unknown navButton ${button}`); console.error(`Unknown navButton ${button}`);
} }

View file

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

View file

@ -304,6 +304,7 @@ class WeatherDisplay {
} else { } else {
this.screenIndexChange(this.screenIndex); this.screenIndexChange(this.screenIndex);
} }
this.showCanvas();
} }
// navigate to previous screen // navigate to previous screen
@ -329,6 +330,7 @@ class WeatherDisplay {
} else { } else {
this.screenIndexChange(this.screenIndex); this.screenIndexChange(this.screenIndex);
} }
this.showCanvas();
} }
// calculate a baseCount from the screen index for the array timings // calculate a baseCount from the screen index for the array timings