Changeset 567 in tmcsimulator for trunk/webapps/GTEC
- Timestamp:
- 01/24/2020 12:54:29 PM (6 years ago)
- File:
-
- 1 edited
-
trunk/webapps/GTEC/js/vdsLayer.js (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/webapps/GTEC/js/vdsLayer.js
r566 r567 1 1 var postmileList = []; // the list of postmiles saved from the json file. 2 var chosenColor = null; 3 2 var chosenColor = null; // stores color that user picks 3 4 // function to find differences between two arrays 4 5 Array.prototype.diff = function(a) { 5 6 return this.filter(function(i) {return a.indexOf(i) < 0;}); … … 52 53 }; 53 54 }); 54 var clicked = false; 55 var first = []; 56 var asc = false; 57 var color_arr = [];58 var white_arr = []; 55 var clicked = false; 56 var first = []; // stores first dot 57 var asc = false; //ascending 58 //var color_arr = []; 59 var white_arr = []; //stores all white dots 59 60 map.data.addListener('click', function(event) 60 61 { 61 62 var event_arr = event.feature.getId().split(/[ ,]+/); 62 // var start = parseFloat(event[4]); // extract postmile field 63 // if user has already made the first click and the second click is 64 // on the same highway and same direction 63 65 if (clicked && event_arr[0] === first[0] && event_arr[1] === first[1]) 64 66 { 65 // co nsole.log('clicked ' + first + "/" + event_arr + event.feature);67 // compute range between the two clicked dots 66 68 var range = Math.abs(parseFloat(event_arr[2]) - parseFloat(first[2])); 67 69 var clicked_dots = []; 70 // checks highway direction to determine if postmiles are ascending or descending 68 71 if (parseFloat(event_arr[2]) < parseFloat(first[2])) 69 72 { … … 74 77 asc = true; 75 78 } 79 // searches map for all dots between the two clicked dots and adds it to list "clicked_dots" 76 80 map.data.forEach(function (marker) 77 81 { 78 82 var marker_arr = marker.getId().split(/[ ,]+/); 83 // if the dot in the map matches the highway and direction of the clicked dot 79 84 if (marker_arr[0] === event_arr[0] && marker_arr[1] === event_arr[1]) 80 85 { 86 // compute distance based on direction of highway 81 87 if (asc) 82 88 { … … 87 93 var dist = parseFloat(parseFloat(first[2]) - (marker_arr[2])); 88 94 } 95 // if dist within range of the two clicked dots, add to list "clicked_dots" 89 96 if (dist <= range && dist >= 0) 90 97 { … … 93 100 } 94 101 }); 95 color_arr.push(clicked_dots);102 //color_arr.push(clicked_dots); 96 103 console.log(clicked_dots); 97 104 console.log(range); 105 // extracts ids for all the white dots 98 106 var white_arr_ids = white_arr.map(function (marker) { 99 107 return marker.id; 100 108 }); 109 // extracts ids for all the clicked dots 101 110 var clicked_dots_ids = clicked_dots.map(function (marker) { 102 111 return marker.getId(); 103 112 }); 113 // computes difference between the white dots and clicked dots to find the unused dots 104 114 var unused_ids = white_arr_ids.diff(clicked_dots_ids); 105 115 console.log("Unused: ",unused_ids, "White: ",white_arr_ids); 116 // change the dot color of all the unused white dots back to their previous color 106 117 unused_ids.forEach(function (id){ 107 118 var marker = white_arr.filter(function (dot) { … … 112 123 }); 113 124 white_arr = []; 125 // change the color of all the dots between the two clicked dots to the user picked color 114 126 if (chosenColor) 115 127 { … … 131 143 xhr.send("msg="+lineOut + "\n") 132 144 } 145 // if user has not yet clicked on a dot 133 146 else if (!clicked) 134 147 { … … 171 184 } 172 185 } 186 // if the user's second click is made on a dot not on the first dot's highway 173 187 else 174 188 { … … 249 263 } 250 264 251 // Builds array to store the previous colors of the targetDots252 /*function storePrev(marker, targetMarkers)253 {254 target = marker.id;255 newColor = marker.properties.color;256 // see if new color is different than current color257 currentFeature = map.data.getFeatureById(target);258 currentColor = currentFeature.getProperty("color");259 // if a new color is desired then assign it to the feature's color property260 if (currentColor != newColor)261 {262 targetMarkers.push({"id" : currentFeature.getId(),263 "properties" : {"color" : currentColor}});264 }265 }*/266 267 265 // Load the highways dynamic json file and update the map 268 266 function updateVDSlayer() … … 288 286 } 289 287 288 // gets the starting letter of a given color 290 289 function getColorAbbr(str){ 291 290 if (str === "red") … … 297 296 } 298 297 299 // Parses the traffic events file and builds an array of target dots for each line300 /*function processVDS() {301 var parsed_JSON;302 loadJSON(kVDSstatusFile, function(response)303 {304 // Parse JSON string into object305 parsed_JSON = JSON.parse(response);306 // Process each new marker - lookup in current map307 var parsed_features = parsed_JSON.features;308 var eventsFile = '';309 var xmlhttp = new XMLHttpRequest();310 xmlhttp.onreadystatechange = function(){311 if(xmlhttp.status == 200 && xmlhttp.readyState == 4){312 eventsFile = xmlhttp.responseText;313 var lines = eventsFile.toString().split("\n");314 for (var line = 1; line < lines.length; line++) {315 if (lines[line][0] !== '#') //ignores lines with #316 {317 var dots = [];318 var event = lines[line].split(/[ ,]+/);319 var start = parseFloat(event[4]); // extract postmile field320 var range = parseFloat(event[5]); // extract distance321 var newColor = getColorName(event[6]); // extract DotColor322 eventTimes.push(event[1]);323 parsed_features.forEach(function (marker) {324 var id_arr = marker.id.split(" ");325 if (id_arr[0] === event[2] && id_arr[1] === event[3]){326 var dist = parseFloat(id_arr[2]) - start; //computes difference in postmiles327 if (dist <= range && dist >= 0){ // adds all dots within computed range328 dots.push({"marker": marker, "color": newColor});329 }330 }331 });332 targetDots.push(dots);333 }334 }335 }336 };337 xmlhttp.open("GET",trafficEventsFile,true); //read traffic events text file338 xmlhttp.send();339 });340 }341 342 // Increments the eventIndex from and updates all the targetDots on map343 function updateForwards() {344 eventIndex++;345 // limit eventIndex to length of targetDots346 if (eventIndex >= targetDots.length)347 {348 eventIndex = targetDots.length - 1;349 }350 // update all the target dots351 if (targetDots[eventIndex] !== undefined) {352 targetDots[eventIndex].forEach(function(item){353 item.marker.properties.color = item.color;354 updateMarker(item.marker);355 });356 }357 }358 359 // Decrements the eventIndex and updates all the targetDots from diff_arr on map360 function updateBackwards() {361 //update each target dot in order to revert to previous color362 if (diff_arr[eventIndex] !== undefined) {363 diff_arr[eventIndex].forEach(function(item){364 updateMarker(item);365 });366 }367 eventIndex--;368 // restrict eventIndex to -1369 if (eventIndex < -1)370 {371 eventIndex = -1;372 }373 }374 375 // Calls updateMarker for all targetDots after storing the previous marker in diff_arr376 function buildDiff() {377 for (var i = 0; i <= targetDots.length; i++)378 {379 if (targetDots[i] !== undefined)380 {381 var targetMarkers = new Array();382 targetDots[i].forEach(function(item){383 item.marker.properties.color = item.color;384 storePrev(item.marker, targetMarkers);385 updateMarker(item.marker);386 });387 diff_arr.push(targetMarkers);388 }389 }390 }391 */392 /*function initVDSbutton()393 {394 395 var vdsBtnDiv = document.getElementById('vdsButton');396 map.controls[google.maps.ControlPosition.LEFT_BOTTOM].push(vdsBtnDiv)397 vdsBtnDiv.title = 'Click to toggle vds view';398 399 // Setup the click event listeners to toggle icon display400 vdsBtnDiv.addEventListener('click', function()401 {402 vds_showing = !vds_showing;403 // reveal or hide all the dots404 map.data.forEach(function(feature)405 {406 map.data.overrideStyle(feature,407 {408 visible: vds_showing409 });410 });411 // Determine which button image to show412 if (vds_showing)413 {414 pic = "images/btnDepressed_VDS.png"415 }416 else417 {418 pic = "images/btnReady_VDS.png"419 }420 document.getElementById('vdsBtnImg').src = pic;421 });422 }*/423 424 298 function initColorButtons() 425 299 { 300 // add the respective color buttons onto the map 426 301 var redColor = document.getElementById('redButton'); 427 302 var greenColor = document.getElementById('greenButton'); … … 430 305 map.controls[google.maps.ControlPosition.BOTTOM_CENTER].push(greenColor); 431 306 map.controls[google.maps.ControlPosition.BOTTOM_CENTER].push(yellowColor); 307 // store the user picked color in "chosenColor" 432 308 redColor.addEventListener('click', function() { 433 309 chosenColor = "red"; … … 440 316 }); 441 317 } 442 443 // init beginning, forward and back buttons as well as time display on map444 /*function initControlButtons()445 {446 var i = 0;447 var time = document.getElementById('time');448 map.controls[google.maps.ControlPosition.BOTTOM_CENTER].push(time)449 var start = document.getElementById('start');450 map.controls[google.maps.ControlPosition.BOTTOM_CENTER].push(start)451 start.title = 'Click to see the first event';452 var forward = document.getElementById('forward');453 map.controls[google.maps.ControlPosition.BOTTOM_CENTER].push(forward)454 var backward = document.getElementById('backward');455 map.controls[google.maps.ControlPosition.BOTTOM_CENTER].push(backward)456 forward.title = 'Click to see the next event';457 forward.addEventListener('click', function() {458 updateForwards();459 backward.disabled = false;460 if (i < eventTimes.length - 1) // get the next eventTime461 {462 ++i;463 time.innerHTML = eventTimes[i];464 }465 if (eventIndex === targetDots.length - 1) // disable next button if last event reached466 {467 forward.disabled = true;468 }469 });470 backward.addEventListener('click', function() {471 updateBackwards();472 forward.disabled = false;473 if (i > 0) // get the prev eventTime474 {475 --i;476 time.innerHTML = eventTimes[i];477 }478 if (eventIndex < 0) // disable back button if at first event479 {480 backward.disabled = true;481 }482 });483 start.addEventListener('click', function() {484 updateVDSlayer(); // redraw markers on map from startup file485 i = 0;486 time.innerHTML = "00:00:00";487 });488 }489 */
Note: See TracChangeset
for help on using the changeset viewer.
