Skip to content

Commit

Permalink
Update script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jwasilgeo authored Jun 4, 2024
1 parent d041fb3 commit 29a8af3
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions iss-view/script.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
require([
'dojo/request/script',

'esri/Basemap',
'esri/geometry/Circle',
'esri/layers/WebTileLayer',
Expand All @@ -12,7 +10,6 @@ require([

'dojo/domReady!'
], function (
dojoRequestScript,
Basemap, Circle, WebTileLayer, Map, QueryTask, Query, SceneView, BasemapToggle
) {
var previousCoordinates;
Expand All @@ -23,8 +20,7 @@ require([
var creditsNode = document.getElementById('creditsNode');
var infoMessageNode = document.getElementById('infoMessageNode');

// var issLocationUrl = 'http://api.open-notify.org/iss-now.json';
var issLocationUrl = 'https://open-notify-api.herokuapp.com/iss-now.json';
var issLocationUrl = 'https://api.wheretheiss.at/v1/satellites/25544';

// var firstUpdateDelay = 3000;
var firstCameraViewChangeDuration = 3000;
Expand Down Expand Up @@ -143,24 +139,23 @@ require([
}

function establishIssLocation() {
dojoRequestScript.get(issLocationUrl, {
jsonp: 'callback'
}).then(establishIssLocationSuccess, establishIssLocationError);
fetch(issLocationUrl).then(establishIssLocationSuccess, establishIssLocationError);
}

function establishIssLocationSuccess(res) {
async function establishIssLocationSuccess(response) {
// get two initial locations to be able to determine the heading
if (res.message === 'success') {
if (response.ok) {
const res = await response.json();
if (!previousCoordinates) {
previousCoordinates = {
latitude: res.iss_position.latitude,
longitude: res.iss_position.longitude
latitude: res.latitude,
longitude: res.longitude
};
setTimeout(establishIssLocation, 1000);
} else {
updateCameraPosition({
latitude: res.iss_position.latitude,
longitude: res.iss_position.longitude
latitude: res.latitude,
longitude: res.longitude
}, firstCameraViewChangeDuration)
.then(function () {
getCurrentIssLocation();
Expand Down Expand Up @@ -197,9 +192,7 @@ require([
}

function getCurrentIssLocation() {
dojoRequestScript.get(issLocationUrl, {
jsonp: 'callback'
}).then(getCurrentIssLocationSuccess, getCurrentIssLocationError);
fetch(issLocationUrl).then(getCurrentIssLocationSuccess, getCurrentIssLocationError)
}

function getCurrentIssLocationSuccess(res) {
Expand All @@ -208,8 +201,8 @@ require([
infoMessageNode.style.display = 'none';

updateCameraPosition({
latitude: res.iss_position.latitude,
longitude: res.iss_position.longitude
latitude: res.latitude,
longitude: res.longitude
}, cameraViewChangeDuration);

// update the location after a delay (continue indefinitely from here)
Expand Down

0 comments on commit 29a8af3

Please sign in to comment.