﻿/// <reference path="VeJavaScriptIntellisenseHelper.js" />

var map = null;
var Location = new VELatLong(45.644691, 13.848061); //location di default

function SetDestination(office) {
    switch (office) {
        case '1': //Trieste
            {
                Location = new VELatLong(45.644691, 13.848061);
                break;
            }
        case '2': //Milano
            {
                Location = new VELatLong(45.516873, 9.297416);
                break;
            }
        default: //Trieste
            {
                Location = new VELatLong(45.644691, 13.848061);
                break;
            }
    }
}

function GetMap(init) {
    //SetDestination(destination);
    map = new VEMap('myMap');
    map.LoadMap(Location, 12);

    var options = new VERouteOptions();
    options.DistanceUnit = VERouteDistanceUnit.Kilometer;
    options.RouteCallback = onGotRoute;
    map.GetDirections([init, Location], options);
}

function onGotRoute(route) {
    var legs = route.RouteLegs;
    var turns = "Distanza totale: " + route.Distance.toFixed(1) + " Km<ol>";
    var numTurns = 0;
    var leg = null;

    for (var i = 0; i < legs.length; i++) {
        // Get this leg so we don't have to derefernce multiple times
        leg = legs[i];  // Leg is a VERouteLeg object

        // Unroll each intermediate leg
        var turn = null;  // The itinerary leg

        for (var j = 0; j < leg.Itinerary.Items.length; j++) {
            turn = leg.Itinerary.Items[j];  // turn is a VERouteItineraryItem object
            numTurns++;
            turns += "<li>" + turn.Text + " (" + turn.Distance.toFixed(1) + " Km)</li>";
        }
    }
    $get('myDirections').innerHTML = turns + "</ol>";
}