

// JavaScript Document

// code modifié par L.DEJEAN HELIANTIS 22/10/2008

 var map = null;
 

//var InfobullePos = new VELatLong(34.0540, -118.2370);
var pinPoint = null;
var pinPixel = null;

var latLong = null;



function GetAdminMap()
{
	
	
	InfobulleTitre = document.getElementById('ibtitre').value
	InfobulleDesc = document.getElementById('ibdesc').value.replace("\n","<br>");

	
	
	map = new VEMap('worldMap');
	InfobullePos = new VELatLong(document.getElementById('lattitude').value,document.getElementById('longitude').value);

	
	map.LoadMap(InfobullePos , 9);	
	
	map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
	map.AttachEvent('onclick', onMapClick);
	
	
	 var shape = new VEShape(VEShapeType.Pushpin, InfobullePos);  
 	
         shape.SetCustomIcon("../admin/images/icons/mapInfobulle.gif");      
 		shape.SetTitle(InfobulleTitre);  
      	shape.SetDescription(InfobulleDesc);       	
        map.AddShape(shape); 
		map.SetCenter(InfobullePos);
	
} 



function GetMap()
{
	
	InfobulleTitre = document.getElementById('ibtitre').value
	InfobulleDesc = document.getElementById('ibdesc').value.replace("\n","<br>");

	
	
	map = new VEMap('worldMap');
	InfobullePos = new VELatLong(document.getElementById('lattitude').value,document.getElementById('longitude').value);

	map.LoadMap(InfobullePos, 10);
	map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
	//map.HideDashboard();

	
	 var shape = new VEShape(VEShapeType.Pushpin, InfobullePos);  
 	
         shape.SetCustomIcon("../com/VirtualEarth/mapInfobulle.gif");      
 		shape.SetTitle(InfobulleTitre);  
      	shape.SetDescription(InfobulleDesc);       	
        map.AddShape(shape); 
		map.SetCenter(InfobullePos);
} 

function getInfo()
         {
            var info;

            if (map.IsBirdseyeAvailable())
            {
                var be = map.GetBirdseyeScene();

                info  = "ID: "          + be.GetID() + "\n";
                info += "orientation: " + be.GetOrientation()+ "\n";
                info += "height: "      + be.GetHeight() + "\n";
                info += "width: "       + be.GetWidth() + "\n";

                var pixel = be.LatLongToPixel(map.GetCenter(), map.GetZoomLevel());

                info += "LatLongToPixel: " + pixel.x + ", " + pixel.y + "\n";

                // Check to see if the current birdseye view contains the pushpin pixel point.
                info += "contains pixel " + pinPixel.x + ", " + pinPixel.y + ": " + 
                        be.ContainsPixel(pinPixel.x, pinPixel.y, map.GetZoomLevel()) + "\n";
                
                // Check to see if the current view contains the pushpin LatLong.
                info += "contains latlong " + pinPoint + ": " + be.ContainsLatLong(pinPoint) + "\n";
                
                // This method may return null, depending on the selected view and map style.
                info += "latlong: " + map.PixelToLatLong(pixel);

                alert(info);
            }
            else
            {
                var center = map.GetCenter();

                info  = "Zoom level:\t" + map.GetZoomLevel() + "\n";
                info += "Latitude:\t"   + center.Latitude    + "\n";
                info += "Longitude:\t"  + center.Longitude;

                alert(info);
            }
         }
         
         
 
         
 function onMapClick(e)
{
	

	var x = e.mapX;
    var y = e.mapY;
    
    pixel = new VEPixel(x, y);

	 if (e.rightMouseButton) {
	// alert('lolo test 2');
	 	map.DeleteAllShapes();
	 	
        var latLong = map.PixelToLatLong(pixel);          
       
         
       var shape = new VEShape(VEShapeType.Pushpin, latLong);  
 		
        shape.SetCustomIcon("../admin/images/icons/mapInfobulle.gif");      
 		shape.SetTitle(InfobulleTitre);  
      	shape.SetDescription(InfobulleDesc); 
      	map.AddShape(shape);        
      	map.SetCenter(latLong)
      	
      	
      	 document.getElementById('lattitude').value = latLong.Latitude;        
        document.getElementById('longitude').value = latLong.Longitude;  


    }

		
	 
	
}

