2020-10-02 02:35:49 +00:00
|
|
|
/* globals NoSleep, states, navigation, UNITS, utils */
|
2020-09-30 03:25:28 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
2020-09-17 19:37:54 +00:00
|
|
|
index.init();
|
|
|
|
});
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
const index = (() => {
|
2020-09-17 21:34:38 +00:00
|
|
|
const overrides = {
|
|
|
|
// '32899, Orlando, Florida, USA': { x: -80.6774, y: 28.6143 },
|
|
|
|
};
|
2020-10-29 21:44:28 +00:00
|
|
|
const AutoRefreshIntervalMs = 500;
|
|
|
|
const AutoRefreshTotalIntervalMs = 600000; // 10 min.
|
2020-09-17 21:34:38 +00:00
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
let AutoSelectQuery = false;
|
2020-09-17 19:37:54 +00:00
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
let LastUpdate = null;
|
|
|
|
let AutoRefreshIntervalId = null;
|
|
|
|
let AutoRefreshCountMs = 0;
|
2020-09-17 19:37:54 +00:00
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
let FullScreenOverride = false;
|
2020-09-17 19:37:54 +00:00
|
|
|
|
2020-10-02 03:09:47 +00:00
|
|
|
const categories = [
|
|
|
|
'Land Features',
|
|
|
|
'Bay', 'Channel', 'Cove', 'Dam', 'Delta', 'Gulf', 'Lagoon', 'Lake', 'Ocean', 'Reef', 'Reservoir', 'Sea', 'Sound', 'Strait', 'Waterfall', 'Wharf', // Water Features
|
|
|
|
'Amusement Park', 'Historical Monument', 'Landmark', 'Tourist Attraction', 'Zoo', // POI/Arts and Entertainment
|
|
|
|
'College', // POI/Education
|
|
|
|
'Beach', 'Campground', 'Golf Course', 'Harbor', 'Nature Reserve', 'Other Parks and Outdoors', 'Park', 'Racetrack',
|
|
|
|
'Scenic Overlook', 'Ski Resort', 'Sports Center', 'Sports Field', 'Wildlife Reserve', // POI/Parks and Outdoors
|
|
|
|
'Airport', 'Ferry', 'Marina', 'Pier', 'Port', 'Resort', // POI/Travel
|
|
|
|
'Postal', 'Populated Place',
|
|
|
|
];
|
|
|
|
const cats = categories.join(',');
|
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
const init = () => {
|
2020-09-30 03:25:28 +00:00
|
|
|
document.getElementById('txtAddress').addEventListener('focus', (e) => {
|
|
|
|
e.target.select();
|
|
|
|
});
|
2020-09-17 19:37:54 +00:00
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
document.getElementById('NavigateMenu').addEventListener('click', btnNavigateMenuClick);
|
|
|
|
document.getElementById('NavigateRefresh').addEventListener('click', btnNavigateRefreshClick);
|
|
|
|
document.getElementById('NavigateNext').addEventListener('click', btnNavigateNextClick);
|
|
|
|
document.getElementById('NavigatePrevious').addEventListener('click', btnNavigatePreviousClick);
|
|
|
|
document.getElementById('NavigatePlay').addEventListener('click', btnNavigatePlayClick);
|
|
|
|
document.getElementById('ToggleFullScreen').addEventListener('click', btnFullScreenClick);
|
|
|
|
document.getElementById('btnGetGps').addEventListener('click', btnGetGpsClick);
|
2020-09-17 19:37:54 +00:00
|
|
|
|
2020-09-30 03:25:28 +00:00
|
|
|
document.getElementById('divTwc').addEventListener('click', () => {
|
|
|
|
if (document.fullscreenElement) UpdateFullScreenNavigate();
|
2020-09-26 04:07:13 +00:00
|
|
|
});
|
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
document.addEventListener('keydown', documentKeydown);
|
|
|
|
document.addEventListener('touchmove', (e) => { if (FullScreenOverride) e.preventDefault(); });
|
2020-09-30 03:25:28 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
$('#frmGetLatLng #txtAddress').devbridgeAutocomplete({
|
2020-10-16 20:16:46 +00:00
|
|
|
serviceUrl: 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest',
|
2020-09-17 19:37:54 +00:00
|
|
|
deferRequestBy: 300,
|
|
|
|
paramName: 'text',
|
|
|
|
params: {
|
|
|
|
f: 'json',
|
2020-10-29 21:44:28 +00:00
|
|
|
countryCode: 'USA', // 'USA,PRI,VIR,GUM,ASM',
|
2020-09-17 19:37:54 +00:00
|
|
|
category: cats,
|
|
|
|
maxSuggestions: 10,
|
|
|
|
},
|
|
|
|
dataType: 'json',
|
|
|
|
transformResult: (response) => {
|
2020-10-29 21:44:28 +00:00
|
|
|
if (AutoSelectQuery) {
|
|
|
|
AutoSelectQuery = false;
|
2020-09-17 19:37:54 +00:00
|
|
|
window.setTimeout(() => {
|
|
|
|
$(ac.suggestionsContainer.children[0]).click();
|
|
|
|
}, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2020-10-29 21:44:28 +00:00
|
|
|
suggestions: $.map(response.suggestions, (i) => ({
|
|
|
|
value: i.text,
|
|
|
|
data: i.magicKey,
|
|
|
|
})),
|
2020-09-17 19:37:54 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
minChars: 3,
|
|
|
|
showNoSuggestionNotice: true,
|
|
|
|
noSuggestionNotice: 'No results found. Please try a different search string.',
|
2020-09-17 21:34:38 +00:00
|
|
|
onSelect: autocompleteOnSelect,
|
2020-09-17 19:37:54 +00:00
|
|
|
width: 490,
|
|
|
|
});
|
|
|
|
|
|
|
|
const ac = $('#frmGetLatLng #txtAddress').devbridgeAutocomplete();
|
2020-09-17 21:34:38 +00:00
|
|
|
$('#frmGetLatLng').submit(() => {
|
|
|
|
if (ac.suggestions[0]) $(ac.suggestionsContainer.children[0]).click();
|
2020-09-17 19:37:54 +00:00
|
|
|
return false;
|
|
|
|
});
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
// Auto load the previous query
|
|
|
|
const TwcQuery = localStorage.getItem('TwcQuery');
|
|
|
|
if (TwcQuery) {
|
2020-10-29 21:44:28 +00:00
|
|
|
AutoSelectQuery = true;
|
2020-09-30 03:25:28 +00:00
|
|
|
const txtAddress = document.getElementById('txtAddress');
|
2020-09-30 03:29:20 +00:00
|
|
|
txtAddress.value = TwcQuery;
|
2020-09-30 03:25:28 +00:00
|
|
|
txtAddress.blur();
|
|
|
|
txtAddress.focus();
|
2020-09-17 19:37:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const TwcPlay = localStorage.getItem('TwcPlay');
|
2020-09-17 21:34:38 +00:00
|
|
|
if (TwcPlay === null || TwcPlay === 'true') postMessage('navButton', 'play');
|
2020-09-17 19:37:54 +00:00
|
|
|
|
2020-09-30 03:25:28 +00:00
|
|
|
document.getElementById('btnClearQuery').addEventListener('click', () => {
|
|
|
|
document.getElementById('spanCity').innerHTML = '';
|
|
|
|
document.getElementById('spanState').innerHTML = '';
|
|
|
|
document.getElementById('spanStationId').innerHTML = '';
|
|
|
|
document.getElementById('spanRadarId').innerHTML = '';
|
|
|
|
document.getElementById('spanZoneId').innerHTML = '';
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
localStorage.removeItem('TwcScrollText');
|
|
|
|
localStorage.removeItem('TwcScrollTextChecked');
|
|
|
|
|
2020-09-30 03:25:28 +00:00
|
|
|
document.getElementById('chkAutoRefresh').checked = true;
|
2020-09-17 19:37:54 +00:00
|
|
|
localStorage.removeItem('TwcAutoRefresh');
|
|
|
|
|
2020-09-30 03:25:28 +00:00
|
|
|
document.getElementById('radEnglish').checked = true;
|
2020-09-17 19:37:54 +00:00
|
|
|
localStorage.removeItem('TwcUnits');
|
|
|
|
|
|
|
|
localStorage.removeItem('TwcPlay');
|
2020-09-17 21:34:38 +00:00
|
|
|
postMessage('navButton', 'play');
|
2020-09-17 19:37:54 +00:00
|
|
|
|
|
|
|
localStorage.removeItem('TwcQuery');
|
|
|
|
});
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
const TwcUnits = localStorage.getItem('TwcUnits');
|
|
|
|
if (!TwcUnits || TwcUnits === 'ENGLISH') {
|
2020-09-30 03:25:28 +00:00
|
|
|
document.getElementById('radEnglish').checked = true;
|
2022-08-04 18:59:21 +00:00
|
|
|
navigation.message({ type: 'units', message: 'english' });
|
2020-09-17 19:37:54 +00:00
|
|
|
} else if (TwcUnits === 'METRIC') {
|
2020-09-30 03:25:28 +00:00
|
|
|
document.getElementById('radMetric').checked = true;
|
2022-08-04 18:59:21 +00:00
|
|
|
navigation.message({ type: 'units', message: 'metric' });
|
2020-09-04 18:02:20 +00:00
|
|
|
}
|
|
|
|
|
2020-09-30 03:25:28 +00:00
|
|
|
document.getElementById('radEnglish').addEventListener('change', changeUnits);
|
|
|
|
document.getElementById('radMetric').addEventListener('change', changeUnits);
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-30 03:25:28 +00:00
|
|
|
document.getElementById('chkAutoRefresh').addEventListener('change', (e) => {
|
|
|
|
const Checked = e.target.checked;
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
if (LastUpdate) {
|
2020-09-17 19:37:54 +00:00
|
|
|
if (Checked) {
|
|
|
|
StartAutoRefreshTimer();
|
|
|
|
} else {
|
|
|
|
StopAutoRefreshTimer();
|
|
|
|
}
|
|
|
|
}
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
localStorage.setItem('TwcAutoRefresh', Checked);
|
|
|
|
});
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
const TwcAutoRefresh = localStorage.getItem('TwcAutoRefresh');
|
|
|
|
if (!TwcAutoRefresh || TwcAutoRefresh === 'true') {
|
2020-09-30 03:25:28 +00:00
|
|
|
document.getElementById('chkAutoRefresh').checked = true;
|
2020-09-17 19:37:54 +00:00
|
|
|
} else {
|
2020-09-30 03:25:28 +00:00
|
|
|
document.getElementById('chkAutoRefresh').checked = false;
|
2020-09-04 18:02:20 +00:00
|
|
|
}
|
|
|
|
|
2020-10-16 20:52:56 +00:00
|
|
|
// swipe functionality
|
|
|
|
document.getElementById('container').addEventListener('swiped-left', () => swipeCallBack('left'));
|
|
|
|
document.getElementById('container').addEventListener('swiped-right', () => swipeCallBack('right'));
|
2020-09-17 19:37:54 +00:00
|
|
|
};
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-30 03:25:28 +00:00
|
|
|
const changeUnits = (e) => {
|
|
|
|
const Units = e.target.value;
|
|
|
|
localStorage.setItem('TwcUnits', Units);
|
|
|
|
AssignLastUpdate();
|
|
|
|
postMessage('units', Units);
|
|
|
|
};
|
|
|
|
|
2020-10-02 02:35:49 +00:00
|
|
|
const autocompleteOnSelect = async (suggestion) => {
|
2020-09-17 21:34:38 +00:00
|
|
|
// Do not auto get the same city twice.
|
2020-10-29 21:44:28 +00:00
|
|
|
if (this.previousSuggestionValue === suggestion.value) return;
|
2020-09-17 21:34:38 +00:00
|
|
|
|
|
|
|
if (overrides[suggestion.value]) {
|
|
|
|
doRedirectToGeometry(overrides[suggestion.value]);
|
|
|
|
} else {
|
2020-10-02 02:35:49 +00:00
|
|
|
const data = await utils.fetch.json('https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find', {
|
2020-09-17 21:34:38 +00:00
|
|
|
data: {
|
|
|
|
text: suggestion.value,
|
|
|
|
magicKey: suggestion.data,
|
|
|
|
f: 'json',
|
|
|
|
},
|
|
|
|
});
|
2020-10-02 02:35:49 +00:00
|
|
|
|
|
|
|
const loc = data.locations[0];
|
|
|
|
if (loc) {
|
|
|
|
doRedirectToGeometry(loc.feature.geometry);
|
|
|
|
} else {
|
2020-10-29 21:44:28 +00:00
|
|
|
console.error('An unexpected error occurred. Please try a different search string.');
|
2020-10-02 02:35:49 +00:00
|
|
|
}
|
2020-09-17 21:34:38 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const doRedirectToGeometry = (geom) => {
|
2020-10-29 21:44:28 +00:00
|
|
|
const latLon = { lat: Math.round2(geom.y, 4), lon: Math.round2(geom.x, 4) };
|
2020-09-17 21:34:38 +00:00
|
|
|
LoadTwcData(latLon);
|
|
|
|
// Save the query
|
2020-09-30 03:25:28 +00:00
|
|
|
localStorage.setItem('TwcQuery', document.getElementById('txtAddress').value);
|
2020-09-17 21:34:38 +00:00
|
|
|
};
|
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
const btnFullScreenClick = () => {
|
2020-09-26 04:07:13 +00:00
|
|
|
if (!document.fullscreenElement) {
|
2020-09-17 19:37:54 +00:00
|
|
|
EnterFullScreen();
|
|
|
|
} else {
|
|
|
|
ExitFullscreen();
|
|
|
|
}
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 21:34:38 +00:00
|
|
|
if (navigation.isPlaying()) {
|
2020-10-29 21:44:28 +00:00
|
|
|
noSleep(true);
|
2020-09-17 19:37:54 +00:00
|
|
|
} else {
|
2020-10-29 21:44:28 +00:00
|
|
|
noSleep(false);
|
2020-09-17 19:37:54 +00:00
|
|
|
}
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
UpdateFullScreenNavigate();
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
return false;
|
|
|
|
};
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
const EnterFullScreen = () => {
|
2020-09-25 21:36:43 +00:00
|
|
|
const element = document.getElementById('divTwc');
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
// Supports most browsers and their versions.
|
2020-10-29 21:44:28 +00:00
|
|
|
const requestMethod = element.requestFullScreen || element.webkitRequestFullScreen
|
|
|
|
|| element.mozRequestFullScreen || element.msRequestFullscreen;
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
if (requestMethod) {
|
|
|
|
// Native full screen.
|
|
|
|
requestMethod.call(element, { navigationUI: 'hide' }); // https://bugs.chromium.org/p/chromium/issues/detail?id=933436#c7
|
|
|
|
} else {
|
|
|
|
// iOS doesn't support FullScreen API.
|
|
|
|
window.scrollTo(0, 0);
|
2020-10-29 21:44:28 +00:00
|
|
|
FullScreenOverride = true;
|
2020-09-17 19:37:54 +00:00
|
|
|
}
|
2022-09-23 20:55:37 +00:00
|
|
|
navigation.resize();
|
2020-09-17 19:37:54 +00:00
|
|
|
UpdateFullScreenNavigate();
|
2022-11-14 20:07:55 +00:00
|
|
|
|
|
|
|
// change hover text
|
|
|
|
document.getElementById('ToggleFullScreen').title = 'Exit fullscreen';
|
2020-09-17 19:37:54 +00:00
|
|
|
};
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
const ExitFullscreen = () => {
|
|
|
|
// exit full-screen
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
if (FullScreenOverride) {
|
|
|
|
FullScreenOverride = false;
|
2020-09-17 19:37:54 +00:00
|
|
|
}
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
if (document.exitFullscreen) {
|
|
|
|
// Chrome 71 broke this if the user pressed F11 to enter full screen mode.
|
|
|
|
document.exitFullscreen();
|
|
|
|
} else if (document.webkitExitFullscreen) {
|
|
|
|
document.webkitExitFullscreen();
|
|
|
|
} else if (document.mozCancelFullScreen) {
|
|
|
|
document.mozCancelFullScreen();
|
|
|
|
} else if (document.msExitFullscreen) {
|
|
|
|
document.msExitFullscreen();
|
2020-09-04 18:02:20 +00:00
|
|
|
}
|
2022-09-23 20:55:37 +00:00
|
|
|
navigation.resize();
|
2022-11-14 20:07:55 +00:00
|
|
|
// change hover text
|
|
|
|
document.getElementById('ToggleFullScreen').title = 'Enter fullscreen';
|
2020-09-04 18:02:20 +00:00
|
|
|
};
|
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
const btnNavigateMenuClick = () => {
|
2020-09-17 19:37:54 +00:00
|
|
|
postMessage('navButton', 'menu');
|
|
|
|
UpdateFullScreenNavigate();
|
|
|
|
return false;
|
|
|
|
};
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
const LoadTwcData = (_latLon) => {
|
|
|
|
// if latlon is provided store it locally
|
|
|
|
if (_latLon) LoadTwcData.latLon = _latLon;
|
|
|
|
// get the data
|
2020-10-29 21:44:28 +00:00
|
|
|
const { latLon } = LoadTwcData;
|
2020-09-17 19:37:54 +00:00
|
|
|
// if there's no data stop
|
|
|
|
if (!latLon) return;
|
|
|
|
|
2020-09-30 03:25:28 +00:00
|
|
|
document.getElementById('txtAddress').blur();
|
2020-09-17 19:37:54 +00:00
|
|
|
StopAutoRefreshTimer();
|
2020-10-29 21:44:28 +00:00
|
|
|
LastUpdate = null;
|
2020-09-17 19:37:54 +00:00
|
|
|
AssignLastUpdate();
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
postMessage('latLon', latLon);
|
2020-10-16 20:52:56 +00:00
|
|
|
};
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-10-16 20:52:56 +00:00
|
|
|
const swipeCallBack = (direction) => {
|
|
|
|
switch (direction) {
|
|
|
|
case 'left':
|
2020-10-29 21:44:28 +00:00
|
|
|
btnNavigateNextClick();
|
2020-10-16 20:52:56 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'right':
|
|
|
|
default:
|
2020-10-29 21:44:28 +00:00
|
|
|
btnNavigatePreviousClick();
|
2020-10-16 20:52:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-09-17 19:37:54 +00:00
|
|
|
};
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
const AssignLastUpdate = () => {
|
2020-10-29 21:44:28 +00:00
|
|
|
if (LastUpdate) {
|
2020-09-30 03:25:28 +00:00
|
|
|
switch (navigation.units()) {
|
|
|
|
case UNITS.english:
|
2020-10-29 21:44:28 +00:00
|
|
|
LastUpdate = LastUpdate.toLocaleString('en-US', {
|
|
|
|
weekday: 'short', month: 'short', day: 'numeric', year: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric', timeZoneName: 'short',
|
|
|
|
});
|
2020-09-17 19:37:54 +00:00
|
|
|
break;
|
|
|
|
default:
|
2020-10-29 21:44:28 +00:00
|
|
|
LastUpdate = LastUpdate.toLocaleString('en-GB', {
|
|
|
|
weekday: 'short', month: 'short', day: 'numeric', year: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric', timeZoneName: 'short',
|
|
|
|
});
|
2020-09-17 19:37:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-30 03:25:28 +00:00
|
|
|
document.getElementById('spanLastRefresh').innerHTML = LastUpdate;
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
if (LastUpdate && document.getElementById('chkAutoRefresh').checked) StartAutoRefreshTimer();
|
2020-09-17 19:37:54 +00:00
|
|
|
};
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
const btnNavigateRefreshClick = () => {
|
2020-09-17 19:37:54 +00:00
|
|
|
LoadTwcData();
|
|
|
|
UpdateFullScreenNavigate();
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
return false;
|
|
|
|
};
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
const btnNavigateNextClick = () => {
|
2020-09-17 19:37:54 +00:00
|
|
|
postMessage('navButton', 'next');
|
|
|
|
UpdateFullScreenNavigate();
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
return false;
|
|
|
|
};
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
const btnNavigatePreviousClick = () => {
|
2020-09-17 19:37:54 +00:00
|
|
|
postMessage('navButton', 'previous');
|
|
|
|
UpdateFullScreenNavigate();
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
return false;
|
|
|
|
};
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
let NavigateFadeIntervalId = null;
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
const UpdateFullScreenNavigate = () => {
|
2020-09-30 03:25:28 +00:00
|
|
|
document.activeElement.blur();
|
|
|
|
document.getElementById('divTwcBottom').classList.remove('hidden');
|
|
|
|
document.getElementById('divTwcBottom').classList.add('visible');
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
if (NavigateFadeIntervalId) {
|
|
|
|
clearTimeout(NavigateFadeIntervalId);
|
|
|
|
NavigateFadeIntervalId = null;
|
2020-09-04 18:02:20 +00:00
|
|
|
}
|
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
NavigateFadeIntervalId = setTimeout(() => {
|
2020-09-26 04:07:13 +00:00
|
|
|
if (document.fullscreenElement) {
|
2020-09-30 03:25:28 +00:00
|
|
|
document.getElementById('divTwcBottom').classList.remove('visible');
|
|
|
|
document.getElementById('divTwcBottom').classList.add('hidden');
|
2020-09-17 19:37:54 +00:00
|
|
|
}
|
|
|
|
}, 2000);
|
|
|
|
};
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
const documentKeydown = (e) => {
|
2020-09-17 19:37:54 +00:00
|
|
|
const code = (e.keyCode || e.which);
|
|
|
|
|
2020-09-26 04:07:13 +00:00
|
|
|
if (document.fullscreenElement || document.activeElement === document.body) {
|
2020-09-17 19:37:54 +00:00
|
|
|
switch (code) {
|
|
|
|
case 32: // Space
|
2020-10-29 21:44:28 +00:00
|
|
|
btnNavigatePlayClick();
|
2020-09-17 19:37:54 +00:00
|
|
|
return false;
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
case 39: // Right Arrow
|
|
|
|
case 34: // Page Down
|
2020-10-29 21:44:28 +00:00
|
|
|
btnNavigateNextClick();
|
2020-09-17 19:37:54 +00:00
|
|
|
return false;
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
case 37: // Left Arrow
|
|
|
|
case 33: // Page Up
|
2020-10-29 21:44:28 +00:00
|
|
|
btnNavigatePreviousClick();
|
2020-09-17 19:37:54 +00:00
|
|
|
return false;
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
case 36: // Home
|
2020-10-29 21:44:28 +00:00
|
|
|
btnNavigateMenuClick();
|
2020-09-17 19:37:54 +00:00
|
|
|
return false;
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
case 48: // Restart
|
2020-10-29 21:44:28 +00:00
|
|
|
btnNavigateRefreshClick();
|
2020-09-17 19:37:54 +00:00
|
|
|
return false;
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
case 70: // F
|
2020-10-29 21:44:28 +00:00
|
|
|
btnFullScreenClick();
|
2020-09-17 19:37:54 +00:00
|
|
|
return false;
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
default:
|
|
|
|
}
|
2020-09-04 18:02:20 +00:00
|
|
|
}
|
2020-10-29 21:44:28 +00:00
|
|
|
return false;
|
2020-09-17 19:37:54 +00:00
|
|
|
};
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
Math.round2 = (value, decimals) => Number(`${Math.round(`${value}e${decimals}`)}e-${decimals}`);
|
2020-09-17 19:37:54 +00:00
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
const btnNavigatePlayClick = () => {
|
2020-09-17 19:37:54 +00:00
|
|
|
postMessage('navButton', 'playToggle');
|
|
|
|
UpdateFullScreenNavigate();
|
2020-09-04 18:02:20 +00:00
|
|
|
|
|
|
|
return false;
|
2020-09-17 19:37:54 +00:00
|
|
|
};
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
// read and dispatch an event from the iframe
|
2020-09-17 21:34:38 +00:00
|
|
|
const message = (data) => {
|
2020-09-30 03:25:28 +00:00
|
|
|
const playButton = document.getElementById('NavigatePlay');
|
2020-09-17 19:37:54 +00:00
|
|
|
// dispatch event
|
|
|
|
if (!data.type) return;
|
|
|
|
switch (data.type) {
|
|
|
|
case 'loaded':
|
2020-10-29 21:44:28 +00:00
|
|
|
LastUpdate = new Date();
|
2020-09-17 19:37:54 +00:00
|
|
|
AssignLastUpdate();
|
|
|
|
break;
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
case 'weatherParameters':
|
|
|
|
populateWeatherParameters(data.message);
|
|
|
|
break;
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
case 'isPlaying':
|
2020-09-17 21:34:38 +00:00
|
|
|
localStorage.setItem('TwcPlay', navigation.isPlaying());
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 21:34:38 +00:00
|
|
|
if (navigation.isPlaying()) {
|
2020-10-29 21:44:28 +00:00
|
|
|
noSleep(true);
|
2020-09-30 03:25:28 +00:00
|
|
|
playButton.title = 'Pause';
|
|
|
|
playButton.src = 'images/nav/ic_pause_white_24dp_1x.png';
|
2020-09-04 18:02:20 +00:00
|
|
|
} else {
|
2020-10-29 21:44:28 +00:00
|
|
|
noSleep(false);
|
2020-09-30 03:25:28 +00:00
|
|
|
playButton.title = 'Play';
|
|
|
|
playButton.src = 'images/nav/ic_play_arrow_white_24dp_1x.png';
|
2020-09-04 18:02:20 +00:00
|
|
|
}
|
2020-09-17 19:37:54 +00:00
|
|
|
break;
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
default:
|
|
|
|
console.error(`Unknown event '${data.eventType}`);
|
|
|
|
}
|
|
|
|
};
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
// post a message to the iframe
|
2020-10-29 21:44:28 +00:00
|
|
|
const postMessage = (type, myMessage = {}) => {
|
|
|
|
navigation.message({ type, message: myMessage });
|
2020-09-17 19:37:54 +00:00
|
|
|
};
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
const StartAutoRefreshTimer = () => {
|
|
|
|
// Ensure that any previous timer has already stopped.
|
|
|
|
// check if timer is running
|
2020-10-29 21:44:28 +00:00
|
|
|
if (AutoRefreshIntervalId) return;
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
// Reset the time elapsed.
|
2020-10-29 21:44:28 +00:00
|
|
|
AutoRefreshCountMs = 0;
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
const AutoRefreshTimer = () => {
|
|
|
|
// Increment the total time elapsed.
|
2020-10-29 21:44:28 +00:00
|
|
|
AutoRefreshCountMs += AutoRefreshIntervalMs;
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
// Display the count down.
|
2020-10-29 21:44:28 +00:00
|
|
|
let RemainingMs = (AutoRefreshTotalIntervalMs - AutoRefreshCountMs);
|
2020-09-17 19:37:54 +00:00
|
|
|
if (RemainingMs < 0) {
|
|
|
|
RemainingMs = 0;
|
|
|
|
}
|
|
|
|
const dt = new Date(RemainingMs);
|
2020-10-29 21:44:28 +00:00
|
|
|
document.getElementById('spanRefreshCountDown').innerHTML = `${dt.getMinutes() < 10 ? `0${dt.getMinutes()}` : dt.getMinutes()}:${dt.getSeconds() < 10 ? `0${dt.getSeconds()}` : dt.getSeconds()}`;
|
2020-09-17 19:37:54 +00:00
|
|
|
|
|
|
|
// Time has elapsed.
|
2022-11-14 21:10:07 +00:00
|
|
|
if (AutoRefreshCountMs >= AutoRefreshTotalIntervalMs && !navigation.isPlaying()) LoadTwcData();
|
2020-09-17 19:37:54 +00:00
|
|
|
};
|
2020-10-29 21:44:28 +00:00
|
|
|
AutoRefreshIntervalId = window.setInterval(AutoRefreshTimer, AutoRefreshIntervalMs);
|
2020-09-17 19:37:54 +00:00
|
|
|
AutoRefreshTimer();
|
|
|
|
};
|
|
|
|
const StopAutoRefreshTimer = () => {
|
2020-10-29 21:44:28 +00:00
|
|
|
if (AutoRefreshIntervalId) {
|
|
|
|
window.clearInterval(AutoRefreshIntervalId);
|
2020-09-30 03:25:28 +00:00
|
|
|
document.getElementById('spanRefreshCountDown').innerHTML = '--:--';
|
2020-10-29 21:44:28 +00:00
|
|
|
AutoRefreshIntervalId = null;
|
2020-09-17 19:37:54 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
const btnGetGpsClick = async () => {
|
2020-09-17 19:37:54 +00:00
|
|
|
if (!navigator.geolocation) return;
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
const position = await (() => new Promise((resolve) => {
|
|
|
|
navigator.geolocation.getCurrentPosition(resolve);
|
|
|
|
}))();
|
|
|
|
const { latitude, longitude } = position.coords;
|
2020-09-17 19:37:54 +00:00
|
|
|
|
|
|
|
let data;
|
|
|
|
try {
|
2020-10-16 20:16:46 +00:00
|
|
|
data = await utils.fetch.json('https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode', {
|
2020-09-17 19:37:54 +00:00
|
|
|
data: {
|
2020-10-29 21:44:28 +00:00
|
|
|
location: `${longitude},${latitude}`,
|
2020-09-17 19:37:54 +00:00
|
|
|
distance: 1000, // Find location up to 1 KM.
|
|
|
|
f: 'json',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
console.error('Unable to fetch reverse geocode');
|
2020-09-23 16:49:15 +00:00
|
|
|
console.error(e.status, e.responseJSONe);
|
2020-09-04 18:02:20 +00:00
|
|
|
}
|
2020-09-17 19:37:54 +00:00
|
|
|
const ZipCode = data.address.Postal;
|
2020-10-29 21:44:28 +00:00
|
|
|
const { City } = data.address;
|
2020-09-17 19:37:54 +00:00
|
|
|
const State = states.getTwoDigitCode(data.address.Region);
|
|
|
|
const Country = data.address.CountryCode;
|
|
|
|
const TwcQuery = `${ZipCode}, ${City}, ${State}, ${Country}`;
|
|
|
|
|
2020-09-30 03:25:28 +00:00
|
|
|
const txtAddress = document.getElementById('txtAddress');
|
|
|
|
txtAddress.value = TwcQuery;
|
|
|
|
txtAddress.blur();
|
|
|
|
txtAddress.focus();
|
2020-09-17 19:37:54 +00:00
|
|
|
|
|
|
|
// Save the query
|
|
|
|
localStorage.setItem('TwcQuery', TwcQuery);
|
|
|
|
};
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
const populateWeatherParameters = (weatherParameters) => {
|
2020-10-29 21:44:28 +00:00
|
|
|
document.getElementById('spanCity').innerHTML = `${weatherParameters.city}, `;
|
2020-09-30 03:25:28 +00:00
|
|
|
document.getElementById('spanState').innerHTML = weatherParameters.state;
|
|
|
|
document.getElementById('spanStationId').innerHTML = weatherParameters.stationId;
|
|
|
|
document.getElementById('spanRadarId').innerHTML = weatherParameters.radarId;
|
|
|
|
document.getElementById('spanZoneId').innerHTML = weatherParameters.zoneId;
|
2020-09-17 19:37:54 +00:00
|
|
|
};
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-10-29 21:44:28 +00:00
|
|
|
// track state of nosleep locally to avoid a null case error
|
|
|
|
// when nosleep.disable is called without first calling .enable
|
2020-09-25 02:29:03 +00:00
|
|
|
let wakeLock = false;
|
2020-10-29 21:44:28 +00:00
|
|
|
const noSleep = (enable = false) => {
|
|
|
|
// get a nosleep controller
|
|
|
|
if (!noSleep.controller) noSleep.controller = new NoSleep();
|
|
|
|
// don't call anything if the states match
|
|
|
|
if (wakeLock === enable) return false;
|
|
|
|
// store the value
|
|
|
|
wakeLock = enable;
|
|
|
|
// call the function
|
|
|
|
if (enable) return noSleep.controller.enable();
|
|
|
|
return noSleep.controller.disable();
|
2020-09-25 02:29:03 +00:00
|
|
|
};
|
|
|
|
|
2022-11-14 21:10:07 +00:00
|
|
|
const refreshCheck = () => {
|
|
|
|
// Time has elapsed.
|
|
|
|
if (AutoRefreshCountMs >= AutoRefreshTotalIntervalMs) {
|
|
|
|
LoadTwcData();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2020-09-17 19:37:54 +00:00
|
|
|
return {
|
|
|
|
init,
|
2020-09-17 21:34:38 +00:00
|
|
|
message,
|
2022-11-14 21:10:07 +00:00
|
|
|
refreshCheck,
|
2020-09-04 18:02:20 +00:00
|
|
|
};
|
2020-10-29 21:44:28 +00:00
|
|
|
})();
|