// COPYRIGHT © 201 Esri
//
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
//
// This material is licensed for use under the Esri Master License
// Agreement (MLA), and is bound by the terms of that agreement.
// You may redistribute and use this code without modification,
// provided you adhere to the terms of the MLA and include this
// copyright notice.
//
// See use restrictions at http://www.esri.com/legal/pdfs/mla_e204_e300/english
//
// For additional information, contact:
// Environmental Systems Research Institute, Inc.
// Attn: Contracts and Legal Services Department
// 380 New York Street
// Redlands, California, USA 92373
// USA
//
// email: contracts@esri.com
//
// See http://js.arcgis.com/3.34/esri/copyright.txt for details.

define(["require","module","dojo/_base/array","dojo/_base/lang","dojo/has","dojo/Deferred","dojo/DeferredList","dojo/promise/all","dojo/when","dojo/on","dojo/json","../kernel","../Color","../numberUtils","../promiseList","../lang","../styles/type","../styles/size","../styles/choropleth","../styles/heatmap","../styles/predominance","../styles/relationship","../symbols/SimpleMarkerSymbol","../symbols/SimpleLineSymbol","../symbols/SimpleFillSymbol","../symbols/utils","./UniqueValueRenderer","./ClassBreaksRenderer","./HeatmapRenderer","./BlendRenderer","./utils","dojo/i18n!../nls/jsapi"],(function(e,a,n,i,t,r,s,l,o,u,c,d,p,m,f,g,h,v,y,b,x,w,S,I,z,C,R,V,F,M,E,k){var T={},O=Math.pow(2,53)-1,P=k.smartMapping,q=/(https?:)?\/\/services.*\.arcgis\.com/i,B=["id","fips","fid","objectid","_objectid","__objectid","x","y","lat","long","latitude","longitude","shape","shape_length","shape_leng","shape_area","perimeter","stretched_value","fnode_","tnode_","lpoly_","rpoly_","poly_","subclass","rings_ok","rings_nok","st_length(shape)","st_area(shape)"],D=["count","percent","sum","elevation","value","valore","valoare","total","gesamt","score","income","age","expected","average","median","size","cost","expenditure","revenue","profit","growth","sale","quantity","population","price","unit","length","width","difference","distance"],j=["type","name","status","class","category","code","value","label","zone","symbol","color","owner","district","group","species","rating","score","party"],L="esriFieldTypeDate",_=["esriFieldTypeInteger","esriFieldTypeDouble","esriFieldTypeSingle","esriFieldTypeSmallInteger"];function H(e,a){e.reject(new Error(a))}function A(e,a){e.loaded?a.call():u.once(e,"load",a)}function W(e,a,n,i,t){var r,s,l=e.outline&&e.outline.color;switch(a=a?new p(a):null,l=l?new p(l):null,n){case"point":(r=new S).setColor(a),r.setSize(null!=i?i:e.size),(s=new I).setColor(l),s.setWidth(e.outline.width),r.setOutline(s);break;case"line":(r=new I).setColor(a),r.setWidth(null!=i?i:e.width);break;case"polygon":(r=new z).setColor(a),(s=new I).setColor(l),s.setWidth(e.outline.width),null!=t&&s.color&&(s.color.a=t),r.setOutline(s)}return r}function N(e){var a=e.geometryType;return"esriGeometryPoint"===a||"esriGeometryMultipoint"===a?a="point":"esriGeometryPolyline"===a?a="line":("esriGeometryPolygon"===a||e.hasXYFootprint())&&(a="polygon"),a}function U(e,a){var n=e.scheme;return n=n?h.cloneScheme(n):(n=h.getSchemes({theme:e.theme||"default",basemap:e.basemap,geometryType:a}))&&n.primaryScheme}function Q(e,a){return e.label<a.label?-1:e.label>a.label?1:0}function G(e,a){return e.value<a.value?-1:e.value>a.value?1:0}function $(e,a){var n=a.count-e.count;return 0===n&&(n=Q(e,a)),n}function X(e,a){var n=a.count-e.count;return 0===n&&(n=G(e,a)),n}function Y(e,a,t){var r,s,l,o,u,c,d=t.layer,p=t.field,m=i.isFunction(p),f=p&&!m?d.getField(p):null,g=f?d.getDomain(f.name):null,h=-1,v=null==t.numTypes?10:-1===t.numTypes?e.length:t.numTypes,y=null==t.showOthers||t.showOthers,b=null==t.sortBy?"count":t.sortBy,w=t&&t.labelCallback,S=N(d),I=U(t,S),z=a&&a.opacity,C=new R(null,p),V=t.customScheme,F=t.useSizeInfo;if(V){var M="polygon"===S,k=M&&F,O=V.sizeInfo,q=F?M?O.marker:O:null,B=k&&O?O.background:null;B&&(C.backgroundFillSymbol=W(B,B.color,"polygon",null,z)),u=c=M?k?q.size:null:"line"===S?V.width:V.size,I=V,S=k?"point":S}var D={domain:g,fieldInfo:f};for(n.forEach(e,(function(e,a){D.value=e.value,e.label=E.createUniqueValueLabel(D),w&&(e.label=w(e)),null===e.value&&(h=a)})),h>-1&&(o=e.splice(h,1)[0]),!1!==t.sortEnabled&&function(e,a,n){var t;i.isFunction(a)?t=a:"count"===a?(t=X,n&&n.codedValues&&(t=$)):"value"===a&&(t=G,n&&n.codedValues&&(t=Q)),t&&e.sort(t)}(e,b,g),f&&f.type===L&&(D.dateFormatInterval=E.calculateDateFormatInterval(n.map(n.filter(e,(function(e,a){return a<v})),(function(e){return e.value})))),l=T.createColors(I.colors,e.length),n.forEach(e,(function(e,a){D.value=e.value,e.label=E.createUniqueValueLabel(D),w&&(e.label=w(e)),e.symbol=W(I,l[a],S,c,z)})),t.valueExpression&&(C.setValueExpression(t.valueExpression),C.valueExpressionTitle=t.valueExpressionTitle),C.legendOptions=t.legendOptions,l=T.createColors(I.colors,v),r=0;r<v;r++)(s=e[r])&&C.addValue({value:s.value,label:s.label,symbol:W(I,l[r],S,c,z)});return y&&(C.defaultSymbol=W(I,I.noDataColor,S,u,z),C.defaultLabel=P.other),o&&(o.symbol=W(I,I.noDataColor,S,u,z),e.push(o)),a&&a.widthInfo&&C.setVisualVariables([a.widthInfo]),{renderer:C,uniqueValueInfos:e,othersStartIndex:C.infos.length===e.length?-1:C.infos.length,scheme:V?x.cloneScheme(V):U(t,S)}}function J(e,a,n){var i=e.scheme;return i=i?y.cloneScheme(i):(i=y.getSchemes({theme:n||e.theme||"high-to-low",basemap:e.basemap,geometryType:a}))&&i.primaryScheme}function K(e,a){var n,i=e.avg,t=i-e.stddev,r=i+e.stddev;return t<e.min&&(t=e.min),r>e.max&&(r=e.max),a&&(i=t+(r-t)/2),n=[t=(n=m.round([t,r],{strictBounds:!0}))[0],t+(i-t)/2,i,i+((r=n[1])-i)/2,r],m.round(n,{strictBounds:!0})}function Z(e,a,n,i){var t,r,s=e.statisticsPlugin.getSuggestedDataRange({statistics:a,isDate:n});return s.defaultStatistics?(t=s.min,r=s.max):!i||null!=a.avg&&a.stddev||(t=a.min,r=a.max),null!=t?[t,r]:null}function ee(e,a,t,r,s){var l=null==r.useDefaultStatistics||r.useDefaultStatistics;if(!e||e.count||l){var o,u,c,d=r.layer,f=r.field,g=i.isFunction(f),h=f&&!g?d.getField(f):null,v=h&&h.type===L,y=N(d),b=J(r,y),x=r.semiContinuous,w=a&&a.classBreakInfos,S=w&&w.length,I=a?S:5;if(b){var z=b.id.indexOf("seq-")>-1,C=a&&z?me(b,{length:I}):T.createColors(b.colors,I);if(C.length<I)H(s,"smartMapping.createColorInfo: not enough colors in the scheme.");else{if(a){var R;o=[],1===S?(u=[w[0].minValue,w[0].maxValue],o=[0,1],R=T.createColors(C,I)[0],c=[R,new p(R)]):x?(u=[],c=[],n.forEach(w,(function(e,a){var n=.1*(e.maxValue-e.minValue);0===a?u.push(e.minValue):u.push(e.minValue+n),a===S-1?u.push(e.maxValue):u.push(e.maxValue-n),R=new p(C[a]),c.push(R),c.push(new p(R)),o.push(2*a),o.push(2*a+1)}))):(u=n.map(w,(function(e,a){return o.push(a),(e.minValue+e.maxValue)/2})),c=T.createColors(C,I)),u=m.round(u,{strictBounds:!0})}else{var V=l?Z(d,e,v,!0):null;u=V?function(e,a,n){var i,t=(a-e)/(n-1),r=[e];for(i=1;i<=n-2;i++)r.push(e+i*t);return r.push(a),m.round(r,{strictBounds:!0})}(V[0],V[1],5):K(e,z),o=[0,2,4],c=T.createColors(C,I)}var F={type:"colorInfo",field:f,valueExpression:r.valueExpression,valueExpressionTitle:r.valueExpressionTitle,normalizationField:t,stops:E.createColorStops({values:u,isDate:v,dateFormatOptions:v?E.timelineDateFormatOptions:null,colors:c,labelIndexes:o}),legendOptions:r.legendOptions};s.resolve({colorInfo:F,statistics:e,classBreaks:a,scheme:J(r,y)})}}else H(s,"smartMapping.createColorInfo: unable to find the specified scheme.")}else H(s,"smartMapping.createColorInfo: cannot create renderer when statistics.count is 0.")}var ae=["HH","HL","LH","LL"];function ne(e,a){var n=E.getClassValuesForRelationship();return n=i.clone(n[e]),w.flatten2DArray(n,a)}function ie(e){var a=e.field1.field,i=e.field2.field,t=e.field1.normalizationField,r=e.field2.normalizationField,s=n.map(e.breaks1,(function(e){return[e.minValue,e.maxValue]})),l=n.map(e.breaks2,(function(e){return[e.minValue,e.maxValue]})),o=s.length,u=E.getClassCodesForRelationship()[o];return["var field1 = $feature['"+a+"'];","var field2 = $feature['"+i+"'];","var hasNormField1 = "+(t?"true":"false")+";","var hasNormField2 = "+(r?"true":"false")+";","var normField1 = "+(t?"$feature['"+t+"']":"null")+";","var normField2 = "+(r?"$feature['"+r+"']":"null")+";","if (","  IsEmpty(field1) || ","  IsEmpty(field2) ||","  (hasNormField1 && (IsEmpty(normField1) || normField1 == 0)) ||","  (hasNormField2 && (IsEmpty(normField2) || normField2 == 0))",") {","  return null; ","}","var value1 = IIf(hasNormField1, (field1 / normField1), field1);","var value2 = IIf(hasNormField2, (field2 / normField2), field2);","var breaks1 = "+c.stringify(s)+";","var breaks2 = "+c.stringify(l)+";","var classCodes = "+c.stringify(u)+";","function getClassCode(value, breaks) {","  var code = null;","  for (var i in breaks) {","    var info = breaks[i];","    if (value >= info[0] && value <= info[1]) {","      code = classCodes[i];","      break;","    }","  }","  return code;","}","var code1 = getClassCode(value1, breaks1);","var code2 = getClassCode(value2, breaks2);","var classValue = IIf(IsEmpty(code1) || IsEmpty(code2), null, code1 + code2);","return classValue;"].join("\n")}var te={"equal-interval":"esriClassifyEqualInterval","natural-breaks":"esriClassifyNaturalBreaks",quantile:"esriClassifyQuantile"},re=function(e){return{minValue:e.minValue,maxValue:e.maxValue}};function se(e,a,t,r,s){var l,o=a.numClasses,u=t.cbResponse.classBreakInfos,c=r.cbResponse.classBreakInfos;if(o===u.length&&u.length===c.length){var d=function(e,a){var i=ne(e,a);return n.map(i,(function(e){return{value:e,count:0}}))}(o,a.focus),p=ie({field1:a.field1,field2:a.field2,breaks1:u,breaks2:c}),m=function(e,a){var n=e.scheme;return n=n?w.cloneScheme(n):(n=w.getSchemes({theme:e.theme||"default",basemap:e.basemap,geometryType:a}))&&n.primaryScheme}(a,N(a.layer)),f=Y(d,s,{layer:a.layer,valueExpression:p,valueExpressionTitle:P.relationship.legendTitle,labelCallback:(l=P.relationship,function(e){return l[e.value]}),numTypes:-1,showOthers:a.showOthers,sortEnabled:!1,customScheme:i.mixin({colors:w.getColors(m,o,a.focus)},m)});f.renderer.setAuthoringInfo(function(e,a,i){return{type:"relationship",classificationMethod:te[e.classificationMethod]||null,numClasses:e.numClasses,focus:e.focus,field1:{field:e.field1.field,normalizationField:e.field1.normalizationField,classBreakInfos:n.map(a,re)},field2:{field:e.field2.field,normalizationField:e.field2.normalizationField,classBreakInfos:n.map(i,re)}}}(a,u,c)),e.resolve({classBreaks:{field1:t.cbResponse,field2:r.cbResponse},renderer:f.renderer,uniqueValueInfos:f.uniqueValueInfos,scheme:w.cloneScheme(m)})}else H(e,"smartMapping.createRelationshipRenderer: incompatible class breaks.")}function le(e,a,n,t){var r=null==n.useDefaultStatistics||n.useDefaultStatistics;if(!e||e.count||r){var s=n.layer,l=n.field,o=l&&!i.isFunction(l)?s.getField(l):null,u=o&&o.type===L,c=n.useStdDev,d=c?K(e):null,p=r?Z(s,e,u,c):null,m=p||(c?[d[0],d[4]]:[e.min,e.max]),f={type:"opacityInfo",field:l,valueExpression:n.valueExpression,valueExpressionTitle:n.valueExpressionTitle,normalizationField:a,stops:[{value:m[0],opacity:.3},{value:m[1],opacity:1}],legendOptions:n.legendOptions};t.resolve({opacityInfo:f,statistics:e,defaultStatistics:!!p})}else H(t,"smartMapping.createOpacityInfo: cannot create opacityInfo when statistics.count is 0.")}function oe(e,a){var n=e.scheme;return n=n?v.cloneScheme(n):(n=v.getSchemes({theme:e.theme||"default",basemap:e.basemap,geometryType:a}))&&n.primaryScheme}function ue(e,a){var n;switch(a){case"point":n=[e.minSize,e.maxSize];break;case"line":n=[e.minWidth,e.maxWidth];break;case"polygon":n=[e.marker.minSize,e.marker.maxSize]}return n}function ce(e,a,n,t,r){var s=null==t.useDefaultStatistics||t.useDefaultStatistics,l=a&&[a.minSize,a.maxSize];if(!e||e.count||s){var o=t.layer,u=t.field,c=u&&!i.isFunction(u)?o.getField(u):null,d=c&&c.type===L,p=N(o),m=oe(t,p),f=l||ue(m,p),g=t.useStdDev,h=g?K(e):null,v=s?Z(o,e,d,g):null,y=v||(g?[h[0],h[4]]:[e.min,e.max]),b={type:"sizeInfo",field:u,valueExpression:t.valueExpression,valueExpressionTitle:t.valueExpressionTitle,valueUnit:"unknown",normalizationField:n,legendOptions:t.legendOptions,minSize:f[0],maxSize:f[1],minDataValue:y[0],maxDataValue:y[1]};r.resolve({sizeInfo:b,statistics:e,defaultStatistics:!!v,suggestedSizeRange:a,scheme:oe(t,p)})}else H(r,"smartMapping.createSizeInfo: cannot create renderer when statistics.count is 0.")}function de(e,a,n){var i,t=[],r=1/(n+1);for(i=1;i<=n;i++)t.push(p.blendColors(e,a,r*i));return t}function pe(e,a){var n=[];if(1===a)n=[e[0]];else if(2===a)n=[e[0],e[2]];else if(3===a)n=e;else{var i,t,r=a-e.length,s=r/2;r%2==0?(i=de(e[0],e[1],s),t=de(e[1],e[2],s)):(i=de(e[0],e[1],Math.floor(s)),t=de(e[1],e[2],Math.ceil(s))),n=[e[0]].concat(i).concat([e[1]]).concat(t).concat([e[2]])}return n}function me(e,a,i){var t,r=a.length,s=-1;if(i&&n.some(a,(function(e,a){return e.hasAvg&&(s=a),s>-1})),s>-1){var l=e.colors,o=s+1,u=r-s,c=l.slice(0,3),d=l.slice(2);c.reverse(),c=pe(c,o),d=pe(d,u),c.reverse(),t=[].concat(c).concat(d.slice(1))}else{var p=e.colorsForClassBreaks;if(p&&p.length>0&&(n.some(p,(function(e){return e.numClasses===r&&(t=e.colors),!!t})),!t)){var m=p[p.length-1],f=r-m.numClasses;if(f>0){var g,h=m.colors[m.numClasses-1];for(t=m.colors.splice(0),g=1;g<=f;g++)t.push(h)}}}return t&&(t=T.createColors(t,t.length)),t}function fe(e){var a=new r,n=e.layer,t=null==e.useDefaultBreaks||e.useDefaultBreaks,l=e.optimizeOutline,u=[n.statisticsPlugin.getClassBreaks(e)];return l&&u.push(n.statisticsPlugin.getSuggestedOutline("object"==typeof l?l:null)),new s(u).then((function(r){var s=r[0],u=r[1],c=l&&u[0]?u[1]:null;if(s[0]||t&&!n.graphics.length){var d=s[1],p=t?Z(n,d?{min:d.minValue,max:d.maxValue}:{}):null;p&&(d=function(e,a){return a.layer.statisticsPlugin.getClassBreaks(i.mixin(a,{classificationMethod:"equal-interval",numClasses:1,analyzeData:!1,minValue:e[0],maxValue:e[1],normalizationTotal:e[0]+e[1]}))}(p,e)),o(d).then((function(e){e.defaultStatistics=!!p,a.resolve({cbResponse:e,suggestedOutline:c})})).otherwise((function(){H(a,"smartMapping: error when calculating default class breaks.")}))}else H(a,"smartMapping: error when calculating class breaks.")})),a.promise}function ge(e,a,i,t,r){var s,l=t.layer,o=t.field,u=N(l),c=null==t.showOthers||t.showOthers,d=i&&i.opacity,p=t.classificationMethod||"equal-interval",m=t.normalizationType,f=e.classBreakInfos,g=oe(t,u),h=function(e,a,n,i){var t,r=i||ue(e,a),s=r[0],l=(r[1]-s)/(n>=4?n-1:n),o=[];for(t=0;t<n;t++)o.push(s+l*t);return o}(g,u,f.length,a),v="polygon"===u,y=v?g.marker:g,b=v?g.background:null;s=new V(null,o),t.valueExpression&&(s.setValueExpression(t.valueExpression),s.valueExpressionTitle=t.valueExpressionTitle),s.legendOptions=t.legendOptions,s.classificationMethod=p,s.normalizationType=m,s.normalizationField="field"===m?t.normalizationField:void 0,s.normalizationTotal="percent-of-total"===m?e.normalizationTotal:void 0,c&&(s.defaultSymbol=W(y,y.noDataColor,v?"point":u),s.defaultLabel=P.other),b&&(s.backgroundFillSymbol=W(b,b.color,u,null,d)),n.forEach(f,(function(e,a){s.addBreak({minValue:e.minValue,maxValue:e.maxValue,symbol:W(y,y.color,v?"point":u,h[a]),label:e.label})})),"standard-deviation"!==p&&E.setLabelsForClassBreaks({classBreaks:s.infos,classificationMethod:p,normalizationType:m,round:!0}),i&&i.widthInfo&&s.setVisualVariables([i.widthInfo]),e.renderer=s,e.scheme=oe(t,u),r.resolve(e)}function he(e){var a=e.scheme;return a=a?b.cloneScheme(a):(a=b.getSchemes({theme:e.theme||"default",basemap:e.basemap}))&&a.primaryScheme}function ve(e,a,i){var t=null==a.useDefaultStatistics||a.useDefaultStatistics;if(e.count||t){var r=e.fieldOffset,s=null==a.blurRadius?10:a.blurRadius,l=null==a.minRatio?.01:a.minRatio,o=null==a.maxRatio?1:a.maxRatio,u=null==a.fadeToTransparent||a.fadeToTransparent,c=he(a).colors,d=c.length,m=!e.count&&t,f=m?[0,100]:[e.min,e.max],g=new F;g.setBlurRadius(s),g.setField(a.field),null!=r&&g.setFieldOffset(r),g.setMinPixelIntensity(f[0]),g.setMaxPixelIntensity(f[1]);var h=c[0],v=[{ratio:0,color:new p([h.r,h.g,h.b,0])},{ratio:.01,color:new p([h.r,h.g,h.b,0])},{ratio:u?l:.01,color:h}],y=(o-l)/(d-1);c=T.createColors(c,d),n.forEach(c,(function(e,a){v.push({ratio:l+y*a,color:e})})),g.setColorStops(v),i.resolve({renderer:g,statistics:e,defaultStatistics:m,scheme:he(a)})}else H(i,"smartMapping.createHeatmapRenderer: cannot create renderer when statistics.count is 0.")}function ye(e,a){var i={};return n.forEach(e,(function(e){var n=a.getField(e.name);i[e.name]=e.label||n&&n.alias||e.name})),function(e){return i[e.value]}}function be(e,a,i,t){var s=a.length,l=N(e.layer),o=function(e,a,n){var i=e.scheme;return i=i?x.cloneScheme(i):(i=x.getSchemes({theme:e.theme||"default",basemap:e.basemap,geometryType:a,numColors:n}))&&i.primaryScheme}(e,l,s);e.layer.statisticsPlugin.getPredominanceExpressions({fields:a}).then((function(s){var l,u,c=function(e,a,i,t,s){var l=new r,o=e.layer;return o.statisticsPlugin.getPredominantCategories({fields:a}).always((function(r){r&&r.predominantCategoryInfos||(r={predominantCategoryInfos:n.map(a,(function(e){return{value:e,count:0}}))});var u=Y(r.predominantCategoryInfos,s,{layer:o,valueExpression:t.valueExpression,valueExpressionTitle:P.predominantCategory,labelCallback:ye(e.fields,o),numTypes:-1,showOthers:e.showOthers,sortBy:"count",customScheme:i,useSizeInfo:e.includeSizeInfo});u.predominantCategoryInfos=u.uniqueValueInfos,delete u.uniqueValueInfos,u.source=r.source,l.resolve(u)})),l.promise}(e,a,o,s.predominantCategory,i);e.includeSizeInfo&&(l=function(e,a,n,i){var t=new r;return T.createSizeInfo({layer:e.layer,valueExpression:i.valueExpression,sqlExpression:i.statisticsQuery.sqlExpression,sqlWhere:i.statisticsQuery.sqlWhere,scheme:n,optimizeForScale:e.optimizeForScale}).then((function(e){e.sizeInfo.legendOptions={title:P.sumOfCategories},t.resolve(e)})).otherwise((function(e){H(t,"smartMapping.createPredominanceRenderer: error when calculating statistics for visual variable(size).")})),t.promise}(e,0,o.sizeInfo,s.size)),e.includeOpacityInfo&&(u=function(e,a,n){var i=new r;return e.layer.statisticsPlugin.getFieldStatistics({valueExpression:n.valueExpression,sqlExpression:n.statisticsQuery.sqlExpression,sqlWhere:n.statisticsQuery.sqlWhere}).then((function(e){var t=null==e.avg||null==e.stddev,r=1/a.length*100,s=t?100:e.avg+1.285*e.stddev;s>100&&(s=100);var l=m.round([r,s],{strictBounds:!0});i.resolve({opacityInfo:{type:"opacityInfo",valueExpression:n.valueExpression,stops:[{value:l[0],opacity:.15},{value:l[1],opacity:1}],legendOptions:{title:P.strengthOfPredominance}},statistics:e,defaultStatistics:t})})).otherwise((function(e){H(i,"smartMapping.createPredominanceRenderer: error when calculating statistics for visual variable(opacity).")})),i.promise}(e,a,s.opacity)),f([c,l,u]).then((function(e){var a,n=e[0],i=e[1],r=e[2],s=[];if(n instanceof Error)H(t,"smartMapping.createPredominanceRenderer: unable to create unique-value renderer.");else{if(a=n,l){if(i instanceof Error)return void H(t,"smartMapping.createPredominanceRenderer: unable to create visual variable for symbol size.");s.push(E.cloneSizeInfo(i.sizeInfo)),delete i.scheme,a.size=i}if(u){if(r instanceof Error)return void H(t,"smartMapping.createPredominanceRenderer: unable to create visual variable for symbol opacity.");s.push(E.cloneOpacityInfo(r.opacityInfo)),a.opacity=r}if(s.length){var o=a.renderer.visualVariables;o&&(Array.prototype.push.apply(o,s),s=o),a.renderer.setVisualVariables(s)}t.resolve(a)}}))})).otherwise((function(e){H(t,"smartMapping.createPredominanceRenderer: unable to generate expressions.")}))}var xe=["hours","minutes","seconds"];function we(e,a,i){var t=e;if("string"==typeof e){var r=i.getField(e);r&&r.type===L&&(t=i.getFieldLabel(r.name))}else if("number"==typeof e||e instanceof Date){var s=n.indexOf(xe,a)>-1?null:"date";t=E.formatDate(e,{selector:s})}return t}function Se(e,a){var i,t,r,s,l,o,u={};return i=n.filter(e,(function(e){return t=e.name,r=t.toLowerCase(),(s=t!==a&&-1===n.indexOf(B,r))&&(l=l||(n.indexOf(_,e.type)>-1?t:null),o=o||("esriFieldTypeString"===e.type?t:null)),s})),n.forEach(i,(function(e){t=e.name,r=t.toLowerCase(),n.indexOf(_,e.type)>-1&&(u=Ie(t,r,D,u,"number")),u.rank&&"string"!==u.fieldType||"esriFieldTypeString"===e.type&&(u=Ie(t,r,j,u,"string"))})),u.fieldName||l||o}function Ie(e,a,i,t,r){var s=function(e,a){var i,t,r=-1;for(i=n.indexOf(a,e),t=0;t<a.length;t++)if(e.indexOf(a[t])>-1){r=t;break}return{exactRank:i,containRank:r}}(a,i);return s.exactRank>-1&&(!t.rank||t.fieldType!==r||"exact"===t.matchType&&t.fieldType===r&&t.rank>s.exactRank)?t={rank:s.exactRank,matchType:"exact",fieldType:r,fieldName:e}:s.containRank>-1&&(!t.rank||t.fieldType===r&&"contains"===t.matchType&&t.rank>s.containRank)&&(t={rank:s.containRank,matchType:"contains",fieldType:r,fieldName:e}),t}var ze,Ce=(ze="../plugins/FeatureLayerStatistics",e.toAbsMid?e.toAbsMid(ze):a.id.replace(/\/[^\/]*$/gi,"/")+ze);return i.mixin(T,{createColors:function(e,a){var n,i=[],t=e.length;for(n=0;n<a;n++)i.push(new p(e[n%t]));return i},createTypeRenderer:function(e){var a=new r;if(!e||!e.layer||!e.field&&!e.valueExpression||!e.scheme&&!e.basemap)return H(a,"smartMapping.createTypeRenderer: missing parameters."),a.promise;var n=e.layer,i=e.optimizeOutline;return n.addPlugin(Ce).then((function(){var t=[n.statisticsPlugin.getUniqueValues({field:e.field,valueExpression:e.valueExpression,includeAllCodedValues:e.includeAllCodedValues})];i&&t.push(n.statisticsPlugin.getSuggestedOutline("object"==typeof i?i:null)),new s(t).then((function(n){var t=n[0],r=n[1],s=i&&r[0]?r[1]:null;t[0]?function(e,a,n,i){var t=Y(e.uniqueValueInfos,a,n);t.source=e.source,t.partialData=e.partialData,i.resolve(t)}(t[1],s,e,a):H(a,"smartMapping.createTypeRenderer: error when calculating unique values.")}))})).otherwise((function(e){H(a,"smartMapping.createTypeRenderer: error when adding feature layer statistics plugin.")})),a.promise},createColorInfo:function(e){var a=new r;if(!(e&&e.layer&&(e.field||e.valueExpression||e.sqlExpression)))return H(a,"smartMapping.createColorInfo: missing parameters."),a.promise;var n=e.layer,i=e.normalizationField,t=i?"field":void 0;return e.statistics?ee(e.statistics,null,i,e,a):n.addPlugin(Ce).then((function(){var r="group-similar"===e.theme||e.scheme&&0===e.scheme.id.indexOf("group-similar/");(r?n.statisticsPlugin.getClassBreaks({field:e.field,valueExpression:e.valueExpression,classificationMethod:"natural-breaks",numClasses:e.numGroups||5,normalizationType:t,normalizationField:i,minValue:e.minValue,maxValue:e.maxValue}):n.statisticsPlugin.getFieldStatistics({field:e.field,valueExpression:e.valueExpression,sqlExpression:e.sqlExpression,sqlWhere:e.sqlWhere,normalizationType:t,normalizationField:i,minValue:e.minValue,maxValue:e.maxValue})).then((function(n){var t,s;r?t=n:s=n,ee(s,t,i,e,a)})).otherwise((function(e){H(a,r?"smartMapping.createColorInfo: error when calculating class breaks.":"smartMapping.createColorInfo: error when calculating field statistics.")}))})).otherwise((function(e){H(a,"smartMapping.createColorInfo: error when adding feature layer statistics plugin.")})),a.promise},createColorRenderer:function(e){var a=new r;if(!(e&&e.layer&&(e.field||e.valueExpression||e.sqlExpression)))return H(a,"smartMapping.createColorRenderer: missing parameters."),a.promise;var n=e.layer,i=e.normalizationField,t=i?"field":void 0,l=e.optimizeOutline;return n.addPlugin(Ce).then((function(){var r=[T.createColorInfo(e)];l&&r.push(n.statisticsPlugin.getSuggestedOutline("object"==typeof l?l:null)),new s(r).then((function(n){var r=n[0],s=n[1],o=l&&s[0]?s[1]:null;r[0]?function(e,a,n,i,t,r){var s=t.layer,l=t.field,o=N(s),u=null==t.showOthers||t.showOthers,c=a&&a.opacity,d=y.cloneScheme(e.scheme),p=new V(null,l);t.valueExpression&&p.setValueExpression(t.valueExpression),u&&(p.defaultSymbol=W(d,d.noDataColor,o,null,c),p.defaultLabel=P.other),p.addBreak({minValue:-O,maxValue:O,symbol:W(d,d.noDataColor,o,null,c)}),p.normalizationType=n,p.normalizationField=i;var m=[E.cloneColorInfo(e.colorInfo)];a&&a.widthInfo&&m.push(a.widthInfo),p.setVisualVariables(m),r.resolve({renderer:p,colorInfo:E.cloneColorInfo(e.colorInfo),statistics:e.statistics,classBreaks:e.classBreaks,scheme:y.cloneScheme(e.scheme)})}(r[1],o,t,i,e,a):H(a,"smartMapping.createColorRenderer: error when calculating colorInfo.")}))})).otherwise((function(e){H(a,"smartMapping.createColorRenderer: error when adding feature layer statistics plugin.")})),a.promise},createRelationshipRenderer:function(e){var a=new r;if(!(e&&e.layer&&e.field1&&e.field2))return H(a,"smartMapping.createRelationshipRenderer: missing parameters."),a.promise;(e=i.mixin({},e)).classificationMethod=e.classificationMethod||"quantile",e.numClasses=e.numClasses||3,e.focus=e.focus||null;var t=e.classificationMethod,l=e.numClasses,o=e.layer;return"standard-deviation"===t||"geometrical-interval"===t?(H(a,"smartMapping.createRelationshipRenderer: classification method '"+t+"' is not supported."),a.promise):l<2||l>4?(H(a,"smartMapping.createRelationshipRenderer: numClasses must be 2, 3 or 4."),a.promise):e.focus&&-1===n.indexOf(ae,e.focus)?(H(a,"smartMapping.createRelationshipRenderer: 'focus' must be 'HH', 'HL', 'LH', 'LL' or null."),a.promise):(o.addPlugin(Ce).then((function(){var n=e.field1,r=e.field2,u={layer:o,classificationMethod:t,numClasses:l},c=[fe(i.mixin({field:n.field,normalizationField:n.normalizationField,normalizationType:n.normalizationField?"field":null,minValue:n.minValue,maxValue:n.maxValue,analyzeData:!(null!=n.minValue&&null!=n.maxValue)},u)),fe(i.mixin({field:r.field,normalizationField:r.normalizationField,normalizationType:r.normalizationField?"field":null,minValue:r.minValue,maxValue:r.maxValue,analyzeData:!(null!=r.minValue&&null!=r.maxValue)},u))],d=e.optimizeOutline;d&&c.push(o.statisticsPlugin.getSuggestedOutline("object"==typeof d?d:null)),new s(c).then((function(n){var i=n[0],t=n[1];if(i[0]&&t[0]){var r=n[2],s=d&&r[0]?r[1]:null;se(a,e,i[1],t[1],s)}else H(a,"smartMapping.createRelationshipRenderer: error when calculating class breaks.")})).otherwise((function(e){var n=e&&e.message||"error when calculating components.";H(a,"smartMapping.createRelationshipRenderer: "+n)}))})).otherwise((function(e){var n=e&&e.message||"error when adding feature layer statistics plugin.";H(a,"smartMapping.createRelationshipRenderer: "+n)})),a.promise)},updateRelationshipRenderer:function(e){if(e&&e.renderer&&e.numClasses){var a=e.field1,i=e.field2;if(!a&&!i||a&&i&&a.field&&i.field)if(a&&!a.classBreakInfos||i&&!i.classBreakInfos)console.log("smartMapping.updateRelationshipRenderer: 'field1' and/or 'field2' is missing 'classBreakInfos'");else{var t=e.renderer,r=e.numClasses,s=e.focus||null,l=Math.pow(r,2);if(t.infos.length===l){var o,u=e.colors;if(u&&(u=n.map(u,(function(e){return T.createColors(e,e.length)})),(o=w.flatten2DArray(u,s)).length!==l))console.log("smartMapping.updateRelationshipRenderer: invalid 'colors'. Must have "+l+" colors.");else{if(a&&i){var c=ie({field1:a,field2:i,breaks1:a.classBreakInfos,breaks2:i.classBreakInfos});t.setValueExpression(c)}!function(e,a,i){var t=ne(a,i);e.sort((function(e,a){var i=n.indexOf(t,e.value),r=n.indexOf(t,a.value);return i<r?-1:i>r?1:0}))}(t.infos,r,s),o&&n.map(t.infos,(function(e,a){C.setSymbolFillColor(e.symbol,o[a])})),function(e,a){var i=e.authoringInfo;if(i){i.numClasses=a.numClasses,i.focus=a.focus||null,i.focus||delete i.focus;var t=a.field1,r=a.field2;t&&r&&(i.field1={field:t.field,normalizationField:t.normalizationField,classBreakInfos:n.map(t.classBreakInfos,re)},i.field2={field:r.field,normalizationField:r.normalizationField,classBreakInfos:n.map(r.classBreakInfos,re)}),e.setAuthoringInfo(i)}else console.log("smartMapping.updateRelationshipRenderer: authoringInfo is missing.")}(t,e)}}else console.log("smartMapping.updateRelationshipRenderer: invalid 'renderer.infos'. Must have "+l+" unique value infos.")}else console.log("smartMapping.updateRelationshipRenderer: Both 'field1' and 'field2' are required.")}else console.log("smartMapping.updateRelationshipRenderer: missing parameters: renderer, numClasses.")},createOpacityInfo:function(e){var a=new r;if(!(e&&e.layer&&(e.field||e.valueExpression||e.sqlExpression)))return H(a,"smartMapping.createOpacityInfo: missing parameters."),a.promise;var n=e.layer,i=e.normalizationField,t=i?"field":void 0;return e.statistics?le(e.statistics,i,e,a):n.addPlugin(Ce).then((function(){n.statisticsPlugin.getFieldStatistics({field:e.field,valueExpression:e.valueExpression,sqlExpression:e.sqlExpression,sqlWhere:e.sqlWhere,normalizationType:t,normalizationField:i,minValue:e.minValue,maxValue:e.maxValue,features:e.features}).then((function(n){le(n,i,e,a)})).otherwise((function(e){H(a,"smartMapping.createOpacityInfo: error when calculating field statistics.")}))})).otherwise((function(e){H(a,"smartMapping.createOpacityInfo: error when adding feature layer statistics plugin.")})),a.promise},createBlendRenderer:function(e){var a,i,t,s=new r,o=this,u={},c=[],d=[],m=e.opacityValueCombinationMethod||"avg",f={};return e&&e.layer&&e.blendedFields?(e.basemap=e.basemap||"topo",t=N(e.layer),(a=U({basemap:e.basemap},t)).colors=[new p("#e60000"),new p("#0000e6"),new p("#00e600"),new p("#e67300"),new p("#a900e6")],f.fields=[],f.normalizationField=e.normalizationField,f.blendMode=e.blendMode||"source-over",f.symbol=W(a,a.noDataColor,e.markers?"point":t),u.layer=e.layer,u.normalizationField=e.normalizationField,u.useStdDev=e.useStdDev||!1,i=n.map(e.blendedFields,(function(e,n){return f.fields.push({field:e,color:a.colors[n]}),u.field=e,o.createOpacityInfo(u)})),l(i).then((function(i){d[0]=i[0].opacityInfo.stops[0].value,d[1]=i[1].opacityInfo.stops[1].value,n.forEach(i.slice(0,1),(function(e){var a=e.opacityInfo.stops[0].value,n=e.opacityInfo.stops[1].value;"union"===m?(d[0]=a<d[0]?a:d[0],d[1]=n>d[1]?n:d[1]):"avg"===m&&(d[0]+=e.opacityInfo.stops[0].value,d[1]+=e.opacityInfo.stops[1].value)})),c[0]={value:"avg"===m?d[0]/i.length:d[0],opacity:e.minOpacity?e.minOpacity:i[0].opacityInfo.stops[0].opacity},c[1]={value:"avg"===m?d[1]/i.length:d[1],opacity:e.maxOpacity?e.maxOpacity:i[0].opacityInfo.stops[1].opacity},f.opacityStops=c,s.resolve({renderer:new M(f),scheme:a,opacityInfos:i})})),s.promise):(H(s,"smartMapping.createBlendRenderer: missing parameters."),s.promise)},createSizeInfo:function(e){var a=new r;if(!(e&&e.layer&&(e.field||e.valueExpression||e.sqlExpression)))return H(a,"smartMapping.createSizeInfo: missing parameters."),a.promise;var n=e.layer,i=e.normalizationField,t=i?"field":void 0,l=e.optimizeForScale;return e.statistics?ce(e.statistics,null,i,e,a):n.addPlugin(Ce).then((function(){var r=[n.statisticsPlugin.getFieldStatistics({field:e.field,valueExpression:e.valueExpression,sqlExpression:e.sqlExpression,sqlWhere:e.sqlWhere,normalizationType:t,normalizationField:i,minValue:e.minValue,maxValue:e.maxValue})];l&&r.push(n.statisticsPlugin.getSuggestedSizeRange({optimizeForScale:!0===l?"map-scale":l})),new s(r).then((function(n){var t=n[0],r=l&&n[1],s=l&&r[0]?r[1]:null;t[0]?ce(t[1],s,i,e,a):H(a,"smartMapping.createSizeInfo: error when calculating field statistics.")}))})).otherwise((function(e){H(a,"smartMapping.createSizeInfo: error when adding feature layer statistics plugin.")})),a.promise},createSizeRenderer:function(e){var a=new r;if(!(e&&e.layer&&(e.field||e.valueExpression||e.sqlExpression)))return H(a,"smartMapping.createSizeRenderer: missing parameters."),a.promise;var n=e.layer,i=e.normalizationField,t=i?"field":void 0,l=e.optimizeOutline;return n.addPlugin(Ce).then((function(){var r=[T.createSizeInfo(e)];l&&r.push(n.statisticsPlugin.getSuggestedOutline("object"==typeof l?l:null)),new s(r).then((function(n){var r=n[0],s=n[1],o=l&&s[0]?s[1]:null;r[0]?function(e,a,n,i,t,r){var s=t.layer,l=t.field,o=N(s),u=null==t.showOthers||t.showOthers,c=a&&a.opacity,d=v.cloneScheme(e.scheme),p="polygon"===o,m=p?d.marker:d,f=p?d.background:null,g="line"===o?m.noDataWidth:m.noDataSize,h=new V(null,l);t.valueExpression&&h.setValueExpression(t.valueExpression),u&&(h.defaultSymbol=W(m,m.noDataColor,p?"point":o,g),h.defaultLabel=P.other),h.addBreak({minValue:-O,maxValue:O,symbol:W(m,m.color,p?"point":o)}),f&&(h.backgroundFillSymbol=W(f,f.color,o,null,c)),h.normalizationType=n,h.normalizationField=i;var y=[E.cloneSizeInfo(e.sizeInfo)];a&&a.widthInfo&&y.push(a.widthInfo),h.setVisualVariables(y),r.resolve({renderer:h,sizeInfo:E.cloneSizeInfo(e.sizeInfo),statistics:e.statistics,defaultStatistics:e.defaultStatistics,suggestedSizeRange:e.suggestedSizeRange,scheme:v.cloneScheme(e.scheme)})}(r[1],o,t,i,e,a):H(a,"smartMapping.createSizeRenderer: error when calculating sizeInfo.")}))})).otherwise((function(e){H(a,"smartMapping.createSizeRenderer: error when adding feature layer statistics plugin.")})),a.promise},createClassedColorRenderer:function(e){var a,t=new r,s=e.minValue,l=e.maxValue;return e&&e.layer&&(e.field||e.valueExpression)?(a=null!=s&&null!=l)||null==s&&null==l?((e=i.mixin({analyzeData:!a},e)).layer.addPlugin(Ce).then((function(){fe(e).then((function(a){!function(e,a,i,t){var r,s,l,o=i.layer,u=i.field,c=N(o),d=null==i.showOthers||i.showOthers,p=a&&a.opacity,m=i.classificationMethod||"equal-interval",f="standard-deviation"===m,g=i.normalizationType,h=e.classBreakInfos;(r=J(i,c,"high-to-low"))?(s=me(r,h))&&s.length==h.length?(l=new V(null,u),i.valueExpression&&(l.setValueExpression(i.valueExpression),l.valueExpressionTitle=i.valueExpressionTitle),l.legendOptions=i.legendOptions,l.classificationMethod=m,l.normalizationType=g,l.normalizationField="field"===g?i.normalizationField:void 0,l.normalizationTotal="percent-of-total"===g?e.normalizationTotal:void 0,d&&(l.defaultSymbol=W(r,r.noDataColor,c,null,p),l.defaultLabel=P.other),n.forEach(h,(function(e,a){l.addBreak({minValue:e.minValue,maxValue:e.maxValue,symbol:W(r,s[a],c,null,p),label:e.label})})),f||E.setLabelsForClassBreaks({classBreaks:l.infos,classificationMethod:m,normalizationType:g,round:!0}),a&&a.widthInfo&&l.setVisualVariables([a.widthInfo]),e.renderer=l,e.scheme=J(i,c,"high-to-low"),t.resolve(e)):H(t,"smartMapping.createClassedColorRenderer: unable to find suitable colors for number of classes."):H(t,"smartMapping.createClassedColorRenderer: unable to find suitable style scheme.")}(a.cbResponse,a.suggestedOutline,e,t)})).otherwise((function(e){H(t,"smartMapping.createClassedColorRenderer: error when calculating class breaks.")}))})).otherwise((function(e){H(t,"smartMapping.createClassedColorRenderer: error when adding feature layer statistics plugin.")})),t.promise):(H(t,"smartMapping.createClassedColorRenderer: both minValue and maxValue are required when specifying custom data range."),t.promise):(H(t,"smartMapping.createClassedColorRenderer: missing parameters."),t.promise)},createClassedSizeRenderer:function(e){var a,n=new r,t=e.minValue,s=e.maxValue;if(!e||!e.layer||!e.field&&!e.valueExpression)return H(n,"smartMapping.createClassedSizeRenderer: missing parameters."),n.promise;if(!(a=null!=t&&null!=s)&&(null!=t||null!=s))return H(n,"smartMapping.createClassedColorRenderer: both minValue and maxValue are required when specifying custom data range."),n.promise;var l=(e=i.mixin({analyzeData:!a},e)).layer;return l.addPlugin(Ce).then((function(){fe(e).then((function(a){e.optimizeForScale?l.statisticsPlugin.getSuggestedSizeRange().then((function(i){var t=[i.minSize,i.maxSize];ge(a.cbResponse,t,a.suggestedOutline,e,n)})).otherwise((function(i){ge(a.cbResponse,null,a.suggestedOutline,e,n)})):ge(a.cbResponse,null,a.suggestedOutline,e,n)})).otherwise((function(e){H(n,"smartMapping.createClassedSizeRenderer: error when calculating class breaks.")}))})).otherwise((function(e){H(n,"smartMapping.createClassedSizeRenderer: error when adding feature layer statistics plugin.")})),n.promise},createHeatmapRenderer:function(e){var a=new r;if(!e||!e.layer)return H(a,"smartMapping.createHeatmapRenderer: missing parameters."),a.promise;var n=e.layer;return e.statistics?ve(e.statistics,e,a):n.addPlugin(Ce).then((function(){n.statisticsPlugin.getHeatmapStatistics(e).then((function(n){ve(n,e,a)})).otherwise((function(e){H(a,"smartMapping.createHeatmapRenderer: error when calculating heatmap statistics.")}))})).otherwise((function(e){H(a,"smartMapping.createHeatmapRenderer: error when adding feature layer statistics plugin.")})),a.promise},applyHeatmapScheme:function(e){if(e&&e.renderer&&e.scheme){var a=he({scheme:e.scheme}),t=e.renderer,r=t.colorStops,s=a.colors;if(r.length===s.length+3){var l,o=new p(s[0]),u=n.map(r,(function(e){return i.mixin({},e)}));for(u[0].color=new p([o.r,o.g,o.b,0]),u[1].color=new p([o.r,o.g,o.b,0]),u[2].color=o,l=3;l<u.length;l++)u[l].color=s[l-3];t.setColorStops(u)}else console.log("smartMapping.applyHeatmapScheme: incompatible number of colors in 'colors' and 'renderer.colorStops'.")}else console.log("smartMapping.applyHeatmapScheme: missing parameters.")},sampleSize:500,createPredominanceRenderer:function(e){var a=new r;if(!(e&&e.layer&&e.fields&&e.fields.length>1))return H(a,"smartMapping.createPredominanceRenderer: missing parameters."),a.promise;if(e.fields.length>10)return H(a,"smartMapping.createPredominanceRenderer: too many fields. Maximum supported is 10."),a.promise;var i=e.layer;return i.addPlugin(Ce).then((function(){var t=n.map(e.fields,(function(e){return e.name}));A(i,(function(){var r=i.getOutFields()||[],s=-1!==n.indexOf(r,"*"),l=e.optimizeOutline,u=s?null:n.filter(t,(function(e){return-1===n.indexOf(r,e)}));if(!i.url||i._collection||q.test(i.url))if(u&&u.length)H(a,"smartMapping.createPredominanceRenderer: make sure the layer is configured to fetch all fields specified in parameters.");else{var c=l?i.statisticsPlugin.getSuggestedOutline("object"==typeof l?l:null):null;o(c).always((function(n){n&&!n.widthInfo&&(n=null),be(e,t,n,a)}))}else H(a,"smartMapping.createPredominanceRenderer: predominance renderer is not supported for this layer. Make sure the layer supports advanced SQL expressions and standardized queries.")}))})).otherwise((function(e){H(a,"smartMapping.createPredominanceRenderer: error when adding feature layer statistics plugin.")})),a.promise},createAgeInfo:function(e){var a=new r;if(!(e&&e.layer&&e.startTime&&e.endTime))return H(a,"smartMapping.createAgeInfo: missing parameters."),a.promise;var n=e.layer;return n.addPlugin(Ce).then((function(){var t=e.units?{units:e.units}:n.statisticsPlugin.getSuggestedAgeUnits({startTime:e.startTime,endTime:e.endTime});o(t).then((function(n){!function(e,a,n){var t=a.startTime,r=a.endTime,s=a.layer;s.statisticsPlugin.getAgeExpressions({startTime:t,endTime:r,units:e.units}).then((function(a){var l=e,o=l.units,u="ageInfo_"+o;l.legendOptions={title:g.substitute({units:o,startTime:we(t,o,s),endTime:we(r,o,s)},P[u])},i.mixin(l,a),n.resolve(l)})).otherwise((function(e){H(n,"smartMapping.createAgeInfo: unable to generate expressions to calculate age.")}))}(n,e,a)})).otherwise((function(e){H(a,"smartMapping.createAgeInfo: unable to calculate age units.")}))})).otherwise((function(e){H(a,"smartMapping.createAgeInfo: error when adding feature layer statistics plugin.")})),a.promise},excludedFields:B,getSuggestedField:function(e){var a=new r;return e&&(e.layer||e.fields&&e.objectIdField)?(e.layer?A(e.layer,(function(){a.resolve(Se(e.layer.fields,e.layer.objectIdField))})):a.resolve(Se(e.fields,e.objectIdField)),a.promise):(H(a,"smartMapping.getSuggestedField: missing parameters."),a.promise)}}),t("extend-esri")&&i.setObject("renderer.smartMapping",T,d),T}));