| 1 | function initCCTVbutton() |
|---|
| 2 | { |
|---|
| 3 | var cctvBtnDiv = document.getElementById('cctvButton'); |
|---|
| 4 | map.controls[google.maps.ControlPosition.LEFT_BOTTOM].push(cctvBtnDiv) |
|---|
| 5 | cctvBtnDiv.title = 'Click to toggle cctv view'; |
|---|
| 6 | // Setup the click event listeners to toggle icon display |
|---|
| 7 | cctvBtnDiv.addEventListener('click', function() |
|---|
| 8 | { |
|---|
| 9 | cctv_showing = !cctv_showing; |
|---|
| 10 | // reveal or hide all the icons |
|---|
| 11 | cctvLayer.forEach(function(feature) |
|---|
| 12 | { |
|---|
| 13 | cctvLayer.overrideStyle(feature, |
|---|
| 14 | { |
|---|
| 15 | visible: cctv_showing |
|---|
| 16 | }); |
|---|
| 17 | }); |
|---|
| 18 | // Determine which button image to show |
|---|
| 19 | if (cctv_showing) |
|---|
| 20 | { |
|---|
| 21 | pic = "images/btnDepressed_CCTV.png" |
|---|
| 22 | } |
|---|
| 23 | else |
|---|
| 24 | { |
|---|
| 25 | pic = "images/btnReady_CCTV.png" |
|---|
| 26 | } |
|---|
| 27 | document.getElementById('cctvBtnImg').src = pic; |
|---|
| 28 | }); |
|---|
| 29 | } |
|---|
| 30 | function makecctvIcon(nearVDS) |
|---|
| 31 | { |
|---|
| 32 | var imgIcon = cctvIcon |
|---|
| 33 | if ((typeof map.data.getFeatureById(nearVDS)) == "undefined") |
|---|
| 34 | { |
|---|
| 35 | imgIcon = cctvIconWhite; |
|---|
| 36 | } |
|---|
| 37 | return imgIcon |
|---|
| 38 | } |
|---|
| 39 | function loadCCTVlayer() |
|---|
| 40 | { |
|---|
| 41 | var imgTag = '<IMG WIDTH="700" ONERROR=this.src="images/cctv_unavailable.jpg" SRC="images/'; |
|---|
| 42 | cctv_infowindow = new google.maps.InfoWindow(); // initial the singleton |
|---|
| 43 | cctvLayer = new google.maps.Data(); |
|---|
| 44 | cctvLayer.loadGeoJson(kCCTVfile); // load the features |
|---|
| 45 | // Define the clickable area on an icon (the default is too big) |
|---|
| 46 | var clickRegion = {coords: [0,0,14,8], type: "rect"} |
|---|
| 47 | cctvLayer.setStyle(function(feature) |
|---|
| 48 | { |
|---|
| 49 | // return the StyleOptions |
|---|
| 50 | return { |
|---|
| 51 | icon: makecctvIcon(feature.getProperty("nearVDS")), |
|---|
| 52 | shape: clickRegion, |
|---|
| 53 | title: feature.getId() + " " +feature.getProperty('locationName'), |
|---|
| 54 | visible: false |
|---|
| 55 | }; |
|---|
| 56 | }); |
|---|
| 57 | cctvLayer.addListener('click', function(event) |
|---|
| 58 | { |
|---|
| 59 | //console.log("cctv layer was clicked at " + event.feature.getId()); |
|---|
| 60 | cctvIndex = event.feature.getId(); |
|---|
| 61 | //console.log(this.title + " is looking for " + this.nearVDS); |
|---|
| 62 | cctvLocation = event.feature.getProperty("locationName"); |
|---|
| 63 | nearVDS = map.data.getFeatureById(event.feature.getProperty("nearVDS")); |
|---|
| 64 | currentColor = nearVDS.getProperty("color"); |
|---|
| 65 | // file name scheme |
|---|
| 66 | // rte-id-velocity.jpg |
|---|
| 67 | // rte is route number, e.g., 055 |
|---|
| 68 | // id is 4-digit camera id, e.g., 0012 |
|---|
| 69 | // vel is traffic velocity: "freeflow", "slow", or "stopped" |
|---|
| 70 | var imgDir = "CCTV/"; |
|---|
| 71 | var label = "-day-freeflow"; |
|---|
| 72 | if (currentColor == "red") |
|---|
| 73 | { |
|---|
| 74 | label = "-day-stopped"; |
|---|
| 75 | } |
|---|
| 76 | if (currentColor == "yellow") |
|---|
| 77 | { |
|---|
| 78 | label = "-day-slow"; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | // Demo of video embed - only on highway 241 locations |
|---|
| 82 | if (cctvIndex.startsWith("12-241")) |
|---|
| 83 | { |
|---|
| 84 | cctv_infowindow.setContent('<div style="font-weight:bold;font-family: monospace">' + cctvIndex + " " + cctvLocation + " " + '<BR><video autoplay loop><source src="images/TrafficFreeflow.ogv" type="video/ogg"></div>'); |
|---|
| 85 | } |
|---|
| 86 | else |
|---|
| 87 | // image from fast or slow directories |
|---|
| 88 | { |
|---|
| 89 | cctv_infowindow.setContent('<div style="font-weight:bold;font-family: monospace">' + cctvIndex + " " + cctvLocation + " " +label+ "<BR>" + imgTag + imgDir + cctvIndex + label +'.jpg">' + "</div>"); |
|---|
| 90 | } |
|---|
| 91 | cctv_infowindow.setPosition(event.feature.getGeometry().get()); |
|---|
| 92 | cctv_infowindow.open(map); |
|---|
| 93 | |
|---|
| 94 | }); |
|---|
| 95 | cctvLayer.setMap(map); |
|---|
| 96 | } |
|---|
| 97 | |
|---|