/*
 COPYRIGHT 2009 ESRI

 TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
 Unpublished material - all rights reserved under the
 Copyright Laws of the United States and applicable international
 laws, treaties, and conventions.

 For additional information, contact:
 Environmental Systems Research Institute, Inc.
 Attn: Contracts and Legal Services Department
 380 New York Street
 Redlands, California, 92373
 USA

 email: contracts@esri.com
 */

window[esri._dojoScopeName||"dojo"]._xdResourceLoaded(function(_1,_2,_3){return {depends:[["provide","esri.dijit.editing.SelectionHelper"]],defineResource:function(_4,_5,_6){if(!_4._hasResource["esri.dijit.editing.SelectionHelper"]){_4._hasResource["esri.dijit.editing.SelectionHelper"]=true;_4.provide("esri.dijit.editing.SelectionHelper");_4.declare("esri.dijit.editing.SelectionHelper",null,{constructor:function(_7){this._settings=_7||{};this._sConnects=[];this._mapServiceCount=0;this._map=this._settings.map;this._tolerance=this._settings.singleSelectionTolerance;this._initMapServiceInfos(this._settings.layers);},destroy:function(){for(var _8 in this._sConnects){if(this._sConnects.hasOwnProperty(_8)){_4.disconnect(this._sConnects[_8]);}}},selectFeatures:function(_9,_a,_b,_c){if(_b===esri.layers.FeatureLayer.SELECTION_NEW){this._resetMapServiceInfos();this.getSelection(_9);}var _d=[];_4.forEach(_9,function(_e){if(_e.visible===true&&_e._isMapAtVisibleScale()===true){var _f=_b;if(_e._isSelOnly&&_f===esri.layers.FeatureLayer.SELECTION_NEW){_f=esri.layers.FeatureLayer.SELECTION_ADD;}_d.push(_e.selectFeatures(_a,_f));}});var _10=new _4.DeferredList(_d);_10.addCallback(_4.hitch(this,function(_11){var _12=[];_4.forEach(_11,function(set,idx){_4.forEach(set[1],function(_13){var _14=_13.attributes[_9[idx].objectIdField];_13=_9[idx]._mode._getFeature(_14)||null;if(_13){_12.push(_13);}},this);},this);if(!this._mapServiceCount){_c(_12);return;}var _15=_b===esri.layers.FeatureLayer.SELECTION_SUBTRACT;if(_15){this._resetMapServiceInfos();this._createLayerDefs(this._getLayerInfosFromSelection(_9));}else{this._createLayerDefs(this._getLayerInfosFromFeatures(_12));}this._updateLayerDefs(this._mapServiceInfos,false,!((_12&&_12.length)||_15),_4.hitch(this,_c,_12));}));},selectFeaturesByGeometry:function(_16,_17,_18,_19){var _1a=_17;if(_17.declaredClass.indexOf("Extent")!==-1){if(_17.xmax==_17.xmin&&_17.ymax==_17.ymin){_1a=new esri.geometry.Point(_17.xmax,_17.ymax);}}_1a=(_1a.declaredClass.indexOf("Point")!==-1)?this._extentFromPoint(_1a):_1a;var _1b=new esri.tasks.Query();_1b.geometry=_1a;this.selectFeatures(_16,_1b,_18,_19);},clearSelection:function(_1c){var _1d=this._nonSelOnlyLayers;_4.forEach(_1d,"if (item.clearSelection){ item.clearSelection(); }");if(!this._mapServiceCount){return;}this._resetMapServiceInfos();var _1e=this._getLayerInfosFromSelection(this._settings.layers);var _1f=_4.some(_1e,"return item.oids && item.oids.length");if(_1f){this._createLayerDefs(_1e);this._updateLayerDefs(this._mapServiceInfos,true,_1c||false);}},findMapService:function(_20){var map=this._map;var _21=map.layerIds;var _22=(_20&&_20._url)?_20._url.path.toLowerCase():"";var _23;for(var _24 in _21){if(_21.hasOwnProperty(_24)){_23=map.getLayer(_21[_24]);var _25=_23._url?_23._url.path.toLowerCase().replace("mapserver","featureserver"):"";if(_22.substr(0,_25.length)===_25&&_23.declaredClass==="esri.layers.ArcGISDynamicMapServiceLayer"){return _23;}}}},getSelection:function(_26){var _27=[];_4.forEach(_26,function(_28){if(_28._isSelOnly){_27.push(this._createLayerInfo(_28));}},this);_4.forEach(_27,function(_29){var _2a=this._createMapServiceInfo(this.findMapService(_29.layer));if(_2a){_2a.layerInfos[_29.layer.layerId]=_29;}},this);},_initMapServiceInfos:function(_2b){this._nonSelOnlyLayers=[];this._mapServiceInfos=[];_4.forEach(_2b,function(_2c){var _2d=this.findMapService(_2c);if(_2d){this._mapServiceCount++;this._createMapServiceInfo(_2d);if(_2d){_2d.setDisableClientCaching(true);}}else{this._nonSelOnlyLayers.push(_2c);}},this);},_createMapServiceInfo:function(_2e){if(!_2e){return null;}var _2f=this._mapServiceInfos;var _30=_2f[_2e.id];if(!_30){_30=_2f[_2e.id]={mapService:_2e,layerInfos:[],layerDefs:_4.mixin([],_2e.layerDefinitions||[]),origLayerDefs:_4.mixin([],_2e.layerDefinitions||[])};}return _30;},_resetMapServiceInfo:function(_31){_4.forEach(_31.layerInfos,this._resetLayerInfo);_31.layerDefs=_4.mixin([],_31.origLayerDefs||[]);},_resetMapServiceInfos:function(){var _32=this._mapServiceInfos;for(var _33 in _32){if(_32.hasOwnProperty(_33)){this._resetMapServiceInfo(_32[_33]);}}},_createLayerInfo:function(_34,_35){var _36=_34.objectIdField;var _37=_35?[]:_34.getSelectedFeatures();return {layer:_34,selectedFeatures:_37||[],oids:_4.map(_37,function(_38){return _38.attributes[_36];})};},_resetLayerInfo:function(_39){if(!_39){return;}_39.selectedFeatures=[];_39.oids=[];},_updateLayerDefs:function(_3a,_3b,_3c,_3d){for(var _3e in _3a){if(_3a.hasOwnProperty(_3e)){var _3f=_3a[_3e];var _40=_3f.mapService;var _41=_3f.layerDefs=(_3b?_4.mixin([],_3f.origLayerDefs||[]):_3f.layerDefs);if(_41){if(!_3c){this._sConnects[_40.id]=(_4.connect(_40,"onUpdateEnd",_4.hitch(this,"_onMapServiceUpdate",_3f,_3b,_3d)));}else{if(_3d){_3d();}}_40.setLayerDefinitions(_41,_3c||false);}else{if(_3d){_3d();}}}}},_onMapServiceUpdate:function(_42,_43,_44){_4.disconnect(this._sConnects[_42.mapService.id]);_4.forEach(_42.layerInfos,function(_45){if(_43){if(_45){_45.layer.clearSelection();}}else{var _46=new esri.tasks.Query();_46.objectIds=_45?_45.oids:[];if(_46.objectIds.length){_45.layer.selectFeatures(_46,esri.layers.FeatureLayer.SELECTION_SUBTRACT);}}},this);if(_43){this._resetMapServiceInfo(_42);}if(_44){_44();}},_createLayerDefs:function(_47){_4.forEach(_47,function(_48){var _49=_48.layer;var _4a=this._createMapServiceInfo(this.findMapService(_48.layer));if(!_4a){return;}var _4b=_4a.mapService;var _4c=_4a.layerDefs;var _4d=_49.objectIdField;var _4e=_49.layerId;var _4f="(\""+_4d+"\" NOT IN (";var _50=_48.oids;if(_50&&_50.length){_4.forEach(_48.oids,function(oid,idx){_50=true;if(idx){_4f+=",";}_4f+="'"+oid+"'";});_4f+="))";if(_4c.length&&(_4c[_4e]&&_4c[_4e].length)){_4c[_4e]+=" AND"+_4f;}else{_4c[_4e]=_4f;}}},this);},_getLayerInfosFromFeatures:function(_51){var _52=[];_4.forEach(_51,function(_53){var _54=_53.getLayer();if(_54&&_54._isSelOnly){if(!_52[_54.id]){_52[_54.id]=this._createLayerInfo(_54,true);}_52[_54.id].selectedFeatures.push(_53);_52[_54.id].oids.push(_53.attributes[_54.objectIdField]);}},this);var _55=[];for(var _56 in _52){if(_52.hasOwnProperty(_56)){_55.push(_52[_56]);}}return _55;},_getLayerInfosFromSelection:function(_57){var _58=[];_4.forEach(_57,function(_59){if(_59._isSelOnly){_58.push(this._createLayerInfo(_59,false));}},this);return _58;},_extentFromPoint:function(_5a){var _5b=this._tolerance;var map=this._map;var _5c=map.toScreen(_5a);var _5d=new esri.geometry.Point(_5c.x-_5b,_5c.y+_5b);var _5e=new esri.geometry.Point(_5c.x+_5b,_5c.y-_5b);var _5f=map.toMap(_5d);var _60=map.toMap(_5e);return new esri.geometry.Extent(_5f.x,_5f.y,_60.x,_60.y,map.spatialReference);}});}}};});