Changeset 628 in tmcsimulator for trunk/webapps/cptms/CameraDisplay.html


Ignore:
Timestamp:
02/03/2021 06:10:06 AM (5 years ago)
Author:
jdalbey
Message:

CameraDisplay?.html minor improvements to user interface

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/webapps/cptms/CameraDisplay.html

    r616 r628  
    3030var routeCameras = {};  // for each route, a list of cameras on that route 
    3131var cameraDict = {};    // for each cameraid, the associated nearVDS and locationName properties 
     32 
     33// Extracts VDS and CCTV data and builds a lookup dictionary that maps route to camera id's and adds routes to drop down list 
    3234function init() 
    3335{ 
     
    6668} 
    6769 
    68 // Build a lookup dictionary that maps route to camera id's 
     70// Takes in a CCTV location and builds a lookup dictionary that maps route to camera id's 
    6971function buildDict(cctvItem) 
    7072{ 
     
    9496  removeOptions(document.getElementById(cameraselect));   
    9597  fillOptions(currentRoute, cameraselect); 
     98  showView(cameraselect); //show default first image from camera dropdown for the selected route 
    9699} 
    97100 
     
    128131} 
    129132 
    130 // Display the image requested from a camera dropdrown box 
     133// Display the image requested from a camera dropdown box 
    131134function showView(cameraselect) 
    132135{ 
    133     var quadrant = cameraselect.charAt(1)  // extract numeric part of camera identifier 
    134     var imgElement = document.getElementById("img"+quadrant)     
    135     var e = document.getElementById(cameraselect); 
    136     // if no camera was selected 
    137     if (e.selectedIndex == -1) 
    138     { 
    139         imgElement.src="" // remove the image 
    140     } 
    141     else 
    142     { 
    143         var chosenCamera = e.options[e.selectedIndex].value; 
    144         nearvds = cameraDict[chosenCamera].nearVDS 
    145         // Search for the vds that is nearest 
    146         var idx = 0;  
    147         while (idx < vdsList.features.length && vdsList.features[idx].id != nearvds) 
    148         { 
    149             idx++; 
    150         } 
    151         // If we found the nearVDS 
    152         if (idx < vdsList.features.length) 
    153         { 
    154             // Obtain color and convert to speed 
    155             var foundVDS = vdsList.features[idx] 
    156             var color =  foundVDS.properties['color'] 
    157             var speed = "freeflow" 
    158             if (color == "yellow") 
    159             { 
    160                 speed = "slow" 
    161             } 
    162             if (color == "red") 
    163             { 
    164                 speed = "stopped" 
    165             } 
    166             // construct filename 
    167             var filename =  chosenCamera + "-day-"+speed+".jpg" 
    168             //console.log("Found " + foundVDS.id + " " + foundVDS.properties['color'] + " " + filename) 
    169             // Load the desired image 
    170             var preload = new Image(); 
    171             preload.onload = function() { 
    172                 if (imgElement)  
    173                 {  
    174                     imgElement.src = preload.src; // image 
    175                     imgElement.title=chosenCamera // tooltip 
    176                 } 
    177             }; 
    178             // if couldn't load show as unavailable 
    179             preload.onerror = function() { 
    180                 if (imgElement) { imgElement.src = "images/CCTV/video_unavailable.jpg" } 
    181             }; 
    182             // attempt to load the image 
    183             preload.src = "images/CCTV/"+filename;   
    184     //Reference: https://www.daniweb.com/programming/web-development/threads/272293/javascript-test-for-file-existence 
    185         } 
    186     } 
     136    var quadrant = ""; 
     137    // if route dropdown box is selected, then view image 
     138    if (typeof cameraselect === 'string') 
     139    { 
     140      quadrant = cameraselect.charAt(1)  // extract numeric part of camera identifier 
     141      var chosenRoute = document.getElementById('R' + quadrant); 
     142      var imgElement = document.getElementById("img"+quadrant)     
     143      var e = document.getElementById(cameraselect); 
     144      // if no camera was selected 
     145      if (e.selectedIndex == -1) 
     146      { 
     147          imgElement.src="" // remove the image 
     148      } 
     149      else 
     150      { 
     151          var chosenCamera = e.options[e.selectedIndex].value; 
     152          nearvds = cameraDict[chosenCamera].nearVDS 
     153          // Search for the vds that is nearest 
     154          var idx = 0;  
     155          while (idx < vdsList.features.length && vdsList.features[idx].id != nearvds) 
     156          { 
     157              idx++; 
     158          } 
     159          // If we found the nearVDS 
     160          if (idx < vdsList.features.length) 
     161          { 
     162              // Obtain color and convert to speed 
     163              var foundVDS = vdsList.features[idx] 
     164              var color =  foundVDS.properties['color'] 
     165              var speed = "freeflow" 
     166              if (color == "yellow") 
     167              { 
     168                  speed = "slow" 
     169              } 
     170              if (color == "red") 
     171              { 
     172                  speed = "stopped" 
     173              } 
     174              // construct filename 
     175              var filename =  chosenCamera + "-day-"+speed+".jpg" 
     176              //console.log("Found " + foundVDS.id + " " + foundVDS.properties['color'] + " " + filename) 
     177              // Load the desired image 
     178              var preload = new Image(); 
     179              preload.onload = function() { 
     180                  if (imgElement)  
     181                  {  
     182                      imgElement.src = preload.src; // image 
     183                      imgElement.title=chosenCamera // tooltip 
     184                  } 
     185              }; 
     186              // if couldn't load show as unavailable 
     187              preload.onerror = function() { 
     188                  if (imgElement) { imgElement.src = "images/CCTV/video_unavailable.jpg" }  
     189              }; 
     190              // attempt to load the image 
     191              preload.src = "images/CCTV/"+filename;   
     192      //Reference: https://www.daniweb.com/programming/web-development/threads/272293/javascript-test-for-file-existence 
     193          } 
     194      } 
     195    } 
     196   //console.log("empty"); 
    187197} 
    188198// Execute periodically to reload the vds list with current data 
     
    197207        for (var quadrant of views) 
    198208        { 
    199             showView(quadrant); 
     209            //console.log(quadrant.id); 
     210            showView(quadrant.id); 
    200211        } 
    201212    }); 
Note: See TracChangeset for help on using the changeset viewer.