function onDoubleClickObject(mapobject)//---------------此函数实现双击事件---------------
{
if (mapobject.name != "")
alert(mapobject.name);
}

function onMapLoaded(map)//---------------此函数实现加载主地图的事件---------------
{
map.panMode();
earth("stop");
}
function onDigitizedPolygon(map, numPoints, points)
{
var layer = map.getMapLayer("update");
if (layer == null)
layer = map.createLayer("redline", "update");
var obj = layer.createMapObject("1","","");
// create MGCollection that holds user-specified polygon vertices
var user_vertices = map.createObject("mgcollection");
user_vertices.add(numPoints);
// use MGCollection to create polyline primitive and add it to
// redline object
obj.addPolylinePrimitive(points, user_vertices, false);
// clear contents of 'Polygon Name' text box
}

function onDigitizedPoint(map, point)//---------------此函数实现用户指定范围的查询，调用output_result()显示结果---------------
{
    var layername = '单位';
	var mapLayer = map.getMapLayer(layername);
    if (mapLayer.Visibility==false) 
	{
	 mapLayer.setVisibility(true);
	 map.setAutoRefresh(true);        
	 map.refresh();
	 alert("正在打开图层，请稍等。");
	}		
	var dist = document.all.find1.value;
	if (find_type==1)
	var type = 0;
	if(find_type==2)
	var type = document.all.find3.value;
	
if (find_type==1)//find_type=1时为范围查询
{
//画圆	
	var setup = map.getRedlineSetup();//在被选物体上动态加多边形
	var edgeAttri = setup.getEdgeAttr();
	edgeAttri.setColor(3);
	edgeAttri.setThickness(1);
	var fillAttri = setup.getFillAttr();
	fillAttri.setStyle("diagonal45");
	fillAttri.setColor(3);	
	
	var layer = map.getMapLayer("查询区域");
	if (layer == null)
	layer = map.createLayer("redline", "查询区域");
	layer.setPriority(100);
	layer.removeAllObjects();

	var obj = layer.createMapObject("1","搜索范围"+dist+"米","");
	obj.addCirclePrimitive(point,false,dist,"M",50);
//选中圆
	var mapSel = map.getSelection();
	if (mapSel.NumObjects > 0)
	mapSel.clear();
	var features = layer.getMapObjectsEx();
	 mapSel.addObjectsEx(features, false); 
	 map.setAutoRefresh(false);	
	if (mapSel == null || mapSel.NumObjects == 0)
	{	
	alert("error!");
	return;
	}
//在单位层中求交集
	 
	var layers = map.createObject("MGCollection");
	if (layers.Count > 0 )
	layers.removeAll();
	layers.add(mapLayer);
	map.selectWithin(layers);
	//map.setAutoRefresh(true);
	//map.refresh();
	
//显示结果
    alert("正在查找目标，请稍等。");
	if ( mapSel != null&& mapSel.NumObjects > 0)	
	{
	 output_result(mapSel,layername);
	 jumpto(1,"查询区域");
	 mapSel.clear();
	 	}
	else
	alert("地图上没有找到目标!");
	earth("stop");	
}

if (find_type==2)//find_type=2时为最近点查询
{
	var setup = map.getRedlineSetup();
	var edgeAttri = setup.getEdgeAttr();
	edgeAttri.setColor(6);
	edgeAttri.setThickness(1);
	var fillAttri = setup.getFillAttr();
	fillAttri.setStyle("Solid");
	fillAttri.setColor(5);	

	var layer = map.getMapLayer("查询区域");
	if (layer == null)
	layer = map.createLayer("redline", "查询区域");
	layer.removeAllObjects();

	var obj = layer.createMapObject("1","您的位置","");
	obj.addCirclePrimitive(point,false,10,"M",50);
	earth("start");
	parent.query.location="asp/findnearest.asp?x=" + point.X + "&y=" + point.Y + "&typename=" + type;
 }
}

function output_result(mapSel,layer)//---------------此函数实现显示范围查询结果---------------
{   
	var objs = mapSel.getMapObjectsEx(null);
	var content ='<p align="center" class="style2">查询结果<br><a href="javascript:visible('+"'"+"hidden"+"'"+')">(关闭结果)</a></p><p>查找到下列单位：<table border=0 align="left"></p>';
    for (i=0;i<objs.size();i = i + 2)	
	    {
		var obj = objs.item(i);
		var name = obj.getName();
		var key = obj.getKey();
		content =  content + '<tr><th><P align=right><img src="index/dot1.gif"></p></th><td ><a href = "#" onclick = jumpto(' + key + ',"' + layer + '")><FONT face=隶书>'+name+'</font></a></td></tr>';
        j = i + 1;
		var obj = objs.item(j);
		var name = obj.getName();
		var key = obj.getKey();		
		content =  content + '<tr><th><P align=right><img src="index/dot2.gif"></p></th><td ><a href = "#" onclick = jumpto(' + key + ',"' + layer + '")><FONT face=隶书>'+name+'</font></a></td></tr>';
			}
		content = content + '</table>';		 
	document.all.results.innerHTML = content;
	document.all.rightmenu.src="rightmenu.asp?city="  + cityname;
	visible('visible');
	}

function visible(sta)
{
document.all.results.style.visibility = sta;
}

function list(s1,s2)//---------------此函数实现地名列表查询结果-----------
{
}
