﻿// JScript 文件
function GMapsNamespace2() {
	var xxx=["innerHTML","textSize","printText","textAnchor"];
	function GText(a){
		this.properties=new Object();
		if(a)
		{
			for(var b=0;b<xxx.length;b++)
			{
				var c=xxx[b];
				this[c]=a[c]
			}
		}
	}
	var vGText = new GText();
	vGText.innerHTML = "";
	vGText.printText = "";
	vGText.textSize=new GSize(20,34);
	vGText.textAnchor=new GSize(9,34);

	function appendPXstring(a){return Math.round(a)+"px"}

	function setClassName(a,b)
	{
		if(a.className){a.className+=" "+b}
		else{a.className=b}
	//	alert(b)
	}

	function fa22(){}
	fa22.create=function(a,b,c,d,e,f,h,g,i){
		var m;
		i=i||document;
		m=i.createElement("div")
		if(navigator.userAgent.toLowerCase().indexOf("mozilla")==-1)m.innerText = a;
		else m.appendChild(document.createTextNode(a));
		if(b&&c)
		{
			m.style.width=appendPXstring(b);
			m.style.height=appendPXstring(c);
			m.width=b;
			m.height=c
		}
		if(e||(d||(e==0||d==0)))
		{
			m.style.position="absolute";
			m.style.left=appendPXstring(d);
			m.style.top=appendPXstring(e)
		}
		if(f||f==0)
		{
			m.style.zIndex=f
		}
		m.style.border="0";
		if(g){setClassName(m,g)}
		if(h>=0)
		{
	//		m.setAttribute("className","mapclass"+h);
			setClassName(m,'mapclass'+h);
	/*
			m.style.fontFamily = h.family;
			m.style.fontSize = h.size;
			m.style.color = h.color;
	*/
		}
		return m
	};

	function GFont(family,size,gcolor){this.family=family||"宋体";this.size=size||"9pt";this.color = gcolor||"#ffff00"};

	function GMarker2(a,b,c){this.point=a;this.text=b||vGText;this.classid=c;};
	GMarker2.prototype = new GOverlay();
	GMarker2.prototype.initialize=function(a)
	{
//		this.map=a;
//		var b=this.text;
//		var c=this.classid;
//		this.eText=fa22.create(b.innerHTML,
//								b.textSize.width,
//								b.textSize.height,
//								0,
//								0,
//								null,
//								c,
//								null,
//								a.ownerDocument);
//		var v=navigator.userAgent.toLowerCase();
//	//	v.indexOf("mozilla")!=-1
//		if(b.printText&&v.indexOf("mozilla")==-1)
//		{
//			this.printText=fa22.create(b.printText,
//								b.textSize.width,
//								b.textSize.height,
//								0,
//								0,
//								null,
//								-1,
//								"noscreen",
//								a.ownerDocument);
//		}
//		this.map.div.appendChild(this.eText);
//		if(this.printText) this.map.div.appendChild(this.printText);
		var div = document.createElement("div");
		div.style.border = 0;//this.weight_ + "px solid " + this.color_;
		div.style.width=appendPXstring(this.text.textSize.width);
		div.style.height=appendPXstring(this.text.textSize.height);
		div.style.position = "absolute";  // 我们的矩形相对于地图是平面，所以我们将其添加到 MAP_PANE 面板，该面板与地图本身在 z 轴上的次序相同（即在标记阴影下方）  
		if(navigator.userAgent.toLowerCase().indexOf("mozilla")==-1)div.innerText = this.text.printText;
		else div.appendChild(document.createTextNode(this.text.printText));
		if(this.classid>=0)
		{
			setClassName(div,'mapclass'+this.classid);
		}
		map.getPane(G_MAP_MAP_PANE).appendChild(div);  
		this.map_ = map;  
		this.div_ = div;
	}
	GMarker2.prototype.remove=function(){
//		this.map.div.removeChild(this.eText);
//		if(this.printText) this.map.div.removeChild(this.printText);
		this.div_.parentNode.removeChild(this.div_);
	};
	GMarker2.prototype.redraw=function(force)
	{
//		if(!a)return;
//		var b=this.map.spec.getBitmapCoordinate(this.point.y,this.point.x,this.map.zoomLevel);
//		var c=this.map.getDivCoordinate(b.x,b.y);
//	//alert(c.x+'   '+c.y);
//		var d=c.x+18;//-this.text.textAnchor.x;
//		var e=c.y-30;//-this.text.textAnchor.y;
//		this.eText.style.left=appendPXstring(d);
//		this.eText.style.top=appendPXstring(e)
//		if(this.printText)this.printText.style.left=appendPXstring(d);
//		if(this.printText)this.printText.style.top=appendPXstring(e)
	// 仅当坐标系发生更改时，我们才需要重新绘制  
		if (!force) return;  // 计算边界两个对角的 DIV 坐标，以得到矩形的尺寸和位置  
		var c1 = this.map_.fromLatLngToDivPixel(this.point);  
		var c2 = this.map_.fromLatLngToDivPixel(this.point);  // 现在根据边界的 DIV 坐标放置 DIV  
//		this.div_.style.width = c1.x + "px";  
//		this.div_.style.height = c1.y + "px";  
		this.div_.style.left = (c1.x + 18) + "px";  
		this.div_.style.top = (c1.y - 30) + "px";
	};
//	GMarker2.prototype.getLatitude=function(){return this.point.y};
//	GMarker2.prototype.setZIndex=function(a)
//	{
//		this.eText.style.zIndex=a[6];
//		if(this.printText) this.printText.style.zIndex=a[5];
//	};
	GMarker2.prototype.copy=function(){return new GMarker2(this.point,this.text,this.classid)};
//	GMarker2.prototype.display=function(a)
//	{
//		if(a)
//		{
//			this.eText.style.display="";
//			if(this.printText)this.printText.style.display="";
//		}
//		else
//		{
//			this.eText.style.display="none";
//			if(this.printText)this.printText.style.display="none";
//		}
//	};
	window.GMarker2=GMarker2;
	window.GText=GText;
	window.GFont=GFont;
}

var icon;
var icon2;
var map;
var gMarkers; 
var gInfoHtml; 
var gMarkers2;

function mapFunction(){
	return function() {
		var center = map.getCenter();
		var bounds = map.getBounds(); 
		var southWest = bounds.getSouthWest();
		var northEast = bounds.getNorthEast();
		var x = center.lng();
		var y = center.lat();
		var x1=x;
		var y1=y;
		var latLngStr 
			= '经度=' 
			+ (x>0?Math.round(x-0.5):Math.round(x+0.5)) + '°'
			+ Math.abs(x>0?(Math.round(x*60-0.5)%60):(Math.round(x*60+0.5)%60))+'′'
			+ Math.abs(x>0?(Math.round(x*3600-0.5)%60):(Math.round(x*3600+0.5)%60)) 
			+  '〞(' + x1.toFixed(6) +')<br>'
			+ '纬度=' 
			+  (y>0?Math.round(y-0.5):Math.round(y+0.5)) + '°'
			+ Math.abs(y>0?(Math.round(y*60-0.5)%60):(Math.round(y*60+0.5)%60))+'′'
			+ Math.abs(y>0?(Math.round(y*3600-0.5)%60):(Math.round(y*3600+0.5)%60)) 
			+ '〞(' + y.toFixed(6) + ')';
		document.getElementById("message").innerHTML = latLngStr;

		var lvl = map.getZoom();
		if(lvl<8){
			while(typeof gInfoHtml != "undefined" && gInfoHtml.length>0)gInfoHtml.pop();
			while(typeof gMarkers != "undefined" && gMarkers.length>0) map.removeOverlay(gMarkers.pop());
			while(typeof gMarkers2 != "undefined" && gMarkers2.length>0) map.removeOverlay(gMarkers2.pop());
		}

		if(lvl>7){
			var request = GXmlHttp.create();
			var xmlurl;
			if(lvl>8)xmlurl = 'gcityxml.aspx?minX=';
			else xmlurl = 'gareaxml.aspx?minX=';
			xmlurl += southWest.lng() + '&maxX=' + 
				northEast.lng() + '&minY=' + southWest.lat() + '&maxY=' + northEast.lat();
			request.open( 'GET', xmlurl, true ); 
			request.onreadystatechange = function() {

				if (request.readyState == 4) {
					var xmlDoc = request.responseXML;
					var markers = xmlDoc.documentElement.getElementsByTagName("marker");

					while(typeof gInfoHtml != "undefined" && gInfoHtml.length>0)gInfoHtml.pop();
					while(typeof gMarkers != "undefined" && gMarkers.length>0) map.removeOverlay(gMarkers.pop());
					while(typeof gMarkers2 != "undefined" && gMarkers2.length>0) map.removeOverlay(gMarkers2.pop());

					gMarkers = new Array( markers.length ); 
					gMarkers2 = new Array( markers.length ); 
					gInfoHtml = new Array( markers.length ); 
document.getElementById("citymessage").innerHTML = '视野中共有'+(markers.length)+'座县级以上城市。<br>(点击红色标记，可查详细信息)<br>'
	+'当前浏览级别为'+lvl+'。';

					for (var i = 0; i < markers.length; i++) {
						var Lat = parseFloat(markers[i].getAttribute("lat")); 
						var Lon = parseFloat(markers[i].getAttribute("lon")); 
						var countryid = parseInt(markers[i].getAttribute("countryid")); 
						var country = markers[i].getAttribute("country"); 
						var provid = markers[i].getAttribute("provid"); 
						var prov = markers[i].getAttribute("prov"); 
						var dist = markers[i].getAttribute("area");
						var areaid = parseInt(markers[i].getAttribute("areaid"));
						var city = markers[i].getAttribute("city");
						var cityid = ((lvl<9)?markers[i].getAttribute("cityid"):0);
						var point = new GLatLng(Lat, Lon);
						var text = new GText();
						text.innerHTML = city;
						text.printText = city;
						text.textSize=new GSize(20,34);
						text.textAnchor=new GSize(6,20);
						var vfont = i;
						gMarkers[i] = new GMarker(point,icon);
						var classid=0;
						if (!areaid) classid=countryid%14;
						if (lvl>8)classid=areaid%14;
						else classid=provid%14;
						gMarkers2[i] = new GMarker2(point,text,classid);
						gInfoHtml[i] = '城市名称：'+city+'<br>'
									+'地区：'+dist+'<br>'
									+'省份：'+prov+'<br>'
									+'国家：'+country+'<br>'
									+'经度：'+Lon.toFixed(6)+'<br>'
									+'纬度：'+Lat.toFixed(6)+'<br>'
									+'当前浏览级别：'+map.getZoom()+'<br>'
									+((lvl<9)?('<br>该城市经纬度如有问题，请<a target=_blank style="color:red" href="../gmodifyll.asp?cid='+cityid+'">点击这儿</a>修改。谢谢！'):'');
						map.addOverlay(gMarkers[i]);
						map.addOverlay(gMarkers2[i]);
						GEvent.addListener( gMarkers[i], 'click', makeOpenerCaller(i) ); 
					}
				}else document.getElementById("citymessage").innerHTML = '正在获取城市信息...';
			};
			request.send(null);
		}
		else document.getElementById("citymessage").innerHTML = '当前浏览级别为'+map.getZoom()+'，不能查看城市标记。';
	}
}

function onLoad() {
	if (GBrowserIsCompatible())
	{
		GMapsNamespace2()

		icon = new GIcon();
	//	icon.image = "gmap.gif";
	//	icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
		//icon.image = "gmap_arrow_12.gif";
		icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
		icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
		icon.iconSize = new GSize(14, 20);
		icon.shadowSize = new GSize(20, 20);
		icon.iconAnchor = new GPoint(6, 20);
		icon.infoWindowAnchor = new GPoint(5, 1);
		icon2 = new GIcon(icon);
		icon2.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";

		map = new GMap2(document.getElementById("map"));
		map.setMapType(G_SATELLITE_MAP); 
		map.addControl(new GLargeMapControl());
		map.setCenter(new GLatLng(33, 120), 8);

		GEvent.addListener(map, "moveend", new mapFunction());
		GEvent.addListener(map, "load", new mapFunction());
 		GEvent.addListener(map, "movestart", function() {var latLngStr = '正在获取数据...<br>&nbsp;<br>';document.getElementById("message").innerHTML = latLngStr});
	}
}

function opener(i){ 
 		document.getElementById("citymessage").innerHTML = gInfoHtml[i];
} 
	
function makeOpenerCaller(i) 
{ 
		return function() { opener(i); }; 
} 

function createMarker(point) {
		var marker = new GMarker(point, icon2);
		map.addOverlay(marker);
		GEvent.addListener(marker, "click", function() {
			map.removeOverlay(marker);
		});
}

	var arg = 0;
	var x1,y1,x2,y2;
	var polyline;

    function calc88(){
		var center = map.getCenter();
		arg += 1;
//		alert(arg);
		if (arg==1){
			x1 = center.lng();
			y1 = center.lat();
			var x=x1;
			var y=y1;
			var latLngStr 
				= '<b>起点位置：</b><br>经度=' 
				+ (x>0?Math.round(x-0.5):Math.round(x+0.5)) + '°'
				+ Math.abs(x>0?(Math.round(x*60-0.5)%60):(Math.round(x*60+0.5)%60))+'′'
				+ Math.abs(x>0?(Math.round(x*3600-0.5)%60):(Math.round(x*3600+0.5)%60)) 
				+  '〞(' + x1.toFixed(6) +')<br>'
				+ '纬度=' 
				+  (y>0?Math.round(y-0.5):Math.round(y+0.5)) + '°'
				+ Math.abs(y>0?(Math.round(y*60-0.5)%60):(Math.round(y*60+0.5)%60))+'′'
				+ Math.abs(y>0?(Math.round(y*3600-0.5)%60):(Math.round(y*3600+0.5)%60)) 
				+ '〞(' + y.toFixed(6) + ')';
			document.getElementById("start8").innerHTML = latLngStr;
			document.getElementById("end8").innerHTML = '<b>终点位置：</b>';
			document.getElementById("juli").innerHTML = '<b>直线距离：</b>';
			document.getElementById("ggjl").innerHTML = '<b>勾股距离：</b>';
			document.map2.julib.value = '获取终点位置';
			createMarker(new GLatLng(y1, x1));
    	}
		if (arg==2){
			x2 = center.lng();
			y2 = center.lat();
			var x=x2;
			var y=y2;
			var latLngStr 
				= '<b>终点位置：</b><br>经度=' 
				+ (x>0?Math.round(x-0.5):Math.round(x+0.5)) + '°'
				+ Math.abs(x>0?(Math.round(x*60-0.5)%60):(Math.round(x*60+0.5)%60))+'′'
				+ Math.abs(x>0?(Math.round(x*3600-0.5)%60):(Math.round(x*3600+0.5)%60)) 
				+  '〞(' + x1.toFixed(6) +')<br>'
				+ '纬度=' 
				+  (y>0?Math.round(y-0.5):Math.round(y+0.5)) + '°'
				+ Math.abs(y>0?(Math.round(y*60-0.5)%60):(Math.round(y*60+0.5)%60))+'′'
				+ Math.abs(y>0?(Math.round(y*3600-0.5)%60):(Math.round(y*3600+0.5)%60)) 
				+ '〞(' + y.toFixed(6) + ')';
			document.getElementById("end8").innerHTML = latLngStr;

			var z;
			x=Math.abs(x1-x2)*12756*Math.PI/360;
			y=Math.abs(y1-y2)*12756*Math.PI/360;
			z=Math.sqrt(x*x+y*y);
			var latLngStr = '<b>直线距离：</b>' + z.toFixed(3) + '公里';
			document.getElementById("juli").innerHTML = latLngStr;
			document.getElementById("ggjl").innerHTML = '<b>勾股距离：</b>' + (x+y).toFixed(3) + '公里';
			document.map2.julib.value = '获取起点位置';
			arg=0;

			createMarker(new GLatLng(y2, x2));
			if(polyline) map.removeOverlay(polyline);
			polyline = new GPolyline([new GLatLng(y1, x1), new GLatLng(y2, x2)], "#ffff00", 2, 1);
			map.addOverlay(polyline);

/*
			document.getElementById("juli").innerHTML = '<b>直线距离：</b>';
			document.getElementById("ggjl").innerHTML = '<b>勾股距离：</b>';
			document.map2.julib.value = '计算两点距离';
*/
    	}
		if (arg==3){
			var x;
			var y;
			var z;
			x=Math.abs(x1-x2)*12756*Math.PI/360;
			y=Math.abs(y1-y2)*12756*Math.PI/360;
			z=Math.sqrt(x*x+y*y);
			var latLngStr = '直线距离：' + z.toFixed(3) + '公里';
			document.getElementById("juli").innerHTML = latLngStr;
			document.getElementById("ggjl").innerHTML = '勾股距离：' + (x+y).toFixed(3) + '公里';
			document.map2.julib.value = '获取起点位置';
			arg=0;
    	}
    }
    
    function clear88(){
    	map.removeOverlay(polyline);
    	map.clearOverlays();
    }

    function submit2(){
    	var jd,wd;
    	if(parseInt(document.map1.fs.value)==2){
	    	var jd1 = parseInt(document.getElementById("jd1").value);
	    	var jd2 = parseInt(document.getElementById("jd2").value);
	    	var wd1 = parseInt(document.getElementById("wd1").value);
	    	var wd2 = parseInt(document.getElementById("wd2").value);
	    	if(jd1>=180 || jd1<=-180 || jd2 >=60 || jd2 <0 || wd1>90 || wd1<-90 || wd2 >=60 || wd2 <0)
	    	{
	    		alert('经纬度输入有误，请仔细检查！！！');
	    		return;
	    	}
	    	jd = jd1+jd2/60;
	    	wd = wd1+wd2/60;
    	}else{
	    	jd = parseFloat(document.getElementById("jd").value);
	    	wd = parseFloat(document.getElementById("wd").value);
	    	if(jd>=180 || jd<=-180 || wd1>90 || wd<-90)
	    	{
	    		alert('经纬度输入有误，请仔细检查！！！');
	    		return;
	    	}
    	}
		var point = new GLatLng(wd, jd);
    	map.setCenter(point, 5)
    	createMarker(point);
    }
