// 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/lang dojo/_base/array dojo/Deferred ./RequestBuffer esri/layers/FeatureLayer esri/layers/RasterLayer esri/layers/StreamLayer esri/layers/ArcGISImageServiceLayer esri/layers/ArcGISImageServiceVectorLayer".split(" "),function(m,d,n,h,p,f,q,r,t,u){return m(null,{_layerInfo:null,_layerObjectBuffer:null,constructor:function(a){this._layerInfo=a;this._initLayerObjectBuffer()},_initLayerObjectBuffer:function(){this._layerObjectBuffer=new p(d.hitch(this,this._getLayerObject))},
getLayerObject:function(){var a=this._layerInfo.getUrl();return this._layerObjectBuffer.getRequest(this._layerInfo.subId).request(a)},getLayerObjectWithUrl:function(a){return this._layerObjectBuffer.getRequest(this._layerInfo.subId+"_url").request(a)},_getLayerObject:function(a){var b,c=new h;this._layerInfo.getLayerType().then(d.hitch(this,function(e){var g=d.mixin(this._getLayerOptionsForCreateLayerObject(),this._layerInfo.originOperLayer.options||{})||{};switch(e){case "FeatureLayer":b=new f(a,
g);break;case "RasterLayer":b=new q(a);break;case "StreamLayer":b=new r(a);break;case "ArcGISImageServiceLayer":b=new t(a);break;case "ArcGISImageServiceVectorLayer":b=new u(a);break;case "Table":if(this._layerInfo.layerObject&&!this._layerInfo.layerObject.empty)return this._setLayerObjectProperties(this._layerInfo.layerObject),c.resolve(this._layerInfo.layerObject),c;if(this._layerInfo.layerObject&&this._layerInfo.layerObject.url)b=new f(a,g);else return this._layerInfo.layerObject&&this._layerInfo.layerObject.featureCollectionData?
(b=new f(this._layerInfo.layerObject.featureCollectionData,g),this._setLayerObjectProperties(b),c.resolve(b)):c.resolve(null),c;break;case "GroupLayer":return c=this._getGroupLayerObject();default:return c.resolve(null),c}var k=b.on("load",d.hitch(this,function(){this._setLayerObjectProperties(b);c.resolve(b);k.remove&&k.remove()})),l=b.on("error",d.hitch(this,function(v){c.reject(v);l.remove&&l.remove()}))}),d.hitch(this,function(){c.reject()}));return c},_getGroupLayerObject:function(){var a=new h;
this._layerInfo._getServiceDefinition().then(d.hitch(this,function(b){if(null===b)a.reject();else{var c=this._layerInfo.getUrl();b.url=c;b.id=this._layerInfo.id;a.resolve(b)}}));return a},_getLayerOptionsForCreateLayerObject:function(){var a={},b=[],c=this._layerInfo.getInfoTemplate();c&&c.info&&c.info.fieldInfos?n.forEach(c.info.fieldInfos,function(e){e.visible&&b.push(e.fieldName)},this):b=["*"];a.outFields=b;return a},_setLayerObjectProperties:function(a){a.name&&!d.getObject("_wabProperties.originalLayerName",
!1,a)&&(d.setObject("_wabProperties.originalLayerName",a.name,a),a.name=this._layerInfo.title);a.id=this._layerInfo.id;this._layerInfo.loadInfoTemplate().then(d.hitch(this,function(b){a.infoTemplate=b}))}})});