﻿var tmap;
function actMapInitialize(){
    if($("home"))
        $handler($("home"), 'unload', GUnload);
    if (GBrowserIsCompatible()){
        var abc = getMapAbc();
        if(abc)
            tmap = new GMap2($('act_map'),{mapTypes:[getMapAbc(),G_NORMAL_MAP]});
        else
            tmap = new GMap2($('act_map'));
        tmap.setCenter(new GLatLng(34.23451236236987, 108.720703125), 4);
        tmap.addControl(new GLargeMapControl());
        tmap.enableScrollWheelZoom();
        addPoint();    
    }
}
function chlactMapInitialize() {
    if ($("home"))
        $handler($("home"), 'unload', GUnload);
    if (GBrowserIsCompatible()) {
        var abc = getMapAbc();
        if (abc)
            tmap = new GMap2($('act_map'), { mapTypes: [getMapAbc(), G_NORMAL_MAP] });
        else
            tmap = new GMap2($('act_map'));
        tmap.addControl(new GSmallMapControl());
        var directions = new GDirections(tmap);
        directions.loadFromWaypoints([new GLatLng(actDepartlat, actDepartlng), new GLatLng(actDestlat, actDestlng)]);
    }
}
function setMap(zoom,lat,lng){
    if(!tmap)
        return;
    if(!zoom)
        tmap.setZoom(4);
    else
        tmap.setZoom(zoom);
    if(!lat)
        tmap.panTo(new GLatLng(34.23451236236987, 108.720703125));
    else
        tmap.panTo(new GLatLng(lat, lng));
}
var draged = false;
var dragPoint;
function pointEnd() {
    tmap.closeInfoWindow();
    draged = true;
    $get("lat").value=dragPoint.getPoint().lat();
    $get("lng").value=dragPoint.getPoint().lng();
}
function selectEnd(zoom,lat,lng){
    if(draged)
        return;
    setMap(zoom,lat,lng);
    if(lat&&lng){
        dragPoint.setLatLng(new GLatLng(lat, lng));
        $get("lat").value=lat;
        $get("lng").value=lng;
        dragPoint.openInfoWindowHtml("<B>拖动这里标出的具体位置！</B><br />提示：放大地图，位置会更精确。");
    }
}
function addPoint(){
    draged = false;
    tmap.clearOverlays();
    if ($get("lat").value == '')
        $get("lat").value = '34.23451236236987';
    else
        draged = true;
    if ($get("lng").value == '')
        $get("lng").value = '108.720703125';
    else
        draged = true;
    var point = new GLatLng($get("lat").value, $get("lng").value);
    dragPoint=new GMarker(point,{draggable:true});
    GEvent.addListener(dragPoint, "dragend", pointEnd);
    tmap.addOverlay(dragPoint);
    dragPoint.openInfoWindowHtml("<B>拖动这里标出的具体位置！</B><br />提示：放大地图，位置会更精确。");
}