/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as t}from"tslib";import e from"../../Graphic.js";import r from"../../core/Error.js";import{makeHandle as i}from"../../core/handleUtils.js";import{property as a}from"../../core/accessorSupport/decorators.js";import{isFunctionRaster as s}from"../../layers/raster/datasets/datasetUtils.js";import{getDefaultDatumTransformationForDataset as n,projectDatasetExtent as l,getSourceScale as o}from"../../layers/raster/functions/rasterProjectionHelper.js";import{addMultidimensionalFieldValues as u,commonRasterFieldNames as p,rasterFieldPrefix as c}from"../../layers/support/rasterFieldUtils.js";import{combineTimeExtent as m}from"../../layers/support/timeSupport.js";import y from"./LayerView.js";import{getFetchPopupTemplate as f}from"./support/popupUtils.js";class h extends y{constructor(...t){super(...t),this.layer=null,this.tileInfo=null}get fullExtent(){try{return this.layer.loaded?this._getFullExtent():null}catch{return null}}get timeExtent(){return m(this.layer,this.view?.timeExtent,this._get("timeExtent"))}get hasTilingEffects(){const{renderer:t}=this.layer;return!!("raster-stretch"===t?.type&&t.dynamicRangeAdjustment&&!("min-max"===t.stretchType||"standard-deviation"===t.stretchType))}get datumTransformation(){try{return this.layer.loaded?n(this.layer.fullExtent,this.view.spatialReference,!0):null}catch{return null}}supportsSpatialReference(t){try{return!this.layer.loaded||!!l(this.layer.serviceRasterInfo,t)}catch{return!1}}async fetchPopupFeaturesAtTarget(t,i,a){const{layer:n}=this;if(!i)throw new r("imageryTileLayerView:fetchPopupFeatures","Nothing to fetch without area",{layer:n});const{popupEnabled:l}=n,o=f(n,a);if(!l||null==o)return[];"polygon"===i.type&&(i=i.extent?.center);const m=[],{value:y,magdirValue:h,processedValue:d}=await n.identify(i,{timeExtent:this.timeExtent,signal:a?.signal});let g="";if(y?.length){g="imagery-tile"===n.type&&n.hasStandardTime()&&null!=y[0]?y.map(t=>n.getStandardTimeValue(t)).join(", "):y.join(", ");const t={ObjectId:0};t[p.servicePixelValue]="imagery-tile"===n.type&&s(n.raster)?d?.join(", "):g,t[p.rawServicePixelValue]=g;const r=n.raster?.rasterInfo??n.serviceRasterInfo,i=r?.attributeTable;if(null!=i){const{fields:e,features:r}=i,a=e.find(({name:t})=>"value"===t.toLowerCase()),s=t[p.servicePixelValue],n=a?r.find(t=>String(t.attributes[a.name])===s):null;if(n)for(const i in n.attributes)if(n.attributes.hasOwnProperty(i)){t[c+i]=n.attributes[i]}}const a=r?.dataType;"vector-magdir"!==a&&"vector-uv"!==a||(t[p.magnitude]=h?.[0],t[p.direction]=h?.[1]);const{multidimensionalDefinition:l}=this.layer.normalizeRasterFetchOptions({timeExtent:this.timeExtent});u(n.rasterFields,t,l);const{graphicOrigin:o}=n,f=new e({geometry:this.fullExtent?.clone(),attributes:t,layer:n,origin:o,sourceLayer:n});m.push(f)}return m}highlight(t,e){return i()}async getSourceScale(){return await this.layer.load(),o(this.layer.serviceRasterInfo,this.view.spatialReference)}_getFullExtent(){return l(this.layer.serviceRasterInfo,this.view.spatialReference)}}t([a()],h.prototype,"fullExtent",null),t([a()],h.prototype,"layer",void 0),t([a({readOnly:!0})],h.prototype,"timeExtent",null),t([a()],h.prototype,"tileInfo",void 0),t([a({readOnly:!0})],h.prototype,"hasTilingEffects",null),t([a()],h.prototype,"datumTransformation",null);export{h as default};
