source: tmcsimulator/trunk/webapps/cptms/js/cctvLayer.js @ 357

Revision 357, 3.7 KB checked in by jdalbey, 7 years ago (diff)

minor edits to cptms

Line 
1function 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}
30function makecctvIcon(nearVDS)
31{
32    var imgIcon = cctvIcon
33    if ((typeof map.data.getFeatureById(nearVDS)) == "undefined")
34    {
35        imgIcon = cctvIconWhite;
36    }
37    return imgIcon
38}
39function 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        // Currently, Fast and Slow images are stored in separate folders.
66        // As Neil gets actual images collated, we will change this to a file name scheme
67        // rte-id-velocity.jpg
68        // rte is route number, e.g., 055
69        // id is 4-digit camera id, e.g., 0012
70        // vel is traffic velocity: "freeflow", "slow", or "stopped"
71        var imgDir = "CCTVFast/";
72        if (currentColor == "red" || currentColor == "yellow")
73        {
74            imgDir = "CCTVSlow/"
75        }
76        var label = "freeflow";
77        if (currentColor == "red")
78        {
79            label = "stopped";
80        }
81        if (currentColor == "yellow")
82        {
83            label = "slow";
84        }
85
86        // Demo of video embed - only on highway 241 locations
87        if (cctvIndex.startsWith("12-241"))
88        {
89            cctv_infowindow.setContent('<div style="font-weight:bold;font-family: monospace">' +  cctvIndex + "&nbsp;" + cctvLocation + "&nbsp;" + '<BR><video  autoplay loop><source src="images/TrafficFreeflow.ogv" type="video/ogg"></div>');
90        }
91        else 
92        // image from fast or slow directories
93        {
94            cctv_infowindow.setContent('<div style="font-weight:bold;font-family: monospace">' +  cctvIndex + "&nbsp;" + cctvLocation + "&nbsp;" +label+ "<BR>" + imgTag + imgDir + cctvIndex + '.jpg">' + "</div>");
95        }
96        cctv_infowindow.setPosition(event.feature.getGeometry().get());
97        cctv_infowindow.open(map);
98
99    });
100    cctvLayer.setMap(map);
101}
102
Note: See TracBrowser for help on using the repository browser.