﻿
    /**
     * 通过传入一个div的对象或一个div对象的id名称来创建简单的地图应用
     * @param <any> X
     * @return function 
     */
    function KMap(X)
    {
        this.container = (typeof(X) == "object") ? X : document.getElementById(X);
        if (!this.container)
        {
            alert("没有传入用来显示地图的层");
            return;
        }
        
        //设置地图容器样式
        var containerStyle = this.container.style;
        if (containerStyle.position != "absolute")
        {
            containerStyle.position = "relative";
        }
        containerStyle.overflow = "hidden";

        //设置地图容器不能被选择
        KBase.setUnSelectable(this.container);

        //获取容器大小[0]表示宽、[1]表示高
        var containerSize = this.getContainerSize();

        //取消右键菜单响应事件       
        this.container.oncontextmenu=new Function("return false");     
        

        //信息、操作对象设置
        this.overlays = new Array(0);
        this.controls = new Array(0);
        

        //创建地图显示图层
        this.mapsDiv = KBase.createDiv(1, null, 2);
        KBase.setCursorStyle(this.mapsDiv, "hand.cur");
        KBase.setUnSelectable(this.mapsDiv);
        var zp = this.mapsDiv.style;
        zp.overflow = "visible";
        this.container.appendChild(this.mapsDiv);
        
        //在地图图层下创建图片对象
        this.mapImg=new Image();
        this.mapImg.style.position= "absolute";        
        this.mapImg.useMap="";
        this.mapImg.border=0;
        KBase.getStyle(this.mapImg)["display"] = "none";
        KBase.setUnSelectable(this.mapImg);
        this.mapsDiv.appendChild(this.mapImg);
        
        

        //在地图显示图层中创建标注显示图层
        this.overlaysDiv = KBase.createDiv(1, null, 100);
        this.overlaysDiv.ID = "overlaysDiv";
        KBase.setUnSelectable(this.overlaysDiv);
        var zp = this.overlaysDiv.style;
        zp.overflow = "visible";
        this.container.appendChild(this.overlaysDiv);
        
        //在地图显示图层中绘制VML 20070618新增
        this.overVmlDiv = KBase.createDiv(1, null, 101);
        this.overVmlDiv.ID = "overVmlDiv";
        KBase.setUnSelectable(this.overVmlDiv);
        var zp = this.overVmlDiv.style;
        zp.overflow = "visible";
        this.container.appendChild(this.overVmlDiv);
        
        //创建地图加载等待图片
        this.loadingImg=new Image();
        this.loadingImg.style.position= "absolute";        
        this.loadingImg.useMap="";
        this.loadingImg.src=KConfig.ProgressImage;
        this.loadingImg.border=0;
        KBase.getStyle(this.loadingImg)["display"] = "none";
        KBase.setZIndex(this.loadingImg,1000);
        KBase.setUnSelectable(this.loadingImg);
        KBase.setPosition(this.loadingImg,[(containerSize[0]-this.loadingImg.width)/2,(containerSize[1]-this.loadingImg.height)/2]);
        this.container.appendChild(this.loadingImg);
        this.isHandleProgress =false;
        
        
        //事件绑定
        KEvent.addEventListener(this.container, "dblclick", this, this.onDoubleClick);
        KEvent.addEventListener(this.container, "mousedown", this, this.onMouseDown);
        
        
       // KEvent.addListener(this.container, "mousemove", this, this.onMouseMove);
        
        KEvent.addEventListener(this.mapImg,"readystatechange",this, this.onMapStateChange);     
        
        //szx add 2007-12-07  
        KEvent.addEventListener(this.mapImg,"error",this, this.onError); 
        
        KEvent.addEventListener(window, "resize", this, this.onWindowResize);
        
        

        this.setViewSize(containerSize);

        window.defaultStatus=" ";
		//设置初始化参数--查看Config.js            
        this.mapCmd = KConfig.MapCmd;        
        this.mapPath = "";
        this.userId="";
        this.currTool=null;          
        this.loaded=false;
        this.level=0;
        this.mapTop=0.0;
        this.mapLeft=0.0;
        this.mapBottom=0.0;
        this.mapRight=0.0;
        this.loading=false;
        this.resizeing=false;
        
        //szx add 2007-12-12 用于标识是否是正式退出
        this.isLogout = false;
        
        
        this.mapHistory=new Array(50);
        for (var i=0;i<50;i++)
        {
        	this.mapHistory[i]=new Array(4);
        }
        this.lastMapIndex=-1;
        this.currMapIndex=-1;
        this.isSecond=false;
        
        
        //联接请求--保存session
		//var linkTime=(KConfig.Session-0.5)*60*1000;
		var linkTime=KConfig.Session*60*1000;
		window.setInterval(KMap_Link,linkTime);			
    }
    
    /* ------------------------------地图操作------------------------------*/
    
    /*
     *  加载地图（初始化）
     */
	var KMap_load = function()
	{		
		var containerSize = this.getViewSize();
		this.loading=true;
		this.showProgress();
		var parameter="";
		if (arguments.length==0)//默认全图加载
		{
			parameter=containerSize[0] + ";" + containerSize[1];
		}
		else if (arguments.length==2)//中心点加载
		{
			parameter=containerSize[0] + ";" + containerSize[1] + ";" + arguments[0]+ ";" + arguments[1];
		}
		else if (arguments.length==3)//中心点和比例加载
		{
			parameter=containerSize[0] + ";" + containerSize[1] + ";" + arguments[0]+ ";" + arguments[1]+ ";" + arguments[2];
		}
		else if (arguments.length==4)//范围加载
		{
			parameter=containerSize[0] + ";" + containerSize[1] + ";" + arguments[0]+ ";" + arguments[1]+ ";" + arguments[2]+ ";" + arguments[3];
		}
		else
		{
			KEvent.trigger(objMap, "error", ["属性错误[KMap_load]-->",""]);
			return;
		}
		var sendMessage=KBase.createSendXml("","Load",parameter);
		KRequest.send(this,this.mapCmd,sendMessage,KMap_loadEnd);
	}
	
	/*
     *  通过图层加载地图
     */
	var KMap_loadLayer = function()
	{		
		var containerSize = this.getViewSize();
		this.loading=true;
		this.showProgress(true);
		var parameter="";
		if (arguments.length==2)//全图加载
		{
			parameter=arguments[0] + ";" +  arguments[1] + ";" + containerSize[0] + ";" + containerSize[1];
		}
		else if (arguments.length==3)//按缩放等级加载
		{
			parameter=arguments[0] + ";" +  arguments[1] + ";" + containerSize[0] + ";" + containerSize[1]+ ";" + arguments[2];
		}
		else if (arguments.length==4)//按中心等级加载
		{
			parameter=arguments[0] + ";" +  arguments[1] + ";" + containerSize[0] + ";" + containerSize[1]+ ";" + arguments[2]+ ";" + arguments[3];
		}
		
		else if (arguments.length==5)//中心点与缩放等级加载
		{
			parameter=arguments[0] + ";" +  arguments[1] + ";" + containerSize[0] + ";" + containerSize[1] + ";" + arguments[2]+ ";" + arguments[3]+ ";" + arguments[4];
		}
		else if (arguments.length==6)//范围加载
		{
			parameter=arguments[0] + ";" +  arguments[1] + ";" + containerSize[0] + ";" + containerSize[1] + ";" + arguments[2]+ ";" + arguments[3]+ ";" + arguments[4]+ ";" + arguments[5];
		}
		else
		{
			KEvent.trigger(this, "error", ["属性错误[KMap_loadByLayer]-->",""]);
			return;
		}
		var sendMessage=KBase.createSendXml("","LoadLayer",parameter);
		KRequest.send(this,this.mapCmd,sendMessage,KMap_loadEnd);
	}
	
	
	
	/*
     *  响应请求--加载地图
     */
	var KMap_loadEnd=function()
	{
		var objMap=this.sendObject;
		objMap.loading=false;
		var responseText=this.request.responseText;		
		var message=KBase.getMessage(responseText);
		if (message==null)
		{
			KEvent.trigger(objMap, "error", ["地图加载异常[KMap_loadEnd]-->",responseText]);
			return;
		}
		if (!message.isError)
		{
			objMap.userId=message.text[0];
			objMap.mapImg.src=KConfig.MapPath + message.text[1];
			objMap.mapPath=KConfig.MapPath + message.text[1];
			KBase.getStyle(objMap.mapImg)["display"] = "";			
			objMap.loaded=true;
			objMap.level=message.level;			
			objMap.setMapBorderValue(message.mapLeft,message.mapTop,message.mapRight,message.mapBottom);
			
			KEvent.trigger(objMap, "loaded", [objMap.userId]);
			
			KEvent.trigger(objMap, "mapload", [objMap.mapImg.src]);
			
			KEvent.trigger(objMap, "log", ["地图加载成功[KMap_loadEnd]-->",responseText]);
			
			if (objMap.resizeing)		//加载的时候改变地图大小特殊处理			
			{				
				objMap.resizeing=false;
				objMap.onWindowResize();
			}
		}
		else
		{
			KEvent.trigger(objMap, "error", ["地图加载返回信息错误[KMap_loadEnd]-->",responseText]);			
		}
		objMap.showProgress(false);
	}
   
    /*
     *  地图放大
     */
	var KMap_zoomIn=function (left,top,right,bottom)
	{		
		
		if (this.level<=KConfig.MapMinLevel)	return;		//当到一定的级别不再响应放大
		this.showProgress(true);
		var parameter="";
		
		if (arguments.length==0)//默认放大
		{
			parameter="";
		}
		else if (arguments.length==4)//拉框放大
		{
			parameter=left + ";" + top + ";" + right + ";" + bottom;	
		}
		else 
		{
			return;
		}
		var sendMessage=KBase.createSendXml(this.userId,"ZoomIn",parameter);			
		KRequest.send(this,this.mapCmd,sendMessage,KMap_zoomInEnd);		
	}
	
	/*
     *  响应请求--地图放大
     */
	function KMap_zoomInEnd()
	{			
		var objMap=this.sendObject;
		var responseText=this.request.responseText;
		var message=KBase.getMessage(responseText);
		if (message==null)
		{
			KEvent.trigger(objMap, "error", ["地图放大异常[KMap_zoomInEnd]-->",responseText]);
			return;
		}
		if (!message.isError)
		{
			objMap.level=message.level;			
			objMap.setMapBorderValue(message.mapLeft,message.mapTop,message.mapRight,message.mapBottom);
			var time=new Date();
			objMap.mapImg.src=objMap.mapPath + "?" + time.valueOf();			
			KEvent.trigger(objMap, "mapload", [objMap.mapImg.src]);
			KEvent.trigger(objMap, "log", ["地图放大成功[KMap_zoomInEnd]-->",responseText]);
		}
		else
		{
			KEvent.trigger(objMap, "error", ["地图放大返回信息错误[KMap_zoomInEnd]-->",responseText]);			
		}
		objMap.showProgress(false);
	}

	/*
     *  地图缩小
     */
	var KMap_zoomOut=function (x,y)
	{		
		if (this.level>=KConfig.MapMaxLevel)	return;		//当到一定的级别不再响应缩小
		this.showProgress(true);
		var parameter="";
		
		if (arguments.length==0)//默认缩小
		{
			parameter="";
		}
		else if (arguments.length==2)//鼠标缩小
		{
			parameter=x + ";" + y;		
		}
		else 
		{
			return;
		}	
		var sendMessage=KBase.createSendXml(this.userId,"ZoomOut",parameter);			
		KRequest.send(this,this.mapCmd,sendMessage,KMap_zoomOutEnd);			
	}
	
	/*
     *  响应请求--地图缩小
     */
	function KMap_zoomOutEnd()
	{			
		var objMap=this.sendObject;
		
		var responseText=this.request.responseText;
		var message=KBase.getMessage(responseText);
		if (message==null)
		{
			KEvent.trigger(objMap, "error", ["地图缩小异常[KMap_zoomOutEnd]-->",responseText]);
			return;
		}		
		if (!message.isError)
		{
			objMap.level=message.level;			
			objMap.setMapBorderValue(message.mapLeft,message.mapTop,message.mapRight,message.mapBottom);
			var time=new Date();	
			objMap.mapImg.src=objMap.mapPath + "?" + time.valueOf();			
			KEvent.trigger(objMap, "mapload", [objMap.mapImg.src]);		
			KEvent.trigger(objMap, "log", ["地图缩小成功[KMap_zoomOutEnd]-->",responseText]);			
		}
		else
		{
			KEvent.trigger(objMap, "error", ["地图缩小返回信息错误[KMap_zoomOutEnd]-->",responseText]);			
		}	
		objMap.showProgress(false);	
	}	

	/*
     *  地图移动
     */
	var KMap_move=function(xSize,ySize)
	{
		this.showProgress(true);
		var parameter=xSize + ";" + ySize;		
		var sendMessage=KBase.createSendXml(this.userId,"Move",parameter);			
		KRequest.send(this,this.mapCmd,sendMessage,KMap_moveEnd);		
	}
	
	/*
     *  响应请求--地图移动
     */
	function KMap_moveEnd()
	{			
		var objMap=this.sendObject;
		try
		{
			
			var responseText=this.request.responseText;
			var message=KBase.getMessage(responseText);
			if (message==null)
			{
				KEvent.trigger(objMap, "error", ["地图移动异常[KMap_moveEnd]-->",responseText]);
				return;
			}					
			if (!message.isError)
			{
				objMap.setMapBorderValue(message.mapLeft,message.mapTop,message.mapRight,message.mapBottom);				
				
				KBase.setPosition(objMap.overlaysDiv,[0,0]);							
				KEvent.trigger(objMap, "mapload", [objMap.mapImg.src]);			
				KEvent.trigger(objMap, "log", ["地图移动成功[KMap_moveEnd]-->",responseText]);	
				
				var time=new Date();				
				objMap.mapImg.src=objMap.mapPath + "?" + time.valueOf();				
				if (KBase.getBrowserType()!="IE")
				{
					KBase.setPosition(objMap.mapImg,[0,0]);					
					KBase.getStyle(objMap.mapImg)["display"] = "";
				}
			}
			else
			{
				KEvent.trigger(objMap, "error", ["地图移动返回信息错误[KMap_moveEnd]-->",responseText]);			
			}
			
		}
		catch (ex)
		{		
		}
		objMap.showProgress(false);	
	}

	/*
     *  地图退出
     */
	var KMap_logout=function()
	{
		var parameter="";		
		var sendMessage=KBase.createSendXml(this.userId,"Logout",parameter);			
		KRequest.sendInPhase(this.mapCmd,sendMessage);		
		this.isLogout = true;
		this.depose();
	}

	/*
     *  联接请求
     */
	var KMap_Link=function()
	{		
		try{
			document.getElementById("oSessionFrame").location=KConfig.LinkPath;
		}
		catch(e){}
		//KRequest.sendInPhase(this,KConfig.LinkPath,"");		
	}
	
	/*
     *  全图
     */
	var KMap_fitMap=function()
	{		
		var parameter="";
		this.showProgress(true);
		if (arguments.length==0)//全图加载
		{
			parameter="";
		}
		else if (arguments.length==2)//按中心点加载
		{
			parameter=arguments[0] + ";" +  arguments[1];
		}
		else if (arguments.length==3)//按中心点和缩放比例加载
		{
			var containerSize = this.getViewSize();
			parameter=arguments[0] + ";" +  arguments[1] + ";" + arguments[2] + ";" + containerSize[0] + ";" + containerSize[1];
		}
		else if (arguments.length==4)//范围加载
		{
			parameter=arguments[0] + ";" +  arguments[1] + ";"  + arguments[2]+ ";" + arguments[3];
		}		
		else
		{
			KEvent.trigger(this, "error", ["属性错误[KMap_fitMap]-->",""]);
			return;
		}
		
		var sendMessage=KBase.createSendXml(this.userId,"FitMap",parameter);			
		KRequest.send(this,this.mapCmd,sendMessage,KMap_fitMapEnd);
	}
	
	/*
     *  响应请求--全图
     */
	var KMap_fitMapEnd=function()
	{
		var objMap=this.sendObject;
		var responseText=this.request.responseText;
		var message=KBase.getMessage(responseText);
		if (message==null)
		{
			KEvent.trigger(objMap, "error", ["地图全图异常[KMap_fitMapEnd]-->",responseText]);
			return;
		}				
		if (!message.isError)
		{
			objMap.level=message.level;
			objMap.setMapBorderValue(message.mapLeft,message.mapTop,message.mapRight,message.mapBottom);
			var time=new Date();	
			objMap.mapImg.src=objMap.mapPath + "?" + time.valueOf();
			KEvent.trigger(objMap, "mapload", [objMap.mapImg.src]);
			KEvent.trigger(objMap, "log", ["地图全图成功[KMap_fitMapEnd]-->",responseText]);						
		}
		else
		{
			KEvent.trigger(objMap, "error", ["地图全图返回信息错误[KMap_fitMapEnd]-->",responseText]);			
		}		
		objMap.showProgress(false);				
	}
	
	
	/*
     *  地图按级别缩放
     */
	var KMap_zoomTo=function (zoomTolevel)
	{		
		if (this.level==zoomTolevel)	return;		//当到一定的级别不再响应放大		
		if (this.level>zoomTolevel&&zoomTolevel<KConfig.MapMinLevel) return;
		if (this.level<zoomTolevel&&zoomTolevel>KConfig.MapMaxLevel) return;
		this.showProgress(true);
		var containerSize = this.getViewSize();		
		
		var levelCount=zoomTolevel-this.level;
		
		var left=Math.round((containerSize[0]-Math.pow(1.5,levelCount)*containerSize[0])/2);
		var top=Math.round((containerSize[1]-Math.pow(1.5,levelCount)*containerSize[1])/2);
		var right=containerSize[0]-left;
		var bottom=containerSize[1]-top;		
		
		var parameter=left + ";" + top + ";" + right + ";" +bottom;
		
		var sendMessage=KBase.createSendXml(this.userId,"ZoomTo",parameter);		
		KRequest.send(this,this.mapCmd,sendMessage,KMap_zoomToEnd);		
	}
	
	/*
     *  响应请求--地图按级别缩放
     */
	function KMap_zoomToEnd()
	{			
		var objMap=this.sendObject;
		var responseText=this.request.responseText;
		var message=KBase.getMessage(responseText);
		if (message==null)
		{
			KEvent.trigger(objMap, "error", ["地图按级别缩放异常[KMap_zoomToEnd]-->",responseText]);
			return;
		}					
		if (!message.isError)
		{
			objMap.level=message.level;
			objMap.setMapBorderValue(message.mapLeft,message.mapTop,message.mapRight,message.mapBottom);
			var time=new Date();	
			objMap.mapImg.src=objMap.mapPath + "?" + time.valueOf();			
			KEvent.trigger(objMap, "mapload", [objMap.mapImg.src]);
			KEvent.trigger(objMap, "log", ["地图按级别缩放成功[KMap_zoomToEnd]-->",responseText]);			
		}
		else
		{
			KEvent.trigger(objMap, "error", ["地图按级别缩放返回信息错误[KMap_zoomToEnd]-->",responseText]);			
		}	
		objMap.showProgress(false);		
	}
	
	/*
     *  图层操作
     */
	var KMap_updateLayer=function (openLayer,closeLayer,activeLayer)
	{			
		var parameter=openLayer + ";" + closeLayer + ";" + activeLayer;	
		this.showProgress(true);	
		var sendMessage=KBase.createSendXml(this.userId,"Layer",parameter);		
		KRequest.send(this,this.mapCmd,sendMessage,KMap_updateLayerEnd);		
	}
	
	/*
     *  响应请求--图层操作
     */
	function KMap_updateLayerEnd()
	{			
		var objMap=this.sendObject;
		var responseText=this.request.responseText;
		var message=KBase.getMessage(responseText);
		if (message==null)
		{
			KEvent.trigger(objMap, "error", ["图层操作[KMap_updateLayerEnd]-->",responseText]);
			return;
		}
		if (!message.isError)
		{
			var time=new Date();	
			objMap.mapImg.src=objMap.mapPath + "?" + time.valueOf();			
			KEvent.trigger(objMap, "mapload", [objMap.mapImg.src]);
			KEvent.trigger(objMap, "log", ["图层操作[KMap_updateLayerEnd]-->",responseText]);			
		}
		else
		{
			KEvent.trigger(objMap, "error", ["图层操作[KMap_updateLayerEnd]-->",responseText]);			
		}		
		objMap.showProgress(false);	
	}
	
	/*
     *  改变地图大小
     */
	var KMap_resizeMap=function (width,height)
	{			
		var parameter=width + ";" + height;		
		var sendMessage=KBase.createSendXml(this.userId,"Resize",parameter);		
		KRequest.send(this,this.mapCmd,sendMessage,KMap_resizeMapEnd);		
	}
	
	/*
     *  响应请求--改变地图大小
     */
	function KMap_resizeMapEnd()
	{			
		var objMap=this.sendObject;
		var responseText=this.request.responseText;
		var message=KBase.getMessage(responseText);
		if (message==null)
		{
			KEvent.trigger(objMap, "error", ["改变地图大小[KMap_resizeMapEnd]-->",responseText]);
			return;
		}
		if (!message.isError)
		{
			objMap.level=message.level;
			objMap.setMapBorderValue(message.mapLeft,message.mapTop,message.mapRight,message.mapBottom);
			var time=new Date();	
			objMap.mapImg.src=objMap.mapPath + "?" + time.valueOf();			
			KEvent.trigger(objMap, "mapload", [objMap.mapImg.src]);
			KEvent.trigger(objMap, "log", ["改变地图大小[KMap_resizeMapEnd]-->",responseText]);			
		}
		else
		{
			KEvent.trigger(objMap, "error", ["改变地图大小[KMap_resizeMapEnd]-->",responseText]);			
		}		
	}
	
	/*
     *  上一个视图
     */
	var KMap_previous=function()
	{			
		var objMap=this;
		objMap.showProgress(true);
		if (objMap.currMapIndex==objMap.lastMapIndex+50-KConfig.HistoryBack||objMap.currMapIndex==objMap.lastMapIndex-KConfig.HistoryBack||(objMap.currMapIndex==0&&objMap.isSecond==false))
		{	
			return;
		}
		if (objMap.currMapIndex==0) objMap.currMapIndex=49;
		else	objMap.currMapIndex--;
		var value=objMap.mapHistory[objMap.currMapIndex];		
		var parameter=value[0] + ";" +  value[1] + ";"  + value[2]+ ";" + value[3];		
		var sendMessage=KBase.createSendXml(this.userId,"FitMap",parameter);			
		KRequest.send(this,this.mapCmd,sendMessage,KMap_previousOrNextEnd);
		
		KMap_previousOrNextState(objMap);
		
	}
	
	/*
     *  下一个视图
     */
	var KMap_next=function ()
	{			
		var objMap=this;
		objMap.showProgress(true);
		if (objMap.currMapIndex==objMap.lastMapIndex)
		{			
			return;
		}
		if (objMap.currMapIndex==49) objMap.currMapIndex=0;
		else	objMap.currMapIndex++;
		var value=objMap.mapHistory[objMap.currMapIndex];
		var parameter=value[0] + ";" +  value[1] + ";"  + value[2]+ ";" + value[3];		
		var sendMessage=KBase.createSendXml(this.userId,"FitMap",parameter);			
		KRequest.send(this,this.mapCmd,sendMessage,KMap_previousOrNextEnd);
		
		KMap_previousOrNextState(objMap);
	}
	
	/*
     *  上下视图状态检查
     */
	var KMap_previousOrNextState=function(objMap)
	{
		var isPrevious=true,isNext=true;
		if (objMap.currMapIndex==objMap.lastMapIndex+50-KConfig.HistoryBack||objMap.currMapIndex==objMap.lastMapIndex-KConfig.HistoryBack||(objMap.currMapIndex==0&&objMap.isSecond==false))
		{	
			isPrevious=false;
		}
		if (objMap.currMapIndex==objMap.lastMapIndex)
		{
			isNext=false;
		}
		KEvent.trigger(objMap, "stepchanged", [isPrevious,isNext]);
		
	}
	
	
	
	/*
     *  响应请求--上下视图
     */
	var KMap_previousOrNextEnd=function()
	{
		var objMap=this.sendObject;
		var responseText=this.request.responseText;
		var message=KBase.getMessage(responseText);
		if (message==null)
		{
			KEvent.trigger(objMap, "error", ["地图上下视图[KMap_previousOrNextEnd]-->",responseText]);
			return;
		}				
		if (!message.isError)
		{
			objMap.level=message.level;
			objMap.mapLeft=message.mapLeft;
			objMap.mapTop=message.mapTop;
			objMap.mapRight=message.mapRight;
			objMap.mapBottom=message.mapBottom;			
			var time=new Date();	
			objMap.mapImg.src=objMap.mapPath + "?" + time.valueOf();
			KEvent.trigger(objMap, "mapload", [objMap.mapImg.src]);
			KEvent.trigger(objMap, "log", ["地图上下视图成功[KMap_previousOrNextEnd]-->",responseText]);			
		}
		else
		{
			KEvent.trigger(objMap, "error", ["地图上下视图返回信息错误[KMap_previousOrNextEnd]-->",responseText]);			
		}	
		objMap.showProgress(false);					
	}
	
	
	
	
	/**
	*	地图视图比例
	*/
	var KMap_UserMapViewScale=function()
	{
		return KMap_getCoordinate("UserMapViewScale",this.userId,this.mapCmd);
	}	
	
	/**
	*	直角坐标转化为客户坐标
	*/
	var KMap_mapToClient=function(arryXY)
	{
		return KMap_getCoordinate("MapToClient",arryXY,this.userId,this.mapCmd);
	}
	/**
	*	地理坐标转化为客户坐标
	*/
	var KMap_mapToClient2=function(arryXY)
	{
		return KMap_getCoordinate("MapToClient2",arryXY,this.userId,this.mapCmd);
	}
	/**
	*	客户坐标转化为地理坐标
	*/
	var KMap_clientToMap2=function(arryXY)
	{
		return KMap_getCoordinate("ClientToMap2",arryXY,this.userId,this.mapCmd);
	}
	/**
	*	客户坐标转化为直角坐标
	*/
	var KMap_clientToMap=function(arryXY)
	{
		return KMap_getCoordinate("ClientToMap",arryXY,this.userId,this.mapCmd);
	}
	/**
	*	92坐标转化为经纬度
	*/
	var KMap_XM92ToMap=function(arryXY)
	{
		return KMap_getCoordinate("92ToMap",arryXY,this.userId,this.mapCmd);
	}
	/**
	*	经纬度转化为92坐标
	*/
	var KMap_MapTo92XM=function(arryXY)
	{
		return KMap_getCoordinate("MapTo92",arryXY,this.userId,this.mapCmd);
	}
	
	/**
     *  坐标转换
     *  参数:type类型,arryXY坐标数组,x和y以","号分隔
     */
	var KMap_getCoordinate=function (type,arryXY,userId,mapCmd)
	{		
		var parameter="";
		if (arguments.length==0)
		{
			parameter="";
			return;
		}
		else if (arguments.length==4)
		{
			parameter=type + ";"+arryXY;
		}
		else 
		{
			return;
		}
		var sendMessage=KBase.createSendXml(userId,"Coordinate",parameter);			
		var responseText=KRequest.sendInPhase(mapCmd,sendMessage);	
		var message=KBase.getMessage(responseText);		
		return message.data;
	}
	
	/**
	*	打开图层
	*/
	var KMap_openLayer=function(layerNames)
	{
		return KMap_LayerCtrl("openlayer",layerNames,this);
	}
	/**
	*	关闭图层
	*/
	var KMap_closeLayer=function(layerNames)
	{
		return KMap_LayerCtrl("closelayer",layerNames,this);
	}
	
	/**
	*	显示图层
	*/
	var KMap_setLayerVisible=function(layerNames)
	{
		return KMap_LayerCtrl("setLayerVisible",layerNames,this);
	}
	/**
	*	隐藏图层
	*/
	var KMap_setLayerUnVisible=function(layerNames)
	{
		return KMap_LayerCtrl("setLayerUnVisible",layerNames,this);
	}
	
	
	//图层控制
	var KMap_LayerCtrl = function(workObj,layerNames,objMap)
	{
		var parameter=workObj+";"+layerNames;
		
		var sendMessage=KBase.createSendXml(objMap.userId,"LayerCtrl",parameter);				
		KRequest.send(objMap,objMap.mapCmd,sendMessage,KMap_layerCtrlEnd);			
	}
	//刷新地图
	var KMap_layerCtrlEnd=function()
	{
		var objMap=this.sendObject;
		try
		{
			
			var responseText=this.request.responseText;
			var message=KBase.getMessage(responseText);
			if (message==null)
			{
				KEvent.trigger(objMap, "error", ["地图移动异常[KMap_moveEnd]-->",responseText]);
				return;
			}					
			if (!message.isError)
			{
				var time=new Date();				
				objMap.mapImg.src=objMap.mapPath + "?" + time.valueOf();				
				if (KBase.getBrowserType()!="IE")
				{
					KBase.setPosition(objMap.mapImg,[0,0]);					
					KBase.getStyle(objMap.mapImg)["display"] = "";
				}
			}
			else
			{
				KEvent.trigger(objMap, "error", ["地图移动返回信息错误[KMap_moveEnd]-->",responseText]);			
			}
			
		}
		catch (ex)
		{		
			;
		}
	}
	/**
	*	物理半径转化为客户半径
	*/
	var KMap_mapRToClientR=function(radius,xClient,yClient)
	{
		return KMap_getClntRadius(radius,xClient,yClient,this.userId,this.mapCmd);
	}
	
	/**
     *  根据两客户点计算物理半径
     */
	var KMap_getPoints2MapRadius=function (xSClient,ySClient,xEClient,yEClient)
	{
		return KMap_getMapRadius(xSClient,ySClient,xEClient,yEClient,this.userId,this.mapCmd)
	}
	/**
     *  物理半径转化为客户半径
     *  参数:radius物理半径,xClient，yClient
     */
	var KMap_getClntRadius=function (radius,xClient,yClient,userId,mapCmd)
	{		
		var parameter="";
		if (arguments.length==0)
		{
			parameter="";
			return;
		}
		else if (arguments.length==5)
		{
			parameter="getClntRadius"+";"+radius + ";"+xClient+";"+yClient;
		}
		else 
		{
			return;
		}
		var sendMessage=KBase.createSendXml(userId,"GetRadius",parameter);			
		var responseText=KRequest.sendInPhase(mapCmd,sendMessage);	
		var message=KBase.getMessage(responseText);		
		return message.text;
	}

	/**
     *  根据两客户点计算物理半径
     *  参数:S,E
     */
	var KMap_getMapRadius=function (xSClient,ySClient,xEClient,yEClient,userId,mapCmd)
	{		
		var parameter="";
		if (arguments.length==0)
		{
			parameter="";
			return;
		}
		else if (arguments.length==6)
		{
			parameter="getMapRadius"+";"+xSClient+";"+ySClient+ ";"+xEClient+";"+yEClient;
		}
		else 
		{
			return;
		}
		var sendMessage=KBase.createSendXml(userId,"GetRadius",parameter);			
		var responseText=KRequest.sendInPhase(mapCmd,sendMessage);	
		var message=KBase.getMessage(responseText);		
		return message.text;
	}
	/* ------------------------------操作控件和标注图层相关------------------------------*/
	
    /**
     * 将传入的控件对象添加到地图上
     */
    var KMap_addControl = function(control)
    {
        var mapObject = this;
        var controlObject = control.getObject();
        
        if (controlObject)
        {
            mapObject.container.appendChild(controlObject);
            if (KBase.getStyle(controlObject)["zIndex"] == 0)
            {
                KBase.setZIndex(controlObject,1100);
            }
        }
        
        //控件初始化
        control.initialize(map);
        mapObject.controls.push(control);
    }
    
	/**
	 * 将传入的控件对象从地图上移除
	 */
	var KMap_removeControl = function(control)
    {
        var mapObject = this;
        control.depose();
        var controlObject = control.getObject();
        if (controlObject && controlObject.parentNode)
        {
            controlObject.parentNode.removeChild(controlObject);
        }
        KBase.deleteFromArray(mapObject.controls, control);
    }
    
    
    /**
	 * 初始化地图基本工具
	 */
	var KMap_formatBaseControl = function(isAddStand,isAddNavigate,type,isShow)
    {
        var mapObject = this;
        
        //初始化漫游工具
        mapObject.moveControl= new KMoveControl();		
		mapObject.addControl( mapObject.moveControl);	
		mapObject.moveControl.startup();					
		
		//初始化标准工具
		if (isAddStand==null||isAddStand)
		{
			mapObject.standMapcontrol= new KStandMapControl();			
			
			map.addControl( mapObject.standMapcontrol );		
		}
		
		//初始化鹰眼图工具
		if (isAddNavigate==null||isAddNavigate)
		{
			var windowType=type==null?4:type;
			var windowShow=isShow==null?true:isShow;
			mapObject.navigateControl = new KNavigateControl(windowType,windowShow);
			map.addControl(mapObject.navigateControl);
		}
		
		//初始化放大工具
		mapObject.zoomInControl= new KZoomInControl();		
		mapObject.addControl( mapObject.zoomInControl);			
		
		//初始化缩小工具
		mapObject.zoomOutControl= new KZoomOutControl();		
		mapObject.addControl( mapObject.zoomOutControl);		
		
		//初始化测距工具
		mapObject.polyLineControl= new KPolyLineControl();		
		mapObject.addControl( mapObject.polyLineControl);
		
		//初始化测面工具
		mapObject.polygonControl=new KPolygonControl();		
		mapObject.addControl( mapObject.polygonControl);	
		
    }
    
     /**
	 * 初始化地图查询操作
	 */
     var KMap_formatSearchControl = function()
    {
		var mapObject = this;
		
		//初始化查询工具
		mapObject.search=new KSearch();
		map.addControl( mapObject.search );		
			
		//初始化点选取工具
		mapObject.searchPointControl=new KSearchPointControl();
		map.addControl( mapObject.searchPointControl );
		
		//初始化框选工具
		mapObject.searchRectControl=new KSearchRectControl();
		map.addControl( mapObject.searchRectControl );	
		
		//初始化圆查询工具
		mapObject.searchOvalControl= new KSearchOvalControl();
		map.addControl(mapObject.searchOvalControl);
		
		//初始化多边形查询工具
		mapObject.searchPolygonControl= new KSearchPolygonControl();
		map.addControl(mapObject.searchPolygonControl);	
		
    }
     /**
	 * 初始化地图公交查询、路径分析、标点、删除点操作
	 */
     var KMap_formatSeniorControl = function()
    {
		var mapObject = this;
		
		//初始化路径分析工具
		mapObject.findPathControl= new KFindPath();
		mapObject.addControl(mapObject.findPathControl);	
		
		//初始化公交查询工具
		mapObject.searchbusControl=new KSearchBusControl();
		mapObject.addControl(mapObject.searchbusControl);
		
		//初始化地图编辑工具
		mapObject.editPoint= new KEditPoint();
		mapObject.addControl(mapObject.editPoint);	
    }
    
    
    
    /**
	 * 增加标注图层
	 */
	var KMap_addOverLay = function(overlayObject)
    {
        var mapObject = this;
        overlayObject.initialize(mapObject);
        var overlayControl = overlayObject.getObject();
        if (mapObject)
        {            
            mapObject.overlaysDiv.appendChild(overlayControl);
            if (KBase.getStyle(overlayControl)["zIndex"] == 0)
            {
                KBase.setZIndex(overlayControl, 500);
            }
        }
        overlayObject.reDraw(true);
        mapObject.overlays.push(overlayObject);
    }
    
	/**
	 * 移除标注图层
	 */
	var KMap_removeOverLay = function(overlayObject)
    {
        var mapObject = this;
        var overlayControl = overlayObject.getObject();
        if (overlayControl && overlayControl.parentNode)
        {
            overlayControl.parentNode.removeChild(overlayControl);
        }
        KBase.deleteFromArray(mapObject.overlays,overlayObject);
    }
    
	/**
	 * 清除所有标注图层
	 */
	var KMap_clearOverLays = function()
    {
        var mapObject = this;
        var i=mapObject.overlays.length-1;
        for (;i>-1;i--)
        {
            mapObject.removeOverLay(mapObject.overlays[i]);
        }      
        
    }
    
    
    

	/* ------------------------------窗体事件或鼠标事件--------------------------------
	
	/**
	 * 改变地图图层大小(窗体大小改变)
	 */
	var KMap_onWindowResize = function()
    {
        var mapObject = this;
        if (mapObject.loading) mapObject.resizeing=true;
        if (!mapObject.loaded) return;        
        var containerSize = mapObject.getContainerSize();
        if (mapObject.viewSize && containerSize[0] == mapObject.viewSize[0] && containerSize[1] == mapObject.viewSize[1])
        {
            return;
        }
        mapObject.setViewSize(containerSize);
        
        
        
        mapObject.resizeMap(containerSize[0],containerSize[1]);
        
        KEvent.trigger(mapObject, "resize",[containerSize]);
        
    }
	

	/**
	 * 地图双击事件
	 */
	var KMap_onDoubleClick = function(x)
    {
        var mapObject = this;
        if (!mapObject.loaded) return;
        var point=KBase.getEventPosition(x, this.container);
        var bottonType=KBase.getEventButton(x);
        KEvent.trigger(mapObject, "dblclick",[point,bottonType]);
    }

	/**
	 * 鼠标在地图上移动事件[在状态拦显示经纬度坐标]
	 */
	var KMap_onMouseMove = function(x)
	{
		var mapObject = this;
        if (!mapObject.loaded) return;
        var point=KBase.getEventPosition(x, this.container);
		point=mapObject.clientToMap(x.x+","+x.y);
        window.status="x轴："+point[0].x+"-"+"y轴："+point[0].y;
	}
	
	/**
	 * 地图鼠标按下事件
	 */
	var KMap_onMouseDown = function(x)
    {        
        KEvent.cancelBubble(x); 
        
        //存在拖动对象--结束拖动(释放相关事件)    
        if (this.dragObject){			
        	this.clearMouseEvent();
        }
        
        if (!this.loaded)	return;
        
        var eventObject =
        {
            "startPoint" : KBase.getEventPosition(x, this.container), "startDivPoint" : [x.clientX, x.clientY],
            "startTime" : (new Date()).getTime()
		}
			
        this.dragObject = eventObject;
        
        if (this.container.setCapture)
        {
            this.container.setCapture();
        }
        
        if (!eventObject.mouseMoveListener)
        {
            eventObject.mouseMoveListener = KEvent.addListener(document, "mousemove", this, this.onMouseDrag);
        }
        if (!eventObject.mouseUpListener)
        {
            eventObject.mouseUpListener = KEvent.addListener(document, "mouseup", this, this.onMouseUp);
        }        
        
        KEvent.trigger(this, "mousedown", [eventObject.startPoint, KBase.getEventButton(x)]);
        
        if (KBase.getBrowserType()=="IE")
        {
            try
            {
                document.selection.empty();
            }
            catch (x)
            {
			}

        }
    }

	/**
	 * 地图鼠标拉动事件
	 */
    var KMap_onMouseDrag = function(x)
    {        
        KEvent.cancelBubble(x);
        var mapObject = this;
                
        if (!mapObject.loaded)	return;
		
        var point=KBase.getEventPosition(x, this.container);
        var bottonType=KBase.getEventButton(x);        
        
        KEvent.trigger(mapObject, "mousedrag", [point,bottonType]);
    }

	/**
	 * 地图鼠标放开事件
	 */
    var KMap_onMouseUp = function(x)
    {        
        KEvent.cancelBubble(x);   
        var mapObject = this;
        if (!mapObject.loaded)	return;
        
        var eventObject = mapObject.dragObject;    
        
        var isClick=false;
        
        if (eventObject)
        {
            //计算是否为单击
			var divPoint = eventObject.startDivPoint;
			var time=new Date().getTime();			
			if (time-eventObject.startTime <= 500 && (Math.abs(divPoint[0] - x.clientX) <= 5 && Math.abs(divPoint[1] - x.clientY) <= 5))
			{
				isClick=true;                       
			}
        }       
        
        var point = KBase.getEventPosition(x, mapObject.container);        
        
        
        if (document.releaseCapture)
        {
            document.releaseCapture();
        }             
        
        var point=KBase.getEventPosition(x, this.container);
        var bottonType=KBase.getEventButton(x);        
        
        
		
        
        if (isClick)
        {		
            KEvent.trigger(mapObject, "click", [point,bottonType]); 
		}
		else
		{
			KEvent.trigger(mapObject, "mouseup", [point,bottonType]); 
		}
			
        
        mapObject.clearMouseEvent();
    }

	/**
	 * 清除鼠标事件
	 */
    var KMap_clearMouseEvent = function()
    {
        var mapObject = this;
        var eventObject = mapObject.dragObject;
        if (eventObject)
        {            
            eventObject.enableDrag = false;             
                     
            if (eventObject.mouseMoveListener)
            {
                KEvent.removeListener(eventObject.mouseMoveListener);
                eventObject.mouseMoveListener = null;
            }
            if (eventObject.mouseUpListener)
            {
                KEvent.removeListener(eventObject.mouseUpListener);
                eventObject.mouseUpListener = null;
            }            
			mapObject.dragObject = null;
        }
    }
    
    
    /**
	 * 响应地图文件状态改变
	 */
    var KMap_onMapStateChange = function()
    {
		var ready = this.mapImg.readyState;		
		if (ready == "loading")
		{
			KBase.setPosition(this.mapImg,[0,0]);			
			if (KBase.getStyle(this.mapImg)["display"] == "none")	KBase.getStyle(this.mapImg)["display"] = "";
		}	
		
    }
    
    /**
    *szx add 2007-12-07  
    *图片无法正常加载，使用替换页面。
    */
    var KMap_onError = function(){		
		this.load();
		//alert("图片无法正常加载");
    }
    
    
    /**
	 * 允许操作鼠标滚动
	 */
	var KMap_handleMouseScroll = function(type)
    {
        var mapObject = this;
        mapObject.mouseScrollType=type?type:"ALL";
        mapObject.clearMouseScroll();
        mapObject.mouseWheelListener = KEvent.addListener(mapObject.container, "mousewheel", mapObject, this.onMouseWheel);
    }

	/**
	 * 清除鼠标滚动
	 */
	var KMap_clearMouseScroll = function()
    {
        var mapObject = this;        
        if (mapObject.mouseWheelListener)
        {
            KEvent.removeListener(mapObject.mouseWheelListener);
            mapObject.mouseWheelListener = null;
        }
    }

	/**
	 * 响应鼠标滚动事件
	 */
	var KMap_onMouseWheel = function(x)
    {
        if (isBusy) return;
        var mapObject = this;
        KEvent.cancelBubble(x);
        
        
        
        var wheelCount =-1* x.wheelDelta / 120; 
               
        if (mapObject.mouseScrollType=="ALL")
        {
			mapObject.zoomTo(mapObject.level+wheelCount);        
        }
        else if (mapObject.mouseScrollType=="UP" && wheelCount<0)
        {
			mapObject.zoomTo(mapObject.level+wheelCount);
        }
        else if (mapObject.mouseScrollType=="DOWN" && wheelCount>0)
        {
			mapObject.zoomTo(mapObject.level+wheelCount);
        }
        
        return;
    }

	
    
    //==========================属性相关方法===============================================

	/**
	 * 设置地图图层大小
	 */
	var KMap_setViewSize = function(size)
    {
        var mapObject = this;
        KBase.setSize(mapObject.mapImg, size);        
        KBase.setSize(mapObject.overlaysDiv, size);        
        mapObject.viewSize = size;
        KBase.setPosition(mapObject.loadingImg,[(size[0]-mapObject.loadingImg.width)/2,(size[1]-mapObject.loadingImg.height)/2]);
        KEvent.trigger(mapObject, "resize", [size]);
    }
    
	/**
	 * 获取地图图层大小
	 */
	var KMap_getViewSize = function()
	{
		return this.viewSize;
	}	
	
	
	/**
	 * 获取缩放级别
	 */
	var KMap_getZoomLevel = function()
	{
		return this.level;
	}
	
	/**
	 * 获取用户Id
	 */
	var KMap_getUserId = function()
	{
		return this.userId;
	}
	
	/**
	 * 点是否包括在范围之内
	 */
	var KMap_isInclude = function(x,y)
	{
		var size = this.getViewSize();
		if (x>0&&y>0&&x<size[0]&&y<size[1])
			return true;			
		else
			return false;
	}
	
	/**
	 * 显示/关闭进度条
	 */
	var KMap_showProgress = function(isShow)
	{
		var mapObject = this;  		
		if (isShow)
		{
			if (mapObject.isHandleProgress)
			{
				this.loadingImg.src=KConfig.ProgressImage;
				KBase.getStyle(mapObject.loadingImg)["display"] = "";
			}
		}
		else
		{		
			KBase.getStyle(mapObject.loadingImg)["display"] = "none";
		}			
	}
	
	/**
	 * 运用进度条设置
	 */
	var KMap_handleProgress = function(isHandle)
    {
        var mapObject = this;        
        mapObject.isHandleProgress=isHandle;        
    }
	
	/*
     *  生成鹰眼地图
     */
	var KMap_createMapGisView=function (layerNames,iWidth,iHeight)
	{			
		var objMap=this;
		
		var parameter=layerNames + ";" + iWidth + ";" + iHeight;
		
		var sendMessage=KBase.createSendXml(this.userId,"CreateGisMapView",parameter);				
		KRequest.send(this,this.mapCmd,sendMessage,KMap_createMapGisViewEnd);			
	}
	var KMap_createMapGisViewEnd=function()
	{
		;
	}
	
	
		
    /*-----------------------------私有方法----------------------------*/
    
    /**
    * 得到地图左顶上角和右下角的地图直角坐标
    * 可以用于鹰眼图参数设置
    */
    var KMap_getMapBorderValue = function()
    {
		 var mapObject = this;
		 var message = "topY:"+mapObject.mapTop;
		 message += "topX:"+mapObject.mapLeft;
		 message += "bottomY:"+mapObject.mapBottom;
		 message += "bottomX:"+mapObject.mapRight;
		 return message;
    }
        
    /**
	 * 获取容器大小数组，size[0]为宽度、size[1]为高度
	 */
	var KMap_getContainerSize = function()
    {
        var mapObject = this;
        var container = mapObject.container;
        var containerSize = [container.offsetWidth, container.offsetHeight];
        if (!containerSize[0])	containerSize[0] = container.clientWidth;
        if (!containerSize[0])	containerSize[0] = parseInt(KBase.getStyle(container)["width"]);
        if (!containerSize[1])	containerSize[1] = container.clientHeight;
        if (!containerSize[1])	containerSize[1] = parseInt(KBase.getStyle(container)["height"]);
        
        if (!containerSize[0] || !containerSize[1])
        {
            var parentElement = container.parentElement;
            while (parentElement)
            {
                if (!containerSize[0] && parentElement.offsetWidth)
					containerSize[0] = parentElement.offsetWidth;
		        if (!containerSize[1] && parentElement.offsetHeight)
					containerSize[1] = parentElement.offsetHeight;
                if (containerSize[0] && containerSize[1])
					break;
               parentElement = parentElement.parentElement;
            }
        }
        return containerSize;
    }
    
    /**
	 * 设置地图边界直角坐标(并保存边界历史数据、以及后退、前进状态检查)
	 */
	var KMap_setMapBorderValue=function (left,top,right,bottom)
	{
		var objMap=this;
		objMap.mapLeft=left;
		objMap.mapTop=top;
		objMap.mapRight=right;
		objMap.mapBottom=bottom;
		
		objMap.lastMapIndex=objMap.currMapIndex;
		
		if (objMap.lastMapIndex==49)
		{ 
			objMap.lastMapIndex=0;
			objMap.isSecond=true;
		}		
		else objMap.lastMapIndex++;		
		objMap.mapHistory[objMap.lastMapIndex][0]=left;
		objMap.mapHistory[objMap.lastMapIndex][1]=top;
		objMap.mapHistory[objMap.lastMapIndex][2]=right;
		objMap.mapHistory[objMap.lastMapIndex][3]=bottom;
        
        objMap.currMapIndex=objMap.lastMapIndex;        
        
        if ((objMap.currMapIndex==0&&objMap.isSecond==false))
		{	
			KEvent.trigger(objMap, "stepchanged", [false,false]);
		}
		else
		{
			KEvent.trigger(objMap, "stepchanged", [true,false]);
		}		
	}
	
	/**
	 * 根据经纬度计算距离，返回值单位公里
	 * 计算当前视野
	 */
	var KMap_getGeoDistanceMeasure=function (j1, w1, j2, w2)
	{
		//系数
		var dParam = 4.848136728395E-6 * 3600;
		var a = 6378245.0;
		var b = 6356863.0188;
		var m_fRadius = (a+b+a)/3.0;

		var PC, PA, AC, AB, PQ, QA;
		var cos_BPC,cos_AOC,cos_APC,cos_APB,cos_AOB;
		var center_corner;
		var longitude_t12;
		var latitude_t12;

		var m_pArcLen, circle_distance;
			m_pArcLen = 0;
	      
		longitude_t12 = Math.abs(j1 - j2)*dParam;
		latitude_t12  = Math.abs(w1 - w2)*dParam;

		cos_BPC = Math.cos(longitude_t12);
		cos_AOC = Math.cos(latitude_t12);

		AC = Math.sqrt(2 * m_fRadius * m_fRadius * (1 - cos_AOC));

		PC = m_fRadius * Math.cos(w2*dParam);
		QA = m_fRadius * Math.cos(w1*dParam);
		PQ = Math.abs(m_fRadius * Math.sin(w2*dParam) - m_fRadius * Math.sin(w1*dParam));
		PA = Math.sqrt(QA*QA + PQ*PQ);

		cos_APC = (PA*PA + PC*PC - AC *AC) / (2 * PA * PC);
		cos_APB = cos_APC*cos_BPC;

		AB = Math.sqrt(PA*PA + PC*PC - 2*PA*PC*cos_APB);

		cos_AOB = (2 * (m_fRadius*m_fRadius) - AB * AB) / (2*m_fRadius*m_fRadius);

		center_corner = Math.acos( cos_AOB );
		circle_distance = m_fRadius * center_corner ;

		m_pArcLen += circle_distance;

		return Math.round(Math.abs(m_pArcLen)*10)/10000;
	}
	
	
	var KMap_depose = function()
    {
		//alert(this.container.innerHTML);
		var controlObject = this;   
		for (var i=0;i<50;i++)
        {
        	controlObject.mapHistory[i]=null;
        }
		
		
		this.clearOverLays();
		
		
		for(var i=0; i<controlObject.controls.length;i++){
			try{
				controlObject.controls[i].depose();
			}
			catch(e)
			{}
		}
		KBase.removeDeepChildren(controlObject.container);
		controlObject.container.removeAttribute("cursor");
		//var oChildren=controlObject.container.children;	
		//for(var i=oChildren.length-1;i>=0; i--)
		//{
			
		//	controlObject.container.removeChild(oChildren(i));
		//}
		
		controlObject.container = null;        
        controlObject.overlays =  null;
        controlObject.controls =  null;        
        controlObject.mapsDiv =  null;        
        controlObject.mapImg= null;
        controlObject.overlaysDiv =  null;
        controlObject.overVmlDiv = null;
        controlObject.loadingImg= null;
        controlObject.isHandleProgress = null;
        controlObject.mapCmd = null;    
        controlObject.mapPath = null;
        controlObject.userId= null;
        controlObject.currTool=null;          
        controlObject.loaded= null;
        controlObject.level= null;
        controlObject.mapTop= null;
        controlObject.mapLeft= null;
        controlObject.mapBottom= null;
        controlObject.mapRight= null;
        controlObject.loading= null;
        controlObject.resizeing= null;
        controlObject.mapHistory= null;
        controlObject.lastMapIndex= null;
        controlObject.currMapIndex= null;
        controlObject.isSecond= null;
    }
	
	
	
	
    
	KConfig.defineClass("KMap", KMap);
	
	KConfig.defineFunction(KMap,"load",KMap_load);	
	KConfig.defineFunction(KMap,"loadLayer",KMap_loadLayer);	
	KConfig.defineFunction(KMap,"zoomIn",KMap_zoomIn);
	KConfig.defineFunction(KMap,"zoomOut",KMap_zoomOut);
	KConfig.defineFunction(KMap,"move",KMap_move);
    KConfig.defineFunction(KMap,"logout",KMap_logout);  
    KConfig.defineFunction(KMap,"fitMap",KMap_fitMap);
    KConfig.defineFunction(KMap,"zoomTo",KMap_zoomTo);
    KConfig.defineFunction(KMap,"updateLayer",KMap_updateLayer);
    KConfig.defineFunction(KMap,"resizeMap",KMap_resizeMap);
    KConfig.defineFunction(KMap,"previous",KMap_previous);
    KConfig.defineFunction(KMap,"next",KMap_next);
    
    KConfig.defineFunction(KMap,"addControl",KMap_addControl);
    KConfig.defineFunction(KMap,"removeControl",KMap_removeControl); 
    KConfig.defineFunction(KMap,"formatBaseControl",KMap_formatBaseControl); 
    KConfig.defineFunction(KMap,"formatSearchControl",KMap_formatSearchControl); 
    KConfig.defineFunction(KMap,"formatSeniorControl",KMap_formatSeniorControl); 
    
    KConfig.defineFunction(KMap, "addOverLay", KMap_addOverLay); 
    KConfig.defineFunction(KMap, "removeOverLay", KMap_removeOverLay); 
    KConfig.defineFunction(KMap, "clearOverLays", KMap_clearOverLays);
    
    KConfig.defineFunction(KMap,"onWindowResize",KMap_onWindowResize);
    KConfig.defineFunction(KMap,"onDoubleClick",KMap_onDoubleClick);
    KConfig.defineFunction(KMap,"onMouseDown",KMap_onMouseDown);
    KConfig.defineFunction(KMap,"onMouseDrag",KMap_onMouseDrag);
    KConfig.defineFunction(KMap,"onMouseUp",KMap_onMouseUp);    
    KConfig.defineFunction(KMap,"onMouseMove",KMap_onMouseMove);
    KConfig.defineFunction(KMap,"clearMouseEvent",KMap_clearMouseEvent);
    KConfig.defineFunction(KMap,"onMapStateChange",KMap_onMapStateChange);
    
    //szx add 2007-12-07  
    KConfig.defineFunction(KMap,"onError",KMap_onError);
    
    KConfig.defineFunction(KMap, "handleMouseScroll", KMap_handleMouseScroll);
    KConfig.defineFunction(KMap, "clearMouseScroll", KMap_clearMouseScroll);
    KConfig.defineFunction(KMap, "onMouseWheel", KMap_onMouseWheel);
      
	KConfig.defineFunction(KMap,"setViewSize",KMap_setViewSize);    
    KConfig.defineFunction(KMap,"getViewSize",KMap_getViewSize);   
    KConfig.defineFunction(KMap,"getZoomLevel",KMap_getZoomLevel); 
    KConfig.defineFunction(KMap,"getUserId",KMap_getUserId); 
    KConfig.defineFunction(KMap,"isInclude",KMap_isInclude);  
     
    KConfig.defineFunction(KMap,"showProgress",KMap_showProgress);   
    KConfig.defineFunction(KMap,"handleProgress",KMap_handleProgress);
   
    KConfig.defineFunction(KMap,"getContainerSize",KMap_getContainerSize); 
    KConfig.defineFunction(KMap,"setMapBorderValue",KMap_setMapBorderValue); 
    KConfig.defineFunction(KMap,"getGeoDistanceMeasure",KMap_getGeoDistanceMeasure); 
    KConfig.defineFunction(KMap,"getMapBorderValue",KMap_getMapBorderValue); 
       
	KConfig.defineFunction(KMap,"UserMapViewScale",KMap_UserMapViewScale);
    KConfig.defineFunction(KMap,"mapToClient",KMap_mapToClient);    
    KConfig.defineFunction(KMap,"mapToClient2",KMap_mapToClient2);
    KConfig.defineFunction(KMap,"clientToMap",KMap_clientToMap);    
    KConfig.defineFunction(KMap,"clientToMap2",KMap_clientToMap2);
    
    KConfig.defineFunction(KMap,"mapTo92XM",KMap_MapTo92XM);
    KConfig.defineFunction(KMap,"xm92ToMap",KMap_XM92ToMap);
    
    
    KConfig.defineFunction(KMap,"mapRToClientR",KMap_mapRToClientR);  
    KConfig.defineFunction(KMap,"getPoints2MapRadius",KMap_getPoints2MapRadius);  
    KConfig.defineFunction(KMap,"createMapGisView",KMap_createMapGisView);
    KConfig.defineFunction(KMap,"openLyaer",KMap_openLayer);
    KConfig.defineFunction(KMap,"closeLyaer",KMap_closeLayer);
    KConfig.defineFunction(KMap,"setLayerUnVisible",KMap_setLayerUnVisible);
    KConfig.defineFunction(KMap,"setLayerVisible",KMap_setLayerVisible);
    KConfig.defineFunction(KMap,"depose",KMap_depose);

