﻿// JScript 檔

    var map = null; 
    var geocoder = null; 
    var marker; 
     
    function initialize()  
    { 
        if (GBrowserIsCompatible())  
        { 
            map = new GMap2(document.getElementById("map")); 
            map.addControl(new GLargeMapControl());                 //加入地圖縮放工具 
//            map.addControl(new GMapTypeControl());                 //加入地圖切換的工具 
            map.addMapType(G_PHYSICAL_MAP);                         //加入地形圖 
            map.setCenter(new GLatLng(25.001689, 121.460809), 15);   //設定台灣為中心點 
            geocoder = new GClientGeocoder(); 
        } 
    } 

    function createMarker(point,title,html)  
    { 
        var marker = new GMarker(point); 
         
        GEvent.addListener(marker, "click", function()  
        { 
            marker.openInfoWindowHtml( 
                html, 
                { 
                    maxContent: "標記內容", 
                    maxTitle: "標記抬頭"} 
                ); 
        }); 
        return marker; 
    } 
     
    function showAddress(address)  
    { 
        map = new GMap2(document.getElementById("map")); 
        map.addControl(new GLargeMapControl());                 //加入地圖縮放工具 
        map.addMapType(G_PHYSICAL_MAP); 
        geocoder = new GClientGeocoder(); 
        if (geocoder)  
        { 
            geocoder.getLatLng( 
                address, 
                function(point)  
                { 
                    if (!point)  
                    { 
                        alert(address + " not found"); 
                    }  
                    else  
                    { 
                        if(marker)  //移除上一個點 
                        { 
                            map.removeOverlay(marker); 
                        } 
                         
                        map.setCenter(point, 15); 
                         
                        var title = "地址"; 
                         
                        marker = createMarker(point,title,"XXXXXX餐廳"); 

                        map.addOverlay(marker); 

//                        marker.openInfoWindowHtml( 
//                            "XXXXXX餐廳", 
//                            { 
//                                maxContent: "詳細內容", 
//                                maxTitle: "抬頭文字"} 
//                            ); 
                    } 
                } 
            ); 
        } 
    }
    
    function flymap(cimg,div,address) 
    {
        document.all("MapDiv").style.top=window.event.clientY+document.documentElement.scrollTop+10;
        document.all("MapDiv").style.left=350;//event.screenX;
        document.all("MapDiv").style.visibility ="visible"
        //alert(address)
        showAddress(address)
    }
