summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristopher Baines <cb15g11@soton.ac.uk>2014-09-08 12:37:37 +0100
committerChristopher Baines <cb15g11@soton.ac.uk>2014-09-08 12:37:37 +0100
commit47f0d35c5d1e7b210fce4928d62cdfe0ae5b5961 (patch)
treecc5be51a642c3c31059c3707ed0f97e95a2d404f /src
parent2be0a8015327fe4d76aef6217cbaa7fd9f656cf5 (diff)
downloadleaflet-soton-47f0d35c5d1e7b210fce4928d62cdfe0ae5b5961.tar
leaflet-soton-47f0d35c5d1e7b210fce4928d62cdfe0ae5b5961.tar.gz
Improve fetching of workstation data
Wait at least 30 seconds between requests, even if they fail.
Diffstat (limited to 'src')
-rw-r--r--src/leaflet-soton.js41
1 files changed, 24 insertions, 17 deletions
diff --git a/src/leaflet-soton.js b/src/leaflet-soton.js
index baaafa9..4f08e9f 100644
--- a/src/leaflet-soton.js
+++ b/src/leaflet-soton.js
@@ -5,13 +5,15 @@
dataPath: 'data.json',
imagePath: 'images/',
+
data: null,
_dataFetchInProgress: false,
+
workstationData: null,
- updateWorkstationData: true,
- _updatingWorkstationData: false,
- workstationDataUpdateTime: 30000,
+ updateWorkstationData: true, // regularly poll for workstation data
+ workstationDataUpdateTime: 30000, // time to wait between requests
_workstationDataFetchInProgress: false,
+ _workstationDataFetchTimeout: null,
getData: function(callback) {
if (this.data !== null) {
@@ -44,19 +46,13 @@
} else {
this.addOneTimeEventListener("workstationData", callback);
- if (!this._workstationDataFetchInProgress) {
- if (!this._updatingWorkstationData) {
- LS.on("workstationData", function(data) {
- setTimeout(function() {
- LS._workstationdatafetchinprogress = true;
- LS._updateWorkstationData();
- }, LS.workstationDataUpdateTime);
- });
- }
-
- this._workstationdatafetchinprogress = true;
- this._updateWorkstationData();
+ if (this._workstationDataFetchTimeout !== null || // if a fetch is going to happen
+ this._workstationDataFetchInProgress) { // or a fetch is in progress
+ // data will be fetched, so return
+ return;
}
+
+ this._updateWorkstationData();
}
},
getRoomFor: function(uri) {
@@ -181,6 +177,8 @@
return layer;
},
_updateWorkstationData: function() {
+ this._workstationDataFetchInProgress = true;
+
var query;
if (this.data.workstations.features.length > 10) {
@@ -214,6 +212,8 @@ SELECT * WHERE {\
url: 'http://sparql.data.southampton.ac.uk/?query=' + encodeURIComponent(query)
},
function(data) {
+ LS._workstationDataFetchInProgress = false;
+
// If fetching data has failed
if (data === null) {
// Only report this if there is no existing data
@@ -238,14 +238,21 @@ SELECT * WHERE {\
LS.workstationData[workstation] = obj;
});
- LS._workstationDataFetchInProgress = false;
-
LS.fire("workstationData", LS.workstationData);
}
);
}
});
+ if (LS.updateWorkstationData) {
+ LS.on("workstationData", function(data) {
+ LS._workstationDataFetchTimeout = setTimeout(function() {
+ LS._workstationDataFetchTimeout = null;
+ LS._updateWorkstationData();
+ }, LS.workstationDataUpdateTime);
+ });
+ }
+
var busRouteColours = {};
var icons = {