/*
 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
 */
//>>built
define("esri/tasks/locator",["dojo/_base/declare","dojo/_base/lang","dojo/_base/array","dojo/_base/Deferred","dojo/_base/json","dojo/has","esri/kernel","esri/request","esri/deferredUtils","esri/tasks/Task","esri/tasks/AddressCandidate"],function(_1,_2,_3,_4,_5,_6,_7,_8,_9,_a,_b){var _c=_1(_a,{declaredClass:"esri.tasks.Locator",_eventMap:{"address-to-locations-complete":["addresses"],"addresses-to-locations-complete":["addresses"],"location-to-address-complete":["address"]},constructor:function(_d){this._geocodeHandler=_2.hitch(this,this._geocodeHandler);this._geocodeAddressesHandler=_2.hitch(this,this._geocodeAddressesHandler);this._reverseGeocodeHandler=_2.hitch(this,this._reverseGeocodeHandler);this.registerConnectEvents();},outSpatialReference:null,setOutSpatialReference:function(sr){this.outSpatialReference=sr;},_geocodeHandler:function(_e,io,_f,_10,dfd){try{var _11=_e.candidates,_12,out=[],i,il=_11.length,sr=_e.spatialReference,_13;for(i=0;i<il;i++){_12=_11[i];_13=_12.location;if(_13){_13.spatialReference=sr;}out[i]=new _b(_12);}this._successHandler([out],"onAddressToLocationsComplete",_f,dfd);}catch(err){this._errorHandler(err,_10,dfd);}},_geocodeAddressesHandler:function(_14,io,_15,_16,dfd){try{var _17=_14.locations,out=[],i,il=_17.length,sr=_14.spatialReference,_18;for(i=0;i<il;i++){_18=_17[i].location;if(_18){_18.spatialReference=sr;}out[i]=new _b(_17[i]);}this._successHandler([out],"onAddressesToLocationsComplete",_15,dfd);}catch(err){this._errorHandler(err,_16,dfd);}},addressToLocations:function(_19,_1a,_1b,_1c,_1d){if(_19.address){_1c=_1b;_1b=_1a;_1a=_19.outFields;_1d=_19.searchExtent;_19=_19.address;}if(_1d){_1d=_1d._normalize(true);}var _1e=this.outSpatialReference,_1f=this._encode(_2.mixin({},this._url.query,_19,{f:"json",outSR:_1e&&_5.toJson(_1e.toJson()),outFields:(_1a&&_1a.join(","))||null,searchExtent:_1d&&_5.toJson(_1d.toJson())})),_20=this._geocodeHandler,_21=this._errorHandler,dfd=new _4(_9._dfdCanceller);dfd._pendingDfd=_8({url:this._url.path+"/findAddressCandidates",content:_1f,callbackParamName:"callback",load:function(r,i){_20(r,i,_1b,_1c,dfd);},error:function(r){_21(r,_1c,dfd);}});return dfd;},addressesToLocations:function(_22,_23,_24){var _25=this.outSpatialReference,_26=[],_27=_22.addresses;_3.forEach(_27,function(_28,idx){_26.push({attributes:_28});});var _29=this._encode(_2.mixin({},this._url.query,{addresses:_5.toJson({records:_26})},{f:"json",outSR:_25&&_5.toJson(_25.toJson())})),_2a=this._geocodeAddressesHandler,_2b=this._errorHandler,dfd=new _4(_9._dfdCanceller);dfd._pendingDfd=_8({url:this._url.path+"/geocodeAddresses",content:_29,callbackParamName:"callback",load:function(r,i){_2a(r,i,_23,_24,dfd);},error:function(r){_2b(r,_24,dfd);}});return dfd;},_reverseGeocodeHandler:function(_2c,io,_2d,_2e,dfd){try{var _2f=new _b({address:_2c.address,location:_2c.location,score:100});this._successHandler([_2f],"onLocationToAddressComplete",_2d,dfd);}catch(err){this._errorHandler(err,_2e,dfd);}},locationToAddress:function(_30,_31,_32,_33){if(_30&&this.normalization){_30=_30.normalize();}var _34=this.outSpatialReference,_35=this._encode(_2.mixin({},this._url.query,{outSR:_34&&_5.toJson(_34.toJson()),location:_30&&_5.toJson(_30.toJson()),distance:_31,f:"json"})),_36=this._reverseGeocodeHandler,_37=this._errorHandler,dfd=new _4(_9._dfdCanceller);dfd._pendingDfd=_8({url:this._url.path+"/reverseGeocode",content:_35,callbackParamName:"callback",load:function(r,i){_36(r,i,_32,_33,dfd);},error:function(r){_37(r,_33,dfd);}});return dfd;},onAddressToLocationsComplete:function(){},onAddressesToLocationsComplete:function(){},onLocationToAddressComplete:function(){}});if(_6("extend-esri")){_2.setObject("tasks.Locator",_c,_7);}return _c;});