UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 3.21 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{_ as t}from"../../../chunks/tslib.es6.js";import s from"../../../core/Error.js";import has from"../../../core/has.js";import{eachAlways as e,createAbortError as r}from"../../../core/promiseUtils.js";import{property as a}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as o}from"../../../core/accessorSupport/decorators/subclass.js";import i from"../../../geometry/Extent.js";import n from"../../../geometry/SpatialReference.js";import l from"./BaseRaster.js";import m from"./InMemoryRaster.js";import{parsePAMInfo as p}from"./pamParser.js";import{getFormat as c}from"../rasterFormats/RasterCodec.js";import{estimateStatisticsFromHistograms as f}from"../rasterFunctions/stretchUtils.js";import u from"../rasterTransforms/PolynomialTransform.js";let h=class extends l{fetchRawTile(t,s,e,r={}){return this._inMemoryRaster.fetchRawTile(t,s,e,r)}async _open(t){const s=await this._fetchData(t);let{spatialReference:e,statistics:r,histograms:a,transform:o}=await this._fetchAuxiliaryData(t);const l=!e;l&&(e=new n({wkid:3857})),a?.length&&null==r&&(r=f(a));const{width:p,height:c}=s;let u=new i({xmin:-.5,ymin:.5-c,xmax:p-.5,ymax:.5,spatialReference:e});const h=o?o.forwardTransform(u):u;let d=!0;if(o){const t=o.forwardCoefficients;d=t&&0===t[1]&&0===t[2],d&&(o=null,u=h)}const w=new m({source:{extent:h,nativeExtent:u,transform:o,pixelBlocks:[s],statistics:r,histograms:a,keyProperties:{DateType:"Processed"},isPseudoSpatialReference:l},ioConfig:{sampling:"closest",skipStatistics:!0}});this.ioConfig.skipMapInfo&&(w.ioConfig.skipMapInfo=!0),await w.open(),w.source=null,this._set("rasterInfo",w.rasterInfo),this._inMemoryRaster=w}async _fetchData(t){const{data:e}=await this.request(this.url,{responseType:"array-buffer",signal:t?.signal}),r=c(e).toUpperCase();if("JPG"!==r&&"PNG"!==r&&"GIF"!==r&&"BMP"!==r)throw new s("image-aux-raster:open","the data is not a supported format");this._set("datasetFormat",r);const a=r.toLowerCase(),o="gif"===a||"bmp"===a||!has("ios"),i=await this.decodePixelBlock(e,{format:a,useCanvas:o,hasNoZlibMask:!0});if(null==i)throw new s("image-aux-raster:open","the data cannot be decoded");return i}async _fetchAuxiliaryData(t){const s=t?.signal,{skipExtensions:a=[],skipMapInfo:o}=this.ioConfig,i=o||a.includes("aux.xml")?null:this.request(this.url+".aux.xml",{responseType:"xml",signal:s}),n=this.datasetFormat,l="JPG"===n?"jgw":"PNG"===n?"pgw":"BMP"===n?"bpw":null,m=l&&a.includes(l)?null:this.request(this.url.slice(0,this.url.lastIndexOf("."))+"."+l,{responseType:"text",signal:s}),c=await e([i,m]);if(s?.aborted)throw r();const f=p(c[0].value?.data);if(!f.transform){const t=c[1].value?c[1].value.data.split("\n").slice(0,6).map((t=>Number(t))):null;f.transform=6===t?.length?new u({forwardCoefficients:[t[4],t[5],t[0],-t[1],t[2],-t[3]]}):null}return f}};t([a({type:String,json:{write:!0}})],h.prototype,"datasetFormat",void 0),h=t([o("esri.layers.support.rasterDatasets.ImageAuxRaster")],h);const d=h;export{d as default};