// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://@sbaseurl@/jsapi/jsapi/esri/copyright.txt and http://www.arcgis.com/apps/webappbuilder/copyright.txt for details.

//>>built
define("dojo/_base/declare dojo/_base/array dijit/_WidgetBase dijit/_TemplatedMixin dijit/_WidgetsInTemplateMixin dojo/on dojo/Evented dojo/_base/html dojo/_base/lang jimu/symbolUtils jimu/dijit/DrawBox esri/graphic esri/layers/FeatureLayer esri/tasks/query esri/symbols/jsonUtils esri/layers/GraphicsLayer esri/geometry/Circle esri/renderers/SimpleRenderer esri/geometry/geometryEngine".split(" "),function(q,g,r,t,u,l,v,m,k,w,x,n,y,z,h,A,B,C,D){return q([r,t,u,v],{baseClass:"jimu-select-features-tool",
templateString:'\x3cdiv\x3e\x3cdiv data-dojo-attach-point\x3d"drawBoxDiv"\x3e\x3c/div\x3e\x3c/div\x3e',map:null,bufferLayer:null,drawBoxOption:null,nls:null,currentLayerInfo:null,postCreate:function(){this.inherited(arguments);this.map=this.drawBoxOption.map;this.bufferLayer=new A;var a=this._getPolygonSymbol(),c=new C(a);this.bufferLayer.setRenderer(c);this.map.addLayer(this.bufferLayer);this.drawBoxOption.showClear=this.drawBoxOption.showClear;this.drawBoxOption.keepOneGraphic=!0;this.drawBox=new x(this.drawBoxOption);
this.drawBox.setPolygonSymbol(a);a=w.getGreyPinMarkerSymbol();this.drawBox.setPointSymbol(a);this.drawBox.setLineSymbol(h.fromJson({color:[54,93,141,255],width:1.5,type:"esriSLS",style:"esriSLSSolid"}));this.drawBox.placeAt(this.drawBoxDiv);this.own(l(this.drawBox,"user-clear",k.hitch(this,this._onDrawBoxClear)));this.own(l(this.drawBox,"draw-end",k.hitch(this,this._onDrawEnd)));this.drawBox.btnClear?m.removeClass(this.drawBox.btnClear,"jimu-float-trailing"):m.addClass(this.drawBox.btnClear,"jimu-float-leading")},
reset:function(){this.drawBox.reset();this.clearAllGraphics()},clearAllGraphics:function(){this.drawBox.clear();this._clearBufferLayer()},hideTempLayers:function(){this.bufferLayer&&this.bufferLayer.hide();this.drawBox&&this.drawBox.hideLayer()},showTempLayers:function(){this.bufferLayer&&this.bufferLayer.show();this.drawBox&&this.drawBox.showLayer()},deactivate:function(){this.drawBox&&this.drawBox.deactivate()},execute:function(){var a=!1;if(this.currentLayerInfo){if(null!==this.currentLayerInfo.url)var c=
new y(this.currentLayerInfo.url,{outFields:["*"]});else c=this.currentLayerInfo,a=!0;var e=this._getGeometryFromDrawBox();"POINT"===e.geoType&&(e=(new B({center:e,geodesic:!0,radius:25,radiusUnit:"esriFeet"})).getExtent());var p=new z;a?(g.forEach(c.graphics,function(d){if(D.intersects(d.geometry,e)){var b=null;switch(d.geometry.type){case "point":b=this._getPointSymbol();break;case "polyline":b=this._getPolylineSymbol();break;case "polygon":b=this._getPolygonSymbol();break;default:b=null}this.bufferLayer.add(new n(d.geometry,
b))}},this),this.drawBox.clear(),this.emit("selection-complete",{geometry:g.map(this.bufferLayer.graphics,function(d){return d.geometry})})):(p.geometry=e,c.queryFeatures(p,k.hitch(this,function(d){g.forEach(d.features,function(b){var f=null;switch(b.geometry.type){case "point":f=this._getPointSymbol();break;case "polyline":f=this._getPolylineSymbol();break;case "polygon":f=this._getPolygonSymbol();break;default:f=null}this.bufferLayer.add(new n(b.geometry,f))},this);this.drawBox.clear();this.emit("selection-complete",
{geometry:g.map(d.features,function(b){return b.geometry})})})))}},setLayerInfo:function(a){this.currentLayerInfo=a},_getPointSymbol:function(){return h.fromJson({color:[36,181,204,175],size:16,xoffset:0,yoffset:0,type:"esriSMS",style:"esriSMSCircle",outline:{style:"esriSLSSolid",color:[36,181,204,255],width:2,type:"esriSLS"}})},_getPolylineSymbol:function(){return h.fromJson({style:"esriSFSSolid",width:5,color:[36,181,204,175],type:"esriSLS"})},_getPolygonSymbol:function(){return h.fromJson({style:"esriSFSSolid",
color:[36,181,204,175],type:"esriSFS",outline:{style:"esriSLSSolid",color:[36,181,204,255],width:2,type:"esriSLS"}})},_getGeometryFromDrawBox:function(){var a=null,c=this.drawBox.getFirstGraphic();c&&(a=c.geometry);return a},_getGeometryFromBufferLayer:function(){var a=null;0<this.bufferLayer.graphics.length&&(a=this.bufferLayer.graphics[0].geometry);return a},_onDrawBoxClear:function(){this._clearBufferLayer()},_onDrawEnd:function(){this._updateBuffer()},_clearBufferLayer:function(){this.bufferLayer&&
this.bufferLayer.clear()},_updateBuffer:function(){this._clearBufferLayer();this.execute()},destroy:function(){this.bufferLayer&&this.map.removeLayer(this.bufferLayer);this.bufferLayer=null;this.inherited(arguments)}})});