// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.11/esri/copyright.txt for details.
//>>built
define("esri/dijit/Legend","dojo/_base/kernel dojo/_base/declare dojo/_base/lang dojo/_base/array dojo/_base/connect dojo/_base/json dojo/_base/Color dojo/has dojo/sniff dojo/DeferredList dojo/json dojo/number dojo/dom dojo/dom-construct dojo/dom-style dijit/_Widget dojox/gfx dojox/gfx/matrix dojox/html/entities ../kernel ../config ../request ../lang ../renderers/SimpleRenderer ../renderers/UniqueValueRenderer ../renderers/ClassBreaksRenderer ../renderers/ScaleDependentRenderer ../renderers/DotDensityRenderer ../renderers/TemporalRenderer ../symbols/SimpleMarkerSymbol ../symbols/PictureFillSymbol ../symbols/jsonUtils ./_EventedWidget dojo/i18n!../nls/jsapi dojo/i18n!dojo/cldr/nls/number".split(" "),
function(z,K,s,n,m,L,x,u,$,M,N,D,q,e,p,O,E,P,Q,R,F,G,C,A,H,I,S,T,U,V,W,B,X,Y,Z){var w=K([X,O],{declaredClass:"esri.dijit.Legend",widgetsInTemplate:!1,layers:null,alignRight:!1,hoverLabelShowing:!1,dotDensitySwatchSize:26,dotCoverage:75,reZeros:RegExp("\\"+Z.decimal+"0+$","g"),reZerosFractional:RegExp("(\\d)0*$","g"),_ieTimer:100,_isRightToLeft:!1,_align:null,_legendAlign:null,constructor:function(a,b){s.mixin(this,Y.widgets.legend);a=a||{};a.map?b?(this.map=a.map,this.layerInfos=a.layerInfos,this._respectCurrentMapScale=
!1===a.respectCurrentMapScale?!1:!0,this.arrangement=a.arrangement===w.ALIGN_RIGHT?w.ALIGN_RIGHT:w.ALIGN_LEFT,this.arrangement===w.ALIGN_RIGHT&&(this.alignRight=!0),this.autoUpdate=!1===a.autoUpdate?!1:!0,this._surfaceItems=[]):console.error("esri.dijit.Legend: must specify a container for the legend"):console.error("esri.dijit.Legend: unable to find the 'map' property in parameters")},postMixInProperties:function(){this.inherited(arguments);var a=["ar","he"],b,c;for(b=0;b<a.length;b+=1)c=a[b],z.locale&&
-1!==z.locale.indexOf(c)&&(-1!==z.locale.indexOf("-")?-1!==z.locale.indexOf(c+"-")&&(this._isRightToLeft=!0):this._isRightToLeft=!0);this._isRightToLeft?(this._align=this.alignRight?"left":"right",this._legendAlign=this.alignRight?"esriLegendLeft":"esriLegendRight"):(this._align=this.alignRight?"right":"left",this._legendAlign=this.alignRight?"esriLegendRight":"esriLegendLeft")},startup:function(){this.inherited(arguments);this._initialize();9>u("ie")&&(this._repaintItems=s.hitch(this,this._repaintItems),
setTimeout(this._repaintItems,this._ieTimer))},destroy:function(){this._deactivate();this._removeHoverHandlers();this.inherited(arguments)},refresh:function(a){if(this.domNode){a?(this.layerInfos=a,this.layers=[],n.forEach(this.layerInfos,function(a){this._isSupportedLayerType(a.layer)&&(a.title&&(a.layer._titleForLegend=a.title),a.layer._hideDefaultSymbol=!1===a.defaultSymbol?!0:!1,a.hideLayers?(a.layer._hideLayersInLegend=a.hideLayers,this._addSubLayersToHide(a)):a.layer._hideLayersInLegend=[],
a.hoverLabel&&(a.layer._hoverLabel=a.hoverLabel),a.hoverLabels&&(a.layer._hoverLabels=a.hoverLabels),this.layers.push(a.layer))},this)):this.useAllMapLayers&&(this.layers=this.layerInfos=null);for(a=this.domNode.children.length-1;0<=a;a--)e.destroy(this.domNode.children[a]);this._removeHoverHandlers();this.startup()}},_legendUrl:"http://utility.arcgis.com/sharing/tools/legend",_initialize:function(){this.layerInfos&&(this.layers=[],n.forEach(this.layerInfos,function(a){this._isSupportedLayerType(a.layer)&&
(a.title&&(a.layer._titleForLegend=a.title),a.layer._hideDefaultSymbol=!1===a.defaultSymbol?!0:!1,a.hideLayers?(a.layer._hideLayersInLegend=a.hideLayers,this._addSubLayersToHide(a)):a.layer._hideLayersInLegend=[],a.hoverLabel&&(a.layer._hoverLabel=a.hoverLabel),a.hoverLabels&&(a.layer._hoverLabels=a.hoverLabels),this.layers.push(a.layer))},this));this.useAllMapLayers=!1;if(!this.layers){this.useAllMapLayers=!0;this.layers=[];var a=[],b=[];n.forEach(this.map.layerIds,function(c){c=this.map.getLayer(c);
var d;this._isSupportedLayerType(c)&&(c.arcgisProps&&c.arcgisProps.title&&(c._titleForLegend=c.arcgisProps.title),this.layers.push(c));"esri.layers.KMLLayer"==c.declaredClass&&(d=c.getLayers(),n.forEach(d,function(b){a.push(b.id)},this));"esri.layers.GeoRSSLayer"==c.declaredClass&&(d=c.getFeatureLayers(),n.forEach(d,function(a){b.push(a.id)},this))},this);n.forEach(this.map.graphicsLayerIds,function(c){var d=this.map.getLayer(c);-1==n.indexOf(a,c)&&-1==n.indexOf(b,c)&&(this._isSupportedLayerType(d)&&
d._params&&d._params.drawMode)&&(d.arcgisProps&&d.arcgisProps.title&&(d._titleForLegend=d.arcgisProps.title),this.layers.push(d))},this)}this._createLegend()},_activate:function(){this._deactivate();this.autoUpdate&&(this._respectCurrentMapScale&&(this._ozeConnect=m.connect(this.map,"onZoomEnd",this,"_refreshLayers")),this.useAllMapLayers&&(this._olaConnect=m.connect(this.map,"onLayerAdd",this,"_updateAllMapLayers"),this._olrConnect=m.connect(this.map,"onLayerRemove",this,"_updateAllMapLayers"),this._olroConnect=
m.connect(this.map,"onLayersReordered",this,"_updateAllMapLayers")),n.forEach(this.layers,function(a){a.ovcConnect=m.connect(a,"onVisibilityChange",this,"_refreshLayers");a.oscConnect=m.connect(a,"onScaleRangeChange",this,"_refreshLayers");"esri.layers.ArcGISDynamicMapServiceLayer"===a.declaredClass&&a.supportsDynamicLayers&&(a.odcConnect=m.connect(a,"_onDynamicLayersChange",s.hitch(this,"_updateDynamicLayers",a)));"esri.layers.ArcGISImageServiceLayer"===a.declaredClass&&(a.oirConnect=m.connect(a,
"onRenderingChange",s.partial(this._updateImageServiceLayers,this,a)))},this))},_deactivate:function(){this._ozeConnect&&m.disconnect(this._ozeConnect);this._olaConnect&&m.disconnect(this._olaConnect);this._olroConnect&&m.disconnect(this._olroConnect);this._olrConnect&&m.disconnect(this._olrConnect);n.forEach(this.layers,function(a){a.ovcConnect&&m.disconnect(a.ovcConnect);a.oscConnect&&m.disconnect(a.oscConnect);a.odcConnect&&m.disconnect(a.odcConnect);a.oirConnect&&m.disconnect(a.oirConnect)},this)},
_updateDynamicLayers:function(a){delete a.legendResponse;this._refreshLayers()},_updateImageServiceLayers:function(a,b){delete b.legendResponse;a._refreshLayers()},_refreshLayers:function(){this.refresh()},_updateAllMapLayers:function(){this.layers=[];n.forEach(this.map.layerIds,function(a){a=this.map.getLayer(a);this._isSupportedLayerType(a)&&this.layers.push(a)},this);n.forEach(this.map.graphicsLayerIds,function(a){a=this.map.getLayer(a);this._isSupportedLayerType(a)&&(a._params&&a._params.drawMode)&&
this.layers.push(a)},this);this.refresh()},_createLegend:function(){var a=!1;p.set(this.domNode,"position","relative");e.create("div",{id:this.id+"_msg",className:"esriLegendMsg",innerHTML:this.NLS_creatingLegend+"..."},this.domNode);var b=[];n.forEach(this.layers,function(c){if("esri.layers.KMLLayer"==c.declaredClass||"esri.layers.GeoRSSLayer"==c.declaredClass){var f;c.loaded?("esri.layers.KMLLayer"==c.declaredClass?f=c.getLayers():"esri.layers.GeoRSSLayer"==c.declaredClass&&(f=c.getFeatureLayers(),
c._hideLayersInLegend&&(f=n.filter(f,function(a){return-1==n.indexOf(c._hideLayersInLegend,a.id)}))),n.forEach(f,function(a){"esri.layers.FeatureLayer"==a.declaredClass&&c._titleForLegend&&(a._titleForLegend=c._titleForLegend+" - ","esriGeometryPoint"==a.geometryType?a._titleForLegend+=this.NLS_points:"esriGeometryPolyline"==a.geometryType?a._titleForLegend+=this.NLS_lines:"esriGeometryPolygon"==a.geometryType&&(a._titleForLegend+=this.NLS_polygons),b.push(a))},this)):m.connect(c,"onLoad",s.hitch(this,
function(){this.refresh(this.layerInfos)}))}else if("esri.layers.WMSLayer"===c.declaredClass)if(c.loaded){if(c.visible&&0<c.layerInfos.length&&n.some(c.layerInfos,function(a){return a.legendURL})){var h=!1;n.forEach(c.layerInfos,function(b){b.legendURL&&-1<n.indexOf(c.visibleLayers,b.name)&&(h||(e.create("div",{innerHTML:"\x3cspan class\x3d'esriLegendServiceLabel'\x3e"+(c._titleForLegend||c.name||c.id)+"\x3c/span\x3e"},this.domNode),h=!0),e.create("div",{innerHTML:"\x3cimg src\x3d'"+b.legendURL+"'/\x3e"},
this.domNode),a=!0)},this)}}else m.connect(c,"onLoad",s.hitch(this,function(){this.refresh(this.layerInfos)}));else b.push(c)},this);var c=[];n.forEach(b,function(a){if(a.loaded){if(!0===a.visible&&(a.layerInfos||a.renderer||"esri.layers.ArcGISImageServiceLayer"==a.declaredClass)){var b=e.create("div",{id:this.id+"_"+a.id,style:{display:"none"},"class":"esriLegendService"});e.create("span",{innerHTML:this._getServiceTitle(a),"class":"esriLegendServiceLabel"},e.create("td",{align:this._align},e.create("tr",
{},e.create("tbody",{},e.create("table",{width:"95%"},b)))));e.place(b,this.id,"first");a.legendResponse||a.renderer?this._createLegendForLayer(a):c.push(this._legendRequest(a))}}else var h=m.connect(a,"onLoad",this,function(a){m.disconnect(h);h=null;this.refresh()})},this);0===c.length&&!a?(q.byId(this.id+"_msg").innerHTML=this.NLS_noLegend,this._activate()):(new M(c)).addCallback(s.hitch(this,function(b){a?q.byId(this.id+"_msg").innerHTML="":q.byId(this.id+"_msg").innerHTML=this.NLS_noLegend;this._activate()}))},
_createLegendForLayer:function(a){if(a.legendResponse||a.renderer){var b=!1;if(a.legendResponse){var c=a.dynamicLayerInfos||a.layerInfos;c&&c.length?n.forEach(c,function(c,f){if(!a._hideLayersInLegend||-1==n.indexOf(a._hideLayersInLegend,c.id)){var h=this._buildLegendItems(a,c,f);b=b||h}},this):"esri.layers.ArcGISImageServiceLayer"==a.declaredClass&&(b=this._buildLegendItems(a,{id:0,name:null,title:a.name,subLayerIds:null,parentLayerId:-1},0))}else a.renderer&&(c=a.url?a.url.substring(a.url.lastIndexOf("/")+
1,a.url.length):"fc_"+a.id,b=this._buildLegendItems(a,{id:c,name:null,subLayerIds:null,parentLayerId:-1},0));b&&(p.set(q.byId(this.id+"_"+a.id),"display","block"),p.set(q.byId(this.id+"_msg"),"display","none"))}},_legendRequest:function(a){if(a.loaded)return 10.01<=a.version?this._legendRequestServer(a):this._legendRequestTools(a);m.connect(a,"onLoad",s.hitch(this,"_legendRequest"))},_legendRequestServer:function(a){var b=a.url,c=b.indexOf("?"),b=-1<c?b.substring(0,c)+"/legend"+b.substring(c):b+"/legend";
(c=a._getToken())&&(b+="?token\x3d"+c);var d=s.hitch(this,"_processLegendResponse"),c={f:"json"};a._params.dynamicLayers&&(c.dynamicLayers=N.stringify(this._createDynamicLayers(a)),"[{}]"===c.dynamicLayers&&(c.dynamicLayers="[]"));a._params.bandIds&&(c.bandIds=a._params.bandIds);a._params.renderingRule&&(c.renderingRule=a._params.renderingRule);return G({url:b,content:c,callbackParamName:"callback",load:function(b,c){d(a,b,c)},error:F.defaults.io.errorHandler})},_legendRequestTools:function(a){var b=
a.url.toLowerCase().indexOf("/rest/"),b=a.url.substring(0,b)+a.url.substring(b+5,a.url.length),b=this._legendUrl+"?soapUrl\x3d"+window.escape(b);if(!u("ie")||8<u("ie"))b+="\x26returnbytes\x3dtrue";var c=s.hitch(this,"_processLegendResponse");return G({url:b,content:{f:"json"},callbackParamName:"callback",load:function(b,f){c(a,b,f)},error:F.defaults.io.errorHandler})},_processLegendResponse:function(a,b){b&&b.layers?(a.legendResponse=b,q.byId(this.id+"_"+a.id)&&e.empty(q.byId(this.id+"_"+a.id)),e.create("span",
{innerHTML:this._getServiceTitle(a),"class":"esriLegendServiceLabel"},e.create("td",{align:this._align},e.create("tr",{},e.create("tbody",{},e.create("table",{width:"95%"},q.byId(this.id+"_"+a.id)))))),this._createLegendForLayer(a)):console.log("Legend could not get generated for "+a.url+": "+L.toJson(b))},_buildLegendItems:function(a,b,c){var d=!1,f=q.byId(this.id+"_"+a.id),h=b.parentLayerId;if(b.subLayerIds)a=e.create("div",{id:this.id+"_"+a.id+"_"+b.id+"_group",style:{display:"none"},"class":-1==
h?0<c?"esriLegendGroupLayer":"":this._legendAlign},-1==h?f:q.byId(this.id+"_"+a.id+"_"+h+"_group")),e.create("td",{innerHTML:b.name,align:this._align},e.create("tr",{},e.create("tbody",{},e.create("table",{width:"95%","class":"esriLegendLayerLabel"},a))));else{if(a.visibleLayers&&-1==(","+a.visibleLayers+",").indexOf(","+b.id+","))return d;c=e.create("div",{id:this.id+"_"+a.id+"_"+b.id,style:{display:"none"},"class":-1<h?this._legendAlign:""},-1==h?f:q.byId(this.id+"_"+a.id+"_"+h+"_group"));e.create("td",
{innerHTML:b.name||"",align:this._align},e.create("tr",{},e.create("tbody",{},e.create("table",{width:"95%","class":"esriLegendLayerLabel"},c))));a.legendResponse?d=d||this._buildLegendItems_Tools(a,b,c):a.renderer&&(d=d||this._buildLegendItems_Renderer(a,b,c))}return d},_buildLegendItems_Tools:function(a,b,c){var d=b.parentLayerId,f=this.map.getScale(),h=!1,k=function(a,b){var c,d;for(c=0;c<a.length;c++)if(b.dynamicLayerInfos)for(d=0;d<b.dynamicLayerInfos[d].length;d++){if(b.dynamicLayerInfos[d].mapLayerId==
a[c].layerId)return a[c]}else if(b.id==a[c].layerId)return a[c];return{}};if(!this._respectCurrentMapScale||this._respectCurrentMapScale&&this._isLayerInScale(a,b,f)){var l=!0;if("esri.layers.ArcGISDynamicMapServiceLayer"===a.declaredClass||"esri.layers.ArcGISMapServiceLayer"===a.declaredClass){var g=this._getEffectiveScale(a,b);if(g.minScale&&g.minScale<f||g.maxScale&&g.maxScale>f)l=!1}if(l){var f=k(a.legendResponse.layers,b),r=f.legendType,v=f.legend;if(v){c=e.create("table",{cellpadding:0,cellspacing:0,
width:"95%","class":"esriLegendLayer"},c);var t=e.create("tbody",{},c);(a._hoverLabel||a._hoverLabels)&&this._createHoverAction(c,a,b);n.forEach(v,function(c){if(!(10.1<=a.version&&!c.values&&1<v.length&&(a._hideDefaultSymbol||"\x3call other values\x3e"===c.label||!c.label&&!("esri.layers.ArcGISImageServiceLayer"===a.declaredClass&&10.3<=a.version))))if(c.url&&0===c.url.indexOf("http")||c.imageData&&0<c.imageData.length)h=!0,this._buildRow_Tools(c,t,a,b.id,r)},this)}}}h&&(p.set(q.byId(this.id+"_"+
a.id+"_"+b.id),"display","block"),-1<d&&(p.set(q.byId(this.id+"_"+a.id+"_"+d+"_group"),"display","block"),this._findParentGroup(a.id,a,d)));return h},_buildRow_Tools:function(a,b,c,d,f){var h=e.create("tr",{},b),k;this.alignRight?(b=e.create("td",{align:this._isRightToLeft?"left":"right"},h),k=e.create("td",{align:this._isRightToLeft?"left":"right",width:35},h)):(k=e.create("td",{width:35},h),b=e.create("td",{},h));h=a.url;(!u("ie")||9<=u("ie")||9>u("ie")&&"esri.layers.ArcGISImageServiceLayer"===
c.declaredClass)&&a.imageData&&0<a.imageData.length?h="data:image/png;base64,"+a.imageData:0!==a.url.indexOf("http")&&(h=c.url+"/"+d+"/images/"+a.url,(d=c._getToken())&&(h+="?token\x3d"+d));d=e.create("img",{src:h,border:0,style:"opacity:"+c.opacity},k);a=e.create("td",{innerHTML:a.label,align:this._align},e.create("tr",{},e.create("tbody",{},e.create("table",{width:"95%",dir:"ltr"},b))));f&&("Stretched"===f&&10.3<=c.version&&"esri.layers.ArcGISImageServiceLayer"===c.declaredClass)&&(a.style.verticalAlign=
"top",a.style.lineHeight="1",d.style.marginBottom="-1px",d.style.display="block",b.style.verticalAlign="top");9>u("ie")&&(d.style.filter="alpha(opacity\x3d"+100*c.opacity+")")},_buildLegendItems_Renderer:function(a,b,c){var d=b.parentLayerId,f=this.map,h=f.getScale(),k=!1;if(!this._respectCurrentMapScale||this._isLayerInScale(a,b,h)){var l,g=a.renderer,r,v,t,m,y;if(g instanceof S&&(g=(g="zoom"===g.rangeType?g.getRendererInfoByZoom(f.getZoom()):g.getRendererInfoByScale(h))&&g.renderer,!g))return!1;
g.colorInfo?(r=this._getMedianColor(g),t=s.isFunction(g.colorInfo.field)?null:a._getField(g.colorInfo.field,!0)):g.opacityInfo&&(y=s.isFunction(g.opacityInfo.field)?null:a._getField(g.opacityInfo.field,!0));g.proportionalSymbolInfo&&(m=s.isFunction(g.proportionalSymbolInfo.field)?null:a._getField(g.proportionalSymbolInfo.field,!0));if(g instanceof T)k=!0,this._showDotDensityLegend(a,b,g,c);else if(g instanceof U)k=!0,f=e.create("table",{cellpadding:0,cellspacing:0,width:"95%","class":"esriLegendLayer"},
c),l=e.create("tbody",{},f),(a._hoverLabel||a._hoverLabels)&&this._createHoverAction(f,a,b),g.latestObservationRenderer&&g.latestObservationRenderer instanceof A&&this._buildRow_Renderer(a,g.latestObservationRenderer.symbol,r,g.latestObservationRenderer.label||this.NLS_currentObservations,null,l),g.observationRenderer&&g.observationRenderer instanceof A&&this._buildRow_Renderer(a,g.observationRenderer.symbol,r,g.observationRenderer.label||this.NLS_previousObservations,null,l);else if(g instanceof
H){if(g.infos&&0<g.infos.length){k=!0;f=e.create("table",{cellpadding:0,cellspacing:0,width:"95%","class":"esriLegendLayer"},c);l=e.create("tbody",{},f);(a._hoverLabel||a._hoverLabels)&&this._createHoverAction(f,a,b);var J=[];n.forEach(g.infos,function(b){var c=null;a._editable&&a.types&&(c=this._getTemplateFromTypes(a.types,b.value));var d=b.label;null==d&&(d=b.value);-1===n.indexOf(J,d)&&(J.push(d),this._buildRow_Renderer(a,b.symbol,r,d,c,l))},this)}}else g instanceof I?g.infos&&0<g.infos.length&&
(k=!0,f=e.create("table",{cellpadding:0,cellspacing:0,width:"95%","class":"esriLegendLayer"},c),l=e.create("tbody",{},f),(a._hoverLabel||a._hoverLabels)&&this._createHoverAction(f,a,b),n.forEach(g.infos,function(b){var c=b.label;null==c&&(c=b.minValue+" - "+b.maxValue);this._buildRow_Renderer(a,b.symbol,r,c,null,l)},this)):g instanceof A&&(k=!0,f=e.create("table",{cellpadding:0,cellspacing:0,width:"95%","class":"esriLegendLayer"},c),l=e.create("tbody",{},f),(a._hoverLabel||a._hoverLabels)&&this._createHoverAction(f,
a,b),v=null,a._editable&&(a.templates&&0<a.templates.length)&&(v=a.templates[0]),f=(t||y)&&m?null:t||y||m,this._buildRow_Renderer(a,g.symbol,r,f?f.alias||f.name:g.label,v,l),v=g.symbol&&g.symbol.color,f&&(t=y=m=null));k&&(g.colorInfo?this._showColorRamp(a,b,g,null,c,g.colorInfo,t):g.opacityInfo&&v&&this._showColorRamp(a,b,g,v,c,g.opacityInfo,y),g.proportionalSymbolInfo&&this._showProportionalLegend(a,b,g,r,c,m));!a._hideDefaultSymbol&&g.defaultSymbol&&(k=!0,this._buildRow_Renderer(a,g.defaultSymbol,
null,g.defaultLabel||"others",null,l))}k&&(p.set(q.byId(this.id+"_"+a.id+"_"+b.id),"display","block"),-1<d&&(p.set(q.byId(this.id+"_"+a.id+"_"+d+"_group"),"display","block"),this._findParentGroup(a.id,d)));return k},_showColorRamp:function(a,b,c,d,f,h,k){var l;l=e.create("table",{cellpadding:0,cellspacing:0,width:"95%","class":"esriLegendLayer"},f);f=e.create("tbody",{},l);(a._hoverLabel||a._hoverLabels)&&this._createHoverAction(l,a,b);k&&this._addSubHeader(f,k.alias||k.name);b=this._getRampStops(c,
h,d);b.length&&this._drawColorRamp(f,b,a)},_getMedianColor:function(a){var b=a.colorInfo,c,d;b.colors?(c=b.minDataValue,d=b.maxDataValue):b.stops&&(c=b.stops[0].value,d=b.stops[b.stops.length-1].value);return a.getColor(c+(d-c)/2)},_getRampStops:function(a,b,c){var d,f,h;b.colors||b.opacityValues?(f=b.maxDataValue-b.minDataValue,d=n.map([0,0.25,0.5,0.75,1],function(a){h=b.minDataValue+a*f;return Number(h.toFixed(6))}),this._checkPrecision(0,4,d)):b.stops&&(d=n.map(b.stops,function(a){return a.value}));
var k=d[0],e,g;f=d[d.length-1]-k;return n.map(d,function(b){c?(e=new x(c.toRgba()),g=a.getOpacity(b),null!=g&&(e.a=g)):e=a.getColor(b);return{value:b,color:e,offset:1-(b-k)/f,label:D.format(b,{places:20,round:-1}).replace(this.reZerosFractional,"$1").replace(this.reZeros,"")}},this).reverse()},_checkPrecision:function(a,b,c){var d=a+(b-a)/2,f=c[a],h=c[d],e=c[b],l=Math.floor(f),g=Math.floor(h),r=Math.floor(e);l===f&&(r===e&&g!==h&&l!==g&&r!==g)&&(c[d]=g);a+1!==d&&this._checkPrecision(a,d,c);d+1!==
b&&this._checkPrecision(d,b,c)},_drawColorRamp:function(a,b,c){var d=e.create("tr",{},a),f,h,k,l,g,r,m;this.alignRight?(a=e.create("td",{align:this._isRightToLeft?"left":"right"},d),f=e.create("td",{align:this._isRightToLeft?"left":"right",width:34},d)):(f=e.create("td",{width:34,align:"center"},d),a=e.create("td",{},d));h=e.create("div",{style:"position: relative; width:34px;"},f);k=e.create("div",{"class":"esriLegendColorRamp"},h);d=p.get(k,"width");f=p.get(k,"height");p.set(h,"height",f+"px");
k=E.createSurface(k,d,f);9>u("ie")&&(g=k.getEventSource(),p.set(g,"position","relative"),p.set(g.parentNode,"position","relative"));try{r=k.createRect({width:d,height:f}),r.setFill({type:"linear",x1:0,y1:0,x2:0,y2:f,colors:b}).setStroke(null),k.createRect({width:d,height:f}).setFill(new x([255,255,255,1-c.opacity])).setStroke(null),this._surfaceItems.push(k)}catch(t){k.clear(),k.destroy()}l=e.create("div",{"class":"esriLegendColorRampLabels"},a);n.forEach(b,function(a,c){m="top:"+100*a.offset+"%;";
e.create("div",{"class":"esriLegendColorRampTick"+(c===b.length-1?" esriLegendColorRampTickLast":""),innerHTML:"\x26nbsp;",style:m},h);e.create("div",{"class":"esriLegendColorRampLabel",innerHTML:a.label,style:m},l)})},_showDotDensityLegend:function(a,b,c,d){var f=c.legendOptions,h,k,l,g,r,m,t,q=this.dotDensitySwatchSize,p=Math.round(q/2);f&&(k=f.backgroundColor,l=f.outline,g=f.valueUnit,r=f.dotCoverage);r=(r||this.dotCoverage)/100;t=Math.round(q*q/Math.pow(c.dotSize,2)*r);d=e.create("table",{cellpadding:0,
cellspacing:0,width:"95%","class":"esriLegendLayer"},d);m=e.create("tbody",{},d);(a._hoverLabel||a._hoverLabels)&&this._createHoverAction(d,a,b);this._addSubHeader(m,C.substitute({value:c.dotValue,unit:g||""},this.NLS_dotValue));n.forEach(c.fields,function(b){b=s.mixin({},b);b.numPoints=t;h=new W(c._generateImageSrc(q,q,[b],{x:0,y:0},{x:q,y:q},k),l||c.outline,q,q);b=a._getField(b.name,!0)||b;this._buildRow_Renderer(a,h,null,b.alias||b.name,null,m,{type:"path",path:"M "+-p+","+-p+" L "+p+","+-p+" L "+
p+","+p+" L "+-p+","+p+" L "+-p+","+-p+" E"})},this)},_showProportionalLegend:function(a,b,c,d,f,h){var k=c.proportionalSymbolInfo,l=k.legendOptions,l=l&&l.customValues,g,r=k.minDataValue,m=k.maxDataValue,p=this._getProportionalSymbol(c,d);"unknown"!==k.valueUnit||(!p||!l&&(null==r||null==m))||(d=e.create("table",{cellpadding:0,cellspacing:0,width:"95%","class":"esriLegendLayer"},f),g=e.create("tbody",{},d),(a._hoverLabel||a._hoverLabels)&&this._createHoverAction(d,a,b),h&&this._addSubHeader(g,h.alias||
h.name),b=l||this._getDataValues(r,m),n.forEach(b,function(b){p=B.fromJson(p.toJson());this._applySize(p,c,b);b=D.format(b,{places:20,round:-1}).replace(this.reZerosFractional,"$1").replace(this.reZeros,"");this._buildRow_Renderer(a,p,null,b,null,g)},this))},_getProportionalSymbol:function(a,b){var c,d;if(a instanceof A)d=!0,c=a.symbol;else if(a instanceof H||a instanceof I)c=a.infos[0].symbol;if(c=-1!==c.type.indexOf("fillsymbol")?null:c)!d&&"picturemarkersymbol"===c.type?(c=new V,c.setStyle("square"),
c.outline.setWidth(1)):c=B.fromJson(c.toJson()),b?c.setColor(new x(b.toRgba())):d||c.setColor(new x([127,127,127]));return c},_applySize:function(a,b,c){var d=a.type;b=b.getSize(c,-1!==d.indexOf("markersymbol")?{shape:a.style}:null);switch(d){case "simplemarkersymbol":a.setSize(b);break;case "picturemarkersymbol":a.setWidth(b);a.setHeight(b);break;case "simplelinesymbol":case "cartographiclinesymbol":a.setWidth(b)}},_getDataValues:function(a,b){var c=[a,b],d=Math.LN10,f=Math.log(a),h=Math.log(b),
e,l,g,r,m;n.forEach([1,2.5,5],function(a){r=Math.log(a);e=Math.ceil((f-r)/d);l=Math.floor((h-r)/d);if(!(Infinity===Math.abs(e)||Infinity===Math.abs(l)))for(g=e;g<l+1;g++)m=a*Math.pow(10,g),-1===n.indexOf(c,m)&&c.push(m)});c.sort(this._sorter);return c.reverse()},_sorter:function(a,b){return a-b},_buildRow_Renderer:function(a,b,c,d,f,h,k){var l=e.create("tr",{},h),g;this.alignRight?(h=e.create("td",{align:this._isRightToLeft?"left":"right"},l),g=e.create("td",{align:this._isRightToLeft?"left":"right",
width:35},l)):(g=e.create("td",{width:35,align:"center"},l),h=e.create("td",{},l));var m=l=30;"simplemarkersymbol"==b.type?(l=Math.min(Math.max(l,b.size+12),125),m=Math.min(Math.max(m,b.size+12),125)):"picturemarkersymbol"==b.type&&(l=Math.min(Math.max(l,b.width),125),m=Math.min(b.height||m,125));g=e.create("div",{style:"width:"+l+"px;height:"+m+"px;"},g);C.isDefined(d)&&"number"===typeof d&&(d=""+d);e.create("td",{innerHTML:d||"",align:this._align},e.create("tr",{},e.create("tbody",{},e.create("table",
{width:"95%"},h))));a=this._drawSymbol(g,b,c,l,m,f,a,k);this._surfaceItems.push(a)},_addSubHeader:function(a,b){var c=e.create("tr",{},a),c=e.create("td",{align:this._align,colspan:2},c);e.create("td",{innerHTML:b||"",align:this._align},e.create("tr",{},e.create("tbody",{},e.create("table",{width:"95%"},c))))},_drawSymbol:function(a,b,c,d,f,h,e,l){b=B.fromJson(b.toJson());var g=e.opacity;c&&b.setColor(new x(c.toRgba()));if("simplelinesymbol"===b.type||"cartographiclinesymbol"===b.type||"textsymbol"===
b.type){if(!b.color)return;c=b.color.toRgba();c[3]*=g;b.color.setColor(c)}else if("simplemarkersymbol"===b.type||"simplefillsymbol"===b.type){if(!b.color)return;c=b.color.toRgba();c[3]*=g;b.color.setColor(c);b.outline&&b.outline.color&&(c=b.outline.color.toRgba(),c[3]*=g,b.outline.color.setColor(c))}else"picturemarkersymbol"===b.type&&(a.style.opacity=g,a.style.filter="alpha(opacity\x3d("+100*g+"))");a=E.createSurface(a,d,f);9>u("ie")&&(c=a.getEventSource(),p.set(c,"position","relative"),p.set(c.parentNode,
"position","relative"));h=this._getDrawingToolShape(b,h)||B.getShapeDescriptors(b);var m;try{m=a.createShape(l||h.defaultShape).setFill(h.fill).setStroke(h.stroke)}catch(n){a.clear();a.destroy();return}var q=m.getBoundingBox();l=q.width;h=q.height;var g=-(q.x+l/2),w=-(q.y+h/2);c=a.getDimensions();g={dx:g+c.width/2,dy:w+c.height/2};if("simplemarkersymbol"===b.type&&"path"===b.style)d=e._getScaleMatrix(q,b.size),m.applyTransform(P.scaleAt(d.xx,d.yy,{x:c.width/2,y:c.height/2}));else if(l>d||h>f)e=l/
d>h/f,d=((e?d:f)-5)/(e?l:h),s.mixin(g,{xx:d,yy:d});m.applyTransform(g);return a},_getDrawingToolShape:function(a,b){var c;switch(b?b.drawingTool||null:null){case "esriFeatureEditToolArrow":c={type:"path",path:"M 10,1 L 3,8 L 3,5 L -15,5 L -15,-2 L 3,-2 L 3,-5 L 10,1 E"};break;case "esriFeatureEditToolTriangle":c={type:"path",path:"M -10,14 L 2,-10 L 14,14 L -10,14 E"};break;case "esriFeatureEditToolRectangle":c={type:"path",path:"M -10,-10 L 10,-10 L 10,10 L -10,10 L -10,-10 E"};break;case "esriFeatureEditToolCircle":c=
{type:"circle",cx:0,cy:0,r:10};break;case "esriFeatureEditToolEllipse":c={type:"ellipse",cx:0,cy:0,rx:10,ry:5};break;default:return null}return{defaultShape:c,fill:a.getFill(),stroke:a.getStroke()}},_repaintItems:function(){n.forEach(this._surfaceItems,function(a){this._repaint(a)},this)},_repaint:function(a){if(a){a.getStroke&&a.setStroke&&a.setStroke(a.getStroke());try{a.getFill&&a.setFill&&a.setFill(a.getFill())}catch(b){}a.children&&s.isArray(a.children)&&n.forEach(a.children,this._repaint,this)}},
_createHoverAction:function(a,b,c){var d=b._hoverLabel||b._hoverLabels[c.id];d&&(b.mouseMoveHandler=b.mouseMoveHandler||{},b.mouseMoveHandler[c.id]=m.connect(a,"onmousemove",s.hitch(this,function(a,b){this.mouseX=b.clientX;this.mouseY=b.clientY;this.hoverLabelShowing&&(this.hoverLabelShowing=!1,p.set(q.byId(this.id+"_hoverLabel"),"display","none"));setTimeout(s.hitch(this,function(a,b,c){if(a==this.mouseX&&b==this.mouseY&&!this.hoverLabelShowing)if(this.hoverLabelShowing=!0,q.byId(this.id+"_hoverLabel")){var d=
q.byId(this.id+"_hoverLabel");d.innerHTML="\x3cspan\x3e"+c+"\x3c/span\x3e";p.set(d,"top",b+"px");p.set(d,"left",a+15+"px");p.set(d,"display","")}else e.create("div",{innerHTML:"\x3cspan\x3e"+c+"\x3c/span\x3e",id:this.id+"_hoverLabel","class":"esriLegendHoverLabel",style:{top:b+"px",left:a+15+"px"}},document.body)},b.clientX,b.clientY,a),500)},d)),b.mouseOutHandler=b.mouseOutHandler||{},b.mouseOutHandler[c.id]=m.connect(a,"onmouseout",s.hitch(this,function(a){this.mouseY=this.mouseX=-1;this.hoverLabelShowing&&
(this.hoverLabelShowing=!1,p.set(q.byId(this.id+"_hoverLabel"),"display","none"))})))},_removeHoverHandlers:function(){var a;n.forEach(this.layers,function(b){if(b.mouseMoveHandler)for(a in b.mouseMoveHandler)m.disconnect(b.mouseMoveHandler[a]);if(b.mouseOutHandler)for(a in b.mouseOutHandler)m.disconnect(b.mouseOutHandler[a])})},_createDynamicLayers:function(a){var b=[],c;n.forEach(a.dynamicLayerInfos||a.layerInfos,function(d){c={id:d.id};c.source=d.source&&d.source.toJson();var f;a.layerDefinitions&&
a.layerDefinitions[d.id]&&(f=a.layerDefinitions[d.id]);f&&(c.definitionExpression=f);var e;a.layerDrawingOptions&&a.layerDrawingOptions[d.id]&&(e=a.layerDrawingOptions[d.id]);e&&(c.drawingInfo=e.toJson());c.minScale=d.minScale||0;c.maxScale=d.maxScale||0;b.push(c)});return b},_getTemplateFromTypes:function(a,b){var c;for(c=0;c<a.length;c++)if(a[c].id==b&&a[c].templates&&0<a[c].templates.length)return a[c].templates[0];return null},_findParentGroup:function(a,b,c){var d,f=b.dynamicLayerInfos||b.layerInfos;
for(d=0;d<f.length;d++)if(c==f[d].id){-1<f[d].parentLayerId&&(p.set(q.byId(this.id+"_"+a+"_"+f[d].parentLayerId+"_group"),"display","block"),this._findParentGroup(a,b,f[d].parentLayerId));break}},_addSubLayersToHide:function(a){function b(c,d){var f=a.layer.dynamicLayerInfos||a.layer.layerInfos,e,k;for(e=0;e<f.length;e++)if(f[e].id===c&&f[e].subLayerIds)for(k=0;k<f[e].subLayerIds.length;k++){var l=f[e].subLayerIds[k];-1===n.indexOf(d,l)&&(d.push(l),b(l,d))}}a.layer.layerInfos&&n.forEach(a.layer._hideLayersInLegend,
function(c){b(c,a.layer._hideLayersInLegend)})},_isLayerInScale:function(a,b,c){var d,f=!0;if(a.legendResponse&&a.legendResponse.layers)for(d=0;d<a.legendResponse.layers.length;d++){var e=a.legendResponse.layers[d];if(b.id==e.layerId){var k,l;!a.minScale&&0!==a.minScale||!a.maxScale&&0!==a.maxScale?(0==e.minScale&&a.tileInfo&&(k=a.tileInfo.lods[0].scale),0==e.maxScale&&a.tileInfo&&(l=a.tileInfo.lods[a.tileInfo.lods.length-1].scale)):(k=Math.min(a.minScale,e.minScale)||a.minScale||e.minScale,l=Math.max(a.maxScale,
e.maxScale));if(0<k&&k<c||l>c)f=!1;break}}else if(a.minScale||a.maxScale)if(a.minScale&&a.minScale<c||a.maxScale&&a.maxScale>c)f=!1;return f},_getServiceTitle:function(a){var b=a._titleForLegend;b||((b=a.url)?-1<a.url.indexOf("/MapServer")?(b=a.url.substring(0,a.url.indexOf("/MapServer")),b=b.substring(b.lastIndexOf("/")+1,b.length)):-1<a.url.indexOf("/ImageServer")?(b=a.url.substring(0,a.url.indexOf("/ImageServer")),b=b.substring(b.lastIndexOf("/")+1,b.length)):-1<a.url.indexOf("/FeatureServer")&&
(b=a.url.substring(0,a.url.indexOf("/FeatureServer")),b=b.substring(b.lastIndexOf("/")+1,b.length)):b="",a.name&&(b=0<b.length?b+(" - "+a.name):a.name));return Q.encode(b)},_getEffectiveScale:function(a,b){var c=b.minScale,d=b.maxScale;if(C.isDefined(b.parentLayerId)){var e=a.layerInfos,h=b.parentLayerId,k;for(k=e.length-1;0<=k;k--)if(e[k].id==h)if(0==c&&0<e[k].minScale?c=e[k].minScale:0<c&&0==e[k].minScale||0<c&&0<e[k].minScale&&(c=Math.min(c,e[k].minScale)),d=Math.max(d||0,e[k].maxScale||0),-1<
e[k].parentLayerId)h=e[k].parentLayerId;else break}return{minScale:c,maxScale:d}},_isSupportedLayerType:function(a){return a&&("esri.layers.ArcGISDynamicMapServiceLayer"===a.declaredClass||"esri.layers.ArcGISImageServiceLayer"===a.declaredClass&&10.2<=a.version||"esri.layers.ArcGISTiledMapServiceLayer"===a.declaredClass||"esri.layers.FeatureLayer"===a.declaredClass||"esri.layers.StreamLayer"===a.declaredClass||"esri.layers.KMLLayer"===a.declaredClass||"esri.layers.GeoRSSLayer"===a.declaredClass||
"esri.layers.WMSLayer"===a.declaredClass||"esri.layers.CSVLayer"===a.declaredClass)?!0:!1}});s.mixin(w,{ALIGN_LEFT:0,ALIGN_RIGHT:1});u("extend-esri")&&s.setObject("dijit.Legend",w,R);return w});