Changeset 585 in tmcsimulator


Ignore:
Timestamp:
03/08/2020 02:15:25 PM (6 years ago)
Author:
jdalbey
Message:

Add LIVE indicator

Location:
branches/realtime_VDS/cptms
Files:
5 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/realtime_VDS/cptms/index.html

    r584 r585  
    149149    var kCCTVfile = "data_layers/cctv_locations_D12.gjson"; // CCTV locations 
    150150    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" 
    151154    var iconCMSactive = "images/icon_cms_active.png"; 
    152155    var iconCMSidle = "images/icon_cms_idle.png"; 
     
    200203        initVDSbutton(); 
    201204        initVDSicons(); 
     205        checkLastFetch(); 
    202206    } 
    203207 
     
    235239        var harTimer = setInterval(loadAllharMessages, 10000); 
    236240 
     241        var fetchTimer = setInterval(checkLastFetch, 10000); 
     242 
    237243        // Listen for zoom changes and move the vds dots so as to keep a nice 
    238244        // visual distance between them appropriate to the zoom factor 
  • branches/realtime_VDS/cptms/js/vdsLayer.js

    r584 r585  
    160160} 
    161161 
     162//initialize live indicator icon 
     163function 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 
     190function 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.