source: tmcsimulator/trunk/webapps/js/cctvLayer.js @ 338

Revision 338, 2.7 KB checked in by jdalbey, 7 years ago (diff)

Add items to adhoc_incidents.xml, add unavailable image for cctv files not found - and corresponding code in cctvLayer.js. Make HAR messages upper case.

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();
43    cctvLayer = new google.maps.Data();
44    cctvLayer.loadGeoJson(kCCTVfile);
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        var imgDir = "CCTVFast/";
66        if (currentColor == "red" || currentColor == "yellow")
67        {
68            imgDir = "CCTVSlow/"
69        }
70
71        cctv_infowindow.setContent('<div style="font-weight:bold;font-family: monospace">' +  cctvIndex + "&nbsp;" + cctvLocation + "&nbsp;" +currentColor + "<BR>" + imgTag + imgDir + cctvIndex + '.jpg">' + "</div>");
72        cctv_infowindow.setPosition(event.feature.getGeometry().get());
73        cctv_infowindow.open(map);
74
75    });
76    cctvLayer.setMap(map);
77}
78
Note: See TracBrowser for help on using the repository browser.