- Timestamp:
- 02/03/2021 06:10:06 AM (5 years ago)
- File:
-
- 1 edited
-
trunk/webapps/cptms/CameraDisplay.html (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/webapps/cptms/CameraDisplay.html
r616 r628 30 30 var routeCameras = {}; // for each route, a list of cameras on that route 31 31 var 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 32 34 function init() 33 35 { … … 66 68 } 67 69 68 // Builda lookup dictionary that maps route to camera id's70 // Takes in a CCTV location and builds a lookup dictionary that maps route to camera id's 69 71 function buildDict(cctvItem) 70 72 { … … 94 96 removeOptions(document.getElementById(cameraselect)); 95 97 fillOptions(currentRoute, cameraselect); 98 showView(cameraselect); //show default first image from camera dropdown for the selected route 96 99 } 97 100 … … 128 131 } 129 132 130 // Display the image requested from a camera dropd rown box133 // Display the image requested from a camera dropdown box 131 134 function showView(cameraselect) 132 135 { 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"); 187 197 } 188 198 // Execute periodically to reload the vds list with current data … … 197 207 for (var quadrant of views) 198 208 { 199 showView(quadrant); 209 //console.log(quadrant.id); 210 showView(quadrant.id); 200 211 } 201 212 });
Note: See TracChangeset
for help on using the changeset viewer.
