From 17f77c99bdfa5267f3bdcef90c04923ffb68554e Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 24 Aug 2021 22:16:45 -0400 Subject: [PATCH] fix api error with undefined cities (somehow) --- webroot/js/data-manager.js | 1 - webroot/js/location.js | 9 ++++++--- webroot/js/slides-loop.js | 2 ++ webroot/js/weather.js | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/webroot/js/data-manager.js b/webroot/js/data-manager.js index 9d1a506..f9a34aa 100644 --- a/webroot/js/data-manager.js +++ b/webroot/js/data-manager.js @@ -54,7 +54,6 @@ function DataManager(pointSearch){ locList.push({lat: latgeo, long:longeo, distance:dist, stationUrl:feature.stationId[i]}); } } - if (locList.length===0) { $this.trigger('allinit'); return diff --git a/webroot/js/location.js b/webroot/js/location.js index 9c2e6de..f2b0b05 100644 --- a/webroot/js/location.js +++ b/webroot/js/location.js @@ -55,10 +55,11 @@ function Location() { // onReady, onRefresh, onAllComplete // ajax the latest observation $.getJSON(url, function(data) { + if (data['v3-location-point'] != null) { _observations[0] = json = data['v3-wx-observations-current']; _observations[0].latitude = loclat; _observations[0].longitude = loclong; - _observations[0].cityname = data['v3-location-point'].location.city; + _observations[0].cityname = data['v3-location-point'].location.displayName; $this.trigger('refresh'); // the following block only runs on init @@ -71,14 +72,16 @@ function Location() { // onReady, onRefresh, onAllComplete that.city = data['v3-location-point'].location.city; - $this.trigger('init'); + $this.trigger('init'); } // set the expiration date/time _observations[0].xdate = dateFns.addMinutes(json.lastBuildDate, json.ttl); setTimeout(checkRefresh, getRandom(5000, 10000)); - + } else { + $this.trigger('init'); + } }); } diff --git a/webroot/js/slides-loop.js b/webroot/js/slides-loop.js index 8bf4813..dbde83f 100644 --- a/webroot/js/slides-loop.js +++ b/webroot/js/slides-loop.js @@ -1211,9 +1211,11 @@ RADAR < MAIN CITY < CITY 1 < CITY 2 airport='AIRPORTS'; for (var location of dataMan.locations) { + if (location.city !== undefined) { city = location.city; cities += arrow+'' + city + ''; } + } $('#info-slides-header .hscroller').append(cities + arrow + (radar + arrow + airport + arrow + health + cities + arrow).repeat(4)); } diff --git a/webroot/js/weather.js b/webroot/js/weather.js index 685951c..39bb883 100644 --- a/webroot/js/weather.js +++ b/webroot/js/weather.js @@ -52,7 +52,7 @@ function WeatherManager() { var queryString = window.location.search; if (queryString) { - $.getJSON("https://api.weather.com/v3/location/search?query="+queryString.split("?")[1]+"&language=en-US&format=json&apiKey=" + process.env.API_KEY, function(data) { + $.getJSON("https://api.weather.com/v3/location/search?query="+queryString.split("?")[1]+"&language=en-US&format=json&apiKey=" + api_key, function(data) { dataMan = createDataManager( data.location.latitude[0]+','+data.location.longitude[0] ); mainloc = data.location.city[0] });