text: // COPYRIGHT © 2021 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.36/esri/copyright.txt for details.
  
  define(["dojo/_base/declare","dojo/_base/lang","dojo/_base/Deferred","dojo/_base/array","dojo/_base/json","dojo/_base/config","dojo/_base/connect","dojo/has","dojo/io-query","dojo/DeferredList","../kernel","../config","../lang","../request","../deferredUtils","../urlUtils","../geometry/Extent","../geometry/Point","../geometry/Polygon","../renderers/colorRampUtils","./MosaicRule","./RasterFunction","./DimensionalDefinition","./Raster","./PixelBlock","./pixelFilters/VectorFieldPixelFilter","./rasterFormats/ImageCanvasDecoder","./TimeInfo","./Field","../graphic","../tasks/ImageServiceIdentifyTask","../tasks/ImageServiceIdentifyParameters"],(function(e,t,i,n,r,s,a,l,o,u,h,c,d,f,m,p,g,R,_,v,b,x,T,y,F,D,I,C,w,P,V,S){var A=e(null,{declaredClass:"esri.layers.ImageServiceLayerMixin",_rasterFieldPrefix:"Raster.",_renderingRuleFieldSubPrefix:"ServicePixelValue.",_rasterFunctionServiceInfoProps:["bandCount","pixelType","hasRasterAttributeTable","hasColormap","hasHistograms","minValues","maxValues","meanValues","stdvValues","serviceDataType"],_pixelTypeRanges:{U1:[0,1],U2:[0,3],U4:[0,15],U8:[0,255],S8:[-128,127],U16:[0,65535],S16:[-32768,32767]},_eventMap:{"rendering-change":!0,"mosaic-rule-change":!0,"spatial-reference-change":!0,"renderer-change":!0},_cachedVariableStats:{},_cachedVariableHistogram:{},constructor:function(e,t){this.useMapTime=!t||!t.hasOwnProperty("useMapTime")||!!t.useMapTime},_initialize:function(e,i){this._url=p.urlToObject(e),this.raster=new y(this._url.path),this._rasterFunctionTemplateInfos={},this._customRenderingRuleId={},this.infoTemplate=i&&i.infoTemplate;var n=i&&i.imageServiceParameters;this.format=n&&n.format,this.compressionTolerance=n&&n.compressionTolerance?n.compressionTolerance:.01,this.interpolation=n?n.interpolation:null,this.compressionQuality=n?n.compressionQuality:null,this.bandIds=n?n.bandIds:null,this.mosaicRule=n?n.mosaicRule:null,this.renderingRule=n?n.renderingRule:null,this.renderer=n?n.renderer:null,this.useMapDimensionValue=!i||!i.hasOwnProperty("useMapDimensionValue")||!!i.useMapDimensionValue,this.hasImageFilter=i&&i.hasImageFilter,this.activeMapDimensions=i&&i.activeMapDimensions,this._params=t.mixin({},this._url.query,{f:"image",interpolation:this.interpolation,format:this.format,compressionQuality:this.compressionQuality,bandIds:this.bandIds?this.bandIds.join(","):null},n?n.toJson():{}),this.pixelFilter=i&&i.pixelFilter,this.pixelData=null,this.originalPixelData=null,this.hasDataChanged=!0,this._requestDataHandler=t.hitch(this,this._requestDataHandler),this._requestDataErrorHandler=t.hitch(this,this._requestDataErrorHandler),this._rasterReadPromise=null,this._initLayer=t.hitch(this,this._initLayer),this._queryVisibleRastersHandler=t.hitch(this,this._queryVisibleRastersHandler),this._visibleRasters=[],this._rasterAttributeTableFields=[],this._rasterAttributeTableFeatures=[],this._renderingRuleAttributeTable={},this._renderingRuleColormap={},this._useRenderingRuleAttributeTable=!1,this._loadCallback=i&&i.loadCallback,n&&n.renderer&&(n.renderer.outputUnit||n.renderer.inputUnit)&&(this.vectorFieldPixelFilter=new D,this.vectorFieldPixelFilter.setUnits(n.renderer.inputUnit,n.renderer.outputUnit));var r=i&&i.resourceInfo;r?this._initLayer(r):f({url:this._url.path,content:t.mixin({f:"json"},this._url.query),callbackParamName:"callback",load:this._initLayer,error:this._errorHandler}),this.registerConnectEvents()},disableClientCaching:!1,_initLayer:function(e,i){if(null!=e){this._findCredential(),(this.credential&&this.credential.ssl||e&&e._ssl)&&this._useSSL();var r=this.minScale,s=this.maxScale;t.mixin(this,e),this.minScale=r,this.maxScale=s,this.initialExtent=this.fullExtent=this.extent=new g(e.extent),this.spatialReference=this.initialExtent.spatialReference,this.pixelSizeX=parseFloat(this.pixelSizeX),this.pixelSizeY=parseFloat(this.pixelSizeY);var a,l,o=this.minValues,u=this.maxValues,h=this.meanValues,c=this.stdvValues,f=this.bands=[];for(a=0,l=this.bandCount;a<l;a++)f[a]={min:o[a],max:u[a],mean:h[a],stddev:c[a]};var m=this.timeInfo;this.timeInfo=m&&m.timeExtent?new C(m):null;var p,R=this.fields=[],_=e.fields;if(_)for(a=0;a<_.length;a++)R.push(new w(_[a]));if(this._updateInfoTemplateFields(this.fields),this.version=e.currentVersion,!this.version)p="fields"in e||"objectIdField"in e||"timeInfo"in e?10:9.3,this.version=p;d.isDefined(e.minScale)&&!this._hasMin&&"Raster"!==e.cacheType&&this.setMinScale(e.minScale),d.isDefined(e.maxScale)&&!this._hasMax&&"Raster"!==e.cacheType&&this.setMaxScale(e.maxScale);var v={};if(e.defaultMosaicMethod?(v.method=e.defaultMosaicMethod,v.operation=e.mosaicOperator,v.sortField=e.sortField,v.sortValue=e.sortValue):v.method=b.METHOD_NONE,this.defaultMosaicRule=new b(v),this.defaultMosaicRule.ascending=!0,this._useRenderingRuleAttributeTable=this.version>10&&"esriImageServiceDataTypeThematic"===this.serviceDataType,this._setDefaultRenderingRule(!0),this._getRenderingRuleAttributeTableAndColormap(),this._isScientificData()&&(!this.mosaicRule||this.mosaicRule&&!this.mosaicRule.multidimensionalDefinition)&&this._setDefaultMultidimensionalDefinition(!0),this.version>10&&this.hasRasterAttributeTable)this.getRasterAttributeTable().then(t.hitch(this,(function(e){e&&(e.features&&e.fields&&(this.rasterAttributeTable=t.clone(e)),e.features&&e.features.length>0&&(this._rasterAttributeTableFeatures=t.clone(e.features)),e.fields&&e.fields.length>0&&(this._rasterAttributeTableFields=t.clone(e.fields)),this.renderingRule||!this.renderer||"esri.renderer.ClassBreaksRenderer"!==this.renderer.declaredClass&&"esri.renderer.UniqueValueRenderer"!==this.renderer.declaredClass||this.refresh())})));this._initVectorPixelFilter(),this.bandIds||2!==this.bandCount||this.renderingRule||"esri.layers.ArcGISImageServiceLayer"!==this.declaredClass||this.setBandIds([0,0,0],!0),this.version>=10.3&&this.rasterFunctionInfos&&this.rasterFunctionInfos.length&&this.getRasterFunctionInfos().then(t.hitch(this,(function(e){if(e&&e.length){this.rasterFunctionInfos=e;var t,i=[];n.forEach(e,(function(e){if(e){var n=e.functionType;t=t||1===n||2===n,i.push(e.name)}}),this),this._hasItemLevelRFT=t,this._rasterFunctionNames=i,t&&(this._initVectorPixelFilter(),this.refresh())}}))),this.loaded=!0,this._setDefaultFilter(),this.onLoad(this);var x=this._loadCallback;x&&(delete this._loadCallback,x(this))}},_updateInfoTemplateFields:function(e){var t,i,n,r;if(e&&!(e.length<1)&&(this.infoTemplate&&this.infoTemplate.info&&this.infoTemplate.info.fieldInfos&&!(this.infoTemplate.info.fieldInfos.length<1)))for(r=this.infoTemplate.info.fieldInfos,t=0;t<e.length;t++)for(n=e[t],i=0;i<r.length;i++)if(r[i].fieldName.toLowerCase()===n.name.toLowerCase()&&r[i].fieldName!==n.name){r[i].fieldName=n.name;break}},getKeyProperties:function(e){var t=this._url.path+"/keyProperties",n=new i(m._dfdCanceller),a={f:"json"};if(e&&e.renderingRule&&(a.renderingRule=r.toJson(e.renderingRule.toJson())),this.version>10)n._pendingDfd=f({url:t,content:a,handleAs:"json",callbackParamName:"callback"}),n._pendingDfd.then((function(e){n.callback(e)}),(function(e){n.errback(e)}));else{var l=new Error("Layer does not have key properties");l.log=!!s.isDebug,n.errback(l)}return n},getRasterAttributeTable:function(e){var t=this._url.path+"/rasterAttributeTable",n=new i(m._dfdCanceller),a={f:"json"},l=this.hasRasterAttributeTable;if(e&&e.renderingRule&&(a.renderingRule=r.toJson(e.renderingRule.toJson()),l=!0),!this.loaded||this.version>10&&l)n._pendingDfd=f({url:t,content:a,handleAs:"json",callbackParamName:"callback"}),n._pendingDfd.then((function(e){n.callback(e)}),(function(e){n.errback(e)}));else{var o=new Error("Layer does not support raster attribute table");o.log=!!s.isDebug,n.errback(o)}return n},getRenderingRuleAttributeTable:function(e){var n=new i(m._dfdCanceller);if(!e||!e.renderingRule){var r=new Error("Rendering rule is not specified");return n.errback(r),n}var s=e.renderingRule,a=this._getRenderingRuleId(s);return this._renderingRuleAttributeTable&&a&&this._renderingRuleAttributeTable.hasOwnProperty(a)?n.resolve(this._renderingRuleAttributeTable[a]):n=this.getRasterAttributeTable({renderingRule:s}).then(t.hitch(this,(function(e){var i;return e&&e.features&&e.features.length&&e.fields&&e.fields.length&&(i={features:t.clone(e.features),fields:t.clone(e.fields)},a&&(this._renderingRuleAttributeTable[a]=i)),i}))),n},_initVectorPixelFilter:function(){var e,i;if(this._hasItemLevelRFT&&this.renderingRule&&(e=this._getItemLevelRenderingRule(this.renderingRule)),i=e||this.renderingRule)return this.getRenderingRuleServiceInfo(i).then(t.hitch(this,(function(e){e&&(!this._isVectorData(e)&&"esri.layers.ArcGISImageServiceVectorLayer"!==this.declaredClass||d.isDefined(this.pixelFilter)||(this.vectorFieldPixelFilter=this.vectorFieldPixelFilter||new D,this.vectorFieldPixelFilter.isDataUV="esriImageServiceDataTypeVector-UV"===e.serviceDataType,this.pixelFilter=this.vectorFieldPixelFilter.computeMagnitudeAndDirection,this.getKeyProperties().then(t.hitch(this,this._setFlowRepresentation)),this._applyVectorResamplingType(e.serviceDataType)))})))},_applyVectorResamplingType:function(e){if(e){var t=this.renderingRule;if(t&&"Resample"===t.functionName)(t.functionArguments||{}).ResamplingType="esriImageServiceDataTypeVector-UV"===e?7:10,this.setRenderingRule(new x(t.toJson()))}},_getRasterAttributeTableFeatures:function(){var e=new i;if(this._rasterAttributeTableFeatures&&this._rasterAttributeTableFeatures.length>0)return e.resolve(this._rasterAttributeTableFeatures),e;if(this.version>10&&this.hasRasterAttributeTable){var n=this.getRasterAttributeTable();return n.then(t.hitch(this,(function(e){e&&e.features&&e.features.length>0&&(this._rasterAttributeTableFeatures=t.clone(e.features))}))),n}return e.resolve(this._rasterAttributeTableFeatures),e},_getRenderingRuleAttributeTableFeatures:function(e){var t=e&&e.renderingRule;if(!t){var n=new i,r=new Error("Rendering rule is not specified");return n.errback(r),n}return this.getRenderingRuleAttributeTable({renderingRule:t}).then((function(e){return e&&e.features}))},_getRenderingRuleAttributeTableAndColormap:function(){this.renderingRule&&this.getRenderingRuleServiceInfo(this.renderingRule).then(t.hitch(this,(function(e){e.hasRasterAttributeTable&&this.getRenderingRuleAttributeTable({renderingRule:this.renderingRule}).then(t.hitch(this,(function(){!this.renderer||"esri.renderer.ClassBreaksRenderer"!==this.renderer.declaredClass&&"esri.renderer.UniqueValueRenderer"!==this.renderer.declaredClass||this.refresh()}))),e.hasColormap&&this.getRenderingRuleColormap({renderingRule:this.renderingRule}).then(t.hitch(this,(function(){this.renderer&&"esri.renderer.ColormapRenderer"===this.renderer.declaredClass&&this.refresh()})))})))},getCustomRasterFields:function(e){var i=e?e.rasterAttributeTableFieldPrefix:this._rasterFieldPrefix,r=this.version>=10.3?"esriFieldTypeDouble":"esriFieldTypeString",s={name:this._rasterFieldPrefix+"ItemPixelValue",alias:"Item Pixel Value",domain:null,editable:!1,length:50,type:r},a={name:this._rasterFieldPrefix+"ServicePixelValue",alias:"Service Pixel Value",domain:null,editable:!1,length:50,type:r},l={name:this._rasterFieldPrefix+"ServicePixelValue.Raw",alias:"Raw Service Pixel Value",domain:null,editable:!1,length:50,type:"esriFieldTypeDouble"},o=this.fields?t.clone(this.fields):[],u=o.length;if(o[u]=a,this.version>=10.4&&"esri.layers.ArcGISImageServiceLayer"===this.declaredClass&&(!this.rasterFunctionInfos||!this.rasterFunctionInfos.length||this._isRenderingRuleAProcessingTemplate({functionName:"none"}))&&(u++,o[u]=l),(this.capabilities&&this.capabilities.toLowerCase().indexOf("catalog")>-1||this.fields&&this.fields.length>0)&&(u++,o[u]=s),d.isDefined(this.pixelFilter)&&("esriImageServiceDataTypeVector-UV"===this.serviceDataType||"esriImageServiceDataTypeVector-MagDir"===this.serviceDataType)){var h={name:this._rasterFieldPrefix+"Magnitude",alias:"Magnitude",domain:null,editable:!1,type:"esriFieldTypeDouble"},c={name:this._rasterFieldPrefix+"Direction",alias:"Direction",domain:null,editable:!1,type:"esriFieldTypeDouble"};u++,o[u]=h,u++,o[u]=c}var f=this._rasterAttributeTableFields,m=this.renderingRule&&this._getRenderingRuleId(this.renderingRule);if(m&&this._renderingRuleAttributeTable&&this._renderingRuleAttributeTable.hasOwnProperty(m)&&(f=this._renderingRuleAttributeTable[m].fields),f&&f.length>0){var p=n.filter(f,(function(e){return"esriFieldTypeOID"!==e.type&&"value"!==e.name.toLowerCase()})),g=n.map(p,(function(e){var n=t.clone(e);return n.name=i+e.name,n}));o=o.concat(g)}var R=this._rasterFieldPrefix+this._renderingRuleFieldSubPrefix;return this.version>=10.4&&this.rasterFunctionInfos&&n.forEach(this.rasterFunctionInfos,(function(e){if(e&&e.name&&"none"!==e.name.toLowerCase()){var t={name:R+e.name.replace(/ /gi,"_"),alias:e.name,domain:null,editable:!1,type:"esriFieldTypeDouble"};o.push(t)}})),o},_applyTimeToMultidimensionalCRF:function(e,i){var n=this._isTimeSupportedOnCRF();if(n&&(!e||!e.multidimensionalDefinition))return e;var r=this.timeInfo&&this.timeInfo.startTimeField;if((i=i||this._params.time)&&r&&this._isMultidimensionalCRF()){(e=t.clone(e||this.defaultMosaicRule)||new b).multidimensionalDefinition=e.multidimensionalDefinition||[];var s=e.multidimensionalDefinition.filter((function(e){return e.dimensionName===r})),a=i.split(",").map((function(e){return parseInt(e,10)}));if(2===a.length&&a[0]===a[1]&&(a.length=1),s.length>0)n?e.multidimensionalDefinition.forEach((function(e){e.dimensionName===r&&(e.dimensionName=null,e.isSlice=null,e.values=null)})):e.multidimensionalDefinition.forEach((function(e){e.dimensionName===r&&(e.isSlice=1===a.length,e.values=1===a.length?a:[a])}));else if(!n){e.multidimensionalDefinition.some((function(e){return null!=e.variableName&&null==e.dimensionName}))?e.multidimensionalDefinition.forEach((function(e){null!=e.variableName&&null==e.dimensionName&&(e.dimensionName=r,e.isSlice=1===a.length,e.values=1===a.length?a:[a])})):e.multidimensionalDefinition.push(new T({variableName:"",dimensionName:r,isSlice:1===a.length,values:1===a.length?a:[a]}))}this._cleanupMultidimensionalDefinition(e)}return e},_prepareGetImageParameters:function(e,i,n,s){if(s=d.isDefined(s)?s:this._params,this.renderer||this._hasItemLevelRFT&&this.renderingRule){var a=this.getExportImageRenderingRule();s.renderingRule=a?r.toJson(a.toJson()):null}var l=this.getExportImageMosaicRule(s);s.mosaicRule=l?r.toJson(l.toJson()):null;var o=e.spatialReference.wkid||r.toJson(e.spatialReference.toJson(!1));delete s._ts,t.mixin(s,{bbox:e.xmin+","+e.ymin+","+e.xmax+","+e.ymax,imageSR:o,bboxSR:o,size:i+","+n},this.disableClientCaching?{_ts:(new Date).getTime()}:{}),delete s.compressionTolerance,s.format&&"LERC"===s.format.toUpperCase()&&(s.compressionTolerance=this.compressionTolerance),s.token=this._getToken()},getImageUrl:function(e,i,n,r,s){s=d.isDefined(s)?s:this._params,this._prepareGetImageParameters(e,i,n,s);var a=t.clone(s);this._cleanupRequestParams(a);var l=this._url.path+"/exportImage?",u=p.addProxy(l+o.objectToQuery(t.mixin(a,{f:"image"}))),h=a.token;u.length>c.defaults.io.postLength||this.useMapImage?this._jsonRequest=f({url:l,content:t.mixin(a,{f:"json"}),callbackParamName:"callback",load:function(e,t){var i=e.href;h&&(i+=-1===i.indexOf("?")?"?token="+h:"&token="+h),r(p.addProxy(i))},error:this._errorHandler}):r(u)},onRenderingChange:function(){},onMosaicRuleChange:function(){},onRendererChange:function(){},setInterpolation:function(e,t){this.interpolation=this._params.interpolation=e,t||this.refresh(!0)},setCompressionQuality:function(e,t){this.compressionQuality=this._params.compressionQuality=e,t||this.refresh(!0)},setCompressionTolerance:function(e,t){this.compressionTolerance=e,t||this.refresh(!0)},setBandIds:function(e,t){var i=!1;this.bandIds!==e&&(i=!0),this.bandIds=e,this._params.bandIds=e?e.join(","):null,i&&!t&&this.onRenderingChange(),t||this.refresh(!0)},setDefaultBandIds:function(e){this.bandIds=this._params.bandIds=null,e||this.refresh(!0)},setDisableClientCaching:function(e){this.disableClientCaching=e},setMosaicRule:function(e,t){var i=!1;this.mosaicRule!==e&&(i=!0),this.mosaicRule=e,this._params.mosaicRule=r.toJson(e.toJson()),i&&!t&&this.onMosaicRuleChange(),t||this.refresh(!0)},getRasterFunctionInfos:function(){if(!(this.version<10.3)&&this.rasterFunctionInfos&&this.rasterFunctionInfos.length){var e=this._url.path+"/rasterFunctionInfos";return f({url:e,content:{f:"json"},handleAs:"json",load:function(e){return e&&e.rasterFunctionInfos}})}console.log("Layer doesn't support /rasterFunctionInfos resource.")},setRenderingRule:function(e,t){var i=!1;this.renderingRule!==e&&(i=!0),this.renderingRule=e,this._params.renderingRule=e?r.toJson(e.toJson()):null,this._useRenderingRuleAttributeTable?this.getRenderingRuleAttributeTable({renderingRule:e}):"esri.layers.RasterXLayer"!==this.declaredClass&&this._getRenderingRuleAttributeTableAndColormap(),i&&this.onRenderingChange(),this._setDefaultFilter(),t||this.refresh(!0)},setImageFormat:function(e,t){this.format=this._params.format=e,this._setDefaultFilter(),t||this.refresh(!0)},setInfoTemplate:function(e){this.infoTemplate=e,this._updateInfoTemplateFields(this.fields)},setDefinitionExpression:function(e,t){var i=this.mosaicRule?this.mosaicRule.toJson():{};this.mosaicRule||(this.defaultMosaicRule?i=this.defaultMosaicRule.toJson():i.method=b.METHOD_NONE),i.where=e;var n=new b(i);return this.setMosaicRule(n,t),this},getDefinitionExpression:function(){return this.mosaicRule?this.mosaicRule.where:null},setPixelFilter:function(e){this.pixelFilter=e,this._isDefaultPixelFilter=!1},getPixelData:function(e){return e?(this._useBrowserDecoding()&&(this.originalPixelData={pixelBlock:this._getPixelBlockFromCanvas(this._context,this._map.width,this._map.height),extent:this._map.extent}),this.originalPixelData):this.pixelData},getExportImageRenderingRule:function(){var e;return this._hasItemLevelRFT&&this.renderingRule&&(e=this._getServiceLevelRenderingRule(this.renderingRule)),e=e||this.renderingRule,this._isItemLevelRasterFunction(this.renderingRule)&&(e=void 0),this._combineRenderingRule(this._convertRendererToRenderingRule(this.renderer),e)},getExportImageMosaicRule:function(){var e,t=this.mosaicRule;return this._hasItemLevelRFT&&this.renderingRule&&(e=this._getItemLevelRenderingRule(this.renderingRule)),e&&((t=t||this.defaultMosaicRule||new b).itemRenderingRule=e),t=this._applyTimeToMultidimensionalCRF(t)},redraw:function(){this.hasDataChanged=!1,this._setPixelData(this.originalPixelData)},getHistograms:function(e){var n=new i(m._dfdCanceller);if(e&&this._cachedVariableHistogram[e])return n.resolve(this._cachedVariableHistogram[e]),n;if(this.hasHistograms){var r={f:"json"};e&&(r.variable=e),n._pendingDfd=f({url:this._url.path+"/histograms",content:r,handleAs:"json",callbackParamName:"callback"}),n._pendingDfd.then(t.hitch(this,(function(t){e&&(this._cachedVariableHistogram[e]=t),n.callback(t)})),(function(e){n.errback(e)}))}else{var a=new Error("Layer does not have histograms.");a.log=!!s.isDebug,n.errback(a)}return n},computeHistograms:function(e){var n=new i(m._dfdCanceller);if(this.currentVersion>=10.1){var r=(e=e||{}).geometry||this.fullExtent,a=(e.geometry||this.fullExtent).toJson(),l="extent"===r.type?"esriGeometryEnvelope":"esriGeometryPolygon",o=e.renderingRule||this.renderingRule||this.defaultRenderingRule;o=o?o.toJson():null;var u=e.mosaicRule||this.mosaicRule||this.defaultMosaicRule;u=u?u.toJson():null;var h=e.pixelSize||{x:this.pixelSizeX,y:this.pixelSizeY};n._pendingDfd=f({url:this._url.path+"/computeHistograms",content:t.mixin({f:"json",geometry:JSON.stringify(a),geometryType:l,renderingRule:JSON.stringify(o),mosaicRule:JSON.stringify(u),pixelSize:JSON.stringify(h),callbackParamName:"callback"}),handleAs:"json"}),n._pendingDfd.then((function(e){n.callback(e)}),(function(e){n.errback(e)}))}else{var c=new Error("Layer doesn't support computeHistograms.");c.log=!!s.isDebug,n.errback(c)}return n},getRenderingRuleServiceInfo:function(e,r){var s=new m._fixDfd(new i(m._dfdCanceller));if(!e){var a=new Error("Rendering rule is not specified");return s.errback(a),s}function l(e){return e.name&&e.arguments&&e.function&&e.hasOwnProperty("functionType")}if(l(e))"ClipFunction"===e.function.type&&(e=this._handleClipFunctionInRenderingRule(e));else{var o=this._getRenderingRuleId(e);if(o&&this._rasterFunctionTemplateInfos[o])return s.resolve(this._rasterFunctionTemplateInfos[o]),s}return f({url:this._url.path,content:t.mixin(t.mixin({f:"json",renderingRule:JSON.stringify(e.toJson())},this._url.query)),callbackParamName:"callback",load:t.hitch(this,(function(t){var i={};return n.forEach(this._rasterFunctionServiceInfoProps,(function(e){i[e]=t[e]})),l(e)||(this._rasterFunctionTemplateInfos[o]=i),i})),error:r||this._errorHandler})},queryVisibleRasters:function(e,r,s,a){var l,o=this._map,u=m._fixDfd(new i(m._dfdCanceller));this._visibleRasters=[];var h,c,d=!0,f=!0,p=null,g=this.infoTemplate?this.infoTemplate.info:null,_=g?t.clone(this.infoTemplate.info.fieldInfos):null;if(r=r||{},g&&this.infoTemplate.info.mediaInfos&&this.infoTemplate.info.mediaInfos.length){var v=[];n.forEach(this.infoTemplate.info.mediaInfos,(function(e){var t=e&&e.value&&e.value.fields||[];v=v.concat(t)})),v.length&&n.forEach(_,(function(e){e&&v.indexOf(e.fieldName)>-1&&(e.visible=!0)}))}var b=function(e){var t=g&&g.title&&g.title.toLowerCase().indexOf(e.toLowerCase())>-1,i=g&&g.description&&g.description.toLowerCase().indexOf(e.toLowerCase())>-1;return t||i};if(_&&_.length>0)for(d=!1,h=0;h<_.length;h++)if((c=_[h])&&c.fieldName.toLowerCase()!==this._rasterFieldPrefix.toLowerCase()+"servicepixelvalue"&&(c.visible||b(c.fieldName))){d=!0;break}this.infoTemplate&&this.infoTemplate.info&&this.infoTemplate.info.layerOptions&&this.infoTemplate.info.layerOptions.hasOwnProperty("returnTopmostRaster")&&(p=this.infoTemplate.info.layerOptions.returnTopmostRaster?1:null),_&&_.length>0&&(f=!1,n.some(_,(function(e){if(e&&e.fieldName.toLowerCase()===this._rasterFieldPrefix.toLowerCase()+"itempixelvalue"&&e.visible)return f=!0,!0}),this),b(this._rasterFieldPrefix.toLowerCase()+"itempixelvalue")&&(f=!0));var T=this._removeVisualizationStretchFunction(this.renderingRule),y=T&&T.functionName,F=[];if(this.version>=10.4){var D=!1;if(this.rasterFunctionInfos&&_){var I=this._rasterFieldPrefix+this._renderingRuleFieldSubPrefix;n.forEach(this.rasterFunctionInfos,(function(e){var t=I+e.name.replace(/ /gi,"_");n.some(_,(function(e){return e.visible&&e.fieldName===t}))&&(D=D||y&&y===e.name,F.push(new x({rasterFunction:e.name})))}))}T&&!D&&F.push(T)}var C=new S;if(C.geometry=e.geometry,C.returnGeometry=this._map.spatialReference.equals(this.spatialReference),C.returnCatalogItems=d,C.timeExtent=this.timeInfo?e.timeExtent:null,C.returnPixelValues=f,C.maxItemCount=p||e.maxItemCount,this._params.time&&this.mosaicRule?(l=t.clone(this.mosaicRule),l=this._filterOutTimeDimension(l),C.mosaicRule=l):C.mosaicRule=this.mosaicRule||null,this._isMultidimensionalCRF()&&C.timeExtent&&(C.mosaicRule=this._applyTimeToMultidimensionalCRF(C.mosaicRule,C.timeExtent.toJson().join(",")),this._isTimeSupportedOnCRF()||delete C.timeExtent),C.renderingRule=this.version<10.4&&T||null,C.renderingRules=F||null,this.version<10.8&&(C.returnPixelValues=void 0,C.maxItemCount=void 0),o){var w=(o.extent.xmax-o.extent.xmin)/o.width,P=(o.extent.ymax-o.extent.ymin)/o.height,A=o.extent.spatialReference,k=new R(w,P,A);C.pixelSize=k}r.requestParams=C;var M=this,L=new V(this.url);return(u._pendingDfd=L.execute(C)).addCallbacks((function(e){M._queryVisibleRastersHandler(e,r,s,a,u)}),(function(e){M._resolve([e],null,a,u,!0)})),u},_queryVisibleRastersHandler:function(e,i,s,a,l){var o,u,h,c,m,p,R=e.value,v=e.value,b=0,x=0,T=this,y=this.objectIdField,D=[],I=i.requestParams.renderingRules,C=e.processedValues,w=this.renderingRule&&r.toJson(this._removeVisualizationStretchFunction(this.renderingRule).toJson());if(I&&C&&I.length===C.length){var V=this._rasterFieldPrefix+this._renderingRuleFieldSubPrefix;n.forEach(I,(function(e,t){if(e.functionName){var i={name:V+e.functionName.replace(/ /gi,"_"),value:C[t].replace(/ /gi,"").split(",")};D.push(i),w&&w===r.toJson(e.toJson())&&(R=C[t])}}))}if(c=!(this.infoTemplate&&this.infoTemplate.info&&this.infoTemplate.info.layerOptions&&this.infoTemplate.info.layerOptions.hasOwnProperty("showNoDataRecords"))||this.infoTemplate.info.layerOptions.showNoDataRecords,e.catalogItems){var S,A,k=0,M=e.catalogItems.features.length,L=0;if(u=new Array(M),o=new Array(M),h=new Array(M),e.properties&&e.properties.Values){var N=e.properties.Values.length;for(b=0;b<N;b++)e.properties.Values[b].toLowerCase().indexOf("nodata")>-1&&L++;for(S=N-L,b=0;b<N;b++)m=!0,e.properties.Values[b].toLowerCase().indexOf("nodata")>-1?(A=S++,c||(m=!1,u.length--,o.length--,h.length--)):A=k++,m&&(u[A]=e.catalogItems.features[b],o[A]=e.properties.Values[b],h[A]=u[A].attributes[y])}else{for(b=0;b<M;b++)u[b]=e.catalogItems.features[b],h[b]=u[b].attributes[y];o=null}}this._visibleRasters=[];var E=R.toLowerCase().indexOf("nodata")>-1;if(E&&!c&&(u=[],o=[],h=[]),R&&!u&&!E){y="ObjectId",u=[];var j={ObjectId:0};p=new P(new g(this.fullExtent),null,j),u.push(p)}var O=[];function J(){var e,r,a,h,c,f,m,_,b,x,T=this.getCustomRasterFields(i),I=this._getDomainFields(T),C=!!i&&i.returnDomainValues,w=i&&i.rasterAttributeTableFieldPrefix,P=this._getRenderingRuleId(this.renderingRule),V=P&&this._rasterFunctionTemplateInfos[P];this.renderingRule&&(this._useRenderingRuleAttributeTable||V)?(b=this._getRenderingRuleAttributeTableFeatures({renderingRule:this.renderingRule}),this.hasRasterAttributeTable||(x=R)):b=this._getRasterAttributeTableFeatures(),b.then(t.hitch(this,(function(i){for(e=0;e<u.length;e++){if(p=u[e],p.attributes[y],p.setInfoTemplate(this.infoTemplate),p._layer=this,R){if(_=R.replace(/ /gi,"").split(","),r=R,a=_,o&&o.length>=e&&(r=o[e].replace(/ /gi,", "),a=o[e].split(" ")),p.attributes[this._rasterFieldPrefix+"ItemPixelValue"]=a,p.attributes[this._rasterFieldPrefix+"ServicePixelValue"]=_,v&&(p.attributes[this._rasterFieldPrefix+"ServicePixelValue.Raw"]=v.replace(/ /gi,"").split(",")),this.pixelFilter){var b=new F({height:1,width:1,pixelType:"F32",pixels:[],statistics:[]});n.forEach(a,(function(e){b.addData({pixels:[e],statistics:{minValue:e,maxValue:e,noDataValue:null}})})),this.pixelFilter({pixelBlock:b,extent:new g(0,0,0,0,this._map.spatialReference)}),"esriImageServiceDataTypeVector-UV"!==this.serviceDataType&&"esriImageServiceDataTypeVector-MagDir"!==this.serviceDataType||(p.attributes[this._rasterFieldPrefix+"Magnitude"]=b.pixels[0][0],p.attributes[this._rasterFieldPrefix+"Direction"]=b.pixels[1][0])}var T;if(n.forEach(D,(function(e){p.attributes[e.name]=e.value})),T=this.fields.length>0?x||r:x||v,i&&i.length>0&&(h=n.filter(i,(function(e){if(e&&e.attributes)return e.attributes.hasOwnProperty("Value")?e.attributes.Value==T:e.attributes.VALUE==T}))).length>0&&(c=t.clone(h[0]),w&&c)){for(f in m={},c.attributes)c.attributes.hasOwnProperty(f)&&(m[w+f]=c.attributes[f]);c.attributes=m,p.attributes=t.mixin(p.attributes,c.attributes)}}C&&I&&I.length>0&&n.forEach(I,(function(e){if(e){var t=p.attributes[e.name];if(d.isDefined(t)){var i=this._getDomainValue(e.domain,t);d.isDefined(i)&&(p.attributes[e.name]=i)}}}),this),O.push(p),this._visibleRasters.push(p)}this._resolve([O,null,!0],null,s,l)})))}u?!this._map.spatialReference.equals(this.spatialReference)&&h&&h.length>0?f({url:this._url.path+"/query",content:{f:"json",objectIds:h.join(","),returnGeometry:!0,outSR:r.toJson(T._map.spatialReference.toJson()),outFields:y},handleAs:"json",callbackParamName:"callback",load:function(e){if(0!==e.features.length){for(b=0;b<e.features.length;b++)for(x=0;x<u.length;x++)u[x].attributes[y]==e.features[b].attributes[y]&&(u[x].geometry=new _(e.features[b].geometry),u[x].geometry.setSpatialReference(T._map.spatialReference));J.call(T)}else T._resolve([O,null,null],null,s,l)},error:function(e){T._resolve([O,null,null],null,s,l)}}):J.call(this):this._resolve([O,null,null],null,s,l)},getVisibleRasters:function(){var e,t=this._visibleRasters,i=[];for(e in t)t.hasOwnProperty(e)&&i.push(t[e]);return i},_getDomainFields:function(e){if(e){var t=[];return n.forEach(e,(function(e){if(e.domain){var i={};i.name=e.name,i.domain=e.domain,t.push(i)}})),t}},_getDomainValue:function(e,t){var i;if(e&&e.codedValues)return n.some(e.codedValues,(function(e){return e.code===t&&(i=e.name,!0)})),i},_requestData:function(e,i,n){this._rasterReadPromise&&this._rasterReadPromise.cancel();var r=t.clone(e),s=r._normalize(!0);this._prepareGetImageParameters(s,i,n);var a=t.clone(this._params);this._cleanupRequestParams(a),a.extent=r,a.format=a.format||(this.version>=10.3?"lerc":"jpgpng"),"lerc"===a.format.toLowerCase()&&!a.lercVersion&&this.version>=10.5&&(a.lercVersion=2),this._params.time&&this._isMultidimensionalCRF()&&!this._isTimeSupportedOnCRF()&&delete a.time;var l=null;this._useBrowserDecoding()&&(l=new I({ctx:this._context}));var o={imageServiceParameters:a,nBands:Math.min(this.bandCount,3),pixelType:this.pixelType,decodeFunc:l?t.hitch(l,"decode"):null};this._rasterReadPromise=this.raster.read(o,this._requestDataHandler,this._requestDataErrorHandler)},_requestDataHandler:function(e){this._rasterReadPromise&&this._rasterReadPromise.isCanceled()||(this.originalPixelData=e,this.hasDataChanged=!0,this._setPixelData(e))},_setPixelData:function(e){var t=this._clonePixelData(e);this.pixelFilter&&this.pixelFilter(t),this.pixelData=t,this._rasterReadPromise&&this._rasterReadPromise.isCanceled()||(this._drawPixelData(),this._rasterReadPromise=null)},_clonePixelData:function(e){if(null==e)return e;var i={};e.extent&&(i.extent=t.clone(e.extent));var n=e.pixelBlock;return null==n?i:(i.pixelBlock=n.clone(),i)},_setDefaultFilter:function(){},_getPixelBlockFromCanvas:function(e,t,i){var n,r,s,a=e.getImageData(0,0,t,i).data,l=t*i,o=0,u=0,h=new Uint8Array(l),c=new Uint8Array(l),d=new Uint8Array(l),f=new Uint8Array(l),m=1/0,p=1/0,g=1/0,R=-1/0,_=-1/0,v=-1/0;for(o=0;o<l;o++)m=m<(n=a[u++])?m:n,R=R>n?R:n,p=p<(r=a[u++])?p:r,_=_>r?_:r,g=g<(s=a[u++])?g:s,v=v>s?v:s,h[o]=n,c[o]=r,d[o]=s,f[o]=1&a[u++];return new F({width:t,height:i,pixels:[h,c,d],pixelType:"U8",mask:f,statistics:[{minValue:m,maxValue:R},{minValue:p,maxValue:_},{minValue:g,maxValue:v}]})},_useBrowserDecoding:function(){return(void 0===this.pixelFilter||null===this.pixelFilter)&&("jpeg"===this.format.toLowerCase()||"jpg"===this.format.toLowerCase()||this.format.toLowerCase().indexOf("png")>-1)},getMultidimensionalInfo:function(){var e=this._url.path+"/multiDimensionalInfo",n=new i(m._dfdCanceller);if(this._multidimensionalInfo)return n.resolve(this._multidimensionalInfo),n;if(!this.loaded||this.version>=10.3&&this.hasMultidimensions)n._pendingDfd=f({url:e,content:{f:"json"},handleAs:"json",callbackParamName:"callback"}),n._pendingDfd.then(t.hitch(this,(function(e){this._multidimensionalInfo=e.multidimensionalInfo,n.callback(e.multidimensionalInfo)})),(function(e){n.errback(e)}));else{var r=new Error("Layer does not support multidimensional info");r.log=!!s.isDebug,n.errback(r)}return n},getStatistics:function(e){var n=new i(m._dfdCanceller);if(e&&this._cachedVariableStats[e])n.resolve(this._cachedVariableStats[e]);else{var r={f:"json"};e&&(r.variable=e),n._pendingDfd=f({url:this._url.path+"/statistics",content:r,handleAs:"json",callbackParamName:"callback"}),n._pendingDfd.then(t.hitch(this,(function(t){var i=t.statistics||t.statitsics,r=[];i&&i[0]&&null!=i[0].min?i.forEach((function(e){r.push([e.min,e.max,e.mean,e.standardDeviation])})):r=i,e&&(this._cachedVariableStats.variableName=r),n.callback(r)})),(function(e){n.errback(e)}))}return n},getDefaultMultidimensionalDefinition:function(){var e=new i(m._dfdCanceller);return this._defaultMultidimensionalDefinition?(e.resolve(t.clone(this._defaultMultidimensionalDefinition)),e):(e._pendingDfd=this.getMultidimensionalInfo(),e._pendingDfd.then(t.hitch(this,(function(t){var i=this._getDefaultMultidimensionalDefinition(t);e.callback(i)})),(function(t){e.errback(t)})),e)},_getDefaultMultidimensionalDefinition:function(e,i,n){var r,s,a=[],l="",o=e.variables[0].dimensions;for(s in n&&(l=e.variables[0].name),o)o.hasOwnProperty(s)&&(i||"StdTime"!==o[s].name)&&(r=o[s],a.push(new T({variableName:l,dimensionName:r.name,isSlice:!r.hasRanges,values:[this._getDefaultDimensionValue(r)]})));return this._defaultMultidimensionalDefinition=a,t.clone(a)},_getDefaultDimensionValue:function(e){if(e&&e.values&&e.values.length){var t,i,n,r,s=1/0;if(e.hasRanges)return e.values[0];if(e.name&&"stdz"===e.name.toLowerCase()){for(r=0;r<e.values.length&&(n=e.values[r],(i=Math.abs(n-0))<s&&(s=i,t=n),0!==i);r++);return t}return e.extent[0]}},_setDefaultMultidimensionalDefinition:function(e){var i,n={};this.getDefaultMultidimensionalDefinition().then(t.hitch(this,(function(r){(i=r).length>0&&(this.mosaicRule?(n=t.clone(this.mosaicRule)).multidimensionalDefinition=i:this.defaultMosaicRule?(n=t.clone(this.defaultMosaicRule)).multidimensionalDefinition=i:n=new b({multidimensionalDefinition:i}),this.setMosaicRule(n,e))})))},_setDefaultRenderingRule:function(e){var t={},i=this.renderingRule;if(!i&&"esri.layers.ArcGISImageServiceVectorLayer"!==this.declaredClass&&!this.bandIds&&this.rasterFunctionInfos&&this.rasterFunctionInfos.length&&"none"!==this.rasterFunctionInfos[0].name.toLowerCase())t.rasterFunction=this.rasterFunctionInfos[0].name;else if("esri.layers.ArcGISImageServiceVectorLayer"===this.declaredClass&&this.version>10.3&&(!i||"Resample"!==i.functionName)){var n="esriImageServiceDataTypeVector-UV"===this.serviceDataType?7:10;t.rasterFunction="Resample",t.rasterFunctionArguments={ResamplingType:n,InputCellSize:{x:this.pixelSizeX,y:this.pixelSizeY}},i&&(t.rasterFunctionArguments.Raster=i.toJson())}t.hasOwnProperty("rasterFunction")&&(this.defaultRenderingRule=new x(t),this.setRenderingRule(this.defaultRenderingRule,e))},_cleanupRequestParams:function(e){if(!e)return e;if(e.time&&e.mosaicRule){var t=new b(r.fromJson(e.mosaicRule));t=this._filterOutTimeDimension(t),e.mosaicRule=r.toJson(t.toJson())}var i,n=["displayOnPan","drawMode","styling","id","opacity","visible","resourceInfo","useMapDimensionValue","extent","renderer"];for(i in n)e.hasOwnProperty(n[i])&&delete e[n[i]];return e},_filterOutTimeDimension:function(e){if(this._isMultidimensionalCRF())return e;if(e&&e.multidimensionalDefinition&&e.multidimensionalDefinition.length>0){var t=n.filter(e.multidimensionalDefinition,(function(e){return"StdTime"!==e.dimensionName}));e.multidimensionalDefinition=t}return e},_removeVisualizationStretchFunction:function(e){var t=e&&e.functionName;if(!t||"stretch"!==t.toLowerCase())return e;var i=e.functionArguments.Raster;if(i&&i.functionName&&n.some(this.rasterFunctionInfos,(function(e){return i.functionName===e.name})))return i;return e},_isMultidimensionalCRF:function(){return this.version>=10.71&&this.hasMultidimensions&&this.timeInfo&&!(this.objectIdField&&this.fields&&this.fields.length>1)},_isTimeSupportedOnCRF:function(){return this.version>=10.8},_cleanupMultidimensionalDefinition:function(e){e&&e.multidimensionalDefinition&&(e.multidimensionalDefinition=e.multidimensionalDefinition.filter((function(e){return!(!e.variableName&&!e.dimensionName)})),0===e.multidimensionalDefinition.length&&(e.multidimensionalDefinition=null))},_isScientificData:function(){return"esriImageServiceDataTypeVector-UV"===this.serviceDataType||"esriImageServiceDataTypeVector-MagDir"===this.serviceDataType||"esriImageServiceDataTypeScientific"===this.serviceDataType||this.hasMultidimensions},_isVectorData:function(e){var t=(e=e||this)&&e.serviceDataType;return"esriImageServiceDataTypeVector-UV"===t||"esriImageServiceDataTypeVector-MagDir"===t},_isRenderingRuleAProcessingTemplate:function(e){var t=e&&e.functionName;return!(!t||e.functionArguments)&&n.some(t&&(this.rasterFunctionInfos||[]),(function(e){return e&&e.name&&e.name.toLowerCase()===t.toLowerCase()}))},_getRenderingRuleId:function(e){var t=e&&e.functionName;if(t){if(this._isRenderingRuleAProcessingTemplate(e))return t;var i=this._customRenderingRuleId[t];if(i){if(i!==e){for(var n in this._customRenderingRuleId)if(this._customRenderingRuleId[n]===e)return n;for(var r=0;this._customRenderingRuleId[s];)r+=1;var s=t+r;this._customRenderingRuleId[s]=e}}else this._customRenderingRuleId[t]=e;return t}},_createPixelData:function(e){var t=new F({width:2,height:2,pixels:e,pixelType:this.pixelType,statistics:e}),i=this.fullExtent.getCenter();return{pixelBlock:t,extent:new g(i.x,i.y,i.x+this.pixelSizeX,i.y+this.pixelSizeY,this.spatialReference)}},_convertRendererToRenderingRule:function(e){var t=e&&e.declaredClass;if(!t||"esri.renderer.UniqueValueRenderer"!==t&&"esri.renderer.ClassBreaksRenderer"!==t&&"esri.renderer.StretchRenderer"!==t&&"esri.renderer.ShadedReliefRenderer"!==t&&"esri.renderer.ColormapRenderer"!==t)return null;var i=null;return"esri.renderer.StretchRenderer"===t?i=e.toRenderingRule({convertToColormap:this.version<10.6}):"esri.renderer.ClassBreaksRenderer"===t?i=this._convertClassifyRenderer(e):"esri.renderer.UniqueValueRenderer"===t?i=this._convertUniqueValueRenderer(e):"esri.renderer.ShadedReliefRenderer"===t?i=this._convertShadedReliefRenderer(e):"esri.renderer.ColormapRenderer"===t&&(i=this._convertColormapRenderer(e)),i},_getValueField:function(e){var t,i;if(e&&e.length)return n.some(e,(function(e){if((i=e.name)&&"value"===i.toLowerCase())return t=i,!0})),t},_convertColormapRenderer:function(e){var t=new x;t.functionName="Colormap",t.functionArguments={};var i=e.colormapInfos.map((function(e){return[e.value].concat(e.color)}));return t.functionArguments.Colormap=i,t},_convertShadedReliefRenderer:function(e){var t=new x;t.functionName="Hillshade";var i="traditional"===e.hillshadeType?0:1,n="none"===e.scalingType?1:3,r={HillshadeType:i,SlopeType:n,ZFactor:e.zFactor};return 0===i&&(r.Azimuth=e.azimuth,r.Altitude=e.altitude),3===n&&(r.PSPower=e.pixelSizePower,r.PSZFactor=e.pixelSizeFactor),t.functionArguments=r,t.variableName="Raster",e.colorRamp&&(t.functionName="ShadedRelief",r.Colormap=v.convertColorRampToColormap(e.colorRamp,256)),t},_convertClassifyRenderer:function(e){var t,i,r,s,a,l,o,u,h=[],c=[],d=[],f=[],m=this.renderingRule&&this._getRenderingRuleId(this.renderingRule),p=this.hasRasterAttributeTable;if(m&&(p=this._rasterFunctionTemplateInfos[m]?this._rasterFunctionTemplateInfos[m].hasRasterAttributeTable:this.hasRasterAttributeTable,s=this._renderingRuleAttributeTable[m],u=this._rasterFunctionTemplateInfos[m]),r=s&&s.features?s.features:this._rasterAttributeTableFeatures,a=s&&s.fields?s.fields:this._rasterAttributeTableFields,l=this._getValueField(a),p&&r){n.forEach(e.infos,(function(t,i){var s,a=t.symbol.color;a.a&&n.forEach(r,(function(n){((s=n.attributes[e.attributeField])>=t.minValue&&s<t.maxValue||i===e.infos.length-1&&s>=t.minValue)&&f.push([n.attributes[l],a.r,a.g,a.b])}),this)}),this),o=u&&u.pixelType||this.pixelType,this._adjustColormapToPixelTypeRange(f,o);var g=new x;g.functionName="Colormap",g.functionArguments={},g.functionArguments.Colormap=f,g.variableName="Raster",t=g}else{n.forEach(e.infos,(function(e,t){(i=e.symbol&&e.symbol.color).a?(0===t?h.push.call(h,e.minValue,e.maxValue+1e-4):h.push.call(h,e.minValue+1e-4,e.maxValue+1e-4),c.push(t),f.push([t,i.r,i.g,i.b])):d.push(e.minValue,e.maxValue)})),o=u&&u.pixelType||this.pixelType,this._adjustColormapToPixelTypeRange(f,o);var R=new x;R.functionName="Remap",R.functionArguments={InputRanges:h,OutputValues:c,NoDataRanges:d},R.variableName="Raster";var _=new x;_.functionName="Colormap",_.functionArguments={Colormap:f,Raster:R},t=_}return t},_convertUniqueValueRenderer:function(e){var t,i,r,s,a,l,o=[],u=this.renderingRule&&this._getRenderingRuleId(this.renderingRule);u&&(this._rasterFunctionTemplateInfos[u]?this._rasterFunctionTemplateInfos[u].hasRasterAttributeTable:this.hasRasterAttributeTable,i=this._renderingRuleAttributeTable[u],l=this._rasterFunctionTemplateInfos[u]),t=i&&i.features?i.features:this._rasterAttributeTableFeatures,s=i&&i.fields?i.fields:this._rasterAttributeTableFields,r=s&&s.length?this._getValueField(s):"Value",n.forEach(e.infos,(function(i){var s=i.symbol.color;s.a&&(e.attributeField!==r&&t?n.forEach(t,(function(t){t.attributes[e.attributeField]==i.value&&o.push([t.attributes[r],s.r,s.g,s.b])}),this):o.push([i.value,s.r,s.g,s.b]))}),this),a=l&&l.pixelType||this.pixelType,this._adjustColormapToPixelTypeRange(o,a);var h=new x;return h.functionName="Colormap",h.functionArguments={},h.functionArguments.Colormap=o,h.variableName="Raster",h},_adjustColormapToPixelTypeRange:function(e,t){var i=this._pixelTypeRanges[t];return i&&e.push([Math.floor(i[0]-1),0,0,0],[Math.ceil(i[1]+1),0,0,0]),e},_combineRenderingRule:function(e,i){if(!e||!i)return e||i;var n=function(e){var t=e.Raster;return t=t&&"esri.layers.RasterFunction"===t.declaredClass?n(t.functionArguments):e},r=t.clone(e);"none"!==i.functionName.toLocaleLowerCase()&&(n(r.functionArguments).Raster=i);return r},_isItemLevelRasterFunction:function(e){var t=e&&e.functionName;if(!t||!this._hasItemLevelRFT)return!1;var i=!1;return n.some(this.rasterFunctionInfos,(function(e){if(e&&e.name===t)return 1!==e.functionType&&2!==e.functionType||(i=!0),!0})),i},_getServiceLevelRenderingRule:function(e){if(!this._hasItemLevelRFT||!e)return e;for(var t,i=new x(e.toJson()),n=i,r=n.functionArguments;;){if(!((t=r&&r.Raster)&&t.functionArguments&&t.functionArguments.Raster)){this._isItemLevelRasterFunction(t)&&delete r.Raster;break}r=(n=t).functionArguments}return i},_getItemLevelRenderingRule:function(e){if(!this._hasItemLevelRFT||!e)return null;if(this._isItemLevelRasterFunction(e))return e;for(var t,i=new x(e.toJson()),n=i.functionArguments;;){if(!((t=n&&n.Raster)&&t.functionArguments&&t.functionArguments.Raster)){if(this._isItemLevelRasterFunction(t))return t;break}n=(i=t).functionArguments}},_resolve:function(e,t,i,n,r){t&&this[t].apply(this,e),i&&i.apply(null,e),n&&m._resDfd(n,e,r)},_toggleTime:function(){var e=this._map;this.timeInfo&&this.useMapTime&&e&&!this.suspended?(this._timeConnect||(this._timeConnect=a.connect(e,"onTimeExtentChange",this,this._onTimeExtentChangeHandler)),this._setTime(e.timeExtent)):(a.disconnect(this._timeConnect),this._timeConnect=null,this._setTime(null))},setUseMapTime:function(e,t){this.useMapTime=e,this._toggleTime(),!t&&this._map&&this.refresh(!0)},_setTime:function(e){this._params&&(this._params.time=e?e.toJson().join(","):null)},_onTimeExtentChangeHandler:function(e){this.suspended||(this._setTime(e),this.refresh(!0))},handleSpatialReferenceChange:function(){this.onSpatialReferenceChange()},getColormap:function(e){var t=this._url.path+"/colormap",n=new i(m._dfdCanceller),a={f:"json"};if(e&&e.renderingRule&&(a.renderingRule=r.toJson(e.renderingRule.toJson())),this.hasColormap)n._pendingDfd=f({url:t,content:a,handleAs:"json",callbackParamName:"callback"}),n._pendingDfd.then((function(e){n.callback(e)}),(function(e){n.errback(e)}));else{var l=new Error("Layer does not support colormap");l.log=!!s.isDebug,n.errback(l)}return n},getRenderingRuleColormap:function(e){var n=new i(m._dfdCanceller);if(!e||!e.renderingRule){var r=new Error("Rendering rule is not specified");return n.errback(r),n}var s=e.renderingRule,a=this._getRenderingRuleId(s);return this._renderingRuleColormap&&a&&this._renderingRuleColormap.hasOwnProperty(a)?n.resolve(this._renderingRuleColormap[a]):n=this.getColormap({renderingRule:s}).then(t.hitch(this,(function(e){var t=e&&e.colormap;return a&&(this._renderingRuleColormap[a]=t),t}))),n},_handleClipFunctionInRenderingRule:function(e){var i=t.clone(e),n=i.arguments,r=n.ClippingRaster&&n.ClippingRaster.value,s=n.ClippingGeometry&&n.ClippingGeometry.value,a=n.Extent&&n.Extent.value;if(!r&&!s&&!a){var l=this._map.extent.toJson();i.arguments.Extent.value=l,i.functionArguments.Extent.value=l,i._isTemplate&&(i._templateJson.arguments.Extent.value=l)}return i}});return l("extend-esri")&&t.setObject("layers.ImageServiceLayerMixin",A,h),A}));