summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <cb15g11@soton.ac.uk>2014-09-06 12:53:44 +0100
committerChristopher Baines <cb15g11@soton.ac.uk>2014-09-06 12:53:44 +0100
commit0c8f13133109b7f954f145c4a22cd332ed5e4b35 (patch)
tree8e08444ed9270b59ce98e45839c3ac2748871164
parent312dadcac1b6580f9c57f9b1165811eb994120a5 (diff)
downloadleaflet-soton-0c8f13133109b7f954f145c4a22cd332ed5e4b35.tar
leaflet-soton-0c8f13133109b7f954f145c4a22cd332ed5e4b35.tar.gz
Periodically refresh workstation data
-rw-r--r--src/leaflet-soton.js31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/leaflet-soton.js b/src/leaflet-soton.js
index 009df98..a90c163 100644
--- a/src/leaflet-soton.js
+++ b/src/leaflet-soton.js
@@ -8,6 +8,9 @@
data: null,
_dataFetchInProgress: false,
workstationData: null,
+ updateWorkstationData: true,
+ _updatingWorkstationData: false,
+ workstationDataUpdateTime: 30000,
_workstationDataFetchInProgress: false,
getData: function(callback) {
@@ -36,12 +39,22 @@
}
},
getWorkstationData: function(callback) {
- if (this.workstationData !== null) { // TODO: Some kind of periodic refresh
+ if (this.workstationData !== null) {
callback(this.workstationData);
} else {
this.addOneTimeEventListener("workstationData", callback);
+
if (!this._workstationDataFetchInProgress) {
- this._workstationDataFetchInProgress = true;
+ if (!this._updatingWorkstationData) {
+ LS.on("workstationData", function(data) {
+ setTimeout(function() {
+ LS._workstationdatafetchinprogress = true;
+ LS._updateWorkstationData();
+ }, LS.workstationDataUpdateTime);
+ });
+ }
+
+ this._workstationdatafetchinprogress = true;
this._updateWorkstationData();
}
}
@@ -201,13 +214,15 @@ SELECT * WHERE {\
url: 'http://sparql.data.southampton.ac.uk/?query=' + encodeURIComponent(query)
},
function(data) {
- LS.workstationData = {};
-
- if (data === null) {
+ // Only report no data if fetching data failed, and there
+ // is no local data
+ if (data === null && LS.workstationData === null) {
LS.fire("workstationData", null);
return;
}
+ LS.workstationData = {};
+
data.results.bindings.forEach(function(result) {
var workstation = result.uri.value;
var id = "#" + workstation.split('/').slice(-1)[0];
@@ -714,6 +729,12 @@ SELECT * WHERE {\
var workstationMarkerLayer;
if (options.workstations) {
workstationMarkerLayer = LS.workstationLayer();
+
+ LS.on("workstationData", function(data) {
+ map.removeLayer(workstationMarkerLayer);
+ workstationMarkerLayer = LS.workstationLayer();
+ map.addLayer(workstationMarkerLayer);
+ });
}
if (options.indoor) {