Warning: Can't use blame annotator:
svn blame failed on trunk/webapps/cptms/js/harLayer.js: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator/trunk/webapps/cptms/js/harLayer.js @ 373

Revision 373, 5.7 KB checked in by jdalbey, 7 years ago (diff)

Update filenames in code to match dir reorg

RevLine 
1function initHARbutton()
2{
3    var harBtnDiv = document.getElementById('harButton');
4    map.controls[google.maps.ControlPosition.LEFT_BOTTOM].push(harBtnDiv)
5    harBtnDiv.title = 'Click to toggle har view';
6    // Setup the click event listeners to toggle icon display
7    harBtnDiv.addEventListener('click', function()
8    {
9        har_showing = !har_showing;
10        // Determine which button image to show
11        if (har_showing)
12        {
13            pic = "images/btnDepressed_HAR.png"
14            // It's nice when icons become visible that the messages have been refreshed.
15            loadAllharMessages();
16        }
17        else
18        {
19            pic = "images/btnReady_HAR.png"
20        }
21        document.getElementById('harBtnImg').src = pic;
22        // reveal or hide all the icons
23        harLayer.forEach(function(feature)
24        {
25            harLayer.overrideStyle(feature,
26            {
27                visible: har_showing
28            });
29        });
30    });
31}
32function loadHARlayer()
33{
34    harLayer = new google.maps.Data();
35    harLayer.setMap(map);
36    harLayer.loadGeoJson(kHARfile); 
37    harLayer.setStyle(function(feature)
38    {
39        // return the StyleOptions
40        return {
41            icon: iconHARactive,
42            title: feature.getId()+ " " +feature.getProperty("location")+ " " 
43                    + feature.getProperty("street"),
44            visible: false
45        };
46    });
47   
48    harLayer.addListener('click', function(event)
49    {
50        var dialog = document.getElementById('har-dialog');
51        // Note: If the dialog is already being displayed when someone else
52        // updates the message, it won't be reflected in the dialog, until
53        // you close and reopen it.
54        dialog.style.display = 'block';
55        harID = event.feature.getId();
56        // Assign to the hidden field
57        document.getElementById('harID').value = harID;
58        showHARMessage(harID); // note: this is async
59        document.getElementById('har-info-label').innerHTML = "HAR ID: " +
60            harID + "   LOCATION: " + event.feature.getProperty("location")
61            + "  " + event.feature.getProperty("street");
62        // clear input fields
63        document.getElementById('har-msgcontent1').value = "";
64        document.getElementById('har-msgcontent1').focus();
65        var span = document.getElementById('har-close');
66            // When the user clicks on <span> (x), close the modal
67        span.addEventListener('click',function()
68        {
69            hideElementById('har-dialog');
70        });
71    });
72}
73
74    function handleHARsubmit()
75    {
76        // recover the user's response
77        var response1 = document.getElementById('har-msgcontent1').value.trim();
78
79        var newMsg = response1;
80        if (newMsg.length == 0)
81        {
82            alert("Nothing to Send ... input fields are empty.");
83        }
84        else
85        {
86            document.getElementById('har-msgdisplay1').value = response1;
87
88            saveHARMessage(response1);
89        }
90    }
91
92    function handleHARclear()
93    {
94        document.getElementById('har-msgdisplay1').value = "";
95        saveHARMessage("");
96    }
97
98    // Save an updated har message to the file
99    function saveHARMessage(outMessage)
100    {
101        // Fetch harID from hidden field where it was put when dialog opened.
102        var harID = document.getElementById('harID').value;
103        HARmessageDict[harID].har.message.phase1.Line1 = outMessage;
104        // Set icon to reflect message state
105        if (outMessage == "")
106        {
107            currentIcon = {icon: iconHARidle};
108        }
109        else
110        {
111            currentIcon = {icon: iconHARactive};
112        }
113        harLayer.overrideStyle(harLayer.getFeatureById(harID), currentIcon)
114        // convert messasge to json string
115        jsonstring = JSON.stringify(Object.values(HARmessageDict));
116        outString = "{\"data\":" + jsonstring + "}";
117
118        var xhttp = new XMLHttpRequest();
119        xhttp.open("GET", "../cgi-bin/saveHARmessage.py?msg=" + outString, true);
120        xhttp.send();
121        // Using POST might be a better idea ... haven't tried this yet
122        //      var xhr = new XMLHttpRequest();
123        //      xhr.open("POST", "/cgi-bin/saveMessage.py?", true);
124        //      xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
125        // send the collected data as JSON
126        //      xhr.send(JSON.stringify(messageList));
127    }
128
129    // retrieve the current har message file
130    function showHARMessage(harID)
131    {
132        loadAllharMessages();  // because someone else may have made a recent update
133        // lookup the message for this har ID
134        var message = HARmessageDict[harID].har.message;
135        // show the message in the display
136        document.getElementById('har-msgdisplay1').value = message.phase1.Line1.toUpperCase();
137
138    }
139    function loadAllharMessages()
140    {
141        loadJSON("../dynamicdata/har_messages.json", function(response)
142        {
143            // Parse JSON string into object
144            messagejson = JSON.parse(response);
145            // Add each message to a lookup dictionary
146            for (var i = 0; i < messagejson.data.length; i++)
147            {
148                var item = messagejson.data[i];
149                HARmessageDict[item.har.index] = item;
150                // Set the appropriate icon on the har icon
151                //  if there's currently no message
152                if (item.har.message.phase1.Line1 == "")
153                {
154                    harLayer.overrideStyle(harLayer.getFeatureById(item.har.index), {icon: iconHARidle})
155                }
156                else
157                {
158                    harLayer.overrideStyle(harLayer.getFeatureById(item.har.index), {icon: iconHARactive})
159                }   
160            }
161        });
162    }
163
164
Note: See TracBrowser for help on using the repository browser.