﻿var map = null;



function GetMap(sLat, sLong, zoom, bAddPushpin, sTitle, sDescr) {
    map = new VEMap('divMap');
    map.LoadMap(new VELatLong(sLat, sLong), zoom, 'h', false);
    map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
    if (bAddPushpin == 'true')
        AddPushpin(sLat, sLong, sTitle, sDescr);
    //map.AttachEvent("onclick", MouseHandler);
}



function AddPushpin(sLat, sLong, sTitle, sDescr)
{
    var shape = new VEShape(VEShapeType.Pushpin, new VELatLong(sLat, sLong));
    var icon = "<img src='/images/pushpin.gif' />";
    shape.SetCustomIcon(icon);
    if (sTitle != "")
        shape.SetTitle(sTitle);
    if (sDescr != "")
        shape.SetDescription(sDescr);
    map.AddShape(shape);
}


function AddAdsPoint(sLat, sLong, sImagePoint, sTitle, sDescr) {
    var shape = new VEShape(VEShapeType.Pushpin, new VELatLong(sLat, sLong));
    var icon = "<img src='/images/" + sImagePoint + "' />"; //
    shape.SetCustomIcon(icon);
    if (sTitle != "")
        shape.SetTitle(sTitle);
    if (sDescr != "")
        shape.SetDescription(sDescr);
    map.AddShape(shape);
}


//function MouseHandler(e)
//{
//    var msg;
//    if (e.eventName == "onclick")
//    {
//        if (e.leftMouseButton)
//        {
//            map.DeleteAllShapes();
//            var x = e.mapX;
//            var y = e.mapY;
//            var pixel = new VEPixel(x, y);
//            var LL = map.PixelToLatLong(pixel);
//            AddPushpin(LL.Latitude, LL.Longitude, "", "");
//            document.getElementById(tbLatID).value = LL.Latitude;
//            document.getElementById(tbLongID).value = LL.Longitude;
//        }
//    }
//}




///****** GOOGLE section *******/
//function localizza(street,city,cap,title)
//{
//    // Create new geocoding object
//      geocoder = new GClientGeocoder();
//      
//      address = document.getElementById(street).value + ', ' + document.getElementById(city).value + ', ' + document.getElementById(cap).value + ', IT';

//      // Retrieve location information, pass it to addToMap()
//      geocoder.getLocations(address, addToMap);
//}

//function addToMap(response)
//{
//      // Retrieve the object
//      place = response.Placemark[0];

//      // Retrieve the latitude and longitude
//      point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
//      
//      GetMap(place.Point.coordinates[1], place.Point.coordinates[0], 15, 'true', '', '')
//      
//      document.getElementById(tbLatID).value = place.Point.coordinates[1];
//      document.getElementById(tbLongID).value = place.Point.coordinates[0];
//}

