﻿// JScript 文件

var pos_djh = "";
function ShowMap2D()
{
    alert("this is 2D map,now close mapdiv");
    document.getElementById("mapDiv").style.display='none';
    document.getElementById("Map2DDivIframe").style.display='block';
    //window.open('Map2D.aspx','index','top=0,left=0,width=600,height=400');
    //if(arguments[0] != "")
    //{
   //    var par = document.web.WebSearchBuilding('_BUILDING_B_XCAa_46','建筑');
        //parent.parent.parent.document.getElementById('analyzeDivIframe').style.height = '57px';
   //     alert(par);
    //}
    //else
    //{
        alert('3Dmap and 2.5Dmap are closed,and 2Dmap is opened');    
    //}
}
function ShowMap3D()
{
    alert("this is 3D/2.5D map");
    document.getElementById("mapDiv").style.display='block';
    document.getElementById("Map2DDivIframe").style.display='none';
    alert('3Dmap and 2.5Dmap are opened,and 2Dmap is closed');    
}
function ShowMap(style)
{
    if (style=="2D")
    {
        document.getElementById("Map2DDivIframe").style.display='block';
        document.getElementById("btnList2D").className="btnList2";
        document.getElementById("btnList2").className="btnList1";
        document.getElementById("btnList1").className="btnList1";//alert(document.getElementById("Map2DDivIframe").contentWindow.pos_djh)
	document.getElementById("Map2DDivIframe").contentWindow.load(document.getElementById("Map2DDivIframe").contentWindow.pos_djh);
    }
    else if ((style=="25D")||(style=="3D"))
    {
        document.getElementById("Map2DDivIframe").style.display='none';
        document.getElementById("btnList2D").className="btnList1";
        
    }
}

var map;
var geocoder=null;
var marker1;
//var myIcon= new GIcon();
////前景图片
//myIcon.image = "IMAGE/定位标签1.png";
////阴影图片
//myIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
////前景图片大小，长x宽
//myIcon.iconSize = new GSize(16, 16);
////阴影图片大小，长x宽
//myIcon.shadowSize = new GSize(12, 20);

////以下两个属性很难解释，读者可自行调整其数值以便理解其意义
//// myIcon锚定点相对于myIcon图片左上角的像素距离
//myIcon.iconAnchor = new GPoint(6, 10);
////信息窗口相对于myIcon图片左上角的像素距离
////关于信息窗口会在以后介绍
//myIcon.infoWindowAnchor = new GPoint(5, 1);


function load() {//alert("args"+arguments[0])
//    alert(parent.document.documentElement.offsetHeight);
//    alert(parent.document.documentElement.offsetWidth);
//    
//    alert(document.documentElement.offsetHeight);
//    alert(document.documentElement.offsetWidth);
//    
 //   alert(document.getElementById('map').style.height);
 //   alert(document.getElementById('map').style.width);
//alert("document.documentElement.offsetHeight:"+parent.document.documentElement.offsetHeight+"\n parent.document.documentElement.offsetWidth:"+parent.document.documentElement.offsetWidth+"\n document.documentElement.offsetHeight:"+document.documentElement.offsetHeight+"\n document.documentElement.offsetWidth"+document.documentElement.offsetWidth+"\n document.getElementById('map').style.height:"+document.getElementById('map').style.height+"\n document.getElementById('map').style.width"+document.getElementById('map').style.width)
    if (GBrowserIsCompatible()) {  
        map = new GMap2(document.getElementById("map"));
        
        //添加两个GOverviewMapControl()控件
        //map.addControl( new GOverviewMapControl() );
		//map.setUIToDefault();
		
		map.addControl(new GLargeMapControl(),
				new GControlPosition(G_ANCHOR_BOTTOM_LEFT , new GSize(5,5)));
		
        //map.addControl(new GOverviewMapControl(),new GControlPosition(G_ANCHOR_TOP_RIGHT  , new GSize(0,0)));
        // 下沙坐标，缩放值13
        map.setCenter(new GLatLng(30.304865, 120.349883), 10);
		
		//GEvent.addListener(map, "click", getAddress);
      geocoder = new GClientGeocoder();
	  
	  document.getElementById("map").childNodes[1].style.display =
"none";
   document.getElementById("map").childNodes[2].style.display =
"none"; 

    }
	
	if(arguments[0]!="" && arguments[0]!=undefined && arguments[0] != null)
	{
		GetPosition(arguments[0]);
		setNull();
	}
}

function setNull()
{
	pos_djh = "";
}
	
// 等坐标稳定后使用
/*	
function GetPosition(position)
{
    //alert('remove');
    map.clearOverlays();
    var positionInfo = position.split(",");
    // 校正系统和Google地图
    var glat = positionInfo[1]-0.0970;
    var glng = positionInfo[0]-0+0.1100;
    
    if (geocoder) {
        var latlng = new GLatLng(glat,glng);
        map.setCenter(latlng, 13);
        
        //alert(positionInfo[2]);
//        var marker = new GMarker(latlng);
//		map.addOverlay(marker);
//		//marker.openInfoWindowHtml(latlng);
//		//创建GInfoWindowTab数组
		//var tabs = [new GInfoWindowTab("基本信息", "<div style='width:300px;height:200px'>基本信息</div>"),
		//            new GInfoWindowTab("详细信息", "<div style='width:300px;height:200px'>详细信息</div>"),
		//            new GInfoWindowTab("周边搜索", "<div style='width:300px;height:200px'>周边搜索</div>")];
        marker1 = new GMarker(latlng,//创建自定义的GMarker
                                {icon: myIcon,
                                 title: positionInfo[2]});
                                 //alert(positionInfo[2]);
        //显示自定义了图标的地标对象marker1
        map.addOverlay(marker1); 
        var content924 = '<div style="background-color: White;font-size: 1.1em; padding: 8px; color:Red">'+positionInfo[2]+'</div>';
		marker1.openInfoWindowHtml(content924);
        //var marker = new GMarker(latlng);
		//map.addOverlay(marker);
		//alert(positionInfo[2]);
        //var content924 = '<div style="background-color: White;font-size: 1.1em; padding: 8px; color:Red">'+positionInfo[2]+'</div>';
        //var label924 = new TLabel();
        
        //label924.id = 'label924';
        //label924.anchorLatLng = latlng;
        //label924.anchorPoint = 'bottomLeft';
        //label924.markerOffset = new GSize(1,1);
        //label924.content = content924;
        //label924.percentOpacity = 90;
        
        //map.addTLabel(label924);
        //alert('remove label');
        
        //addlabel(positionInfo[2],latlng);
        //map.removeTLabel(label924);
      }
}
*/
function clearMarkers()
{
    map.clearOverlays();
}
function GotoMarker(markername){
	// 解析xml文件
	GDownloadUrl("data.xml", function(data) {
          var xml = GXml.parse(data);
          var markers = xml.documentElement.getElementsByTagName("marker");
          for (var i = 0; i < markers.length; i++) {
			if (markers[i].getAttribute("name")==markername) {
					var latlng = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                                     parseFloat(markers[i].getAttribute("lng")));
					map.setCenter(latlng, 13);
					var marker = new GMarker(latlng);
					map.addOverlay(marker);
					//marker.openInfoWindowHtml(latlng);
					//创建GInfoWindowTab数组
					var content924 = '<div style="background-color: White;font-size: 1.1em; padding: 8px; color:Red">'+markername+'</div>';
		            marker.openInfoWindowHtml(content924);

				}
          }
        });
	}
function GetPosition(position)
{pos_djh = position;//alert(pos_djh)
//load();

    var positionInfo = position.split(",");
    GDownloadUrl("data.xml", function(data) {
          var xml = GXml.parse(data);
          var markers = xml.documentElement.getElementsByTagName("marker");
          for (var i = 0; i < markers.length; i++) {
			if (markers[i].getAttribute("name")==positionInfo[2]) {
					var latlng = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                                     parseFloat(markers[i].getAttribute("lng")));
					map.setCenter(latlng, 13);
					var marker = new GMarker(latlng);
					map.addOverlay(marker);
					//marker.openInfoWindowHtml(latlng);
					//创建GInfoWindowTab数组
					var content924 = '<div style="background-color: White;font-size: 1.1em; padding: 8px; color:Red">'+positionInfo[2]+'</div>';
		            marker.openInfoWindowHtml(content924);

				}
          }
        });
}
