﻿var map = null;                  
function GetMap(elem, point, zoomLevel, type, HideDashboard){            
    map = new VEMap(elem);
    map.LoadMap(point,zoomLevel ,type ,false);
    //map.SetMapMode(VEMapMode.Mode3D);
    map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
    if(HideDashboard){
        map.HideDashboard();
    }
}


function DoPixelToLL(x,y){
    return ll = map.PixelToLatLong(new VEPixel(x,y)).toString();
}

function AddPushpin(lat, lng, title, description, isCenter , zoomLevel, icon){          
    var shape = new VEShape(VEShapeType.Pushpin, new VELatLong(lat, lng));          
    //Set the icon         
    if (icon != ''){
        shape.SetCustomIcon(icon);
    }
    //map.ClearInfoBoxStyles();
    shape.SetTitle(title);          
    shape.SetDescription(description);          
    map.AddShape(shape);
    if (isCenter){
        DoCenterZoom(lat, lng, zoomLevel);
    }      
}  

function AddPolyline(points, title, description){         
    var shape = new VEShape(VEShapeType.Polyline, points); 
    //Set the line color         
    var lineColor = new VEColor(Math.round(254*Math.random()),Math.round(254*Math.random()),Math.round(254*Math.random()),Math.random());         
    shape.SetLineColor(lineColor);                  
    //Set the line width         
    var lineWidth = Math.round(5*Math.random()+1);         
    shape.SetLineWidth(lineWidth);        
    shape.SetTitle(title);         
    shape.SetDescription(description);         
    map.AddShape(shape);      
} 

function DoZoomIn(){         
    map.ZoomIn();      
}          

function DoZoomOut(){         
    map.ZoomOut();      
}          

function DoZoom(zoomLevel){         
    map.SetZoomLevel(zoomLevel);      
} 

function DoCenterZoom(lat, lng, zoomLevel){         
    map.SetCenterAndZoom(new VELatLong(lat, lng), zoomLevel);      
}

function ChangeMapStyle(){
    var s=map.GetMapStyle();
    if (s==VEMapStyle.Hybrid){
        map.SetMapStyle(VEMapStyle.Road);            
    }            
    else {
        map.SetMapStyle(VEMapStyle.Hybrid);            
    }
}

/*function AddPolygon(){         
    var ll = map.GetCenter();         
    var lat = ll.Latitude;         
    var lon = ll.Longitude;         
    var shape = new VEShape(VEShapeType.Polygon, [
        new VELatLong(lat,lon-0.15),
        new VELatLong(lat+0.1,lon-0.05),
        new VELatLong(lat+0.1,lon+0.05),
        new VELatLong(lat,lon+0.15),
        new VELatLong(lat-0.1,lon+0.05),
        new VELatLong(lat-0.1,lon-0.05)
        ]);         
    //Set the fill color         
    var fillColor = new VEColor(Math.round(254*Math.random()),Math.round(254*Math.random()),Math.round(254*Math.random()),Math.random());         
    shape.SetFillColor(fillColor);
    shape.SetTitle('My polygon');         
    shape.SetDescription('This is shape number '+pinid);         
    pinid++;         
    map.AddShape(shape);      
 } 
 function AddMyLayer(type){            
    var l = new VEShapeLayer();            
    var veLayerSpec = new VEShapeSourceSpecification(type, txtSource.value, l);
    map.ImportShapeLayerData(veLayerSpec, onFeedLoad);         
 }     
 
 function onFeedLoad(feed){            
    alert('RSS or Collection loaded. There are ' + feed.GetShapeCount() + ' items in this list.');         
 }
 
  map.GetDirections(["Microsoft", "Everett WA", "Bellingham WA"]);
  
 function deleteRoute(){            
    try
    {                
        map.DeleteRoute();            
    }            
        catch (err)            
    {                
        alert(err.message);            
    }         
 }
*/