Changeset 528 in tmcsimulator for trunk/webapps/visualizer


Ignore:
Timestamp:
11/19/2019 06:47:43 AM (6 years ago)
Author:
jdalbey
Message:

Visualizer - add Back button functionality

Location:
trunk/webapps/visualizer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/webapps/visualizer/index.html

    r516 r528  
    4848    <button id="cmsButton" class="unstyled-button"><img id="cmsBtnImg" src="images/btnReady_CMS.png"></button>--> 
    4949    <button id="vdsButton" class="unstyled-button"><img id="vdsBtnImg" src="images/btnDepressed_VDS.png"></button> 
    50     <p id="time">Time</p> 
     50    <p id="time">00:00:00</p> 
    5151    <button id="start" >Beginning</button> 
    5252    <button id="forward" >Next</button> 
     53        <button id="backward" >Back</button> 
    5354    <script  src="../common/js/fileutils.js"></script> 
    5455    <script  src="../common/js/revision_number.dat"></script> 
     
    9596    var filters = []; //array to hold markers for visualizer 
    9697    var times = []; //array to hold times of each traffic event 
     98    times[0] = "00:00:00"; 
     99    var diff_arr = []; // array to hold difference in target markers 
    97100    var index = -1; //to index into above array 
    98101 
     
    154157 
    155158        updateVDSlayer(); 
     159        setTimeout(function() { 
     160            buildDiff(); 
     161            updateVDSlayer(); 
     162        }, 3000); 
    156163 
    157164        // Listen for zoom changes and move the vds dots so as to keep a nice 
  • trunk/webapps/visualizer/js/vdsLayer.js

    r516 r528  
    6060        // go adjust the marker coordinates so dots don't overlap 
    6161        adjustCoords(calcDistanceFactor()); 
    62     } 
     62    }  
    6363 
    6464    // magic formula controls distance between dots proportionate to zoom factor 
     
    114114    } 
    115115 
     116    function storePrev(marker, targetMarkers)  
     117    { 
     118        target = marker.id; 
     119        newColor = marker.properties.color; 
     120        // see if new color is different than current color 
     121        currentFeature = map.data.getFeatureById(target); 
     122        currentColor = currentFeature.getProperty("color"); 
     123        // if a new color is desired then assign it to the feature's color property 
     124        if (currentColor != newColor) 
     125        { 
     126            targetMarkers.push({"id" : currentFeature.getId(), 
     127                "properties" : {"color" : currentColor}}); 
     128        } 
     129    } 
    116130 
    117131    // Load the highways dynamic json file and update the map 
     
    178192    // updates color for each marker based on color in filters array 
    179193    function updateVDS(forwards) {  
    180         index++; 
    181         if  (filters[index] !== undefined){ 
    182             filters[index].forEach(function(item){ 
    183                 item.marker.properties.color = item.color; 
    184                 updateMarker(item.marker); 
    185             }); 
     194                if (forwards) { 
     195            index++; 
     196            if (index >= filters.length)  
     197            { 
     198                index = filters.length - 1; 
     199            } 
     200            if  (filters[index] !== undefined) { 
     201                filters[index].forEach(function(item){ 
     202                    item.marker.properties.color = item.color; 
     203                    updateMarker(item.marker); 
     204                }); 
     205            } 
     206        } 
     207                else { 
     208            if  (diff_arr[index] !== undefined) { 
     209                diff_arr[index].forEach(function(item){ 
     210                    updateMarker(item); 
     211                }); 
     212            } 
     213            index--;  
     214            if (index < -1) 
     215            { 
     216                index = -1; 
     217            } 
     218        } 
     219    } 
     220 
     221    function buildDiff()  
     222    { 
     223        for (var i = 0; i <= filters.length; i++) 
     224        { 
     225            if  (filters[i] !== undefined) 
     226            { 
     227                var targetMarkers = new Array(); 
     228                filters[i].forEach(function(item){ 
     229                    item.marker.properties.color = item.color; 
     230                    storePrev(item.marker, targetMarkers); 
     231                    updateMarker(item.marker); 
     232                }); 
     233                diff_arr.push(targetMarkers); 
     234            } 
    186235        } 
    187236    } 
     
    230279    var forward = document.getElementById('forward'); 
    231280    map.controls[google.maps.ControlPosition.BOTTOM_CENTER].push(forward) 
     281        var backward = document.getElementById('backward'); 
     282        map.controls[google.maps.ControlPosition.BOTTOM_CENTER].push(backward) 
    232283    forward.title = 'Click to see the next event'; 
    233     console.log(times); 
     284    //console.log(diff_arr); 
    234285    forward.addEventListener('click', function() { 
    235286        updateVDS(1); 
    236         if (i < times.length) 
    237             time.innerHTML = times[i++]; 
     287        if (i < times.length - 1) 
     288        { 
     289            ++i; 
     290            time.innerHTML = times[i]; 
     291        } 
    238292    }); 
     293        backward.addEventListener('click', function() { 
     294        updateVDS(0); 
     295        if (i > 0) 
     296        { 
     297            --i; 
     298            time.innerHTML = times[i]; 
     299        } 
     300        }); 
    239301    start.addEventListener('click', function() { 
    240302        updateVDSlayer(); 
    241303        i = 0; 
    242         time.innerHTML = "Time" 
     304        time.innerHTML = "00:00:00"; 
    243305    }); 
    244306} 
Note: See TracChangeset for help on using the changeset viewer.