// 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
require({cache:{"url:jimu/dijit/templates/SpatialFilterByFeatures.html":'\x3cdiv\x3e\r\n\t\x3cdiv class\x3d"layer-tip second-stress" data-dojo-attach-point\x3d"tipNode"\x3e${nls.relatedLayer}\x3c/div\x3e\r\n\t\x3ctable\x3e\r\n\t\t\x3ccolgroup\x3e\r\n\t\t\t\x3ccol width\x3d"auto"\x3e\x3c/col\x3e\r\n\t\t\t\x3ccol width\x3d"100"\x3e\x3c/col\x3e\r\n\t\t\x3c/colgroup\x3e\r\n\t\t\x3ctbody\x3e\r\n\t\t\t\x3ctr\x3e\r\n\t\t\t\t\x3ctd\x3e\r\n\t\t\t\t\t\x3cdiv class\x3d"layers-select-div" data-dojo-attach-point\x3d"layerSelectDiv"\x3e\x3c/div\x3e\r\n\t\t\t\t\x3c/td\x3e\r\n\t\t\t\t\x3ctd\x3e\r\n\t\t\t\t\t\x3cdiv class\x3d"jimu-float-trailing" data-dojo-attach-point\x3d"featureSetChooserDiv"\x3e\x3c/div\x3e\r\n\t\t\t\t\x3c/td\x3e\r\n\t\t\t\x3c/tr\x3e\r\n\t\t\x3c/tbody\x3e\r\n\t\x3c/table\x3e\r\n\r\n\t\x3cdiv class\x3d"selection-option not-visible" data-dojo-attach-point\x3d"selectionOptionDiv"\x3e\x3c/div\x3e\r\n\r\n\t\x3cdiv class\x3d"search-distance-div" data-dojo-attach-point\x3d"searchDistanceDiv"\x3e\x3c/div\x3e\r\n\t\x3cdiv data-dojo-attach-point\x3d"loading" data-dojo-type\x3d"jimu/dijit/LoadingShelter" data-dojo-props\x3d\'hidden:true\'\x3e\x3c/div\x3e\r\n\x3c/div\x3e'}});
define("dojo/_base/array dojo/_base/declare dijit/_WidgetBase dijit/_TemplatedMixin dijit/_WidgetsInTemplateMixin dojo/text!./templates/SpatialFilterByFeatures.html dojo/on dojo/Evented dojo/Deferred dojo/_base/html dojo/_base/lang jimu/utils jimu/Query jimu/dijit/CheckBox jimu/dijit/FeaturelayerChooserFromMap jimu/dijit/LayerChooserFromMapWithDropbox jimu/dijit/SearchDistance jimu/LayerInfos/LayerInfos esri/graphic esri/tasks/query esri/symbols/jsonUtils esri/layers/GraphicsLayer esri/renderers/SimpleRenderer esri/geometry/geometryEngine jimu/dijit/FeatureSetChooserForSingleLayer".split(" "),
function(r,l,t,u,v,w,g,x,m,h,e,p,y,z,A,B,C,D,E,F,G,H,I,n,J){l=l([t,u,v,x],{baseClass:"jimu-dijit-spatial-filter-features",templateString:w,_bufferLayer:null,_defaultRelationship:"SPATIAL_REL_INTERSECTS",drawBox:null,selectionRadio:null,_selectionHandle:null,layerInfosObj:null,_layerAllFeaturesCache:null,map:null,types:null,enableBuffer:!1,distance:0,unit:"",showLoading:!1,ignoredFeaturelayerIds:null,postMixInProperties:function(){this.inherited(arguments);this.nls=window.jimuNls.spatialFilterByFeatures;
this.ignoredFeaturelayerIds||(this.ignoredFeaturelayerIds=[]);this._layerAllFeaturesCache={}},postCreate:function(){this.inherited(arguments);this.selectionRadio=new z({label:this.nls.selectedFeatures});this.selectionRadio.placeAt(this.selectionOptionDiv);this.selectionRadio.setStatus(!1);this.own(g(this.selectionRadio,"change",e.hitch(this,this._onRadioChanged)));h.setStyle(this.domNode,"position","relative");var a=G.fromJson({style:"esriSFSSolid",color:[79,129,189,77],type:"esriSFS",outline:{style:"esriSLSSolid",
color:[54,93,141,255],width:1.5,type:"esriSLS"}});a=new I(a);this._bufferLayer=new H;this._bufferLayer.setRenderer(a);this.map.addLayer(this._bufferLayer);a=new A({createMapResponse:this.map.webMapResponse,types:this.types,showLayerFromFeatureSet:!0,onlyShowVisible:!1,updateWhenLayerInfosIsShowInMapChanged:!0,ignoredFeaturelayerIds:this.ignoredFeaturelayerIds});this.layerChooserFromMapWithDropbox=new B({label:this.nls.relatedLayer,layerChooser:a});this.layerChooserFromMapWithDropbox.placeAt(this.layerSelectDiv);
this.own(g(this.layerChooserFromMapWithDropbox,"selection-change",e.hitch(this,this._onLayerChanged)));this.layerInfosObj=D.getInstanceSync();this.own(g(this.layerInfosObj,"layerInfosIsShowInMapChanged",e.hitch(this,this._onLayerInfosIsShowInMapChanged)));this.searchDistance=new C({tip:window.jimuNls.searchDistance.applySearchDistanceToFeatures,distance:this.distance,unit:this.unit});this.searchDistance.placeAt(this.searchDistanceDiv);this.enableBuffer?(this.searchDistance.enable(),this.own(g(this.searchDistance,
"change",e.hitch(this,this._onSearchDistanceChange)))):(this.searchDistance.disable(),h.setStyle(this.searchDistanceDiv,"display","none"));this._onLayerChanged()},reset:function(a){a&&(this.searchDistance.reset(),this.searchDistance.setDistance(this.distance),this.searchDistance.setUnit(this.unit));this.clearAllGraphics()},hideTempLayers:function(){this._bufferLayer&&this._bufferLayer.hide();this.drawBox&&this.drawBox.hideLayer();this.featureSetChooserForSingleLayer&&this.featureSetChooserForSingleLayer.hideMiddleFeatureLayer()},
showTempLayers:function(){this._bufferLayer&&this._bufferLayer.show();this.drawBox&&this.drawBox.showLayer();this.featureSetChooserForSingleLayer&&this.featureSetChooserForSingleLayer.showMiddleFeatureLayer()},disable:function(a){a&&this._hideAllLayers()},enable:function(){this._showAllLayers()},deactivate:function(){this.featureSetChooserForSingleLayer&&this.featureSetChooserForSingleLayer.deactivate()},clearAllGraphics:function(){this._clearBufferLayer();this.featureSetChooserForSingleLayer&&this.featureSetChooserForSingleLayer.clearAllGraphics()},
setSelectedLayer:function(a){return this.layerChooserFromMapWithDropbox.setSelectedLayer(a)},getSelectedLayer:function(){return this._getSelectedLayerInfomation().layer},checkSelectedFeaturesRadio:function(){this.selectionRadio.getValue()||this.selectionRadio.check()},uncheckSelectedFeaturesRadio:function(){this.selectionRadio.getValue()&&this.selectionRadio.uncheck()},isValidSearchDistance:function(){return 0<=this.searchDistance.getStatus()},getGeometryInfo:function(a){var b=new m,c={status:null,
geometry:null};this._updateBuffer();if(0===this._getSelectedLayerInfomation().type)return c.status=-1,b.resolve(c),b;if(0>this.searchDistance.getData().status)return c.status=-2,b.resolve(c),b;this._getFeatures(a).then(e.hitch(this,function(){c.geometry=this._updateBuffer();c.status=c.geometry?1:0;b.resolve(c)}),e.hitch(this,function(d){b.reject(d)}));return b},getFeatureSet:function(a){var b=new m,c=null,d=this._getSelectedLayerInfomation().layer;d?this._getFeatures(a).then(e.hitch(this,function(f){c=
p.getFeatureSetByLayerAndFeatures(d,f);b.resolve(c)}),e.hitch(this,function(f){b.reject(f)})):b.resolve(c);return b},_getFeatures:function(){var a=new m,b=[],c=this._getSelectedLayerInfomation(),d=c.type;0===d?a.resolve(b):this.selectionRadio.getStatus()&&this.selectionRadio.getValue()?(b=c.layer.getSelectedFeatures(),a.resolve(b)):this.featureSetChooserForSingleLayer.isLoading()?a=this.featureSetChooserForSingleLayer.getFeatures():(b=this.featureSetChooserForSingleLayer.syncGetFeatures(),0<b.length?
a.resolve(b):3===d?(b=c.layer.graphics,a.resolve(b)):a=this._getAllFeaturesFromFeaturelayer(c.layer));return a},_getAllFeaturesFromFeaturelayer:function(a){var b=new m;if(this._layerAllFeaturesCache[a.id])b.resolve(this._layerAllFeaturesCache[a.id]);else{var c=p.getFeatureLayerDefinition(a);c||(c={currentVersion:a.currentVersion,fields:e.clone(a.fields)});this.emit("loading");c=new F;c.where=a.getDefinitionExpression()||"1\x3d1";c.geometry=null;c.outSpatialReference=this.map.spatialReference;c.returnGeometry=
!0;(new y({url:a.url,query:c})).getAllFeatures().then(e.hitch(this,function(d){this.emit("unloading");d?(d=d.features||[],this._layerAllFeaturesCache[a.id]=d,b.resolve(d)):b.reject("Can't get all features from featureLayer "+a.id)}),e.hitch(this,function(d){this.emit("unloading");b.reject(d)}))}return b},_syncGetFeatures:function(){var a=[],b=this._getSelectedLayerInfomation(),c=b.type;0!==c&&(this.selectionRadio.getStatus()&&this.selectionRadio.getValue()?a=b.layer.getSelectedFeatures():(a=this.featureSetChooserForSingleLayer.syncGetFeatures(),
0===a.length&&(3===c?a=b.layer.graphics:(b=this._layerAllFeaturesCache[b.layer.id])&&(a=b))));return a},isLoading:function(){return this.featureSetChooserForSingleLayer&&this.featureSetChooserForSingleLayer.isLoading()},_onLoading:function(){this.showLoading&&this.loading.show();this.emit("loading")},_onUnloading:function(){this.loading.hide();this.emit("unloading")},_showAllLayers:function(){this._bufferLayer&&this._bufferLayer.show()},_hideAllLayers:function(){this._bufferLayer&&this._bufferLayer.hide()},
_onRadioChanged:function(){this.selectionRadio.getValue()&&this.featureSetChooserForSingleLayer&&(this.featureSetChooserForSingleLayer.deactivate(),this.featureSetChooserForSingleLayer.clearAllGraphics());this._updateBuffer()},_getSelectedLayerInfomation:function(){var a=0,b=null,c=null,d=this.layerChooserFromMapWithDropbox.getSelectedItems();0<d.length&&(b=d[0]);b&&(c=b.layerInfo.layerObject,a=c.url?0<=this.map.graphicsLayerIds.indexOf(c.id)?1:2:3);return{type:a,layerItem:b,layer:c}},_onLayerChanged:function(){this.clearAllGraphics();
this._clearSelectionHandle();this._updateSelectedFeaturesCount();this.featureSetChooserForSingleLayer&&this.featureSetChooserForSingleLayer.destroy();this.featureSetChooserForSingleLayer=null;var a=this._getSelectedLayerInfomation();0<a.type&&(this.featureSetChooserForSingleLayer=new J({map:this.map,featureLayer:a.layer,updateSelection:!1}),this._selectionHandle=g(a.layer,"selection-complete",e.hitch(this,function(){var b=this.selectionRadio.getStatus()&&this.selectionRadio.getValue();this._updateSelectedFeaturesCount();
b&&this._updateBuffer()})),this.own(g(this.featureSetChooserForSingleLayer,"user-clear",e.hitch(this,this._onUserClear))),this.own(g(this.featureSetChooserForSingleLayer,"loading",e.hitch(this,e.hitch(this,function(){this._clearBufferLayer();this._onLoading()})))),this.own(g(this.featureSetChooserForSingleLayer,"unloading",e.hitch(this,e.hitch(this,function(){this._onUnloading();this._updateBuffer()})))),this.featureSetChooserForSingleLayer.placeAt(this.featureSetChooserDiv),this.own(g(this.featureSetChooserForSingleLayer,
"draw-activate",e.hitch(this,function(){this.uncheckSelectedFeaturesRadio()}))));this._updateFeatureSetChooserForSingleLayerStatus();this._updateBuffer()},_onLayerInfosIsShowInMapChanged:function(){this._updateFeatureSetChooserForSingleLayerStatus()},_onSearchDistanceChange:function(){this._updateBuffer();this.emit("search-distance-change")},_updateFeatureSetChooserForSingleLayerStatus:function(){if(this.featureSetChooserForSingleLayer){var a=!1,b=this.featureSetChooserForSingleLayer.getFeatureLayer();
(b=this.layerInfosObj.getLayerInfoById(b.id))&&(a=b.isShowInMap());a?(this.featureSetChooserForSingleLayer.enable(),h.removeClass(this.featureSetChooserForSingleLayer.domNode,"not-visible")):(this.featureSetChooserForSingleLayer.disable(),this.featureSetChooserForSingleLayer.clearAllGraphics(),h.addClass(this.featureSetChooserForSingleLayer.domNode,"not-visible"),this._updateBuffer())}},_updateBuffer:function(){this._clearBufferLayer();var a=this.searchDistance.getData(),b=a.status,c=a.distance;a=
a.bufferUnit;if(0>b)return null;var d=this._syncGetFeatures(),f=null,k=[];r.forEach(d,e.hitch(this,function(q){q&&q.geometry&&k.push(q.geometry)}));0<k.length&&(f="polygon"===k[0].type?n.union(k):p.combineGeometries(k));return 0===b?f:f?(f=n.simplify(f),d=f.spatialReference,b=null,b=d.isWebMercator()||4326===d.wkid?n.geodesicBuffer(f,c,a,!0):n.buffer(f,c,a,!0),c=new E(b),this._bufferLayer.add(c),b):null},_onUserClear:function(){this.clearAllGraphics()},_clearBufferLayer:function(){this._bufferLayer&&
this._bufferLayer.clear()},_updateSelectedFeaturesCount:function(){this.selectionRadio.setStatus(!0);var a=this._getSelectedLayerInfomation(),b=0;a.layer&&(a=a.layer.getSelectedFeatures())&&(b=a.length);0===b?(this.selectionRadio.getValue()&&this.selectionRadio.uncheck(),this.selectionRadio.setStatus(!1),h.addClass(this.selectionOptionDiv,"not-visible")):h.removeClass(this.selectionOptionDiv,"not-visible");this.selectionRadio.setLabel(this.nls.selectedFeatures+(window.isRTL?"\x26rlm;":" ")+"("+b+
")")},_clearSelectionHandle:function(){this._selectionHandle&&this._selectionHandle.remove();this._selectionHandle=null},destroy:function(){this._bufferLayer&&this.map.removeLayer(this._bufferLayer);this._bufferLayer=null;this._clearSelectionHandle();this.inherited(arguments)}});l.NONE_SELECTED_FEATURES_NOT_DRAW_SHAPES="NONE_SELECTED_FEATURES_NOT_DRAW_SHAPES";return l});