/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{isFunctionRaster as t}from"../../layers/raster/datasets/datasetUtils.js";import{getPixelLocationAndValue as e}from"../../layers/raster/functions/pixelUtils.js";import{uvComponentToVector as r}from"../../layers/raster/functions/vectorFieldUtils.js";async function n(t){const{pixelData:r}=t,{pixelBlock:n}=r;if(!n)return null;const{extent:i}=r,s={x:i.width/n.width,y:i.height/n.height},l=e({pos:t.mapPoint,pixelData:r,pixelSize:s});return l?.value?.length?a(t.layer,l.value,t.sourceIsUV):null}async function i(r){const{rawPixelData:n,transformGrid:i,tileSize:s}=r.sourceData;if(!n?.pixelBlock)return null;const{extent:l}=n,o={x:l.width/s.width,y:l.height/s.height},c=e({pos:r.mapPoint,pixelData:n,pixelSize:o,transformGrid:i});if(!c?.value?.length)return null;const{layer:u,processRasterFunction:h,sourceIsUV:p}=r;if("imagery-tile"===u.type&&h&&t(u.raster)){const t=await u.raster.processOnePixel(c,n);return t?.length?a(u,t,p):null}return a(u,c.value,p)}function a(t,e,n){const{renderer:i}=t,a="vector-field"===i?.type||"flow"===i?.type?[0,1]:t.bandIds?.length?t.bandIds:Array.from({length:Math.min(3,e.length)},(t,e)=>e),{serviceRasterInfo:s}=t;"imagery"!==t.type&&!s?.storageInfo?.isBsqTile&&(e=a.map(t=>e[t]));const l=s?.dataType,o="vector-magdir"===l||"vector-uv"===l;return o&&2===e?.length&&(n||"vector-uv"===l)&&(e=r(e)),{pixelValue:e,bandIds:a,isMagnitudeAndDirection:o}}function s(t){const{flowData:e,extent:r}=t.sourceData,{data:n,mask:i,width:s,height:l}=e,o={x:r.width/s,y:r.height/l},{mapPoint:c}=t,{xmin:u,ymax:h}=r,p=Math.floor((c.x-u)/o.x),d=Math.floor((h-c.y)/o.y)*s+p;if(i&&!i[d])return null;const f=[n[2*d],-n[2*d+1]];return a(t.layer,f,!0)}export{s as readFromFlowData,n as readFromPixelData,i as readFromTiledRasterData};
