/*
 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/layers/layer",["dojo/_base/declare","dojo/_base/config","dojo/_base/connect","dojo/_base/lang","dojo/_base/Deferred","dojo/_base/json","dojo/has","esri/Evented","esri/kernel","esri/lang","esri/request","esri/deferredUtils","esri/urlUtils","esri/SpatialReference","esri/geometry/Extent"],function(_1,_2,_3,_4,_5,_6,_7,_8,_9,_a,_b,_c,_d,_e,_f){var _10=_1([_8],{declaredClass:"esri.layers.Layer",_eventMap:{"error":["error"],"load":["layer"],"opacity-change":["opacity"],"update-end":["error"],"visibility-change":["visible"]},constructor:function(url,_11){if(url&&_4.isString(url)){this._url=_d.urlToObject(this.url=url);}else{this.url=(this._url=null);_11=_11||url;if(_11&&_11.layerDefinition){_11=null;}}this.spatialReference=new _e(4326);this.initialExtent=new _f(-180,-90,180,90,new _e(4326));this._map=this._div=null;this.normalization=true;if(_11){if(_11.id){this.id=_11.id;}if(_11.visible===false){this.visible=false;}if(_a.isDefined(_11.opacity)){this.opacity=_11.opacity;}if(_a.isDefined(_11.minScale)){this.setMinScale(_11.minScale);}if(_a.isDefined(_11.maxScale)){this.setMaxScale(_11.maxScale);}this.attributionDataUrl=_11.attributionDataUrl||"";this.hasAttributionData=!!this.attributionDataUrl;if(_a.isDefined(_11.showAttribution)){this.showAttribution=_11.showAttribution;}}this._errorHandler=_4.hitch(this,this._errorHandler);if(this.managedSuspension){var _12=this._setMap;this._setMap=function(map){var _13=_12.apply(this,arguments);this.evaluateSuspension();if(this.suspended&&!map.loaded){var _14=_3.connect(map,"onLoad",this,function(){_3.disconnect(_14);_14=null;this.evaluateSuspension();});}return _13;};}this.registerConnectEvents();},id:null,visible:true,loaded:false,minScale:0,maxScale:0,visibleAtMapScale:false,suspended:true,attributionDataUrl:"",hasAttributionData:false,showAttribution:true,_errorHandler:function(err){this.onError(err);},_setMap:function(map,_15,_16,lod){this._map=map;this._lyrZEHandle=_3.connect(map,"onZoomEnd",this,this._processMapScale);if(map.loaded){this.visibleAtMapScale=this._isMapAtVisibleScale();}else{var _17=_3.connect(map,"onLoad",this,function(){_3.disconnect(_17);_17=null;this._processMapScale();});}},_unsetMap:function(map,_18){_3.disconnect(this._lyrZEHandle);this._lyrZEHandle=null;this._map=null;this.suspended=true;},_cleanUp:function(){this._map=this._div=null;},_fireUpdateStart:function(){if(this.updating){return;}this.updating=true;this.onUpdateStart();if(this._map){this._map._incr();}},_fireUpdateEnd:function(_19,_1a){this.updating=false;this.onUpdateEnd(_19,_1a);if(this._map){this._map._decr();}},_getToken:function(){var url=this._url,crd=this.credential;return (url&&url.query&&url.query.token)||(crd&&crd.token)||undefined;},_findCredential:function(){this.credential=_9.id&&this._url&&_9.id.findCredential(this._url.path);},_useSSL:function(){var _1b=this._url,re=/^http:/i,rep="https:";if(this.url){this.url=this.url.replace(re,rep);}if(_1b&&_1b.path){_1b.path=_1b.path.replace(re,rep);}},refresh:function(){},show:function(){this.setVisibility(true);},hide:function(){this.setVisibility(false);},setMinScale:function(_1c){this.setScaleRange(_1c);},setMaxScale:function(_1d){this.setScaleRange(null,_1d);},setScaleRange:function(_1e,_1f){var _20=_a.isDefined(_1e),_21=_a.isDefined(_1f);if(!this.loaded){this._hasMin=this._hasMin||_20;this._hasMax=this._hasMax||_21;}var _22=this.minScale,_23=this.maxScale;this.minScale=(_20?_1e:this.minScale)||0;this.maxScale=(_21?_1f:this.maxScale)||0;if((_22!==this.minScale)||(_23!==this.maxScale)){this.onScaleRangeChange();this._processMapScale();}},suspend:function(){this._suspended=true;this.evaluateSuspension();},resume:function(){this._suspended=false;this.evaluateSuspension();},canResume:function(){return this.loaded&&this._map&&this._map.loaded&&this.visible&&this.visibleAtMapScale&&!this._suspended;},evaluateSuspension:function(){if(this.canResume()){if(this.suspended){this._resume();}}else{if(!this.suspended){this._suspend();}}},_suspend:function(){this.suspended=true;this.onSuspend();if(this._map){this._map.onLayerSuspend(this);}},_resume:function(){this.suspended=false;var _24=(this._resumedOnce===undefined);if(_24){this._resumedOnce=true;}this.onResume({firstOccurrence:_24});if(this._map){this._map.onLayerResume(this);}},_processMapScale:function(){var _25=this.visibleAtMapScale;this.visibleAtMapScale=this._isMapAtVisibleScale();if(_25!==this.visibleAtMapScale){this.onScaleVisibilityChange();this.evaluateSuspension();}},isVisibleAtScale:function(_26){return (_26?_10.prototype._isMapAtVisibleScale.apply(this,arguments):false);},_isMapAtVisibleScale:function(_27){if(!_27&&(!this._map||!this._map.loaded)){return false;}_27=_27||this._map.getScale();var _28=this.minScale,_29=this.maxScale,_2a=!_28,_2b=!_29;if(!_2a&&_27<=_28){_2a=true;}if(!_2b&&_27>=_29){_2b=true;}return (_2a&&_2b)?true:false;},getAttributionData:function(){var url=this.attributionDataUrl,dfd=new _5(_c._dfdCanceller);if(this.hasAttributionData&&url){dfd._pendingDfd=_b({url:url,content:{f:"json"},handleAs:"json",callbackParamName:"callback"});dfd._pendingDfd.then(function(_2c){dfd.callback(_2c);},function(_2d){dfd.errback(_2d);});}else{var err=new Error("Layer does not have attribution data");err.log=_2.isDebug;dfd.errback(err);}return dfd;},getResourceInfo:function(){var _2e=this.resourceInfo;return _4.isString(_2e)?_6.fromJson(_2e):_4.clone(_2e);},setNormalization:function(_2f){this.normalization=_2f;},setVisibility:function(v){if(this.visible!==v){this.visible=v;this.onVisibilityChange(this.visible);this.evaluateSuspension();}},onLoad:function(){},onVisibilityChange:function(){},onScaleRangeChange:function(){},onScaleVisibilityChange:function(){},onSuspend:function(){},onResume:function(){},onUpdate:function(){},onUpdateStart:function(){},onUpdateEnd:function(){},onError:function(){}});if(_7("extend-esri")){_4.setObject("layers.Layer",_10,_9);}return _10;});