﻿/********************************************************************
 *
 * Manages Transvista Image Snapshots RSS 
 * Author: TTI, Gabriel Torres
 * Date:   January 25, 2008
 *
 *******************************************************************/

var veLayerSections  = new VEShapeLayer();

//color lines
var kLineGreen  = new VEColor(0,225,0,1.0);
var kLineRed    = new VEColor(225,0,0,1.0);
var kLineYellow = new VEColor(255,255,0,1.0);
var kLineSilver = new VEColor(150,150,150,1.0);
//line width
var kDefLineWidth = 4;
var kSectionsRSSFile = "RSS/Sections.xml?";


// Configure speed map line colors and icons
// Created: Gabriel, 5/15/07
function ConfigureSpeedLines(layer)
{   
    var sTite, sStatus;
    var sSectionIcon = "";
    var lineColor;
    var iShapes = layer.GetShapeCount();
    for(var i=0; i < iShapes; ++i) {
        var shape = layer.GetShapeByIndex(i);
        sTitle = shape.GetTitle();
        sStatus = sTitle.substring(sTitle.length-2,sTitle.length);
        sTitle = sTitle.substring(0,sTitle.length-2);
                
        if (sTitle.indexOf("westbound") >= 0)
            sSectionIcon = "<img style='position:relative; margin-top:-2px;' " + 
                           "src='../Images/Section-WB.gif' height='8px' width='14px' />";
        else
            sSectionIcon = "<img style='position:relative; margin-top:+15px;' " +
                           "src='../Images/Section-EB.gif' height='8px' width='14px' />";
            
        if (sStatus == "~r") lineColor = kLineRed;
        else if (sStatus == "~y") lineColor = kLineYellow;
        else if (sStatus == "~s") lineColor = kLineSilver;
        else lineColor = kLineGreen;        

        shape.SetCustomIcon(sSectionIcon);
        shape.SetLineColor(lineColor);
        shape.SetLineWidth(kDefLineWidth);
        shape.SetTitle(sTitle);
    }
}

// Load Speed map (colored lines) layer
// Created: Gabriel, 5/15/07
// Updated: Gabriel, 7/18/07, Use RSS feed
function LoadSpeeds(go)
{
    showProgressIndicator("Updating speeds");
    if (!go) {
        setTimeout(function() { LoadSpeeds(1); }, iAsyncDelay);
    }
    else {
        veLayerSections.DeleteAllShapes();
        var veShapeSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, 
            kSectionsRSSFile + GetRan(), veLayerSections);
        map.ImportShapeLayerData(veShapeSpec, ConfigureSpeedLines, false);
        veLayerSections.Show();
        ttiTools.showElement("imgRefreshSpeeds");
        window.status = "Speeds loaded";
        hideProgressIndicator();        
    }
}
function HideSections()
{
    veLayerSections.Hide();
    ttiTools.hideElement("imgRefreshSpeeds");
}


