- Timestamp:
- 03/08/2020 02:15:25 PM (6 years ago)
- Location:
- branches/realtime_VDS/cptms
- Files:
-
- 5 added
- 2 edited
-
images/fetchError.jpg (added)
-
images/fetchError.png (added)
-
images/live.svg (added)
-
images/sad.svg (added)
-
index.html (modified) (3 diffs)
-
js/vdsLayer.js (modified) (1 diff)
-
last_fetch_time.txt (added)
Legend:
- Unmodified
- Added
- Removed
-
branches/realtime_VDS/cptms/index.html
r584 r585 149 149 var kCCTVfile = "data_layers/cctv_locations_D12.gjson"; // CCTV locations 150 150 var kHARfile = "data_layers/har_locations_D12.gjson"; // CMS locations 151 var lastFetchFile = "last_fetch_time.txt"; 152 var fetchInterval = 15; 153 var liveImage = "images/live.svg" 151 154 var iconCMSactive = "images/icon_cms_active.png"; 152 155 var iconCMSidle = "images/icon_cms_idle.png"; … … 200 203 initVDSbutton(); 201 204 initVDSicons(); 205 checkLastFetch(); 202 206 } 203 207 … … 235 239 var harTimer = setInterval(loadAllharMessages, 10000); 236 240 241 var fetchTimer = setInterval(checkLastFetch, 10000); 242 237 243 // Listen for zoom changes and move the vds dots so as to keep a nice 238 244 // visual distance between them appropriate to the zoom factor -
branches/realtime_VDS/cptms/js/vdsLayer.js
r584 r585 160 160 } 161 161 162 //initialize live indicator icon 163 function initLiveIcon(success) { 164 //create new img tags for live and not-live indicators 165 var live = document.createElement('img'); 166 var notLive = document.createElement('img'); 167 live.src ="images/live.svg"; 168 live.width = 50 ; 169 live.height= 40 ; 170 notLive.src ="images/fetchError.jpg"; 171 notLive.width = 50 ; 172 notLive.height= 50 ; 173 // if fetch is a success, display live img 174 if (success) { 175 console.log(live); 176 if (map.controls[google.maps.ControlPosition.TOP_RIGHT].getLength() > 0) 177 map.controls[google.maps.ControlPosition.TOP_RIGHT].pop(); 178 map.controls[google.maps.ControlPosition.TOP_RIGHT].push(live); 179 } 180 // if error, display sad smiley image 181 else { 182 console.log(notLive); 183 if (map.controls[google.maps.ControlPosition.TOP_RIGHT].getLength() > 0) 184 map.controls[google.maps.ControlPosition.TOP_RIGHT].pop(); 185 map.controls[google.maps.ControlPosition.TOP_RIGHT].push(notLive); 186 } 187 } 188 189 //reads first line on last fetch file and checks if its less than 15 minutes old 190 function checkLastFetch() 191 { 192 var rawFile = new XMLHttpRequest(); 193 rawFile.open("GET", lastFetchFile, false); 194 rawFile.onreadystatechange = function () 195 { 196 if(rawFile.readyState === 4) 197 { 198 if(rawFile.status === 200 || rawFile.status == 0) 199 { 200 var text = rawFile.responseText; 201 // get last fetch time from file 202 var lastFetch = new Date(text); 203 // get current date time 204 var now = new Date(); 205 // calculate time difference 206 var msec = now - lastFetch; 207 var days = Math.floor(msec / 1000 / 60 / (60 * 24)); 208 msec -= days * 1000 * 60 * 60 * 24 209 var hh = Math.floor(msec / 1000 / 60 / 60); 210 msec -= hh * 1000 * 60 * 60; 211 var mm = Math.floor(msec / 1000 / 60); 212 msec -= mm * 1000 * 60; 213 var ss = Math.floor(msec / 1000); 214 msec -= ss * 1000; 215 // display icon if less than 15 216 if (days === 0 && hh === 0 && mm < fetchInterval) 217 initLiveIcon(1) 218 else 219 initLiveIcon(0) 220 //console.log(days + " Days "+ hh + " Hours " + mm + " Minutes " + ss + " Seconds"); 221 } 222 } 223 } 224 rawFile.send(null); 225 }
Note: See TracChangeset
for help on using the changeset viewer.
