// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
define("esri/dijit/Attribution","dojo/_base/declare dojo/_base/lang dojo/_base/array dojo/_base/connect dojo/_base/kernel dojo/has dojo/query dojo/dom dojo/dom-attr dojo/dom-construct dojo/dom-style dojo/dom-class dojo/dom-geometry ../kernel ../lang ../SpatialReference ../geometry/webMercatorUtils ../geometry/Extent".split(" "),function(t,h,k,q,y,z,F,A,u,v,r,l,w,B,x,C,D,E){t=t(null,{declaredClass:"esri.dijit.Attribution",itemDelimiter:" | ",listClass:"esriAttributionList",itemClass:"esriAttributionItem",
lastItemClass:"esriAttributionLastItem",delimiterClass:"esriAttributionDelim",constructor:function(c,a){try{h.mixin(this,c);this._attributions={};this._pendingDfds={};this._activeLayers=[];this._sharedLayers=[];this._layerHandles={};var b=this.domNode=A.byId(a),d=this.map,e="\x3cspan class\x3d'"+this.listClass+"'\x3e\x3c/span\x3e";b&&(u.set(b,"innerHTML",e),this.listNode=y.query(".esriAttributionList",b)[0],this.itemNodes={});this._eventConnections=[q.connect(d,"onLayerAdd",this,this._onLayerAdd),
q.connect(d,"onLayerRemove",this,this._onLayerRemove),q.connect(d,"onLayerSuspend",this,this._onLayerSuspend),q.connect(d,"onLayerResume",this,this._onLayerResume),q.connect(d,"onResize",this,this._adjustFocus),q.connect(d,"onExtentChange",this,this._onExtentChange)];if(d.loaded){var f=d.layerIds.concat(d.graphicsLayerIds),g,n,p=f.length;for(n=0;n<p;n++)g=d.getLayer(f[n]),g.loaded&&this._onLayerAdd(g)}}catch(G){}},startup:function(){},destroy:function(){k.forEach(this._eventConnections,q.disconnect);
v.destroy(this.listNode);var c=this._layerHandles,a;for(a in c)c[a]&&c[a].remove();this.map=this.domNode=this._eventConnections=this.listNode=this._attributions=this._pendingDfds=this.itemNodes=this._activeLayers=this._lastItem=this._sharedLayers=this._layerHandles=null},_onLayerAdd:function(c){try{var a=this._attributions,b=c.id;if(!x.isDefined(a[b])&&c.showAttribution){if(c.hasAttributionData){var d=c.getAttributionData();this._pendingDfds[b]=1;a[b]=d;d.addBoth(h.partial(this._onAttributionLoad,
this,c))}else a[b]=c.copyright||c.copyrightText||"",a[b]?(c.suspended||this._activeLayers.push(b),this._createNode(b)):this._onLayerRemove(c);-1<c.declaredClass.toLowerCase().indexOf("vetiledlayer")&&(this._layerHandles[b]=c.on("map-style-change",h.hitch(this,function(){this._onLayerRemove(c);this._onLayerAdd(c)})))}}catch(e){}},_onAttributionLoad:function(c,a,b){var d=c._attributions,e=c._pendingDfds,f=a.id;if(e&&e[f]){delete e[f];if(!b||b instanceof Error)b="";d[f]=b?c._createIndexByLevel(b,-1!==
a.declaredClass.toLowerCase().indexOf("vetiledlayer")):a.copyright||a.copyrightText||"";d[f]?(a.suspended||c._activeLayers.push(f),c._createNode(f)):c._onLayerRemove(a)}},_onLayerRemove:function(c){try{var a=c.id,b=this.itemNodes,d,e=-1;this._onLayerSuspend(c);this._layerHandles[a]&&this._layerHandles[a].remove();delete this._attributions[a];delete this._pendingDfds[a];delete this._layerHandles[a];d=this._getGroupIndex(a);-1!==d&&(e=k.indexOf(this._sharedLayers[d],a),-1!==e&&(this._sharedLayers[d].splice(e,
1),1>=this._sharedLayers[d].length&&this._sharedLayers.splice(d,1)));b[a]&&-1===e&&v.destroy(b[a]);delete b[a];this._updateLastItem()}catch(f){}},_onLayerSuspend:function(c){try{var a=c.id;if(this._attributions[a]){var b=k.indexOf(this._activeLayers,a),d=this.itemNodes[a];-1!==b&&this._activeLayers.splice(b,1);d&&this._toggleItem(d,!1,this._getGroupIndex(a))}}catch(e){}},_adjustFocus:function(){var c=this.domNode.scrollWidth>this.domNode.clientWidth,a=l.contains(this.domNode,"esriAttributionOpen");
u.set(this.domNode,"tabIndex",c||a?"0":"")},_onLayerResume:function(c){try{var a=c.id,b=this._attributions[a],d=this.itemNodes[a];if(b&&(-1===k.indexOf(this._activeLayers,a)&&this._activeLayers.push(a),d)){var e=h.isString(b)?b:this._getContributorsList(b,this.map.extent,this.map.getLevel());h.isString(b)||u.set(d,"innerHTML",e?e+this._getDelimiter():"");e&&this._toggleItem(d,!0,this._getGroupIndex(a))}}catch(f){}},_onExtentChange:function(c,a,b,d){try{var e=this._activeLayers,f=this._attributions,
g=this.itemNodes,n,p,l,k,q=e.length||0;for(k=0;k<q;k++)if(p=e[k],l=f[p],(n=g[p])&&!h.isString(l)){var m=this._getContributorsList(l,c,d?d.level:-1);u.set(n,"innerHTML",m?m+this._getDelimiter():"");this._toggleItem(n,!!m,-1)}}catch(H){}this._adjustCursorStyle()},_createNode:function(c){if(this.domNode){var a=this._checkShareInfo(c),b=a&&a.sharedWith,b=b&&this.itemNodes[b],d=this.map,e=this._attributions[c],e=h.isString(e)?e:this._getContributorsList(e,d.extent,d.getLevel()),d=!!e&&!d.getLayer(c).suspended;
b?(this.itemNodes[c]=b,this._toggleItem(b,d,a.index)):(c=this.itemNodes[c]=v.create("span",{"class":this.itemClass,innerHTML:e?e+this._getDelimiter():"",style:{display:d?"inline":"none"}},this.listNode),d&&this._setLastItem(c));this._adjustCursorStyle()}},_checkShareInfo:function(c){var a=this._attributions,b,d,e=-1,f=a[c],g;if(f&&h.isString(f)){for(d in a)if(b=a[d],d!==c&&b&&h.isString(b)&&b.length===f.length&&b.toLowerCase()===f.toLowerCase()){g=d;break}a=this._sharedLayers;b=a.length;if(g){for(d=
0;d<b;d++)if(f=a[d],-1!==k.indexOf(f,g)){e=d;f.push(c);break}-1===e&&(e=a.push([g,c])-1)}}return-1<e?{index:e,sharedWith:g}:null},_getGroupIndex:function(c){var a=this._sharedLayers,b,d=a.length,e=-1;for(b=0;b<d;b++)if(-1!==k.indexOf(a[b],c)){e=b;break}return e},_getDelimiter:function(){var c=this.itemDelimiter;return c?"\x3cspan class\x3d'"+this.delimiterClass+"'\x3e"+c+"\x3c/span\x3e":""},_toggleItem:function(c,a,b){if(-1<b&&!a){b=this._sharedLayers[b];var d,e=b.length,f=this._activeLayers;for(d=
0;d<e;d++)if(-1!==k.indexOf(f,b[d]))return}r.set(c,"display",a?"inline":"none");this._updateLastItem()},_updateLastItem:function(){var c=this.listNode.childNodes,a;a=c.length;var b;if(a)for(--a;0<=a;a--)if(b=c[a],"none"!==r.get(b,"display")){this._setLastItem(b);break}this._adjustCursorStyle()},_setLastItem:function(c){var a=this.itemClass,b=this.lastItemClass;this._lastItem&&l.replace(this._lastItem,a,b);c&&(l.replace(c,b,a),this._lastItem=c)},_createIndexByLevel:function(c,a){var b=c.contributors,
d,e,f,g,n=b?b.length:0,p,k,l=new C(4326),h={},m;for(g=0;g<n;g++)for(d=b[g],k=(e=d.coverageAreas)?e.length:0,p=0;p<k;p++)for(f=e[p],m=f.bbox,m={extent:D.geographicToWebMercator(new E(m[1],m[0],m[3],m[2],l)),attribution:d.attribution||"",zoomMin:f.zoomMin-(a&&f.zoomMin?1:0),zoomMax:f.zoomMax-(a&&f.zoomMax?1:0),score:x.isDefined(f.score)?f.score:100,objectId:g},f=m.zoomMin;f<=m.zoomMax;f++)h[f]=h[f]||[],h[f].push(m);return h},_getContributorsList:function(c,a,b){var d="";if(a&&x.isDefined(b)&&-1<b){c=
c[b];b=a.getCenter().normalize();for(var e=c?c.length:0,f=[],g={},d=0;d<e;d++)a=c[d],!g[a.objectId]&&a.extent.contains(b)&&(g[a.objectId]=1,f.push(a));f.sort(function(a,b){return b.score-a.score||a.objectId-b.objectId});e=f.length;for(d=0;d<e;d++)f[d]=f[d].attribution;d=f.join(", ")}return d},_adjustCursorStyle:function(){var c=w.position(this.listNode.parentNode,!0).h;l.contains(this.listNode.parentNode,"esriAttributionOpen")?(l.remove(this.listNode.parentNode,"esriAttributionOpen"),c>w.position(this.listNode.parentNode,
!0).h?(r.set(this.listNode.parentNode,"cursor","pointer"),l.add(this.listNode.parentNode,"esriAttributionOpen")):r.set(this.listNode.parentNode,"cursor","default")):(l.add(this.listNode.parentNode,"esriAttributionOpen"),c<w.position(this.listNode.parentNode,!0).h?r.set(this.listNode.parentNode,"cursor","pointer"):r.set(this.listNode.parentNode,"cursor","default"),l.remove(this.listNode.parentNode,"esriAttributionOpen"));this._adjustFocus()}});z("extend-esri")&&h.setObject("dijit.Attribution",t,B);
return t});