
function SE_RectBuy(bounds,color,bgcolor,weight,opacity)
	{
		this.bounds=bounds;
		color=(color || color=="")?color:"#003366";
		bgcolor=(bgcolor || bgcolor=="")?bgcolor:"#2319DC";
		weight=weight?weight:1;
		opacity=opacity?opacity:0.1;

		this.imgPath = "/img/";
		this.create();
		this.setLineStroke(weight);
		this.setLineColor(color);
		this.setOpacity(opacity);
		this.setFillColor(bgcolor);
		this.setLineStyle("solid");
		this.listeners = [];
//		鹰眼为800,盖住鹰眼
		SE_Function.setZIndex(this.div,65535);
		this.listeners.push(SE_Event.bind(this.div,"click",this,this.onClick));
		this.listeners.push(SE_Event.bind(this.div,"mouseover",this,this.onMouseOver));
		this.listeners.push(SE_Event.bind(this.div,"mouseout",this,this.onMouseOut));
		this.tempListeners = [];
		SE_Event.bind(this,"sizechange",this,this.reSize);
		SE_Event.bind(this,"rectdraw",this,this.reBtn);
	}
	SE_RectBuy.prototype.create=function()
	{
		this.div=SE_Function.createDiv(1);
		this.div.style.fontSize = "0px";
		this.div.style.zIndex = "900";
		SE_Function.setUnSelectable(this.div);
//		填充div
		this.bgdiv = SE_Function.createDiv(1);
		var style = {width:"100%",height:"100%",cursor:"move"};
		SE_Function.inherit(this.bgdiv.style,style);
		this.div.appendChild(this.bgdiv);
//		八个点拖拽	lt:left top; lm:leftmiddle; lb:leftbottom; tc:topcenter; tr:topright; rm:rightmiddle; rb:rightbottom; bc:bottomcenter
		this.curs = {lt:"nw-resize",lm:"w-resize",lb:"ne-resize",tc:"n-resize",tr:"ne-resize",rm:"e-resize",rb:"nw-resize",bc:"s-resize"};
			var style = {width:"7px",height:"7px",left:"-4px",top:"-4px",background:"#000000",fontSize:"0px"};
			this.ltdiv = SE_Function.createDiv(1);
			SE_Function.inherit(this.ltdiv.style,style);
			this.div.appendChild(this.ltdiv);
			
			var style = {width:"7px",height:"7px",left:"-4px",top:"50%",marginTop:"-4px",background:"#000000",fontSize:"0px"};
			this.lmdiv = SE_Function.createDiv(1);
			SE_Function.inherit(this.lmdiv.style,style);
			this.div.appendChild(this.lmdiv);
			
			var style = {width:"7px",height:"7px",left:"-4px",bottom:"-4px",background:"#000000",fontSize:"0px"};
			this.lbdiv = SE_Function.createDiv(1);
			SE_Function.inherit(this.lbdiv.style,style);
			this.div.appendChild(this.lbdiv);
			
			var style = {width:"7px",height:"7px",left:"50%",marginLeft:"-4px",top:"-4px",background:"#000000",fontSize:"0px"};
			this.tcdiv = SE_Function.createDiv(1);
			SE_Function.inherit(this.tcdiv.style,style);
			this.div.appendChild(this.tcdiv);
			
			var style = {width:"7px",height:"7px",top:"-4px",right:"-4px",background:"#000000",fontSize:"0px"};
			this.trdiv = SE_Function.createDiv(1);
			SE_Function.inherit(this.trdiv.style,style);
			this.div.appendChild(this.trdiv);
			
			var style = {width:"7px",height:"7px",top:"50%",marginTop:"-4px",right:"-4px",background:"#000000",fontSize:"0px"};
			this.rmdiv = SE_Function.createDiv(1);
			SE_Function.inherit(this.rmdiv.style,style);
			this.div.appendChild(this.rmdiv);
			
			var style = {width:"7px",height:"7px",bottom:"-4px",right:"-4px",background:"#000000",fontSize:"0px"};
			this.rbdiv = SE_Function.createDiv(1);
			SE_Function.inherit(this.rbdiv.style,style);
			this.div.appendChild(this.rbdiv);
			
			var style = {width:"7px",height:"7px",bottom:"-4px",left:"50%",marginLeft:"-4px",background:"#000000",fontSize:"0px"};
			this.bcdiv = SE_Function.createDiv(1);
			SE_Function.inherit(this.bcdiv.style,style);
			this.div.appendChild(this.bcdiv);
//		左上显示大小
		this.sizeDiv = SE_Function.createDiv(1);
			var style = {left:"2px",top:"2px",background:"#202020",fontSize:"14px",padding:"3px",color:"#FFFFFF",whiteSpace:"nowrap"};
			SE_Function.inherit(this.sizeDiv.style,style);
			this.div.appendChild(this.sizeDiv);
//		右下三个按钮
		this.btnDiv = SE_Function.createDiv(1);
			var style = {display:"none",right:"3px",height:"29px",width:"138px",fontSize:"0px"};
			SE_Function.inherit(this.btnDiv.style,style);
			this.div.appendChild(this.btnDiv);
				this.btn_cancel = SE_Function.createDiv(1);
				this.btn_cancel.title = "取消";
				this.btn_cancel.onoverimg = "buy/cancel_over.png";
				this.btn_cancel.onoutimg = "buy/cancel_out.png";
				this.btn_cancel.eventtype = "1";
				var style = {cursor:"pointer",height:"29px",position:"absolute",top:"3px",width:"69px",left:"0px"};
				style.background = 'url("'+this.imgPath+this.btn_cancel.onoutimg+'") no-repeat';
				
				this.btn_cancel.innerHTML = '<img src="/img/mask.gif" style="width:100%;height:100%">';
				this.btnDiv.appendChild(this.btn_cancel);
				SE_Function.inherit(this.btn_cancel.style,style);
				SE_Event.bind(this.btn_cancel,"mouseover",this,this.onBtnOver(this.btn_cancel));
				SE_Event.bind(this.btn_cancel,"mouseout",this,this.onBtnOut(this.btn_cancel));
				SE_Event.bind(this.btn_cancel,"click",this,this.onBtnClk(this.btn_cancel));
				
				this.btn_show = SE_Function.createDiv(1);
				this.btn_show.title = "订购";
				this.btn_show.onoverimg = "buy/buy_over.png";
				this.btn_show.onoutimg = "buy/buy_out.png";
				this.btn_show.eventtype = "2";
				var style = {cursor:"pointer",height:"29px",position:"absolute",top:"3px",width:"69px",left:"72px"};
				style.background = "url("+this.imgPath+this.btn_show.onoutimg+") no-repeat";
				
				this.btn_show.innerHTML = '<img src="/img/mask.gif" style="width:100%;height:100%">';
				this.btnDiv.appendChild(this.btn_show);
				SE_Function.inherit(this.btn_show.style,style);
				SE_Event.bind(this.btn_show,"mouseover",this,this.onBtnOver(this.btn_show));
				SE_Event.bind(this.btn_show,"mouseout",this,this.onBtnOut(this.btn_show));
				SE_Event.bind(this.btn_show,"click",this,this.onBtnClk(this.btn_show));
				
	}
	
	SE_RectBuy.prototype.setZIndex = function(z){
		SE_Function.setZIndex(this.div,z);
	}
	
	SE_RectBuy.prototype.onBtnOver = function(btn){
		return function(e){
			var style = {background:"url("+this.imgPath+btn.onoverimg+") no-repeat"};
			SE_Function.inherit(btn.style,style);
		}
	}
	SE_RectBuy.prototype.onBtnOut = function(btn){
		return function(e){
			var style = {background:"transparent url("+this.imgPath+btn.onoutimg+") no-repeat"};
			SE_Function.inherit(btn.style,style);
		}
	}
	SE_RectBuy.prototype.onBtnClk = function(btn){
		return function(e){
			SE_Event.trigger(this,"btnclick",[btn.eventtype]);
		}
	}
	SE_RectBuy.prototype.startDrag = function(){
		this.ltdiv.style.cursor = this.curs.lt;
		this.lmdiv.style.cursor = this.curs.lm;
		this.lbdiv.style.cursor = this.curs.lb;
		this.tcdiv.style.cursor = this.curs.tc;
		this.trdiv.style.cursor = this.curs.tr;
		this.rmdiv.style.cursor = this.curs.rm;
		this.rbdiv.style.cursor = this.curs.rb;
		this.bcdiv.style.cursor = this.curs.bc;
		this.listeners.push(SE_Event.bind(this.ltdiv,"mousedown",this,this.onDragDivMd(this.ltdiv)));
		this.listeners.push(SE_Event.bind(this.lmdiv,"mousedown",this,this.onDragDivMd(this.lmdiv)));
		this.listeners.push(SE_Event.bind(this.lbdiv,"mousedown",this,this.onDragDivMd(this.lbdiv)));
		this.listeners.push(SE_Event.bind(this.tcdiv,"mousedown",this,this.onDragDivMd(this.tcdiv)));
		this.listeners.push(SE_Event.bind(this.trdiv,"mousedown",this,this.onDragDivMd(this.trdiv)));
		this.listeners.push(SE_Event.bind(this.rmdiv,"mousedown",this,this.onDragDivMd(this.rmdiv)));
		this.listeners.push(SE_Event.bind(this.rbdiv,"mousedown",this,this.onDragDivMd(this.rbdiv)));
		this.listeners.push(SE_Event.bind(this.bcdiv,"mousedown",this,this.onDragDivMd(this.bcdiv)));
//		位置拖动
//		this.listeners.push(SE_Event.bind(this.bgdiv,"mousedown",this,this.onBdDivMd));
		this.reBtn();
		this.btnDiv.style.display = "";
	}
	SE_RectBuy.prototype.onDragDivMd=function(ddiv){
		return function(e){
			SE_Event.cancelBubble(e);
			this.map.disableDrag();
			this.tempListeners = [
				SE_Event.bind(document,"mousemove",this,this.onDragDivMm(ddiv)),
				SE_Event.bind(document,"mouseup",this,this.onDragDivMu(ddiv))
			];
			this.sizeDragObject = {};
			this.sizeDragObject.startPoint = SE_RectBuy.getPos(e,this.map.container);
			this.sizeDragObject.oldBds = this.bounds;
//			让拖拽间隔一定时间
//			10ms大约能减少一半的调用次数,IE,ff均如此,别的浏览器没测试,10ms以上会卡
			this.sizeDragObject.canDragMove = true;
			var _this = this;
			this.sizeDragObject.interval = window.setInterval(function(){
						_this.sizeDragObject.canDragMove = true;
					},10);
			
			if(document.body.setCapture)
			{
				document.body.setCapture();
			}
		}
	}
	SE_RectBuy.prototype.onDragDivMm=function(ddiv){
		return function(e){
//			间隔100毫秒
			if(!this.sizeDragObject.canDragMove){
				return;
			}else{
				this.sizeDragObject.canDragMove = false;
			}
			
			SE_Event.cancelBubble(e);
			var sbd = SE_MercatorBounds;
			var cp = SE_RectBuy.getPos(e,this.map.container);
			sp = this.sizeDragObject.startPoint;
			var offset = [cp[0]-sp[0],cp[1]-sp[1]];
			var obds = this.sizeDragObject.oldBds;
//			四角可以改变整个大小
			if(ddiv===this.ltdiv){
				var xi = obds.getMercatorXmin()+offset[0];
				var xa = obds.getMercatorXmax();
				var yi = obds.getMercatorYmin()+offset[1];
				var ya = obds.getMercatorYmax();
			}else if(ddiv===this.rbdiv){
				var xi = obds.getMercatorXmin();
				var xa = obds.getMercatorXmax()+offset[0];
				var yi = obds.getMercatorYmin();
				var ya = obds.getMercatorYmax()+offset[1];
			}else if(ddiv===this.lbdiv){
				var xi = obds.getMercatorXmin()+offset[0];
				var xa = obds.getMercatorXmax();
				var yi = obds.getMercatorYmin();
				var ya = obds.getMercatorYmax()+offset[1];
			}else if(ddiv===this.trdiv){
				var xi = obds.getMercatorXmin();
				var xa = obds.getMercatorXmax()+offset[0];
				var yi = obds.getMercatorYmin()+offset[1];
				var ya = obds.getMercatorYmax();
			}else if(ddiv===this.lmdiv){
				var xi = obds.getMercatorXmin()+offset[0];
				var xa = obds.getMercatorXmax();
				var yi = obds.getMercatorYmin();
				var ya = obds.getMercatorYmax();
			}else if(ddiv===this.rmdiv){
				var xi = obds.getMercatorXmin();
				var xa = obds.getMercatorXmax()+offset[0];
				var yi = obds.getMercatorYmin();
				var ya = obds.getMercatorYmax();
			}else if(ddiv===this.tcdiv){
				var xi = obds.getMercatorXmin();
				var xa = obds.getMercatorXmax();
				var yi = obds.getMercatorYmin()+offset[1];
				var ya = obds.getMercatorYmax();
			}else if(ddiv===this.bcdiv){
				var xi = obds.getMercatorXmin();
				var xa = obds.getMercatorXmax();
				var yi = obds.getMercatorYmin();
				var ya = obds.getMercatorYmax()+offset[1];
			}
			var newBds = new sbd(Math.min(xi,xa),Math.min(yi,ya),Math.max(xi,xa),Math.max(yi,ya));
//			var newBds = new sbd(Math.max(0,Math.min(xi,xa)),Math.max(0,Math.min(yi,ya)),Math.min(this.map.viewSize[0],Math.max(xi,xa)),Math.min(this.map.viewSize[1],Math.max(yi,ya)));
			this.setBounds(newBds);
		}
	}
	SE_RectBuy.prototype.onDragDivMu=function(ddiv){
		return function(e){
//			清除间隔
			this.sizeDragObject.canDragMove = true;
			window.clearInterval(this.sizeDragObject.interval);
			
			SE_Event.cancelBubble(e);
			if(document.releaseCapture)
			{
				document.releaseCapture();
			}
			var tmp;
			while(tmp = this.tempListeners.pop()){
				SE_Event.removeListener(tmp);
			}
			this.map.enableDrag();
		}
	}
	SE_RectBuy.prototype.onBdDivMd=function(e){
		SE_Event.cancelBubble(e);
		this.bgListeners = [
				SE_Event.bind(document,"mousemove",this,this.onBdDivMm),
				SE_Event.bind(document,"mouseup",this,this.onBdDivMu)
			];
		this.moveObject = {};
		this.moveObject.startPoint = SE_RectBuy.getPos(e,this.map.container);
		this.oldBd = this.bounds;
		
	}
	SE_RectBuy.prototype.onBdDivMm=function(e){
		SE_Event.cancelBubble(e);
		var cp = SE_RectBuy.getPos(e,this.map.container);
		var sp = this.moveObject.startPoint;
		var offset = [cp[0]-sp[0],cp[1]-sp[1]];
		var sbd = SE_MercatorBounds;
		var obd = this.oldBd;
		var cbd = this.getBounds();
		var xi = obd.getMercatorXmin()+offset[0];
		var xa = obd.getMercatorXmax()+offset[0];
		var yi = obd.getMercatorYmin()+offset[1];
		var ya = obd.getMercatorYmax()+offset[1];
		var wth = xa - xi;
		var hth = ya - yi;
		var newbd;
		newbd = new sbd(xi,yi,xa,ya);
		if(xi<=this.mapBd.getMercatorXmin()){
			newbd.setMercatorXmin(this.mapBd.getMercatorXmin());
			newbd.setMercatorXmax(this.mapBd.getMercatorXmin()+wth);
		}
		if(xa>=this.mapBd.getMercatorXmax()){
			newbd.setMercatorXmin(this.mapBd.getMercatorXmax()-wth);
			newbd.setMercatorXmax(this.mapBd.getMercatorXmax());
		}
		if(yi<=this.mapBd.getMercatorYmin()){
			newbd.setMercatorYmin(this.mapBd.getMercatorYmin());
			newbd.setMercatorYmax(this.mapBd.getMercatorYmin()+hth);
		}
		if(ya>=this.mapBd.getMercatorYmax()){
			newbd.setMercatorYmin(this.mapBd.getMercatorYmax()-hth);
			newbd.setMercatorYmax(this.mapBd.getMercatorYmax());
		}
		this.setBounds(newbd);
		
	}
	SE_RectBuy.prototype.onBdDivMu=function(e){
		SE_Event.cancelBubble(e);
		
		var tp;
		while(tp = this.bgListeners.pop()){
			SE_Event.removeListener(tp);
		}
		
	}
	SE_RectBuy.prototype.onMouseOver=function(e)
	{
		var point=SE_Function.getEventPosition(e,this.map.container);
		SE_Event.trigger(this,"mouseover",[point]);
	}
	SE_RectBuy.prototype.onMouseOut=function(e)
	{
		var point=SE_Function.getEventPosition(e,this.map.container);
		SE_Event.trigger(this,"mouseout",[point]);
	}
	SE_RectBuy.prototype.onClick=function(e)
	{
		var point=SE_Function.getEventPosition(e,this.map.container);
		SE_Event.trigger(this,"click",[point,SE_Function.getEventButton(e)]);
	}
	SE_RectBuy.prototype.initialize=function(map)
	{
		if(!this.div || this.map){return false;}
		this.map=map;
		var sbd = SE_MercatorBounds;
		this.mapBd = new sbd(0,0,this.map.viewSize[0],this.map.viewSize[1]);
		this.reDraw();
	}
	SE_RectBuy.prototype.reDraw=function()
	{
		//进行重绘,对div进行切割,如果边框超出就剪掉
		this.drawSpan = this.map.getDrawBounds();
//		坐标都是像素坐标
		var l = Math.max(-100,this.bounds.getMercatorXmin());
		var b = Math.min(this.map.viewSize[1]+100,this.bounds.getMercatorYmax());
		var r = Math.min(this.map.viewSize[0]+100,this.bounds.getMercatorXmax());
		var t = Math.max(-100,this.bounds.getMercatorYmin());
		var lt=[l,t];//取得范围bounds左上角的坐标
		var rb=[r,b];//取得范围bounds右下角坐标
		
		this.draw(lt,rb);
	}
	SE_RectBuy.prototype.reDraw_FollowMap=function()
	{
		//进行重绘,对div进行切割,如果边框超出就剪掉
		this.drawSpan = this.map.getDrawBounds();
//		坐标都是像素坐标
		var l = Math.max(-100,this.bounds.getMercatorXmin());
		var b = Math.min(this.map.viewSize[1]+100,this.bounds.getMercatorYmax());
		var r = Math.min(this.map.viewSize[0]+100,this.bounds.getMercatorXmax());
		var t = Math.max(-100,this.bounds.getMercatorYmin());
		var lt=[l,t];//取得范围bounds左上角的坐标
		var rb=[r,b];//取得范围bounds右下角坐标
		
		this.draw(lt,rb);
	}
	
	SE_RectBuy.prototype.draw=function(lt,rb)
	{
		SE_Function.setPosition(this.div,lt);
		var size = [];
		//size[0] = Math.abs(rb[0]-lt[0]-parseInt(this.weight)*2);
		//size[1] = Math.abs(rb[1]-lt[1]-parseInt(this.weight)*2);
		var wd = rb[0]-lt[0];
		var ht = rb[1]-lt[1];
		wd>0||(wd=0);
		ht>0||(ht=0);
		size[0] = Math.abs(wd);
		size[1] = Math.abs(ht);
		SE_Function.setSize(this.div,size);
		SE_Event.trigger(this,"rectdraw",[size]);
	}
//	更新左上角文本
	SE_RectBuy.prototype.reSize=function(size){
		var sz = [this.sizeDiv.offsetWidth,this.sizeDiv.offsetHeight];
		this.sizeDiv.style.top = -sz[1]-2+"px";
//		margin为2
		if(this.getBounds().getMercatorYmin()-sz[1]-2<this.mapBd.getMercatorYmin()){
			this.sizeDiv.style.top = "2px";
		}
		this.sizeDiv.innerHTML ="面积："+ SE_RectBuy.getRectArea(this.getMBounds())+"km<sup>2</sup>";
		
	}
//计算面积(矩形)
 	SE_RectBuy.getRectArea=function(abs)
 	{
 		var xMin = abs.getNTUXmin();
		var yMin = abs.getNTUYmin();
		var xMax = abs.getNTUXmax();
		var yMax = abs.getNTUYmax();
		
		var lt = new SE_LngLat(xMax,yMin);
		var rt = new SE_LngLat(xMax,yMax);
		var rb = new SE_LngLat(xMin,yMax);
		var lb = new SE_LngLat(xMin,yMin);
 		var areaArry =[lt,rt,rb,lb];
 		var area =SE_PolygonControl.getPointsArea(areaArry)/1000000;//返回是平方米处理成平方公里
 		return Math.round(area*Math.pow(10, 2))/Math.pow(10, 2);
 		
 	} 	
	
//	更新左下角btn
	SE_RectBuy.prototype.reBtn=function(){
		var sz = [this.btnDiv.offsetWidth,this.btnDiv.offsetHeight];
//		4为margin
		if(this.getBounds().getMercatorYmax()+sz[1]+4>this.mapBd.getMercatorYmax()){
			this.btnDiv.style.bottom = "4px";
		}else{
			this.btnDiv.style.bottom = "-32px";
		}
	}
	SE_RectBuy.prototype.getObject=function(){return this.div;}
	SE_RectBuy.prototype.remove=function()
	{
		this.map=null;
		SE_Event.removeListener(this.mapmoveL);
		SE_Event.removeListener(this.zoomstarthandle);
		SE_Event.removeListener(this.zoomendhandle);
	}
	SE_RectBuy.prototype.depose=function()
	{
		SE_Event.deposeNode(this.div);
		SE_Event.removeListener(this.mapmoveL);
		SE_Event.removeListener(this.zoomstarthandle);
		SE_Event.removeListener(this.zoomendhandle);
		this.div=null;
		this.bounds=null;
	}
	SE_RectBuy.prototype.getBounds=function()
	{
		return this.bounds;
	}
	SE_RectBuy.prototype.getMBounds=function()
	{
		var bd = this.bounds;
//		this.bounds点全部为像素,getMercatorYmin取出的也全是像素
		var ltxy = this.map.fromContainerPixelToLatLng([bd.getMercatorXmin(),bd.getMercatorYmin()]);
		var rbxy = this.map.fromContainerPixelToLatLng([bd.getMercatorXmax(),bd.getMercatorYmax()]);
		var mbd = new SE_MercatorBounds(ltxy.getMercatorLongitude(),rbxy.getMercatorLatitude(),rbxy.getMercatorLongitude(),ltxy.getMercatorLatitude());
		return mbd;
	}
	SE_RectBuy.prototype.setBounds=function(bounds,noSizeChg)
	{
		this.bounds=bounds;
		SE_Event.trigger(this,"boundschange",[this.bounds]);
		noSizeChg||SE_Event.trigger(this,"sizechange",[this.bounds]);
		noSizeChg||SE_Event.trigger(SE_RectBuy,"sizechange",[this.getMBounds()]);
		if(this.map)
		{
			this.reDraw();
		}
	}
	SE_RectBuy.prototype.getLineColor=function()
	{
		return this.color;
	}
	SE_RectBuy.prototype.setLineColor=function(color)
	{
		this.color=color;
		this.div.style.borderColor=color;
	}
	SE_RectBuy.prototype.getFillColor=function()
	{
		return this.bgcolor;
	}
	SE_RectBuy.prototype.setFillColor=function(bgcolor)
	{
		this.bgcolor=bgcolor;
		this.bgdiv.style.backgroundColor=bgcolor;
	}
	SE_RectBuy.prototype.getOpacity=function()
	{
		return this.opacity;
	}
	SE_RectBuy.prototype.setOpacity=function(opacity)
	{
		this.opacity=opacity;
		SE_Function.setOpacity(this.bgdiv,this.opacity);
	}
	SE_RectBuy.prototype.getLineStroke=function()
	{
		return this.weight;
	}
	SE_RectBuy.prototype.setLineStroke=function(weight)
	{
		this.weight=weight;
		this.div.style.borderWidth=parseInt(weight)+"px";
	}
	SE_RectBuy.prototype.getLineStyle=function(style)
	{
		return this.lineStyle;
	}
	SE_RectBuy.prototype.setLineStyle=function(style)
	{
		if(!style){return;}
		this.lineStyle=style;
		if(style.toLowerCase()=="dot"){style="dotted";}
		if(style.toLowerCase()=="dash"){style="dashed";}
		this.div.style.borderStyle=style;
	}
	
	//	大小跟随地图,跟随一个经纬度
	SE_RectBuy.prototype.followMap = function(map){
		this.map = map;
		this.tl = this.map.fromContainerPixelToLatLng([this.bounds.getMercatorXmin(),this.bounds.getMercatorYmin()]);
		this.rb = this.map.fromContainerPixelToLatLng([this.bounds.getMercatorXmax(),this.bounds.getMercatorYmax()]);
		SE_Event.bind(this,"boundschange",this, this.onSizeChange);
		this.mapmoveL = SE_Event.bind(this.map,"move",this,this.onMapMove);
		this.zoomstarthandle = SE_Event.bind(this.map,"zoomstart",this,this.onMapZoomStart);
		this.zoomendhandle = SE_Event.bind(this.map,"zoomend",this,this.onMapZoomEnd);
		this.setZIndex(100);
		this.reDraw = SE_RectBuy.prototype.reDraw_FollowMap;
		this.setBounds(this.bounds);
	}
	SE_RectBuy.prototype.notFollowMap = function(map){
		SE_Event.removeListener(this.mapmoveL);
		SE_Event.removeListener(this.zoomstarthandle);
		SE_Event.removeListener(this.zoomendhandle);
		this.setZIndex(65535);
		this.reDraw = SE_RectBuy.prototype.reDraw;
	}
	SE_RectBuy.prototype.onSizeChange = function(bds){
		this.tl = this.map.fromContainerPixelToLatLng([this.bounds.getMercatorXmin(),this.bounds.getMercatorYmin()]);
		this.rb = this.map.fromContainerPixelToLatLng([this.bounds.getMercatorXmax(),this.bounds.getMercatorYmax()]);
	}
	SE_RectBuy.prototype.onMapMove = function(center,flag){
		var lnglatB = new SE_MercatorBounds(this.tl.getMercatorLongitude(),this.rb.getMercatorLatitude(),this.rb.getMercatorLongitude(),this.tl.getMercatorLatitude());
		this.setLngLatBounds(lnglatB,true);
	}
	SE_RectBuy.prototype.onMapZoomStart = function(){
		this.div.style.display = "none";
	}
	SE_RectBuy.prototype.onMapZoomEnd = function(){
		this.div.style.display = "";
	}
	SE_RectBuy.prototype.setLngLatBounds = function(lnglatBds,noMapMove){
		var pxBounds = this.formLngLatToPxBounds(lnglatBds);
		this.setBounds(pxBounds,noMapMove);
	}
//	以下两个函数将像素和LngLat互转
	SE_RectBuy.prototype.formPxToLngLatBounds = function(bd){
		var minXY = [bd.getMercatorXmin(),bd.getMercatorYmax()];
		var maxXY = [bd.getMercatorXmax(),bd.getMercatorYmin()];
		var minLngLat = this.map.fromContainerPixelToLatLng(minXY);
		var maxLngLat = this.map.fromContainerPixelToLatLng(maxXY);
		return new SE_MercatorBounds(minLngLat.getMercatorLongitude(),minLngLat.getMercatorLatitude(),maxLngLat.getMercatorLongitude(0),maxLngLat.getMercatorLatitude());
	}
	SE_RectBuy.prototype.formLngLatToPxBounds = function(bd){
		var minLngLat = new SE_MercatorLngLat(bd.getMercatorXmin(),bd.getMercatorYmax());
		var maxLngLat = new SE_MercatorLngLat(bd.getMercatorXmax(),bd.getMercatorYmin());
		var minXY = this.map.fromLatLngToContainerPixel(minLngLat);
		var maxXY = this.map.fromLatLngToContainerPixel(maxLngLat);
		return new SE_MercatorBounds(minXY[0],minXY[1],maxXY[0],maxXY[1]);
	}
	
	
	SE_RectBuy.getPos = function(e,container){
		var offset=SE_Function.getPageOffset(container);
		var epos = SE_Function.pointXY(e);
		return [epos[0]-offset[0],epos[1]-offset[1]];
	}



function SE_RectMapSelect(map,html,color,bgcolor,weight,opacity)
	{
		this.initialize(map);
		this.btn = html;
		this.lineColor=(color || color=="")?color:"#003366";
		this.fillColor=(bgcolor || bgcolor=="")?bgcolor:"#2319DC";
		this.lineStroke=weight?weight:1;
		this.fillOpacity=opacity?opacity:0.1;

		this.create();

		SE_Event.bind(this.btn,"click",this,this.btnClick);
		SE_Event.addListener(this.btn,"dblclick",SE_Event.cancelBubble);
		SE_Event.addListener(this.btn,"mousedown",SE_Event.returnTrue);
		SE_Event.addListener(this.btn,"mouseup",SE_Event.cancelBubble);
		this.autoClear=true;
	}
	SE_RectMapSelect.prototype.create=function()
	{
		this.btn.title = "拉框选择";
	}
	SE_RectMapSelect.prototype.btnClick = function(e)
	{
		SE_Event.returnTrue(e);
		this.start();
	}
	SE_RectMapSelect.prototype.start = function(){
		if(!this.flag) { this.end(); return; }
		if(!this.map.startOccupy(this.btn.title))
		{
			return;
		}
		this.map.disableDrag();
		this.flag=false;
		this.mmdl=SE_Event.bind(this.map.container,"mousedown",this,this.onMouseDown);
		this.bounds=[];
		this.rects=[];
		this.index=0;
		this.lastPoint=null;
		if(this.lastRect){
			this.map.removeControl(this.lastRect,true);
			this.lastRect = null;
		}
		this.btn.style.backgroundColor="#FFFFFF";
		SE_Event.trigger(this,"start",[this]);
	}
	SE_RectMapSelect.prototype.end = function(){
		if(this.flag) return;
		this.map.endOccupy(this.btn.title);
		this.map.enableDrag();
		this.flag=true;
		SE_Event.removeListener(this.mmdl);
		SE_Event.removeListener(this.mmdrl);
		SE_Event.removeListener(this.mmul);
		this.mmdl=null;
		this.mmdrl=null;
		this.mmul=null;
//		if(this.autoClear)
//		{
////			this.clear()
//		}
//		this.rects=[];
//		this.bounds=[];
//		this.index=0;
		this.btn.style.backgroundColor="";
		SE_Event.trigger(this,"end",[this]);
	}
	SE_RectMapSelect.prototype.clear=function()
	{
		if(!this.rects){return;}
		var rect;
		while(rect=this.rects.pop())
		{
			this.map.removeControl(rect,true);
		}
		rect=null;
		this.bounds = null;
	}
	SE_RectMapSelect.prototype.drawRect=function(bounds)
	{
		var rect=new SE_RectBuy(bounds,this.lineColor,this.fillColor,this.lineStroke,this.fillOpacity);
		if(this.lineStyle){rect.setLineStyle(this.lineStyle);}
		return rect;
	}
	SE_RectMapSelect.prototype.onMouseDown = function(e)
	{
		if(this.dragObj){this.onMouseUp(e);}
		var dragObj={startPoint:SE_Function.getEventPosition(e,this.map.container),startDivPoint:[e.clientX,e.clientY]};
		dragObj.mmdrl=SE_Event.bind(document,"mousemove",this,this.onMouseMove);
		dragObj.mmul=SE_Event.bind(document,"mouseup",this,this.onMouseUp);
		this.lastPoint=dragObj.startPoint;
		this.lastBounds=new SE_MercatorBounds(this.lastPoint[0],this.lastPoint[1],this.lastPoint[0],this.lastPoint[1]);
		this.bounds.push(this.lastBounds);
		this.lastRect=this.drawRect(this.lastBounds);
		this.rects.push(this.lastRect);
		this.map.addControl(this.lastRect);
		this.lastRect.followMap( this.map);
		this.dragObj=dragObj;
		if(this.map.container.setCapture)
		{
			this.map.container.setCapture();
		}
	}
	SE_RectMapSelect.prototype.onMouseUp = function(e)
	{
		SE_Event.cancelBubble(e);
		if(document.releaseCapture)
		{
			document.releaseCapture();
		}
		this.index++;
		var dragObj=this.dragObj;
		if(dragObj)
		{
			SE_Event.removeListener(dragObj.mmdrl);
			SE_Event.removeListener(dragObj.mmul);
		}
		this.dragObj=null;
		SE_Event.trigger(this,"draw",[this.lastRect,this.bounds[this.index-1]]);
		this.lastPoint=null;
//		不调用这个函数的话是可以支持连续画多个rect的,不过多个rect也没用
		this.end();
		this.lastRect.startDrag();
	}
	SE_RectMapSelect.prototype.onMouseMove = function(e)
	{
		var dragObj=this.dragObj;
		var p=[dragObj.startPoint[0]+e.clientX-dragObj.startDivPoint[0],dragObj.startPoint[1]+e.clientY-dragObj.startDivPoint[1]];
		this.lastBounds=new SE_MercatorBounds(Math.min(p[0],this.lastPoint[0]),Math.min(p[1],this.lastPoint[1]),Math.max(p[0],this.lastPoint[0]),Math.max(p[1],this.lastPoint[1]));
		this.bounds[this.index]=this.lastBounds;
		this.lastRect.setBounds(this.lastBounds);
	}
	
	SE_RectMapSelect.prototype.initialize=function(map)
	{
		this.map=map;
		this.flag = true;
	}
	SE_RectMapSelect.prototype.remove=function()
	{
		if(this.flag){
			this.end();
		}
		this.clear();
		this.map=null;
	}