﻿var map=null;
function GetMap(lt,lg, alt){
    try{
    if (map!=null){map.Dispose()}
    mapDiv=document.getElementById("VEMAP")
    if (mapDiv){
        mapDiv.style.width=getWinWidth()+'px'
        mapDiv.style.height=getWinHeight()+'px'
    }
    map = new VEMap('VEMAP');
    var firstltlg=new VELatLong(lt,lg)
    map.LoadMap(firstltlg, 12, 'o', false, VEMapMode.Mode2D, true);
    map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
    var llPoint   = new VELatLong(46.171754,6.142766);
    pPoint = new VEShape(VEShapeType.Pushpin, llPoint);
    map.AddShape(pPoint)
    map.ShowMiniMap(5,getWinHeight()-195,VEMiniMapSize.Small);
    if (alt!=null){
        firstMapView = new VEMapViewSpecification(firstltlg, null, 1000+Altitude, -45, VEMapMode.Mode3D);
    }
    map.ZoomOut()
    }
    catch(e){
        try{
            map.Dispose();
            alert("une erreur est survenue lors du chargement de Virtual Earth:"+e)
        }
        catch(e2){
            alert("une erreur est survenue lors du chargement de Virtual Earth (2):"+e)
        }
    }
}
function getWinWidth () {
	var mapFrameWidth = window.innerWidth;
	if (mapFrameWidth == null) {
		if (document.documentElement && document.documentElement.clientWidth)
			mapFrameWidth = document.documentElement.clientWidth
		else	
			mapFrameWidth = document.body.clientWidth;
	}
	return mapFrameWidth;
}

 //get the Map Image height
function getWinHeight () {
	var mapFrameHeight = window.innerHeight;
	if (mapFrameHeight == null) {
		if (document.documentElement && document.documentElement.clientHeight)
			mapFrameHeight = document.documentElement.clientHeight;
		else
			mapFrameHeight = document.body.clientHeight;
	}
	return mapFrameHeight;
}
function ResizeMap() //resize
{
  if (map != null)
  {  
    if( typeof( window.innerWidth ) == 'number' )
    {
    map.Resize(window.innerWidth,window.innerHeight);
    } 
    else if( document.documentElement && ( document.documentElement.clientWidth
       || document.documentElement.clientHeight ) )
    {
    map.Resize(document.documentElement.clientWidth
      ,document.documentElement.clientHeight);
    }
    map.ShowMiniMap(getWinWidth()-200,5,VEMiniMapSize.Large);
  }
}
