﻿        var points = new Array(
        new VELatLong(46.62362332519164,14.304960966110245, 0, VEAltitudeMode. RelativeToGround), //nordost
        new VELatLong(46.62361964097422,14.30447280406952, 0, VEAltitudeMode. RelativeToGround), //nordwest
        new VELatLong(46.62315911182183,14.304558634758, 0, VEAltitudeMode. RelativeToGround), //südwest
        new VELatLong(46.62317753306314,14.305078983306888, 0, VEAltitudeMode. RelativeToGround) //südost
        ); 

        var centerLatitude = 46.623542272350406;
        var centerLongitude = 14.304639101028442;
        var centerCoordinates = new VELatLong(centerLatitude, centerLongitude); 
        
        var myShapeLayer;
        var pinid = 0;
        var icon = "<img src='App_Themes/icon.png' onclick=theMap.ZoomIn(); />";
        var infobox = "<div style='width:160px;z-index:2'><strong>Hotel Sandwirth</strong><br />Pernhartgasse 9<br/>9020 Klagenfurt, <br>"
                    +""
                    +"</div>";
        
        var theMap;  
           
         function loadMap() {  
             theMap = new VEMap("theMap"); 
                           
             theMap.onLoadMap = function() {  
                 theMap.SetZoomLevel(16);  
                 theMap.ZIndex = 1;
                 theMap.HideDashboard();     
                 theMap.SetCenter(centerCoordinates); 
                 theMap.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);  
             }  
               
             theMap.LoadMap();
               
             myShapeLayer = new VEShapeLayer();
             theMap.AddShapeLayer(myShapeLayer);
             
             var myShape = new VEShape(VEShapeType.Polygon, points);
             myShape.SetCustomIcon(icon);

             theMap.ClearInfoBoxStyles();
             myShape.SetTitle("<h2 style='margin-top:0px;'>Hier sind wir!</h2>");
             myShape.SetDescription(infobox);
             pinid++;

             myShapeLayer.AddShape(myShape);

         }  

 function Route()
  {         
    var myLocations = new Array();
    myLocations[0] = document.getElementById('routestart').value;
    myLocations[1] = centerCoordinates, "Klagenfurt, Kärnten, Österreich";

    var myRouteOptions = new VERouteOptions();
    myRouteOptions.SetBestMapView = true; // change map view
    myRouteOptions.RouteCallback = myRouteHandler;  // Gets VERoute
    myRouteOptions.DistanceUnit = VERouteDistanceUnit.Kilometer; // because we are germans!
    theMap.GetDirections(myLocations, myRouteOptions);
    MapStyleHybrid();
  }         
   
   function MapStyleSpider(imgname)
  {           
   var imge = imgname;
   document.getElementById('theMap2').style.display = 'block';
   document.getElementById('theSpider').src='App_Themes/' + imge;
   document.getElementById('routingwerkzeug').style.display = 'none';
  }
  
  function RouteThumbs(id)
  {     
  document.getElementById('theMap2').style.display = 'none'; 
  document.getElementById('routingwerkzeug').style.display = 'block';
  if (id != 2) { document.getElementById('Blickwinkel').style.display = 'none'; };   
  if (id != 4) { document.getElementById('RoadHybrid').style.display = 'none'; };  
  }
          
  function MapStyleBirdsEye()
  {    
   if(theMap.IsBirdseyeAvailable())
   {
   theMap.SetBirdseyeScene();
   }
   else
   {
   theMap.SetCenter(centerCoordinates);       
   theMap.SetZoomLevel(16); 
   theMap.SetBirdseyeScene();
   }
   document.getElementById('Blickwinkel').style.display = 'inline'; 
   RouteThumbs(2);
  }
  
  function ZoomIn()
  {
   theMap.ZoomIn();
  }
  
  function ZoomOut()
  {
   theMap.ZoomOut();
  }
  
  function MapStyleRoad()
  {           
   theMap.SetMapStyle(VEMapStyle.Road);
   RouteThumbs(3);
   document.getElementById('RoadHybrid').style.display = 'inline'; 
  }
  
  function MapStyleAerial()
  {           
   theMap.SetMapStyle(VEMapStyle.Aerial);
   RouteThumbs(4)
  }
  
  function MapStyleHybrid()
  {           
   theMap.SetMapStyle(VEMapStyle.Hybrid);
   RouteThumbs(5);
   document.getElementById('RoadHybrid').style.display = 'inline'; 
  }
  
  function MapHideLayer()
  {           
   myShapeLayer.Hide();
   document.getElementById('HideLayer').style.display = "none";
   document.getElementById('ShowLayer').style.display = "inline";
  }
  
  function MapShowLayer()
  {           
   myShapeLayer.Show();
   document.getElementById('ShowLayer').style.display = "none";
   document.getElementById('HideLayer').style.display = "inline";
  }
  
  function deleteRoute()
  {
  try
  {
  theMap.DeleteRoute();
  document.getElementById('route').style.display = 'none';
  document.getElementById('routestart').value = "";
  document.getElementById('routestart').style.background ='url(App_Themes/route_01.gif) no-repeat';
  }
  catch (err)
  {
  alert(err.message);
  }
  }
         
  function myRouteHandler(route)
{
   // Unroll route and populate alert text
   var legs          = route.RouteLegs;
   var turns         = "<h3>Ihre Route</h3><br>";
   var leg           = null;
   var turnNum       = 0;  // The turn #
   var totalDistance = 0;  // The sum of all leg distances

   // Get intermediate legs
   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
      var legDistance = null;  // The distance for this leg

      for(var j = 0; j < leg.Itinerary.Items.length; j ++)
      {
         turnNum++;
         // turn is a VERouteItineraryItem object
         turn = leg.Itinerary.Items[j];  
         turns += turnNum + ":  " + turn.Text;
         legDistance    = turn.Distance;
         totalDistance += legDistance;

         // Round distances to 1/10ths
         // Note that miles is the default
         turns += " (" + legDistance.toFixed(1) + " km)<br>";
      }
   }
   turns += "<br /><strong>Enfernung (gesamt):  " + totalDistance.toFixed(1) + " km</strong><br>";

   // Show directions
   document.getElementById('route').innerHTML = turns;
   document.getElementById('route').style.display = 'block';
}




