Changeset 566 in tmcsimulator for trunk/webapps


Ignore:
Timestamp:
01/24/2020 12:53:15 PM (6 years ago)
Author:
jdalbey
Message:

GTEC vdsLayer.js Add color buttons.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/webapps/GTEC/js/vdsLayer.js

    r556 r566  
    11var postmileList = [];  // the list of postmiles saved from the json file. 
    2  
     2var chosenColor = null; 
    33 
    44Array.prototype.diff = function(a) { 
     
    2929 
    3030    // Load the map data from a json file and style all the points 
    31     function initializeVDSlayer() 
     31    function loadVDSlayer() 
    3232    { 
    3333        // Load the static map data and call saveCoords when done 
     
    112112                }); 
    113113                white_arr = []; 
     114                if (chosenColor) 
     115                { 
     116                    clicked_dots.forEach(function (dot) { 
     117                        dot.setProperty("color", chosenColor); 
     118                    }); 
     119                } 
     120 
    114121                // Assemble the line to be written to the events file 
    115                 var lineOut = "0:01:00  " + range.toFixed(3); 
     122                var lineOut = "181   00:00:00    " + first[0] + "       " +  
     123                first[1] + "            " + first[2] + "        " + range.toFixed(3) + "         "  
     124                + getColorAbbr(chosenColor); 
    116125 
    117126                // Using Ajax POST to send the data  
    118127                var xhr = new XMLHttpRequest(); 
    119                 xhr.open("POST", "../cgi-bin/saveTrafficEvent.py", true); 
     128                xhr.open("POST", "../../cgi-bin/saveTrafficEvent.py", true); 
    120129                xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); 
    121130                // send the collected data  
     
    228237        // see if new color is different than current color 
    229238        currentFeature = map.data.getFeatureById(target); 
    230         currentColor = currentFeature.getProperty("color"); 
    231         // if a new color is desired then assign it to the feature's color property 
    232         if (currentColor != newColor) 
    233         { 
    234             currentFeature.setProperty("color", newColor); 
    235             // set zIndex for slowed traffic to a higher value so they overlap 
    236             currentFeature.setProperty("zIndex", colorZvalues[newColor]); 
     239        if (currentFeature) { 
     240            currentColor = currentFeature.getProperty("color"); 
     241            // if a new color is desired then assign it to the feature's color property 
     242            if (currentColor != newColor) 
     243            { 
     244                currentFeature.setProperty("color", newColor); 
     245                // set zIndex for slowed traffic to a higher value so they overlap 
     246                currentFeature.setProperty("zIndex", colorZvalues[newColor]); 
     247            } 
    237248        } 
    238249    } 
     
    275286        else if (str === "G\r" || str === "G") 
    276287            return "lime"; 
     288    } 
     289 
     290    function getColorAbbr(str){ 
     291        if (str === "red") 
     292            return "R"; 
     293        else if (str === "yellow") 
     294            return "Y"; 
     295        else if (str === "lime") 
     296            return "G"; 
    277297    } 
    278298 
     
    402422}*/ 
    403423 
     424function initColorButtons() 
     425{ 
     426    var redColor = document.getElementById('redButton'); 
     427    var greenColor = document.getElementById('greenButton'); 
     428    var yellowColor = document.getElementById('yellowButton'); 
     429    map.controls[google.maps.ControlPosition.BOTTOM_CENTER].push(redColor); 
     430    map.controls[google.maps.ControlPosition.BOTTOM_CENTER].push(greenColor); 
     431    map.controls[google.maps.ControlPosition.BOTTOM_CENTER].push(yellowColor); 
     432    redColor.addEventListener('click', function() { 
     433        chosenColor = "red"; 
     434    }); 
     435    greenColor.addEventListener('click', function() { 
     436        chosenColor = "lime"; 
     437    }); 
     438    yellowColor.addEventListener('click', function(){ 
     439        chosenColor = "yellow"; 
     440    }); 
     441} 
     442 
    404443// init beginning, forward and back buttons as well as time display on map 
    405 function initControlButtons() 
     444/*function initControlButtons() 
    406445{ 
    407446    var i = 0; 
    408     /*var time = document.getElementById('time'); 
     447    var time = document.getElementById('time'); 
    409448    map.controls[google.maps.ControlPosition.BOTTOM_CENTER].push(time) 
    410449    var start = document.getElementById('start'); 
     
    446485        i = 0; 
    447486        time.innerHTML = "00:00:00"; 
    448     });*/ 
     487    }); 
    449488} 
    450  
     489*/ 
Note: See TracChangeset for help on using the changeset viewer.