
OpenLayers.GreaseOl.Control.GreaseControlDrawRect=OpenLayers.Class(OpenLayers.Control,{defaultHandlerOptions:{},defaultGreaseOptions:{'execFn':defaultClick,'ajaxFunction':null,'showLoading':true,'resetImages':false,'showLoadingToc':false,'command':'','cursorClass':null},greaseOptions:null,box:null,setGreaseOptions:function(greaseOptions){this.greaseOptions=OpenLayers.Util.extend({},this.defaultGreaseOptions);this.greaseOptions=OpenLayers.Util.extend(this.greaseOptions,greaseOptions);return true;},draw:function(){this.box=new OpenLayers.Handler.Box(this,{"done":this.notice});},initialize:function(cssStyle,options){this.greaseOptions=OpenLayers.Util.extend({},this.defaultGreaseOptions);options=OpenLayers.Util.extend({cssStyle:cssStyle},options);this.handlerOptions=OpenLayers.Util.extend({},this.defaultHandlerOptions);OpenLayers.Control.prototype.initialize.apply(this,[options]);},getBounds:function(position){if(position instanceof OpenLayers.Bounds){if(!this.out){var minXY=this.map.getLonLatFromPixel(new OpenLayers.Pixel(position.left,position.bottom));var maxXY=this.map.getLonLatFromPixel(new OpenLayers.Pixel(position.right,position.top));var bounds=new OpenLayers.Bounds(minXY.lon,minXY.lat,maxXY.lon,maxXY.lat);}else{var pixWidth=Math.abs(position.right-position.left);var pixHeight=Math.abs(position.top-position.bottom);var zoomFactor=Math.min((this.map.size.h/pixHeight),(this.map.size.w/pixWidth));var extent=this.map.getExtent();var center=this.map.getLonLatFromPixel(position.getCenterPixel());var xmin=center.lon-(extent.getWidth()/2)*zoomFactor;var xmax=center.lon+(extent.getWidth()/2)*zoomFactor;var ymin=center.lat-(extent.getHeight()/2)*zoomFactor;var ymax=center.lat+(extent.getHeight()/2)*zoomFactor;var bounds=new OpenLayers.Bounds(xmin,ymin,xmax,ymax);}
return bounds;}
return null;},getPoint:function(position){if(position instanceof OpenLayers.Bounds){return null;}else{return this.map.getLonLatFromPixel(position);}
return null;},notice:function(position){var lonlat=new Array();if(this.getBounds(position)!=null){var bounds=this.getBounds(position);lonlat[0]=new OpenLayers.LonLat(bounds.left,bounds.bottom);lonlat[1]=new OpenLayers.LonLat(bounds.right,bounds.bottom);lonlat[2]=new OpenLayers.LonLat(bounds.right,bounds.top);lonlat[3]=new OpenLayers.LonLat(bounds.left,bounds.top);lonlat[4]=new OpenLayers.LonLat(bounds.left,bounds.bottom);}else{lonlat[0]=this.getPoint(position);}
this.greaseOptions.execFn(lonlat,this.map,this.greaseOptions.ajaxFunction,this.greaseOptions,OpenLayers.GreaseOl.Constants.GEOMETRY_TYPE_POLYGON);},deactivate:function(){if(this.box!=null)this.box.deactivate();OpenLayers.Control.prototype.deactivate.apply(this);},activate:function(){if(this.box!=null){this.box.activate();OpenLayers.Control.prototype.activate.apply(this);}},CLASS_NAME:"OpenLayers.GreaseOl.Control.GreaseControlDrawRect"});
