// 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/array dojo/_base/lang esri/graphicsUtils dojo/aspect dojo/topic ./LayerInfo ./LayerInfoForDefault jimu/utils dojo/Deferred esri/lang".split(" "),function(m,h,g,v,n,p,q,w,r,t,u){return m(q,{constructor:function(){},_getExtentAsync:function(){var a=this.layerObject.getLayers(),b=null,d=null;if(0<a.length&&"esri.layers.KMLLayer"===a[0].declaredClass){var e=[];this.traversal(g.hitch(this,function(f){f.id!==this.id&&"esri.layers.KMLLayer"===f.layerObject.declaredClass&&
e.push(f)}));h.forEach(e,function(f){d=f._getExtentAsync();b=b?b.union(d):d},this)}else h.forEach(a,function(f){d=r.graphicsExtent(f.graphics);b=b?b.union(d):d},this);return b},_getExtent:function(){var a=new t;a.resolve(this._getExtentAsync());return a},_resetLayerObjectVisiblity:function(a){var b=a?a[this.id]:null;if(b){var d={},e;for(e in a)a.hasOwnProperty(e)&&"function"!==typeof a[e]&&(d[e]=a[e].visible);this._setSubLayerVisibleByCheckedInfo(d);this._setTopLayerVisible(b.visible)}},_setSubLayerVisibleByCheckedInfo:function(a){this.traversal(g.hitch(this,
function(b){u.isDefined(a[b.id])&&b._setTopLayerVisible(a[b.id])}))},_initVisible:function(){this._visible=this.originOperLayer.layerObject.visible},_setTopLayerVisible:function(a){a?this.layerObject.show():this.layerObject.hide()},obtainNewSubLayers:function(){var a=[];h.forEach(this._getOperLayerByParentFolderId(-1,this),function(b){b=this._layerInfoFactory.create(b);a.push(b);b.init()},this);return a},_getOperLayerByParentFolderId:function(a,b){var d=[],e=this.layerObject.getLayers()||[],f=h.filter(this.layerObject.folders||
[],function(c){return c.parentFolderId===a?!0:!1}),l=[];l=0===f.length?h.filter(e,function(c){return this._flag.kmzSubLayersWereHandled?!1:!0},this):f;h.forEach(l,function(c){if("esri.layers.KMLFolder"===c.declaredClass)var k={layerObject:c,title:c.label||c.title||c.name||"\x26lt;no name\x26gt;",id:this._getSubLayerInfoIdForSubFolder(c),subId:c.id,kml:{layerInfo:this,currentFolder:c},selfType:"kml",parentLayerInfo:b};else"esri.layers.KMLLayer"===c.declaredClass?(k=g.getObject("linkInfo.name",!1,c),
k={layerObject:c,title:c.label||c.title||k||c.name||c.id||" ",id:c.id||"-",subId:c.id||"-",kml:{layerInfo:this,currentFolder:null},selfType:"kml",parentLayerInfo:b},g.setObject("_wabProperties.kmllayerWasHandled",!0,c),this._flag.kmzSubLayersWereHandled=!0):(g.setObject("_wabProperties.kmllayerWasHandled",!0,c),g.setObject("_wabProperties.isTemporaryLayer",!0,c));k&&d.push(k)},this);return d},_getAllSubLayerObject:function(){var a=[];this.traversal(g.hitch(this,function(b){b.layerObject&&b.layerObject.getLayers&&
(a=a.concat(b.layerObject.getLayers()))}));return a},_getSubLayerInfoIdForSubFolder:function(a){return this.id+"_folder_"+a.id},_needToRenew:function(){return h.some(this._getAllSubLayerObject(),function(a){if(!g.getObject("_wabProperties.kmllayerWasHandled",!1,a))return!0},this)},_bindEvent:function(){this.inherited(arguments);if(this.layerObject&&!this.layerObject.empty){var a=n.after(this.layerObject,"setFolderVisibility",g.hitch(this,this._onSubFolderVisibleChanged),!0);this._eventHandles.push(a)}},
_onSubFolderVisibleChanged:function(a){a=this._getSubLayerInfoIdForSubFolder(a);(a=this.findLayerInfoById(a))&&p.publish("layerInfos/layerInfo/visibleChanged",[a])}})});