ws4kp-linhanced/server/scripts/index.mjs

602 lines
19 KiB
JavaScript
Raw Normal View History

2022-11-22 16:19:10 -06:00
import { json } from './modules/utils/fetch.mjs';
2022-12-06 16:14:56 -06:00
import noSleep from './modules/utils/nosleep.mjs';
import {
message as navMessage, isPlaying, resize, resetStatuses, latLonReceived, isIOS,
2022-12-06 16:14:56 -06:00
} from './modules/navigation.mjs';
2022-12-12 14:47:53 -06:00
import { round2 } from './modules/utils/units.mjs';
import { registerHiddenSetting } from './modules/share.mjs';
import settings from './modules/settings.mjs';
2026-04-08 12:49:21 -04:00
import './modules/utils/theme.mjs';
import './modules/latestobservations.mjs';
import './modules/groundview.mjs';
import './modules/hazard-list.mjs';
import AutoComplete from './modules/autocomplete.mjs';
import { loadAllData } from './modules/utils/data-loader.mjs';
import { debugFlag } from './modules/utils/debug.mjs';
import { parseQueryString } from './modules/utils/setting.mjs';
2022-11-22 10:45:17 -06:00
document.addEventListener('DOMContentLoaded', () => {
init();
2025-03-24 22:52:32 -05:00
getCustomCode();
2022-11-22 10:45:17 -06: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',
];
2022-12-08 15:05:51 -06:00
const category = categories.join(',');
const TXT_ADDRESS_SELECTOR = '#txtLocation';
2023-01-06 14:39:39 -06:00
const TOGGLE_FULL_SCREEN_SELECTOR = '#ToggleFullScreen';
const BNT_GET_GPS_SELECTOR = '#btnGetGps';
const LOCATION_STORAGE_KEY = 'latLonLocation';
2022-11-22 10:45:17 -06:00
const init = async () => {
// Load core data first - app cannot function without it
try {
await loadAllData(typeof OVERRIDES !== 'undefined' && OVERRIDES.VERSION ? OVERRIDES.VERSION : '');
} catch (error) {
console.error('Failed to load core application data:', error);
// Show error message to user and halt initialization
document.body.innerHTML = `
<div>
<h2>Unable to load Weather Data</h2>
<p>The application cannot start because core data failed to load.</p>
<p>Please check your connection and try refreshing.</p>
</div>
`;
return; // Stop initialization
}
2023-01-06 14:39:39 -06:00
document.querySelector(TXT_ADDRESS_SELECTOR).addEventListener('focus', (e) => {
2022-11-22 10:45:17 -06:00
e.target.select();
});
2023-01-06 14:39:39 -06:00
document.querySelector('#NavigateMenu').addEventListener('click', btnNavigateMenuClick);
document.querySelector('#NavigateRefresh').addEventListener('click', btnNavigateRefreshClick);
document.querySelector('#NavigateNext').addEventListener('click', btnNavigateNextClick);
document.querySelector('#NavigatePrevious').addEventListener('click', btnNavigatePreviousClick);
document.querySelector('#NavigatePlay').addEventListener('click', btnNavigatePlayClick);
2025-05-29 17:03:50 -05:00
document.querySelector('#ToggleScanlines').addEventListener('click', btnNavigateToggleScanlines);
// Hide fullscreen button on iOS since it doesn't support true fullscreen
const fullscreenButton = document.querySelector(TOGGLE_FULL_SCREEN_SELECTOR);
if (isIOS()) {
fullscreenButton.style.display = 'none';
} else {
fullscreenButton.addEventListener('click', btnFullScreenClick);
}
2023-01-06 14:39:39 -06:00
const btnGetGps = document.querySelector(BNT_GET_GPS_SELECTOR);
2022-12-13 15:43:06 -06:00
btnGetGps.addEventListener('click', btnGetGpsClick);
if (!navigator.geolocation) btnGetGps.style.display = 'none';
2022-11-22 10:45:17 -06:00
document.querySelector('#divTwc').addEventListener('mousemove', () => {
2022-12-12 14:47:53 -06:00
if (document.fullscreenElement) updateFullScreenNavigate();
2022-11-22 10:45:17 -06:00
});
2025-05-13 13:57:50 -05:00
document.querySelector('#btnGetLatLng').addEventListener('click', () => autoComplete.directFormSubmit());
2022-12-21 16:20:31 -06:00
2022-11-22 10:45:17 -06:00
document.addEventListener('keydown', documentKeydown);
document.addEventListener('touchmove', (e) => { if (document.fullscreenElement) e.preventDefault(); });
2022-11-22 10:45:17 -06:00
const autoComplete = new AutoComplete(document.querySelector(TXT_ADDRESS_SELECTOR), {
2022-11-22 10:45:17 -06:00
serviceUrl: 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest',
deferRequestBy: 300,
paramName: 'text',
params: {
f: 'json',
2022-12-08 15:05:51 -06:00
category,
2022-11-22 10:45:17 -06:00
maxSuggestions: 10,
},
dataType: 'json',
transformResult: (response) => ({
2022-12-12 14:47:53 -06:00
suggestions: response.suggestions.map((i) => ({
value: i.text,
data: i.magicKey,
})),
}),
2022-11-22 10:45:17 -06:00
minChars: 3,
showNoSuggestionNotice: true,
noSuggestionNotice: 'No results found. Please try a different search string.',
onSelect(suggestion) { autocompleteOnSelect(suggestion); },
2022-11-22 10:45:17 -06:00
width: 490,
});
2025-05-21 13:49:49 -05:00
window.autoComplete = autoComplete;
2022-11-22 10:45:17 -06:00
2024-04-11 23:42:51 -05:00
// attempt to parse the url parameters
const parsedParameters = parseQueryString();
const loadFromParsed = !!parsedParameters.latLon;
2024-04-11 23:42:51 -05:00
// Auto load the parsed parameters and fall back to the previous query
const query = parsedParameters.latLonQuery ?? localStorage.getItem('latLonQuery');
const latLon = parsedParameters.latLon ?? localStorage.getItem('latLon');
const fromGPS = localStorage.getItem('latLonFromGPS') && !loadFromParsed;
if (parsedParameters.latLonQuery && !parsedParameters.latLon) {
const txtAddress = document.querySelector(TXT_ADDRESS_SELECTOR);
txtAddress.value = parsedParameters.latLonQuery;
const locationResult = await geocodeLatLonQuery(parsedParameters.latLonQuery);
if (locationResult?.geometry) {
doRedirectToGeometry(locationResult.geometry, undefined, locationResult.location);
}
} else if (latLon && !fromGPS) {
// update in-page search box if using cached data, or parsed parameter
if ((query && !loadFromParsed) || (parsedParameters.latLonQuery && loadFromParsed)) {
const txtAddress = document.querySelector(TXT_ADDRESS_SELECTOR);
txtAddress.value = query;
}
// use lat-long lookup if that's all that was provided in the query string
if (loadFromParsed && parsedParameters.latLon && !parsedParameters.latLonQuery) {
const { lat, lon } = JSON.parse(latLon);
getForecastFromLatLon(lat, lon, true);
} else {
// otherwise use pre-stored data
loadData(JSON.parse(latLon));
}
2022-11-22 10:45:17 -06:00
}
2022-12-13 15:43:06 -06:00
if (fromGPS) {
btnGetGpsClick();
}
2022-11-22 10:45:17 -06:00
// Handle kiosk mode initialization
const urlKioskCheckbox = parsedParameters['settings-kiosk-checkbox'];
// If kiosk=false is specified, disable kiosk mode and clear any stored value
if (urlKioskCheckbox === 'false') {
settings.kiosk.value = false;
// Clear stored value by using conditional storage with false
settings.kiosk.conditionalStoreToLocalStorage(false, false);
} else if (urlKioskCheckbox === 'true') {
// if kiosk mode was set via the query string, enable it
settings.kiosk.value = true;
}
// Auto-play logic: also play immediately if kiosk mode is enabled
const play = settings.kiosk.value || urlKioskCheckbox === 'true' ? 'true' : localStorage.getItem('play');
2022-12-14 16:28:33 -06:00
if (play === null || play === 'true') postMessage('navButton', 'play');
2022-11-22 10:45:17 -06:00
2023-01-06 14:39:39 -06:00
document.querySelector('#btnClearQuery').addEventListener('click', () => {
document.querySelector('#spanCity').innerHTML = '';
document.querySelector('#spanState').innerHTML = '';
document.querySelector('#spanStationId').innerHTML = '';
document.querySelector('#spanRadarId').innerHTML = '';
document.querySelector('#spanZoneId').innerHTML = '';
document.querySelector('#spanOfficeId').innerHTML = '';
document.querySelector('#spanGridPoint').innerHTML = '';
2022-11-22 10:45:17 -06:00
2022-12-12 14:47:53 -06:00
localStorage.removeItem('play');
2022-11-22 10:45:17 -06:00
postMessage('navButton', 'play');
2022-12-12 14:47:53 -06:00
localStorage.removeItem('latLonQuery');
2022-12-13 15:43:06 -06:00
localStorage.removeItem('latLon');
localStorage.removeItem(LOCATION_STORAGE_KEY);
2022-12-13 15:43:06 -06:00
localStorage.removeItem('latLonFromGPS');
2023-01-06 14:39:39 -06:00
document.querySelector(BNT_GET_GPS_SELECTOR).classList.remove('active');
2022-11-22 10:45:17 -06:00
});
// swipe functionality
2023-01-06 14:39:39 -06:00
document.querySelector('#container').addEventListener('swiped-left', () => swipeCallBack('left'));
document.querySelector('#container').addEventListener('swiped-right', () => swipeCallBack('right'));
// register hidden settings for search and location query
registerHiddenSetting('latLonQuery', () => localStorage.getItem('latLonQuery'));
registerHiddenSetting('latLon', () => localStorage.getItem('latLon'));
registerHiddenSetting('latLonLocation', () => localStorage.getItem(LOCATION_STORAGE_KEY));
};
const normalizeArcGisLocation = (rawLocation = {}, fallbackLabel = '') => {
const attributes = rawLocation.attributes ?? rawLocation.address ?? {};
const label = fallbackLabel || rawLocation.name || attributes.LongLabel || attributes.Match_addr || '';
const labelParts = label.split(',').map((part) => part.trim()).filter(Boolean);
const fallbackCountryCode = labelParts[labelParts.length - 1] === 'USA' ? 'USA' : null;
const fallbackCountry = fallbackCountryCode ? 'United States' : null;
const fallbackState = labelParts.length >= 2 && /^[A-Z]{2,3}$/.test(labelParts[labelParts.length - 2]) ? labelParts[labelParts.length - 2] : '';
const fallbackCity = labelParts[0] ?? rawLocation.name ?? '';
const countryCode = attributes.CountryCode
?? attributes.countryCode
?? attributes.country_code
?? fallbackCountryCode
?? null;
const country = attributes.CntryName
?? attributes.Country
?? attributes.countryName
?? attributes.country
?? fallbackCountry
?? null;
const state = attributes.RegionAbbr
?? attributes.Region
?? attributes.Subregion
?? attributes.region
?? fallbackState;
const city = attributes.City
?? attributes.CityName
?? attributes.PlaceName
?? attributes.MetroArea
?? rawLocation.name
?? fallbackCity;
return {
city,
state,
country,
countryCode,
label,
};
2022-11-22 10:45:17 -06:00
};
const geocodeLatLonQuery = async (query) => {
try {
const data = await json('https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find', {
data: {
text: query,
f: 'json',
},
});
const loc = data.locations?.[0];
if (loc) {
return {
geometry: loc.feature.geometry,
location: normalizeArcGisLocation(loc, query),
};
}
return null;
} catch (error) {
console.error('Geocoding failed:', error);
return null;
}
};
const reverseGeocodeLatLon = async (latitude, longitude) => {
try {
const data = await json('https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode', {
data: {
location: `${longitude},${latitude}`,
f: 'json',
},
});
if (!data) return null;
const location = normalizeArcGisLocation(data, `${round2(latitude, 4)}, ${round2(longitude, 4)}`);
return {
location,
label: location.label,
};
} catch (error) {
console.error('Reverse geocoding failed:', error);
return null;
}
};
const autocompleteOnSelect = async (suggestion) => {
// Note: it's fine that this uses json instead of safeJson since it's infrequent and user-initiated
const data = await json('https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find', {
data: {
text: suggestion.value,
magicKey: suggestion.data,
f: 'json',
},
});
const loc = data.locations[0];
if (loc) {
localStorage.removeItem('latLonFromGPS');
2023-01-06 14:39:39 -06:00
document.querySelector(BNT_GET_GPS_SELECTOR).classList.remove('active');
doRedirectToGeometry(loc.feature.geometry, undefined, normalizeArcGisLocation(loc, suggestion.value));
2022-11-22 10:45:17 -06:00
} else {
console.error('An unexpected error occurred. Please try a different search string.');
2022-11-22 10:45:17 -06:00
}
};
const doRedirectToGeometry = (geom, haveDataCallback, locationMetadata) => {
2022-12-12 14:47:53 -06:00
const latLon = { lat: round2(geom.y, 4), lon: round2(geom.x, 4) };
2022-11-22 10:45:17 -06:00
// Save the query
const query = locationMetadata?.label ?? document.querySelector(TXT_ADDRESS_SELECTOR).value;
localStorage.setItem('latLonQuery', query);
2022-12-13 15:43:06 -06:00
localStorage.setItem('latLon', JSON.stringify(latLon));
if (locationMetadata) {
localStorage.setItem(LOCATION_STORAGE_KEY, JSON.stringify(locationMetadata));
}
// get the data
2022-12-13 15:43:06 -06:00
loadData(latLon, haveDataCallback);
2022-11-22 10:45:17 -06:00
};
const btnFullScreenClick = () => {
2023-01-06 14:39:39 -06:00
if (document.fullscreenElement) {
2022-12-12 14:47:53 -06:00
exitFullscreen();
2023-01-06 14:39:39 -06:00
} else {
enterFullScreen();
2022-11-22 10:45:17 -06:00
}
2022-12-06 16:14:56 -06:00
if (isPlaying()) {
2022-11-22 10:45:17 -06:00
noSleep(true);
} else {
noSleep(false);
}
2022-12-12 14:47:53 -06:00
updateFullScreenNavigate();
2022-11-22 10:45:17 -06:00
return false;
};
// This is async because modern browsers return a Promise from requestFullscreen
const enterFullScreen = async () => {
2023-01-06 14:39:39 -06:00
const element = document.querySelector('#divTwc');
2022-11-22 10:45:17 -06:00
// Supports most browsers and their versions.
const requestMethod = element.requestFullscreen || element.webkitRequestFullscreen || element.mozRequestFullscreen || element.msRequestFullscreen;
2022-11-22 10:45:17 -06:00
if (requestMethod) {
try {
// Native full screen with options for optimal display
await requestMethod.call(element, {
navigationUI: 'hide',
allowsInlineMediaPlayback: true,
});
if (debugFlag('fullscreen')) {
setTimeout(() => {
console.log(`🖥️ Fullscreen engaged. window=${window.innerWidth}x${window.innerHeight} fullscreenElement=${!!document.fullscreenElement}`);
}, 150);
}
} catch (error) {
console.error('❌ Fullscreen request failed:', error);
}
2022-11-22 10:45:17 -06:00
} else {
// iOS doesn't support FullScreen API.
window.scrollTo(0, 0);
resize(true); // Force resize for iOS
2022-11-22 10:45:17 -06:00
}
2022-12-12 14:47:53 -06:00
updateFullScreenNavigate();
2022-11-22 10:45:17 -06:00
2022-12-07 15:36:02 -06:00
// change hover text and image
2023-01-06 14:39:39 -06:00
const img = document.querySelector(TOGGLE_FULL_SCREEN_SELECTOR);
if (img && img.style.display !== 'none') {
img.src = 'images/nav/ic_fullscreen_exit_white_24dp_2x.png';
img.title = 'Exit fullscreen';
}
2022-11-22 10:45:17 -06:00
};
2022-12-12 14:47:53 -06:00
const exitFullscreen = () => {
2022-11-22 10:45:17 -06:00
// exit full-screen
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();
2022-11-22 10:45:17 -06:00
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
// Note: resize will be called by fullscreenchange event listener
exitFullScreenVisibilityChanges();
};
const exitFullScreenVisibilityChanges = () => {
2022-12-07 15:36:02 -06:00
// change hover text and image
2023-01-06 14:39:39 -06:00
const img = document.querySelector(TOGGLE_FULL_SCREEN_SELECTOR);
if (img && img.style.display !== 'none') {
img.src = 'images/nav/ic_fullscreen_white_24dp_2x.png';
img.title = 'Enter fullscreen';
}
document.querySelector('#divTwc').classList.remove('no-cursor');
const divTwcBottom = document.querySelector('#divTwcBottom');
divTwcBottom.classList.remove('hidden');
divTwcBottom.classList.add('visible');
2022-11-22 10:45:17 -06:00
};
const btnNavigateMenuClick = () => {
postMessage('navButton', 'menu');
return false;
};
2022-12-13 15:43:06 -06:00
const loadData = (_latLon, haveDataCallback) => {
2022-11-22 10:45:17 -06:00
// if latlon is provided store it locally
2022-12-12 14:47:53 -06:00
if (_latLon) loadData.latLon = _latLon;
2022-11-22 10:45:17 -06:00
// get the data
2022-12-12 14:47:53 -06:00
const { latLon } = loadData;
2022-11-22 10:45:17 -06:00
// if there's no data stop
if (!latLon) return;
2023-01-06 14:39:39 -06:00
document.querySelector(TXT_ADDRESS_SELECTOR).blur();
2022-12-13 15:43:06 -06:00
latLonReceived(latLon, haveDataCallback);
2022-11-22 10:45:17 -06:00
};
const swipeCallBack = (direction) => {
switch (direction) {
2024-10-21 19:21:05 -05:00
case 'left':
btnNavigateNextClick();
break;
case 'right':
default:
btnNavigatePreviousClick();
break;
2022-11-22 10:45:17 -06:00
}
};
const btnNavigateRefreshClick = () => {
2022-12-06 16:14:56 -06:00
resetStatuses();
2022-12-12 14:47:53 -06:00
loadData();
2022-11-22 10:45:17 -06:00
return false;
};
const btnNavigateNextClick = () => {
postMessage('navButton', 'next');
return false;
};
const btnNavigatePreviousClick = () => {
postMessage('navButton', 'previous');
return false;
};
2022-12-12 14:47:53 -06:00
let navigateFadeIntervalId = null;
2022-11-22 10:45:17 -06:00
2022-12-12 14:47:53 -06:00
const updateFullScreenNavigate = () => {
2022-11-22 10:45:17 -06:00
document.activeElement.blur();
2023-01-06 14:39:39 -06:00
const divTwcBottom = document.querySelector('#divTwcBottom');
divTwcBottom.classList.remove('hidden');
divTwcBottom.classList.add('visible');
document.querySelector('#divTwc').classList.remove('no-cursor');
2022-11-22 10:45:17 -06:00
2022-12-12 14:47:53 -06:00
if (navigateFadeIntervalId) {
clearTimeout(navigateFadeIntervalId);
navigateFadeIntervalId = null;
2022-11-22 10:45:17 -06:00
}
2022-12-12 14:47:53 -06:00
navigateFadeIntervalId = setTimeout(() => {
2022-11-22 10:45:17 -06:00
if (document.fullscreenElement) {
2023-01-06 14:39:39 -06:00
divTwcBottom.classList.remove('visible');
divTwcBottom.classList.add('hidden');
document.querySelector('#divTwc').classList.add('no-cursor');
2022-11-22 10:45:17 -06:00
}
}, 2000);
};
const documentKeydown = (e) => {
2022-12-19 11:48:59 -06:00
const { key } = e;
2022-11-22 10:45:17 -06:00
// Handle Ctrl+K to exit kiosk mode (even when other modifiers would normally be ignored)
if (e.ctrlKey && (key === 'k' || key === 'K')) {
e.preventDefault();
if (settings.kiosk?.value) {
settings.kiosk.value = false;
}
return false;
}
// don't trigger on ctrl/alt/shift modified key for other shortcuts
if (e.altKey || e.ctrlKey || e.shiftKey) return false;
2022-11-22 10:45:17 -06:00
if (document.fullscreenElement || document.activeElement === document.body) {
2022-12-19 11:48:59 -06:00
switch (key) {
2024-10-21 19:21:05 -05:00
case ' ': // Space
// don't scroll
e.preventDefault();
btnNavigatePlayClick();
return false;
case 'ArrowRight':
case 'PageDown':
// don't scroll
e.preventDefault();
btnNavigateNextClick();
return false;
case 'ArrowLeft':
case 'PageUp':
// don't scroll
e.preventDefault();
btnNavigatePreviousClick();
return false;
case 'ArrowUp': // Home
e.preventDefault();
btnNavigateMenuClick();
return false;
case '0': // "O" Restart
btnNavigateRefreshClick();
return false;
case 'F':
case 'f':
btnFullScreenClick();
return false;
default:
2022-11-22 10:45:17 -06:00
}
}
return false;
};
const btnNavigatePlayClick = () => {
postMessage('navButton', 'playToggle');
return false;
};
2025-05-29 17:03:50 -05:00
const btnNavigateToggleScanlines = () => {
settings.scanLines.value = !settings.scanLines.value;
return false;
};
2022-11-22 10:45:17 -06:00
// post a message to the iframe
const postMessage = (type, myMessage = {}) => {
2022-12-06 16:14:56 -06:00
navMessage({ type, message: myMessage });
2022-11-22 10:45:17 -06:00
};
2022-12-13 15:43:06 -06:00
const getPosition = async () => new Promise((resolve) => {
navigator.geolocation.getCurrentPosition(resolve);
});
2022-11-22 10:45:17 -06:00
const btnGetGpsClick = async () => {
if (!navigator.geolocation) return;
2023-01-06 14:39:39 -06:00
const btn = document.querySelector(BNT_GET_GPS_SELECTOR);
2022-11-22 10:45:17 -06:00
2022-12-13 15:43:06 -06:00
// toggle first
if (btn.classList.contains('active')) {
btn.classList.remove('active');
localStorage.removeItem('latLonFromGPS');
localStorage.removeItem(LOCATION_STORAGE_KEY);
2022-12-13 15:43:06 -06:00
return;
2022-11-22 10:45:17 -06:00
}
2022-12-13 15:43:06 -06:00
// set gps active
btn.classList.add('active');
2022-11-22 10:45:17 -06:00
2022-12-13 15:43:06 -06:00
// get position
const position = await getPosition();
const { latitude, longitude } = position.coords;
await getForecastFromLatLon(latitude, longitude, true);
2025-05-21 13:49:49 -05:00
};
const getForecastFromLatLon = async (latitude, longitude, fromGps = false) => {
2023-01-06 14:39:39 -06:00
const txtAddress = document.querySelector(TXT_ADDRESS_SELECTOR);
2022-12-13 15:43:06 -06:00
txtAddress.value = `${round2(latitude, 4)}, ${round2(longitude, 4)}`;
const reverseLocation = await reverseGeocodeLatLon(latitude, longitude);
const locationMetadata = reverseLocation?.location;
const query = reverseLocation?.label ?? `${round2(latitude, 4)}, ${round2(longitude, 4)}`;
localStorage.setItem('latLon', JSON.stringify({ lat: latitude, lon: longitude }));
localStorage.setItem('latLonQuery', query);
localStorage.setItem('latLonFromGPS', fromGps);
if (locationMetadata) {
localStorage.setItem(LOCATION_STORAGE_KEY, JSON.stringify(locationMetadata));
}
txtAddress.value = query;
2022-12-13 15:43:06 -06:00
doRedirectToGeometry({ y: latitude, x: longitude });
2022-11-22 10:45:17 -06:00
};
2025-03-24 22:52:32 -05:00
const getCustomCode = async () => {
// fetch the custom file and see if it returns a 200 status
const response = await fetch('scripts/custom.js', { method: 'HEAD' });
if (response.ok) {
// add the script element to the page
const customElem = document.createElement('script');
customElem.src = 'scripts/custom.js';
customElem.type = 'text/javascript';
document.body.append(customElem);
}
};
2025-05-21 13:49:49 -05:00
// expose functions for external use
window.getForecastFromLatLon = getForecastFromLatLon;