@arcgis/core 5.1.0-next.61 → 5.1.0-next.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/4dbbf59c79d9e72f20ee.js +1 -0
- package/assets/esri/core/workers/chunks/71326d16b5cc35c3ff7f.js +1 -0
- package/assets/esri/core/workers/chunks/{c69fefe9d51ac7c2b0a6.js → 75f7c1f600c4051bc905.js} +1 -1
- package/assets/esri/core/workers/chunks/ed60b5eaa5765bfcb99c.js +1 -0
- package/config.js +1 -1
- package/interfaces.d.ts +14 -0
- package/kernel.js +1 -1
- package/layers/mixins/ArcGISImageService.js +1 -1
- package/layers/raster/datasets/BaseRaster.js +1 -1
- package/layers/raster/datasets/ImageAuxRaster.js +1 -1
- package/layers/raster/datasets/ImageServerRaster.js +1 -1
- package/layers/raster/formats/ImageCanvasDecoder.js +1 -1
- package/layers/raster/formats/JpgPlus.js +1 -1
- package/layers/raster/formats/RasterCodec.js +1 -1
- package/package.json +1 -1
- package/popup/Feature.d.ts +8 -3
- package/popup/Feature.js +1 -1
- package/popup/Features.d.ts +663 -0
- package/popup/Features.js +2 -0
- package/popup/support/FeatureAbilities.d.ts +30 -0
- package/popup/support/FeatureAbilities.js +2 -0
- package/support/revision.js +1 -1
- package/views/2d/engine/webgl/shaders/sources/shaderRepository.js +1 -1
- package/widgets/Feature/FeatureViewModel.d.ts +2 -1
- package/widgets/Feature/FeatureViewModel.js +1 -1
- package/widgets/Feature.js +1 -1
- package/widgets/Popup/actionUtils.js +1 -1
- package/assets/esri/core/workers/chunks/5f3f50fec18d1642fdf9.js +0 -1
- package/assets/esri/core/workers/chunks/b42487c6a989e11a2559.js +0 -1
- package/assets/esri/core/workers/chunks/dba479176db0a23c8034.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
-
import{__decorate as e}from"tslib";import t from"../../../core/Error.js";import{assertIsSome as i}from"../../../core/maybe.js";import{urlToObject as s}from"../../../core/urlUtils.js";import{property as r,subclass as a}from"../../../core/accessorSupport/decorators.js";import l from"../../../geometry/Extent.js";import n from"../../../geometry/Point.js";import o from"../../../geometry/SpatialReference.js";import c from"./BaseRaster.js";import{setValidBoundary as m}from"../functions/pixelUtils.js";import u from"../transforms/GCSShiftTransform.js";import
|
|
2
|
+
import{__decorate as e}from"tslib";import t from"../../../core/Error.js";import{assertIsSome as i}from"../../../core/maybe.js";import{urlToObject as s}from"../../../core/urlUtils.js";import{property as r,subclass as a}from"../../../core/accessorSupport/decorators.js";import l from"../../../geometry/Extent.js";import n from"../../../geometry/Point.js";import o from"../../../geometry/SpatialReference.js";import c from"./BaseRaster.js";import{setValidBoundary as m}from"../functions/pixelUtils.js";import u from"../transforms/GCSShiftTransform.js";import f from"../../support/RasterInfo.js";import h from"../../support/RasterStorageInfo.js";import p from"../../support/TileInfo.js";import{TilemapCache as d}from"../../support/TilemapCache.js";import{patchServiceInfo as y,fetchServiceRasterInfo as x}from"../../../rest/imageService/fetchRasterInfo.js";let g=class extends c{constructor(){super(...arguments),this._levelOffset=0,this._tilemapCache=null,this._slices=null,this.datasetFormat="RasterTileServer",this.tileType=null}async fetchRawTile(e,t,i,s={}){const{storageInfo:r,extent:a}=this.rasterInfo,{transposeInfo:l}=r,n=null!=l&&!!s.transposedVariableName;if(this._slices&&!n&&null==s.sliceId)return null;const o=n?0:r.maximumPyramidLevel-e+this._levelOffset,c=`${this.url}/tile/${o}/${t}/${i}`,u={...this._slices?n?{variable:s.transposedVariableName}:{sliceId:s.sliceId||0}:null,...s.refreshParameters};let f,h;if(r.isBsqTile){const e=(s.bandIds?.length?s.bandIds:[0,1,2]).map(e=>this.request(c,{query:{...u,bandId:e},responseType:"array-buffer",signal:s.signal})),t=await Promise.all(e),i=t.map(e=>e.data.byteLength).reduce((e,t)=>e+t),r=new Uint8Array(i);h=[];let a=0;for(const{data:s}of t)h.push(a),r.set(new Uint8Array(s),a),a+=s.byteLength;f=r.buffer}else{f=(await this.request(c,{query:u,responseType:"array-buffer",signal:s.signal})).data}if(!f)return null;const{tileInfo:p}=r,d=n?l.tileSize:p.size,y=/^(mixed|jp)/i.test(p.format),x=await this.decodePixelBlock(f,{width:d[0],height:d[1],planes:h?.length,offsets:h,pixelType:null,isPoint:"Elevation"===this.tileType,returnInterleaved:n,noDataValue:this.rasterInfo.noDataValue,applyJpegMask:y});if(null==x)return null;const g=r.blockBoundary[e];if("jpg"!==r.compression||i>g.minCol&&i<g.maxCol&&t>g.minRow&&t<g.maxRow)return x;const{origin:v,blockWidth:S,blockHeight:I}=r,{x:w,y:b}=this.getPyramidPixelSize(e),T=Math.round((a.xmin-v.x)/w)%S,M=Math.round((a.xmax-v.x)/w)%S||S,_=Math.round((v.y-a.ymax)/b)%I,j=Math.round((v.y-a.ymin)/b)%I||I,O=i===g.minCol?T:0,R=t===g.minRow?_:0,z=i===g.maxCol?M:S,N=t===g.maxRow?j:I;return m(x,{x:O,y:R},{width:z-O,height:N-R}),x}getSliceIndex(e){if(!this._slices||null==e||0===e.length)return null;const t=e;for(let i=0;i<this._slices.length;i++){const e=this._slices[i].multidimensionalDefinition;if(e.length===t.length&&!e.some(e=>{const i=t.find(t=>e.variableName===t.variableName&&t.dimensionName===e.dimensionName);if(!i)return!0;return(Array.isArray(e.values[0])?`${e.values[0][0]}-${e.values[0][1]}`:e.values[0])!==(Array.isArray(i.values[0])?`${i.values[0][0]}-${i.values[0][1]}`:i.values[0])}))return i}return null}async fetchVariableStatisticsHistograms(e,t){const i=this.request(this.url+"/statistics",{query:{variable:e,f:"json"},signal:t}).then(e=>e.data?.statistics),s=this.request(this.url+"/histograms",{query:{variable:e,f:"json"},signal:t}).then(e=>e.data?.histograms),r=await Promise.all([i,s]);return r[0]&&r[0].forEach(e=>{e.avg=e.mean,e.stddev=e.standardDeviation}),r[1]?.[0]?.counts?.length||(r[1]=null),{statistics:r[0]||null,histograms:r[1]||null}}async computeBestPyramidLevelForLocation(e,t={}){if(!this._tilemapCache)return 0;let i=this.identifyPixelLocation(e,0,t.datumTransformation);if(null===i)return null;let s=0;const{maximumPyramidLevel:r}=this.rasterInfo.storageInfo;let a=r-s+this._levelOffset;const l=i.srcLocation;for(;a>=0;){try{if("available"===await this._tilemapCache.fetchAvailability(a,i.row,i.col,t))break}catch{}if(a--,s++,i=this.identifyPixelLocation(l,s,t.datumTransformation),null===i)return null}return-1===a||null==i?null:s}async _open(e){const r=e?.signal,a=this.sourceJSON?{data:this.sourceJSON}:await this.request(this.url,{query:{f:"json"},signal:r});a.ssl&&(this.url=this.url.replace(/^http:/i,"https:"));const l=a.data;if(this.sourceJSON=l,!l)throw new t("imageserverraster:open","cannot initialize tiled image service, missing service info");if(!l.tileInfo)throw new t("imageserverraster:open","use ImageryLayer to open non-tiled image services");this._fixScaleInServiceInfo();const n=["jpg","jpeg","png","png8","png24","png32","mixed"];this.tileType=l.cacheType,null==this.tileType&&(n.includes(l.tileInfo.format.toLowerCase())?this.tileType="Map":"lerc"===l.tileInfo.format.toLowerCase()?this.tileType="Elevation":this.tileType="Raster"),this.datasetName=l.name?.slice(l.name.indexOf("/")+1)??"";const o=await this._fetchRasterInfo({signal:r});if(null==o)throw new t("image-server-raster:open","cannot initialize image service");y(o,l);const c="Map"===this.tileType?v(l.tileInfo,l):p.fromJSON(l.tileInfo);i(c);const[m,u]=this._computeMinMaxLOD(o,c),{extent:f,pixelSize:x}=o,g=.001*Math.min(x.x,x.y);(x.x!==x.y||Math.abs(m.resolution-x.x)>g)&&(x.x=x.y=m.resolution,o.width=Math.ceil((f.xmax-f.xmin)/x.x-.1),o.height=Math.ceil((f.ymax-f.ymin)/x.y-.1));const I=m.level-u.level,[w,b]=c.size,T=[],M=[],{lods:_}=c;_.forEach((e,t)=>{e.level>=u.level&&e.level<=m.level&&T.push({x:e.resolution,y:e.resolution}),t<_.length-1&&M.push(Math.round(10*e.resolution/_[t+1].resolution)/10)}),T.sort((e,t)=>e.x-t.x);const j=this.computeBlockBoundary(f,w,b,c.origin,T,I),O=T.length>1?T.slice(1):null;let R;l.transposeInfo&&(R={tileSize:[l.transposeInfo.rows,l.transposeInfo.cols],packetSize:o.keyProperties?._yxs.PacketSize??0});const z=M.length<=1||M.length>=3&&M.slice(0,-1).every(e=>e===M[0])?M[0]??2:Math.round(10/(u.resolution/m.resolution)**(-1/I))/10,N=!!l.bsq&&"Raster"===this.tileType;if(o.storageInfo=new h({blockWidth:c.size[0],blockHeight:c.size[1],pyramidBlockWidth:c.size[0],pyramidBlockHeight:c.size[1],pyramidResolutions:O,pyramidScalingFactor:z,compression:c.format,origin:c.origin,firstPyramidLevel:1,maximumPyramidLevel:I,tileInfo:c,isBsqTile:N,transposeInfo:R,blockBoundary:j}),S(o),this._set("rasterInfo",o),l.capabilities.toLowerCase().includes("tilemap")){const e={tileInfo:o.storageInfo.tileInfo,parsedUrl:s(this.url),url:this.url,tileServers:[]};this._tilemapCache=new d({layer:e})}}async _fetchRasterInfo(e){const t=this.sourceJSON;if("Map"===this.tileType){const e=t.fullExtent||t.extent,i=Math.ceil((e.xmax-e.xmin)/t.pixelSizeX-.1),s=Math.ceil((e.ymax-e.ymin)/t.pixelSizeY-.1),r=o.fromJSON(t.spatialReference||e.spatialReference),a=new n({x:t.pixelSizeX,y:t.pixelSizeY,spatialReference:r});return new f({width:i,height:s,bandCount:3,extent:l.fromJSON(e),spatialReference:r,pixelSize:a,pixelType:"u8",statistics:null,keyProperties:{DataType:"processed"}})}const i={...e,query:{...this.ioConfig.customFetchParameters,f:"json"}},s=x(this.url,this.sourceJSON,i),r=t.hasMultidimensions?this.request(`${this.url}/slices`,i).then(e=>e.data?.slices).catch(()=>null):null,a=await Promise.all([s,r]);return this._slices=a[1],a[0]}_fixScaleInServiceInfo(){const{sourceJSON:e}=this;e.minScale&&e.minScale<0&&(e.minScale=0),e.maxScale&&e.maxScale<0&&(e.maxScale=0)}_computeMinMaxLOD(e,t){const{pixelSize:i}=e,s=.5/e.width*i.x,{lods:r}=t,a=t.lodAt(Math.max.apply(null,r.map(e=>e.level))),l=t.lodAt(Math.min.apply(null,r.map(e=>e.level))),{tileType:n}=this;if("Map"===n)return this._levelOffset=r[0].level,[a,l];if("Raster"===n){return[r.find(e=>e.resolution===i.x)??a,l]}const{minScale:o,maxScale:c}=this.sourceJSON;let m=a;c>0&&(m=r.find(e=>Math.abs(e.scale-c)<s),m||(m=r.filter(e=>e.scale>c).sort((e,t)=>e.scale>t.scale?1:-1)[0]??a));let u=l;return o>0&&(u=r.find(e=>Math.abs(e.scale-o)<s)??l,this._levelOffset=u.level-l.level),[m,u]}};function v(e,t){if(!e)return null;const{minScale:i,maxScale:s,minLOD:r,maxLOD:a}=t;if(null!=r&&null!=a)return p.fromJSON({...e,lods:e.lods.filter(({level:e})=>null!=e&&e>=r&&e<=a)});if(0!==i&&0!==s){const t=e=>Math.round(1e4*e)/1e4,r=i?t(i):1/0,a=s?t(s):-1/0;return p.fromJSON({...e,lods:e.lods.filter(e=>{const i=t(e.scale);return i<=r&&i>=a})})}return p.fromJSON(e)}function S(e){const{extent:t,spatialReference:i}=e;t.xmin>-1&&t.xmax>181&&i?.wkid&&i.isGeographic&&(e.nativeExtent=e.extent,e.transform=new u,e.extent=e.transform.forwardTransform(t))}e([r({type:String,json:{write:!0}})],g.prototype,"datasetFormat",void 0),e([r()],g.prototype,"tileType",void 0),g=e([a("esri.layers.raster.datasets.ImageServerRaster")],g);const I=g;export{I as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
-
import
|
|
2
|
+
import e from"../../../core/Error.js";import{isAborted as t,createAbortError as a}from"../../../core/promiseUtils.js";import{F as n}from"../../../chunks/Zlib.js";async function r(n,r,o){if(!n||n.byteLength<10)throw new e("imagecanvasdecoder: decode","required a valid encoded data as input.");let{width:h,height:c,format:d}=r;const{applyJpegMask:l}=r;if(l&&(!h||!c))throw new e("imagecanvasdecoder: decode","image width and height are needed to apply jpeg mask directly to canvas");let g=null;"jpg"===d&&l&&h&&c&&(g=i(n,{width:h,height:c}));try{const e=new Blob([new Uint8Array(n)],{type:"image/"+d=="jpg"?"jpeg":d}),r=await createImageBitmap(e);if(t(o))throw a();h=r.width,c=r.height;const i=new OffscreenCanvas(h,c),l=i.getContext("2d");l.drawImage(r,0,0);const s=l.getImageData(0,0,h,c).data,w=h*c,m=new Uint8Array(w),p=new Uint8Array(w),f=new Uint8Array(w);if(g)for(let t=0;t<w;t++)m[t]=s[4*t],p[t]=s[4*t+1],f[t]=s[4*t+2];else{g=new Uint8Array(w);for(let e=0;e<w;e++)m[e]=s[4*e],p[e]=s[4*e+1],f[e]=s[4*e+2],g[e]=s[4*e+3]}return i.width=0,i.height=0,{width:h,height:c,pixels:[m,p,f],mask:g,pixelType:"u8"}}catch{throw new e("imagecanvasdecoder: decode","cannot load image")}}function i(e,t){try{const a=new Uint8Array(e);let r=Math.ceil(a.length/2);const i=a.length-2;for(;r<i&&(255!==a[r]||217!==a[r+1]);r++);r+=2;let o=null;if(r<a.length-1){const e=new n(a.subarray(r)).getBytes();o=new Uint8Array(t.width*t.height);let i=0;for(let t=0;t<e.length;t++)for(let a=7;a>=0;a--)o[i++]=e[t]>>a&1}return o}catch{return null}}export{r as decode};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
-
import{J as t}from"../../../chunks/Jpg.js";import{F as e}from"../../../chunks/Zlib.js";class r{static decode(r,n=!1){const s=new Uint8Array(r),l=new t;l.parse(s);const{width:o,height:a,numComponents:i,eof:f}=l,h=l.getData(o,a,!0),c=o*a;let u,g=null;if(
|
|
2
|
+
import{J as t}from"../../../chunks/Jpg.js";import{F as e}from"../../../chunks/Zlib.js";class r{static decode(r,n=!1){const s=new Uint8Array(r),l=new t;l.parse(s);const{width:o,height:a,numComponents:i,eof:f}=l,h=l.getData(o,a,!0),c=o*a;let u,g=null;if(n&&f<s.length-1)try{const t=new e(s.subarray(f)).getBytes();g=new Uint8Array(c);let r=0;for(let e=0;e<t.length;e++)for(let n=7;n>=0;n--)g[r++]=t[e]>>n&1}catch{}if(1===i&&h.length===o*a){const t=new Uint8Array(h.buffer);u=[t,t,t]}else{u=[];for(let e=0;e<3;e++)u.push(new Uint8Array(c));let t=0;for(let e=0;e<c;e++)for(let r=0;r<3;r++)u[r][e]=h[t++]}return{width:o,height:a,pixels:u,mask:g}}}export{r as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
-
import t from"../../../core/Error.js";import{assertIsSome as e}from"../../../core/maybe.js";import a from"./ImageCanvasDecoder.js";import i from"./JpgPlus.js";import{load as s,decode as r}from"./Lerc.js";import{decode as n}from"./Lzw.js";import{convertNoDataToMask as o}from"./pixelRangeUtils.js";import{F as h}from"../../../chunks/Zlib.js";import{load as c,decode as l}from"./Qb3.js";import p from"./Raw.js";import{decodeTileOrStrip as d,decode as u}from"./TiffDecoder.js";import{isPlatformLittleEndian as f}from"./utils.js";import m from"../../support/PixelBlock.js";import w from"../../support/SimpleBandStatistics.js";var g=function(t){var e,a,i,s,r,n;function o(t){var e,a,i,s,r,n,o,h,c,l,p,d,u;for(this.data=t,this.pos=8,this.palette=[],this.imgData=[],this.transparency={},this.animation=null,this.text={},r=null;;){switch(e=this.readUInt32(),h=function(){var t,e;for(e=[],t=0;t<4;++t)e.push(String.fromCharCode(this.data[this.pos++]));return e}.call(this).join(""),h){case"IHDR":this.width=this.readUInt32(),this.height=this.readUInt32(),this.bits=this.data[this.pos++],this.colorType=this.data[this.pos++],this.compressionMethod=this.data[this.pos++],this.filterMethod=this.data[this.pos++],this.interlaceMethod=this.data[this.pos++];break;case"acTL":this.animation={numFrames:this.readUInt32(),numPlays:this.readUInt32()||1/0,frames:[]};break;case"PLTE":this.palette=this.read(e);break;case"fcTL":r&&this.animation.frames.push(r),this.pos+=4,r={width:this.readUInt32(),height:this.readUInt32(),xOffset:this.readUInt32(),yOffset:this.readUInt32()},s=this.readUInt16(),i=this.readUInt16()||100,r.delay=1e3*s/i,r.disposeOp=this.data[this.pos++],r.blendOp=this.data[this.pos++],r.data=[];break;case"IDAT":case"fdAT":for("fdAT"===h&&(this.pos+=4,e-=4),t=(null!=r?r.data:void 0)||this.imgData,p=0;0<=e?p<e:p>e;0<=e?++p:--p)t.push(this.data[this.pos++]);break;case"tRNS":switch(this.transparency={},this.colorType){case 3:if(this.transparency.indexed=this.read(e),(c=255-this.transparency.indexed.length)>0)for(d=0;0<=c?d<c:d>c;0<=c?++d:--d)this.transparency.indexed.push(255);break;case 0:this.transparency.grayscale=this.read(e)[0];break;case 2:this.transparency.rgb=this.read(e)}break;case"tEXt":n=(l=this.read(e)).indexOf(0),o=String.fromCharCode.apply(String,l.slice(0,n)),this.text[o]=String.fromCharCode.apply(String,l.slice(n+1));break;case"IEND":return r&&this.animation.frames.push(r),this.colors=function(){switch(this.colorType){case 0:case 3:case 4:return 1;case 2:case 6:return 3}}.call(this),this.hasAlphaChannel=4===(u=this.colorType)||6===u,a=this.colors+(this.hasAlphaChannel?1:0),this.pixelBitlength=this.bits*a,this.colorSpace=function(){switch(this.colors){case 1:return"DeviceGray";case 3:return"DeviceRGB"}}.call(this),void(this.imgData=new Uint8Array(this.imgData));default:this.pos+=e}if(this.pos+=4,this.pos>this.data.length)throw new Error("Incomplete or corrupt PNG file")}}return o.load=function(t,e,a){var i;return"function"==typeof e&&(a=e),(i=new XMLHttpRequest).open("GET",t,!0),i.responseType="arraybuffer",i.onload=function(){var t;return t=new o(new Uint8Array(i.response||i.mozResponseArrayBuffer)),"function"==typeof(null!=e?e.getContext:void 0)&&t.render(e),"function"==typeof a?a(t):void 0},i.send(null)},a=1,i=2,e=0,o.prototype.read=function(t){var e,a;for(a=[],e=0;0<=t?e<t:e>t;0<=t?++e:--e)a.push(this.data[this.pos++]);return a},o.prototype.readUInt32=function(){return this.data[this.pos++]<<24|this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++]},o.prototype.readUInt16=function(){return this.data[this.pos++]<<8|this.data[this.pos++]},o.prototype.decodePixels=function(t){var e,a,i,s,r,n,o,c,l,p,d,u,f,m,w,g,y,x,b,k,T,C,I;if(null==t&&(t=this.imgData),0===t.length)return new Uint8Array(0);for(t=(t=new h(t)).getBytes(),g=(u=this.pixelBitlength/8)*this.width,f=new Uint8Array(g*this.height),n=t.length,w=0,m=0,a=0;m<n;){switch(t[m++]){case 0:for(s=b=0;b<g;s=b+=1)f[a++]=t[m++];break;case 1:for(s=k=0;k<g;s=k+=1)e=t[m++],r=s<u?0:f[a-u],f[a++]=(e+r)%256;break;case 2:for(s=T=0;T<g;s=T+=1)e=t[m++],i=(s-s%u)/u,y=w&&f[(w-1)*g+i*u+s%u],f[a++]=(y+e)%256;break;case 3:for(s=C=0;C<g;s=C+=1)e=t[m++],i=(s-s%u)/u,r=s<u?0:f[a-u],y=w&&f[(w-1)*g+i*u+s%u],f[a++]=(e+Math.floor((r+y)/2))%256;break;case 4:for(s=I=0;I<g;s=I+=1)e=t[m++],i=(s-s%u)/u,r=s<u?0:f[a-u],0===w?y=x=0:(y=f[(w-1)*g+i*u+s%u],x=i&&f[(w-1)*g+(i-1)*u+s%u]),o=r+y-x,c=Math.abs(o-r),p=Math.abs(o-y),d=Math.abs(o-x),l=c<=p&&c<=d?r:p<=d?y:x,f[a++]=(e+l)%256;break;default:throw new Error("Invalid filter algorithm: "+t[m-1])}w++}return f},o.prototype.decodePalette=function(){var t,e,a,i,s,r,n,o,h;for(a=this.palette,r=this.transparency.indexed||[],s=new Uint8Array((r.length||0)+a.length),i=0,a.length,t=0,e=n=0,o=a.length;n<o;e=n+=3)s[i++]=a[e],s[i++]=a[e+1],s[i++]=a[e+2],s[i++]=null!=(h=r[t++])?h:255;return s},o.prototype.copyToImageData=function(t,e){var a,i,s,r,n,o,h,c,l,p,d;if(i=this.colors,l=null,a=this.hasAlphaChannel,this.palette.length&&(l=null!=(d=this._decodedPalette)?d:this._decodedPalette=this.decodePalette(),i=4,a=!0),c=(s=t.data||t).length,n=l||e,r=o=0,1===i)for(;r<c;)h=l?4*e[r/4]:o,p=n[h++],s[r++]=p,s[r++]=p,s[r++]=p,s[r++]=a?n[h++]:this.transparency.grayscale&&this.transparency.grayscale===p?0:255,o=h;else for(;r<c;)h=l?4*e[r/4]:o,s[r++]=n[h++],s[r++]=n[h++],s[r++]=n[h++],s[r++]=a?n[h++]:this.transparency.rgb&&this.transparency.rgb[1]===n[h-3]&&this.transparency.rgb[3]===n[h-2]&&this.transparency.rgb[5]===n[h-1]?0:255,o=h},o.prototype.decode=function(){var t;return t=new Uint8Array(this.width*this.height*4),this.copyToImageData(t,this.decodePixels()),t},r=t.document&&t.document.createElement("canvas"),n=r&&r.getContext("2d"),s=function(t){var e;return n.width=t.width,n.height=t.height,n.clearRect(0,0,t.width,t.height),n.putImageData(t,0,0),(e=new Image).src=r.toDataURL(),e},o.prototype.decodeFrames=function(t){var e,a,i,r,n,o,h,c;if(this.animation){for(c=[],a=n=0,o=(h=this.animation.frames).length;n<o;a=++n)e=h[a],i=t.createImageData(e.width,e.height),r=this.decodePixels(new Uint8Array(e.data)),this.copyToImageData(i,r),e.imageData=i,c.push(e.image=s(i));return c}},o.prototype.renderFrame=function(t,s){var r,n,o;return r=(n=this.animation.frames)[s],o=n[s-1],0===s&&t.clearRect(0,0,this.width,this.height),(null!=o?o.disposeOp:void 0)===a?t.clearRect(o.xOffset,o.yOffset,o.width,o.height):(null!=o?o.disposeOp:void 0)===i&&t.putImageData(o.imageData,o.xOffset,o.yOffset),r.blendOp===e&&t.clearRect(r.xOffset,r.yOffset,r.width,r.height),t.drawImage(r.image,r.xOffset,r.yOffset)},o.prototype.animate=function(t){var e,a,i,s,r,n,o=this;return a=0,n=this.animation,s=n.numFrames,i=n.frames,r=n.numPlays,(e=function(){var n,h;if(n=a++%s,h=i[n],o.renderFrame(t,n),s>1&&a/s<r)return o.animation._timeout=setTimeout(e,h.delay)})()},o.prototype.stopAnimation=function(){var t;return clearTimeout(null!=(t=this.animation)?t._timeout:void 0)},o.prototype.render=function(t){var e,a;return t._png&&t._png.stopAnimation(),t._png=this,t.width=this.width,t.height=this.height,e=t.getContext("2d"),this.animation?(this.decodeFrames(e),this.animate(e)):(a=e.createImageData(this.width,this.height),this.copyToImageData(a,this.decodePixels()),e.putImageData(a,0,0))},o}(self);const y=new Set(["jpg","png","bmp","gif"]);async function x(e,a){if(!f)throw new t("rasterCoded:decode","lerc decoder is not supported on big endian platform");await s();const{offset:i}=a,{width:n,height:o,pixelType:h,statistics:c,depthCount:l,noDataValues:p,bandMasks:d,pixels:u,mask:g}=r(e,{inputOffset:i,returnInterleaved:a.returnInterleaved}),y=new m({width:n,height:o,pixelType:h.toLowerCase(),pixels:u,mask:g,statistics:c.map(({minValue:t,maxValue:e})=>new w(t,e)),bandMasks:d,depthCount:l,noDataValues:p});return c?.length||y.updateStatistics(),y}async function b(e,a){await c();const i=l(e);if(!i)throw new t("rasterCodec:decode","failed to decode the input data.");const{width:s,height:r,pixels:n,pixelType:o}=i,h=new m({width:s,height:r,pixelType:o,pixels:n});return h.updateStatistics(),h}async function k(t,a){const i=await u(t,{...a,noDataValue:a.tiffNoDataValue,matchAllNoData:a.matchAllNoData});e(i);const s=new m({width:i.width,height:i.height,pixels:i.pixels,pixelType:i.pixelType.toLowerCase(),mask:i.mask,bandMasks:i.bandMasks,statistics:null});return s.updateStatistics(),s}async function T(t,e){const a=await d(t,e.customOptions),i=new m({width:a.width,height:a.height,pixels:a.pixels,pixelType:a.pixelType.toLowerCase(),mask:a.mask,statistics:null});return i.updateStatistics(),i}function C(t,e){const a=e.pixelType||"u8",i=m.getPixelArrayConstructor(a),s="u8"===a?t:new i(t.buffer),r=[],n=e.planes||1;if(1===n)r.push(s);else for(let h=0;h<n;h++){const a=(e.width||1)*(e.height||t.length),o=new i(a);for(let t=0;t<a;t++)o[t]=s[t*n+h];r.push(o)}const o=new m({width:e.width||1,height:e.height||t.length,pixels:r,pixelType:a,statistics:null});return o.updateStatistics(),o}function I(t,e){return C(new h(new Uint8Array(t)).getBytes(),e)}function A(t,e){return C(n(t,e.offset,e.eof,!e.isInputBigEndian),e)}function v(t,e,a){const{pixelTypeCtor:i}=P(e.pixelType),s=(0,p.decode)(t,{width:e.width,height:e.height,pixelType:i,format:a}),r=new m({width:e.width,height:e.height,pixels:s.pixels,pixelType:e.pixelType,mask:s.mask,statistics:null});return r.updateStatistics(),r}function D(t,e){const a=i.decode(t,e.hasNoZlibMask??void 0),s=new m({width:a.width,height:a.height,pixels:a.pixels,pixelType:"u8",mask:a.mask,statistics:null});return s.updateStatistics(),s}function U(t,e){const a=new Uint8Array(t),i=new g(a),{width:s,height:r}=e,n=s*r,o=i.decode();let h,c=0,l=0;const p=new Uint8Array(n);for(c=0;c<n;c++)p[c]=o[4*c+3];const d=new m({width:s,height:r,pixels:[],pixelType:"u8",mask:p,statistics:[]});for(c=0;c<3;c++){for(h=new Uint8Array(n),l=0;l<n;l++)h[l]=o[4*l+c];d.addData({pixels:h})}return d.updateStatistics(),d}async function S(t,e,i,s){const r=new a,n={applyJpegMask:!1,format:e,...i},o=await r.decode(t,n,s),h=new m(o);return h.updateStatistics(),h}function j(e){if(null==e)throw new t("rasterCodec:decode","parameter encodeddata is required.");const a=new Uint8Array(e,0,10);let i="";return 255===a[0]&&216===a[1]?i="jpg":137===a[0]&&80===a[1]&&78===a[2]&&71===a[3]?i="png":67===a[0]&&110===a[1]&&116===a[2]&&90===a[3]&&73===a[4]&&109===a[5]&&97===a[6]&&103===a[7]&&101===a[8]&&32===a[9]?i="lerc":76===a[0]&&101===a[1]&&114===a[2]&&99===a[3]&&50===a[4]&&32===a[5]?i="lerc2":73===a[0]&&73===a[1]&&42===a[2]&&0===a[3]||77===a[0]&&77===a[1]&&0===a[2]&&42===a[3]||73===a[0]&&73===a[1]&&43===a[2]&&0===a[3]||77===a[0]&&77===a[1]&&0===a[2]&&43===a[3]?i="tiff":71===a[0]&&73===a[1]&&70===a[2]?i="gif":66===a[0]&&77===a[1]?i="bmp":81===a[0]&&66===a[1]&&51===a[2]?i="qb3":String.fromCharCode.apply(null,a).toLowerCase().includes("error")&&(i="error"),i}function O(e){let a=null;switch(e){case"lerc":case"lerc2":a=x;break;case"jpg":a=D;break;case"png":a=U;break;case"bsq":case"bip":a=(t,a)=>v(t,a,e);break;case"tiff":a=k;break;case"deflate":a=I;break;case"lzw":a=A;break;case"qb3":a=b;break;case"error":a=()=>{throw new t("rasterCodec:decode","input data contains error")};break;default:a=()=>{throw new t("rasterCodec:decode","unsupported raster format")}}return a}function P(t){let e=null,a=null;switch(t?t.toLowerCase():"f32"){case"u1":case"u2":case"u4":case"u8":a=255,e=Uint8Array;break;case"u16":a=a||65535,e=Uint16Array;break;case"u32":a=a||2**32-1,e=Uint32Array;break;case"s8":a=a||-128,e=Int8Array;break;case"s16":a=a||-32768,e=Int16Array;break;case"s32":a=a||0-2**31,e=Int32Array;break;default:e=Float32Array}return{pixelTypeCtor:e,noDataValue:a}}function M(t,e=1){if(!t)return;const{pixels:a,width:i,height:s,mask:r}=t;if(!a||0===a.length)return;const n=i-1,o=s-1,h=[];let c=null;const l=m.getPixelArrayConstructor(t.pixelType);if(0===e){for(const t of a){const e=new l(n*o);for(let a=0;a<o;a++){const s=a*i;for(let i=0;i<n;i++)e[a*n+i]=t[s+i]}h.push(e)}if(null!=r){c=new Uint8Array(n*o);for(let t=0;t<o;t++){const e=t*i;for(let a=0;a<n;a++)c[t*n+a]=r[e+a]}}}else{for(const t of a){const e=new l(n*o);for(let a=0;a<o;a++){const s=a*i;for(let r=0;r<n;r++)e[a*n+r]=(t[s+r]+t[s+r+1]+t[s+i+r]+t[s+i+r+1])/4}h.push(e)}if(r){c=new Uint8Array(n*o);for(let t=0;t<o;t++){const e=t*i;for(let a=0;a<n;a++)c[t*n+a]=Math.min.apply(null,[r[e+a],r[e+a+1],r[e+i+a],r[e+i+a+1]])}}}t.width=n,t.height=o,t.mask=c,t.pixels=h}function L(t){let e=j(t);return"lerc2"===e?e="lerc":"error"===e&&(e=""),e}async function R(e,a={},i){if(null==e)throw new t("rasterCodec:decode","missing encodeddata parameter.");let s=a.format?.toLowerCase();if(!("bsq"!==s&&"bip"!==s||null!=a.width&&null!=a.height))throw new t("rasterCodec:decode","requires width and height in options parameter.");if("tiff"===s&&a.customOptions)return T(e,a);if((!s||"bsq"!==s&&"bip"!==s&&"deflate"!==s&&"lzw"!==s)&&(s=j(e)),a.useCanvas&&y.has(s))return S(e,s,a,i);const r=O(s);let n;a.isPoint&&(null!=(a={...a}).width&&a.width++,null!=a.height&&a.height++);const{offsets:h}=a;if(h&&h.length>1){const t=h.map((t,i)=>r(e.slice(t,h[i+1]),a)),i=await Promise.all(t);n=i[0],n.pixels=i.map(t=>t.pixels[0]);const s=i.map(t=>t.mask);i.some(t=>null!=t)&&(s.forEach((t,e)=>{null==t&&(s[e]=new Uint8Array(n.width*n.height).fill(255))}),n.bandMasks=s,n.mask=m.combineBandMasks(s)),n.updateStatistics()}else n=await r(e,{...a,offset:h?.[0]??a.offset});return"jpg"!==s&&null!=a.noDataValue&&1===n.depthCount&&o(n,a.noDataValue,{customFloatTolerance:a.tolerance}),a.isPoint&&M(n),n}export{R as decode,L as getFormat};
|
|
2
|
+
import t from"../../../core/Error.js";import{assertIsSome as e}from"../../../core/maybe.js";import{isAbortError as a}from"../../../core/promiseUtils.js";import{decode as i}from"./ImageCanvasDecoder.js";import s from"./JpgPlus.js";import{load as r,decode as n}from"./Lerc.js";import{decode as o}from"./Lzw.js";import{convertNoDataToMask as h}from"./pixelRangeUtils.js";import{F as c}from"../../../chunks/Zlib.js";import{load as l,decode as p}from"./Qb3.js";import d from"./Raw.js";import{decodeTileOrStrip as u,decode as f}from"./TiffDecoder.js";import{isPlatformLittleEndian as m}from"./utils.js";import w from"../../support/PixelBlock.js";import g from"../../support/SimpleBandStatistics.js";var y=function(t){var e,a,i,s,r,n;function o(t){var e,a,i,s,r,n,o,h,c,l,p,d,u;for(this.data=t,this.pos=8,this.palette=[],this.imgData=[],this.transparency={},this.animation=null,this.text={},r=null;;){switch(e=this.readUInt32(),h=function(){var t,e;for(e=[],t=0;t<4;++t)e.push(String.fromCharCode(this.data[this.pos++]));return e}.call(this).join(""),h){case"IHDR":this.width=this.readUInt32(),this.height=this.readUInt32(),this.bits=this.data[this.pos++],this.colorType=this.data[this.pos++],this.compressionMethod=this.data[this.pos++],this.filterMethod=this.data[this.pos++],this.interlaceMethod=this.data[this.pos++];break;case"acTL":this.animation={numFrames:this.readUInt32(),numPlays:this.readUInt32()||1/0,frames:[]};break;case"PLTE":this.palette=this.read(e);break;case"fcTL":r&&this.animation.frames.push(r),this.pos+=4,r={width:this.readUInt32(),height:this.readUInt32(),xOffset:this.readUInt32(),yOffset:this.readUInt32()},s=this.readUInt16(),i=this.readUInt16()||100,r.delay=1e3*s/i,r.disposeOp=this.data[this.pos++],r.blendOp=this.data[this.pos++],r.data=[];break;case"IDAT":case"fdAT":for("fdAT"===h&&(this.pos+=4,e-=4),t=(null!=r?r.data:void 0)||this.imgData,p=0;0<=e?p<e:p>e;0<=e?++p:--p)t.push(this.data[this.pos++]);break;case"tRNS":switch(this.transparency={},this.colorType){case 3:if(this.transparency.indexed=this.read(e),(c=255-this.transparency.indexed.length)>0)for(d=0;0<=c?d<c:d>c;0<=c?++d:--d)this.transparency.indexed.push(255);break;case 0:this.transparency.grayscale=this.read(e)[0];break;case 2:this.transparency.rgb=this.read(e)}break;case"tEXt":n=(l=this.read(e)).indexOf(0),o=String.fromCharCode.apply(String,l.slice(0,n)),this.text[o]=String.fromCharCode.apply(String,l.slice(n+1));break;case"IEND":return r&&this.animation.frames.push(r),this.colors=function(){switch(this.colorType){case 0:case 3:case 4:return 1;case 2:case 6:return 3}}.call(this),this.hasAlphaChannel=4===(u=this.colorType)||6===u,a=this.colors+(this.hasAlphaChannel?1:0),this.pixelBitlength=this.bits*a,this.colorSpace=function(){switch(this.colors){case 1:return"DeviceGray";case 3:return"DeviceRGB"}}.call(this),void(this.imgData=new Uint8Array(this.imgData));default:this.pos+=e}if(this.pos+=4,this.pos>this.data.length)throw new Error("Incomplete or corrupt PNG file")}}return o.load=function(t,e,a){var i;return"function"==typeof e&&(a=e),(i=new XMLHttpRequest).open("GET",t,!0),i.responseType="arraybuffer",i.onload=function(){var t;return t=new o(new Uint8Array(i.response||i.mozResponseArrayBuffer)),"function"==typeof(null!=e?e.getContext:void 0)&&t.render(e),"function"==typeof a?a(t):void 0},i.send(null)},a=1,i=2,e=0,o.prototype.read=function(t){var e,a;for(a=[],e=0;0<=t?e<t:e>t;0<=t?++e:--e)a.push(this.data[this.pos++]);return a},o.prototype.readUInt32=function(){return this.data[this.pos++]<<24|this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++]},o.prototype.readUInt16=function(){return this.data[this.pos++]<<8|this.data[this.pos++]},o.prototype.decodePixels=function(t){var e,a,i,s,r,n,o,h,l,p,d,u,f,m,w,g,y,x,b,k,T,I,A;if(null==t&&(t=this.imgData),0===t.length)return new Uint8Array(0);for(t=(t=new c(t)).getBytes(),g=(u=this.pixelBitlength/8)*this.width,f=new Uint8Array(g*this.height),n=t.length,w=0,m=0,a=0;m<n;){switch(t[m++]){case 0:for(s=b=0;b<g;s=b+=1)f[a++]=t[m++];break;case 1:for(s=k=0;k<g;s=k+=1)e=t[m++],r=s<u?0:f[a-u],f[a++]=(e+r)%256;break;case 2:for(s=T=0;T<g;s=T+=1)e=t[m++],i=(s-s%u)/u,y=w&&f[(w-1)*g+i*u+s%u],f[a++]=(y+e)%256;break;case 3:for(s=I=0;I<g;s=I+=1)e=t[m++],i=(s-s%u)/u,r=s<u?0:f[a-u],y=w&&f[(w-1)*g+i*u+s%u],f[a++]=(e+Math.floor((r+y)/2))%256;break;case 4:for(s=A=0;A<g;s=A+=1)e=t[m++],i=(s-s%u)/u,r=s<u?0:f[a-u],0===w?y=x=0:(y=f[(w-1)*g+i*u+s%u],x=i&&f[(w-1)*g+(i-1)*u+s%u]),o=r+y-x,h=Math.abs(o-r),p=Math.abs(o-y),d=Math.abs(o-x),l=h<=p&&h<=d?r:p<=d?y:x,f[a++]=(e+l)%256;break;default:throw new Error("Invalid filter algorithm: "+t[m-1])}w++}return f},o.prototype.decodePalette=function(){var t,e,a,i,s,r,n,o,h;for(a=this.palette,r=this.transparency.indexed||[],s=new Uint8Array((r.length||0)+a.length),i=0,a.length,t=0,e=n=0,o=a.length;n<o;e=n+=3)s[i++]=a[e],s[i++]=a[e+1],s[i++]=a[e+2],s[i++]=null!=(h=r[t++])?h:255;return s},o.prototype.copyToImageData=function(t,e){var a,i,s,r,n,o,h,c,l,p,d;if(i=this.colors,l=null,a=this.hasAlphaChannel,this.palette.length&&(l=null!=(d=this._decodedPalette)?d:this._decodedPalette=this.decodePalette(),i=4,a=!0),c=(s=t.data||t).length,n=l||e,r=o=0,1===i)for(;r<c;)h=l?4*e[r/4]:o,p=n[h++],s[r++]=p,s[r++]=p,s[r++]=p,s[r++]=a?n[h++]:this.transparency.grayscale&&this.transparency.grayscale===p?0:255,o=h;else for(;r<c;)h=l?4*e[r/4]:o,s[r++]=n[h++],s[r++]=n[h++],s[r++]=n[h++],s[r++]=a?n[h++]:this.transparency.rgb&&this.transparency.rgb[1]===n[h-3]&&this.transparency.rgb[3]===n[h-2]&&this.transparency.rgb[5]===n[h-1]?0:255,o=h},o.prototype.decode=function(){var t;return t=new Uint8Array(this.width*this.height*4),this.copyToImageData(t,this.decodePixels()),t},r=t.document&&t.document.createElement("canvas"),n=r&&r.getContext("2d"),s=function(t){var e;return n.width=t.width,n.height=t.height,n.clearRect(0,0,t.width,t.height),n.putImageData(t,0,0),(e=new Image).src=r.toDataURL(),e},o.prototype.decodeFrames=function(t){var e,a,i,r,n,o,h,c;if(this.animation){for(c=[],a=n=0,o=(h=this.animation.frames).length;n<o;a=++n)e=h[a],i=t.createImageData(e.width,e.height),r=this.decodePixels(new Uint8Array(e.data)),this.copyToImageData(i,r),e.imageData=i,c.push(e.image=s(i));return c}},o.prototype.renderFrame=function(t,s){var r,n,o;return r=(n=this.animation.frames)[s],o=n[s-1],0===s&&t.clearRect(0,0,this.width,this.height),(null!=o?o.disposeOp:void 0)===a?t.clearRect(o.xOffset,o.yOffset,o.width,o.height):(null!=o?o.disposeOp:void 0)===i&&t.putImageData(o.imageData,o.xOffset,o.yOffset),r.blendOp===e&&t.clearRect(r.xOffset,r.yOffset,r.width,r.height),t.drawImage(r.image,r.xOffset,r.yOffset)},o.prototype.animate=function(t){var e,a,i,s,r,n,o=this;return a=0,n=this.animation,s=n.numFrames,i=n.frames,r=n.numPlays,(e=function(){var n,h;if(n=a++%s,h=i[n],o.renderFrame(t,n),s>1&&a/s<r)return o.animation._timeout=setTimeout(e,h.delay)})()},o.prototype.stopAnimation=function(){var t;return clearTimeout(null!=(t=this.animation)?t._timeout:void 0)},o.prototype.render=function(t){var e,a;return t._png&&t._png.stopAnimation(),t._png=this,t.width=this.width,t.height=this.height,e=t.getContext("2d"),this.animation?(this.decodeFrames(e),this.animate(e)):(a=e.createImageData(this.width,this.height),this.copyToImageData(a,this.decodePixels()),e.putImageData(a,0,0))},o}(self);const x=new Set(["jpg","png","bmp","gif"]);async function b(e,a){if(!m)throw new t("rasterCoded:decode","lerc decoder is not supported on big endian platform");await r();const{offset:i}=a,{width:s,height:o,pixelType:h,statistics:c,depthCount:l,noDataValues:p,bandMasks:d,pixels:u,mask:f}=n(e,{inputOffset:i,returnInterleaved:a.returnInterleaved}),y=new w({width:s,height:o,pixelType:h.toLowerCase(),pixels:u,mask:f,statistics:c.map(({minValue:t,maxValue:e})=>new g(t,e)),bandMasks:d,depthCount:l,noDataValues:p});return c?.length||y.updateStatistics(),y}async function k(e,a){await l();const i=p(e);if(!i)throw new t("rasterCodec:decode","failed to decode the input data.");const{width:s,height:r,pixels:n,pixelType:o}=i,h=new w({width:s,height:r,pixelType:o,pixels:n});return h.updateStatistics(),h}async function T(t,a){const i=await f(t,{...a,noDataValue:a.tiffNoDataValue,matchAllNoData:a.matchAllNoData});e(i);const s=new w({width:i.width,height:i.height,pixels:i.pixels,pixelType:i.pixelType.toLowerCase(),mask:i.mask,bandMasks:i.bandMasks,statistics:null});return s.updateStatistics(),s}async function I(t,e){const a=await u(t,e.customOptions),i=new w({width:a.width,height:a.height,pixels:a.pixels,pixelType:a.pixelType.toLowerCase(),mask:a.mask,statistics:null});return i.updateStatistics(),i}function A(t,e){const a=e.pixelType||"u8",i=w.getPixelArrayConstructor(a),s="u8"===a?t:new i(t.buffer),r=[],n=e.planes||1;if(1===n)r.push(s);else for(let h=0;h<n;h++){const a=(e.width||1)*(e.height||t.length),o=new i(a);for(let t=0;t<a;t++)o[t]=s[t*n+h];r.push(o)}const o=new w({width:e.width||1,height:e.height||t.length,pixels:r,pixelType:a,statistics:null});return o.updateStatistics(),o}function C(t,e){return A(new c(new Uint8Array(t)).getBytes(),e)}function D(t,e){return A(o(t,e.offset,e.eof,!e.isInputBigEndian),e)}function U(t,e,a){const{pixelTypeCtor:i}=M(e.pixelType),s=(0,d.decode)(t,{width:e.width,height:e.height,pixelType:i,format:a}),r=new w({width:e.width,height:e.height,pixels:s.pixels,pixelType:e.pixelType,mask:s.mask,statistics:null});return r.updateStatistics(),r}function v(t,e){const a=s.decode(t,e.applyJpegMask),i=new w({width:a.width,height:a.height,pixels:a.pixels,pixelType:"u8",mask:a.mask,statistics:null});return i.updateStatistics(),i}function S(t,e){const a=new Uint8Array(t),i=new y(a),{width:s,height:r}=e,n=s*r,o=i.decode(),h=new Uint8Array(n);for(let l=0;l<n;l++)h[l]=o[4*l+3];const c=new w({width:s,height:r,pixels:[],pixelType:"u8",mask:h,statistics:[]});for(let l=0;l<3;l++){const t=new Uint8Array(n);for(let e=0;e<n;e++)t[e]=o[4*e+l];c.addData({pixels:t})}return c.updateStatistics(),c}async function j(t,e,a,s){const r={...a,format:e},n=await i(t,r,s),o=new w(n);return o.updateStatistics(),o}function O(e){if(null==e)throw new t("rasterCodec:decode","parameter encodeddata is required.");const a=new Uint8Array(e,0,10);let i="";return 255===a[0]&&216===a[1]?i="jpg":137===a[0]&&80===a[1]&&78===a[2]&&71===a[3]?i="png":67===a[0]&&110===a[1]&&116===a[2]&&90===a[3]&&73===a[4]&&109===a[5]&&97===a[6]&&103===a[7]&&101===a[8]&&32===a[9]?i="lerc":76===a[0]&&101===a[1]&&114===a[2]&&99===a[3]&&50===a[4]&&32===a[5]?i="lerc2":73===a[0]&&73===a[1]&&42===a[2]&&0===a[3]||77===a[0]&&77===a[1]&&0===a[2]&&42===a[3]||73===a[0]&&73===a[1]&&43===a[2]&&0===a[3]||77===a[0]&&77===a[1]&&0===a[2]&&43===a[3]?i="tiff":71===a[0]&&73===a[1]&&70===a[2]?i="gif":66===a[0]&&77===a[1]?i="bmp":81===a[0]&&66===a[1]&&51===a[2]?i="qb3":String.fromCharCode.apply(null,a).toLowerCase().includes("error")&&(i="error"),i}function P(e){let a=null;switch(e){case"lerc":case"lerc2":a=b;break;case"jpg":a=v;break;case"png":a=S;break;case"bsq":case"bip":a=(t,a)=>U(t,a,e);break;case"tiff":a=T;break;case"deflate":a=C;break;case"lzw":a=D;break;case"qb3":a=k;break;case"error":a=()=>{throw new t("rasterCodec:decode","input data contains error")};break;default:a=()=>{throw new t("rasterCodec:decode","unsupported raster format")}}return a}function M(t){let e=null,a=null;switch(t?t.toLowerCase():"f32"){case"u1":case"u2":case"u4":case"u8":a=255,e=Uint8Array;break;case"u16":a=a||65535,e=Uint16Array;break;case"u32":a=a||2**32-1,e=Uint32Array;break;case"s8":a=a||-128,e=Int8Array;break;case"s16":a=a||-32768,e=Int16Array;break;case"s32":a=a||0-2**31,e=Int32Array;break;default:e=Float32Array}return{pixelTypeCtor:e,noDataValue:a}}function L(t,e=1){if(!t)return;const{pixels:a,width:i,height:s,mask:r}=t;if(!a||0===a.length)return;const n=i-1,o=s-1,h=[];let c=null;const l=w.getPixelArrayConstructor(t.pixelType);if(0===e){for(const t of a){const e=new l(n*o);for(let a=0;a<o;a++){const s=a*i;for(let i=0;i<n;i++)e[a*n+i]=t[s+i]}h.push(e)}if(null!=r){c=new Uint8Array(n*o);for(let t=0;t<o;t++){const e=t*i;for(let a=0;a<n;a++)c[t*n+a]=r[e+a]}}}else{for(const t of a){const e=new l(n*o);for(let a=0;a<o;a++){const s=a*i;for(let r=0;r<n;r++)e[a*n+r]=(t[s+r]+t[s+r+1]+t[s+i+r]+t[s+i+r+1])/4}h.push(e)}if(r){c=new Uint8Array(n*o);for(let t=0;t<o;t++){const e=t*i;for(let a=0;a<n;a++)c[t*n+a]=Math.min.apply(null,[r[e+a],r[e+a+1],r[e+i+a],r[e+i+a+1]])}}}t.width=n,t.height=o,t.mask=c,t.pixels=h}function R(t){let e=O(t);return"lerc2"===e?e="lerc":"error"===e&&(e=""),e}async function B(e,i={},s){if(null==e)throw new t("rasterCodec:decode","missing encodeddata parameter.");let r=i.format?.toLowerCase();if(!("bsq"!==r&&"bip"!==r||null!=i.width&&null!=i.height))throw new t("rasterCodec:decode","requires width and height in options parameter.");if("tiff"===r&&i.customOptions)return I(e,i);if((!r||"bsq"!==r&&"bip"!==r&&"deflate"!==r&&"lzw"!==r)&&(r=O(e)),x.has(r))try{return await j(e,r,i,s)}catch(l){if(a(l))throw l}const n=P(r);let o;i.isPoint&&(null!=(i={...i}).width&&i.width++,null!=i.height&&i.height++);const{offsets:c}=i;if(c&&c.length>1){const t=c.map((t,a)=>n(e.slice(t,c[a+1]),i)),a=await Promise.all(t);o=a[0],o.pixels=a.map(t=>t.pixels[0]);const s=a.map(t=>t.mask);a.some(t=>null!=t)&&(s.forEach((t,e)=>{null==t&&(s[e]=new Uint8Array(o.width*o.height).fill(255))}),o.bandMasks=s,o.mask=w.combineBandMasks(s)),o.updateStatistics()}else o=await n(e,{...i,offset:c?.[0]??i.offset});return"jpg"!==r&&null!=i.noDataValue&&1===o.depthCount&&h(o,i.noDataValue,{customFloatTolerance:i.tolerance}),i.isPoint&&L(o),o}export{B as decode,R as getFormat};
|
package/package.json
CHANGED
package/popup/Feature.d.ts
CHANGED
|
@@ -3,15 +3,19 @@ import type EsriMap from "../Map.js";
|
|
|
3
3
|
import type Accessor from "../core/Accessor.js";
|
|
4
4
|
import type Point from "../geometry/Point.js";
|
|
5
5
|
import type SpatialReference from "../geometry/SpatialReference.js";
|
|
6
|
+
import type FeatureAbilities from "./support/FeatureAbilities.js";
|
|
6
7
|
import type { IdentifiableMixin, IdentifiableMixinProperties } from "../core/Identifiable.js";
|
|
7
8
|
import type { SpatialReferenceProperties } from "../geometry/SpatialReference.js";
|
|
8
|
-
import type {
|
|
9
|
+
import type { FeatureFormattedAttributes, LastEditInfo, PopupTemplateContentResolved, RelatedInfo, State } from "./types.js";
|
|
9
10
|
import type { TimeZone } from "../time/types.js";
|
|
10
11
|
import type { MapViewOrSceneView } from "../views/MapViewOrSceneView.js";
|
|
12
|
+
import type { FeatureAbilitiesProperties } from "./support/FeatureAbilities.js";
|
|
11
13
|
import type { GraphicProperties } from "../Graphic.js";
|
|
12
14
|
import type { PointProperties } from "../geometry/Point.js";
|
|
13
15
|
|
|
14
|
-
export interface FeatureProperties extends IdentifiableMixinProperties, Partial<Pick<Feature, "
|
|
16
|
+
export interface FeatureProperties extends IdentifiableMixinProperties, Partial<Pick<Feature, "defaultPopupTemplateEnabled" | "map" | "view">> {
|
|
17
|
+
/** Defines the specific [Abilities](https://developers.arcgis.com/javascript/latest/references/core/widgets/Feature/types/#Abilities) that the [Feature](https://developers.arcgis.com/javascript/latest/references/map-components/components/arcgis-feature/) component should use when querying and displaying its content. */
|
|
18
|
+
abilities?: FeatureAbilitiesProperties;
|
|
15
19
|
/**
|
|
16
20
|
* The [Graphic](https://developers.arcgis.com/javascript/latest/references/core/Graphic/) used to represent the feature.
|
|
17
21
|
*
|
|
@@ -89,7 +93,8 @@ export type PopupViewModelContent = PopupTemplateContentResolved;
|
|
|
89
93
|
export default class Feature extends FeatureSuperclass {
|
|
90
94
|
constructor(properties?: FeatureProperties);
|
|
91
95
|
/** Defines the specific [Abilities](https://developers.arcgis.com/javascript/latest/references/core/widgets/Feature/types/#Abilities) that the [Feature](https://developers.arcgis.com/javascript/latest/references/map-components/components/arcgis-feature/) component should use when querying and displaying its content. */
|
|
92
|
-
|
|
96
|
+
get abilities(): FeatureAbilities;
|
|
97
|
+
set abilities(value: FeatureAbilitiesProperties);
|
|
93
98
|
/** The [PopupTemplate.content](https://developers.arcgis.com/javascript/latest/references/core/PopupTemplate/#content) of the feature. */
|
|
94
99
|
get content(): PopupViewModelContent | null | undefined;
|
|
95
100
|
/**
|
package/popup/Feature.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
-
import{__decorate as t}from"tslib";import e from"../Graphic.js";import{FeatureSetQueryInterceptor as i}from"../arcade/featureset/support/FeatureSetQueryInterceptor.js";import r from"../core/Accessor.js";import{isSome as s}from"../core/arrayUtils.js";import{createTask as o}from"../core/asyncUtils.js";import{IdentifiableMixin as a}from"../core/Identifiable.js";import n from"../core/Logger.js";import{abortMaybe as l}from"../core/maybe.js";import{eachAlways as p,isAbortError as h,throwIfAborted as c}from"../core/promiseUtils.js";import{watch as u,initial as d,when as f}from"../core/reactiveUtils.js";import{throttle as m}from"../core/throttle.js";import{property as g,cast as y,subclass as _}from"../core/accessorSupport/decorators.js";import v from"../geometry/Point.js";import b from"../geometry/SpatialReference.js";import{getGraphicLayer as T}from"../graphic/graphicOriginUtils.js";import I from"./content/TextContent.js";import{compileExpressionInfos as A,formatArcadeValue as x}from"./support/arcadeFeatureUtils.js";import{preLayerQueryCallback as C,preRequestCallback as E,createFieldInfoMap as w,getAllFieldInfos as k,querySourceLayer as F,queryUpdatedFeature as j,isRelatableFeatureSupportedLayer as P,isAssociatedFeatureSupportedLayer as R,formatEditInfo as O,substituteFieldsInLinksAndAttributes as M,graphicCallback as Z,formatAttributes as U,isRelatedField as L}from"./support/featureUtils.js";import{queryLayerInfos as N,queryRelatedFeatures as S,setRelatedFeatures as G,getRelatedFieldInfo as q,createRelatedInfo as H,updateRelatedInfo as z}from"./support/relatedFeatureUtils.js";import{system as B}from"../time/constants.js";var Q;const D=1,J={attachmentsContent:!0,chartAnimation:!0,customContent:!0,expressionContent:!0,fieldsContent:!0,mediaContent:!0,textContent:!0,relationshipContent:!0,utilityNetworkAssociationsContent:!0};let K=class extends(a(r)){static{Q=this}constructor(t){super(t),this._error=null,this._graphicChangedTask=null,this._evaluateExpressionAttributesTask=null,this._expressionAttributes=null,this._graphicExpressionAttributes=null,this.abilities={...J},this.content=null,this.description=null,this.defaultPopupTemplateEnabled=!1,this.formattedAttributes=null,this.graphic=null,this.lastEditInfo=null,this.location=null,this.relatedInfos=new Map,this.title="",this.view=null,this._graphicChangedThrottled=m(this._graphicChanged,()=>this.notifyChange("waitingForContent"),D,this),this._isAllowedContentType=t=>{const{abilities:e}=this;return"attachments"===t.type&&!!e.attachmentsContent||"custom"===t.type&&!!e.customContent||"fields"===t.type&&!!e.fieldsContent||"media"===t.type&&!!e.mediaContent||"text"===t.type&&!!e.textContent||"expression"===t.type&&!!e.expressionContent||"relationship"===t.type&&!!e.relationshipContent||"utility-network-associations"===t.type&&!!e.utilityNetworkAssociationsContent},this._evaluateExpressionAttributesThrottled=m(this._evaluateExpressionAttributes,()=>this.notifyChange("waitingForContent"),D,this),this.addHandles([u(()=>[this.graphic,this._effectivePopupTemplate,this.abilities,this.timeZone],()=>this._graphicChangedThrottled(),d),f(()=>{if(!this._graphicChangedTask?.finished||null==this._graphicChangedTask.value)return null;const t=this._graphicChangedTask.value,e=t?.expressionInfos?.dependencies;return[t,e?.has("view-scale")?this.view?.scale:null,e?.has("view-time-extent")?this.view?.timeExtent?.start:null,e?.has("view-time-extent")?this.view?.timeExtent?.end:null]},([t])=>this._evaluateExpressionAttributesThrottled(t))])}initialize(){this.addHandles([this._graphicChangedThrottled,this._evaluateExpressionAttributesThrottled])}destroy(){this._clear(),this._graphicChangedTask=l(this._graphicChangedTask),this._evaluateExpressionAttributesTask=l(this._evaluateExpressionAttributesTask),this._error=null,this.graphic=null,this.relatedInfos.clear()}static{this.interceptor=new i(C,E)}get _effectivePopupTemplate(){return null!=this.graphic?this.graphic.getEffectivePopupTemplate(this.defaultPopupTemplateEnabled):null}get _fieldInfoMap(){return w(k(this._effectivePopupTemplate),this._layer)}get _layer(){const{graphic:t}=this;return t?T(t):void 0}castAbilities(t){return{...J,...t}}get isFeatureFromTable(){return this._layer?.isTable||!1}get state(){return this.graphic?this._error?"error":this.waitingForContent?"loading":"ready":"disabled"}get spatialReference(){return this.view?.spatialReference??null}set spatialReference(t){this._override("spatialReference",t)}get timeZone(){return this.view?.timeZone??B}set timeZone(t){this._overrideIfSome("timeZone",t)}get map(){return this.view?.map||null}set map(t){this._override("map",t)}get waitingForContent(){const{_graphicChangedThrottled:t,_evaluateExpressionAttributesThrottled:e,_graphicChangedTask:i,_evaluateExpressionAttributesTask:r}=this;return t.hasPendingUpdates()||e.hasPendingUpdates()||null!=i&&!i.finished||null!=r&&!r.finished}async updateGeometry(){const{graphic:t,spatialReference:e,_layer:i}=this;await(i?.load());const r=i?.objectIdField;if(!r||!t||!i)return;const s=t?.attributes?.[r];if(null==s)return;const o=[s];if(!t.geometry){const r=await F({layer:i,graphic:t,outFields:[],objectIds:o,returnGeometry:!0,spatialReference:e}),s=r?.geometry;s&&(t.geometry=s)}}_clear(){this._set("title",""),this._set("content",null),this._set("formattedAttributes",null)}_graphicChanged(){this._evaluateExpressionAttributesTask=l(this._evaluateExpressionAttributesTask),this._graphicChangedTask=l(this._graphicChangedTask),this._graphicChangedTask=o(async t=>{this._error=null,this._clear();const{graphic:e}=this;try{if(!e)return null;const{_layer:i,_effectivePopupTemplate:r}=this,s=this.spatialReference;await j({graphic:e,popupTemplate:r,layer:i,spatialReference:s},{signal:t});const[{value:o},{value:a}]=await p([this._getContent(),this._getTitle()]),[,{value:n}]=await p([this._checkForRelatedFeatures({signal:t}),A(r?.expressionInfos,e)]);return{expressionInfos:n,content:o,title:a}}catch(i){throw h(i)||(this._error=i,n.getLogger(this).error("error","The popupTemplate could not be displayed for this feature.",{error:i,graphic:e,popupTemplate:this._effectivePopupTemplate})),i}})}_compileContentElement(t){return"relationship"===t.type?P(this._layer)?t:void 0:"utility-network-associations"===t.type?R(this._layer)?t:void 0:t}_compileContent(t){if(this.graphic)return Array.isArray(t)?t.filter(this._isAllowedContentType).map(t=>this._compileContentElement(t)).filter(s):"string"==typeof t?new I({text:t}).text:t}_compileLastEditInfo(){const{_effectivePopupTemplate:t,_layer:e,graphic:i,timeZone:r}=this;if(!t)return;const{lastEditInfoEnabled:s}=t,o=e?.editFieldsInfo;return s&&o?O(o,i?.attributes,r,e):void 0}_compileTitle(t){const{_fieldInfoMap:e,_layer:i,graphic:r,_expressionAttributes:s}=this,o=r?.attributes??{},a=this.formattedAttributes?.global??{};return M({attributes:o,fieldInfoMap:e,globalAttributes:a,expressionAttributes:s,layer:i,text:t})}async _getTitle(){const{_effectivePopupTemplate:t,graphic:e}=this;return e?Z({type:"title",value:t?.title,event:{graphic:e}}):null}async _getContent(){const{_effectivePopupTemplate:t,graphic:e}=this;return e?Z({type:"content",value:t?.content,event:{graphic:e}}):null}_evaluateExpressionAttributes({title:t,content:e,expressionInfos:i}){this._evaluateExpressionAttributesTask=l(this._evaluateExpressionAttributesTask),this._evaluateExpressionAttributesTask=o(async r=>{const{graphic:s,map:o,view:a,spatialReference:l,location:p}=this;try{if(!s)return;let n;if(null!=i){const t=[];for(const[e,n]of i.expressions.entries())null!=n?t.push(n.evaluate({graphic:s,interceptor:Q.interceptor,location:p,map:o,options:{signal:r},spatialReference:l,view:a}).then(t=>[e,"string"==typeof t?x(t):t]).catch(()=>[e,void 0])):t.push(Promise.resolve([e,void 0]));n=Object.fromEntries(await Promise.all(t)),c(r)}this._expressionAttributes=n,this._graphicExpressionAttributes={...s.attributes,...n},this._set("formattedAttributes",this._createFormattedAttributes(e)),this._set("title",this._compileTitle(t)),this._set("lastEditInfo",this._compileLastEditInfo()||null),this._set("content",this._compileContent(e)||null)}catch(u){h(u)||(this._error=u,n.getLogger(this).error("error","The popupTemplate could not be displayed for this feature.",{error:u,graphic:s,popupTemplate:this._effectivePopupTemplate}))}})}_createMediaFormattedAttributes({contentElement:t,contentElementIndex:e,formattedAttributes:i}){const{_effectivePopupTemplate:r,graphic:s,relatedInfos:o,_layer:a,_fieldInfoMap:n,_graphicExpressionAttributes:l,timeZone:p}=this;i.content[e]=U({attributes:{...l,...t.attributes},fieldInfoMap:n,fieldInfos:r?.fieldInfos,graphic:s,layer:a,relatedInfos:o,timeZone:p})}_createFieldsFormattedAttributes({contentElement:t,contentElementIndex:e,formattedAttributes:i}){if(t.fieldInfos){const{graphic:r,relatedInfos:s,_layer:o,_fieldInfoMap:a,_graphicExpressionAttributes:n,timeZone:l}=this;i.content[e]=U({attributes:{...n,...t.attributes},fieldInfoMap:a,fieldInfos:t.fieldInfos,graphic:r,isContentFieldInfos:!0,layer:o,relatedInfos:s,timeZone:l})}}_createFormattedAttributes(t){const{_effectivePopupTemplate:e,graphic:i,relatedInfos:r,_layer:s,_fieldInfoMap:o,_graphicExpressionAttributes:a,timeZone:n}=this,l=e?.fieldInfos,p={global:U({attributes:a,fieldInfoMap:o,fieldInfos:l,graphic:i,layer:s,relatedInfos:r,timeZone:n}),content:[]};return Array.isArray(t)&&t.forEach((t,e)=>{"fields"===t.type&&this._createFieldsFormattedAttributes({contentElement:t,contentElementIndex:e,formattedAttributes:p}),"media"===t.type&&this._createMediaFormattedAttributes({contentElement:t,contentElementIndex:e,formattedAttributes:p})}),p}_checkForRelatedFeatures(t){const{graphic:e,_effectivePopupTemplate:i}=this;return this._queryRelatedInfos(e,k(i),t)}async _queryRelatedInfos(t,e,i){const{relatedInfos:r,_layer:s}=this;r.clear();const o=null!=s?.associatedLayer?await(s?.associatedLayer.load(i)):s;if(!o||!t)return;const a=e.filter(t=>!!t.fieldName&&L(t.fieldName));if(!a?.length)return;e.forEach(t=>this._configureRelatedInfo(t,o));const n=await N({relatedInfos:r,layer:o},i);Object.keys(n).forEach(t=>{const e=r.get(t.toString()),i=n[t]?.value;e&&i&&(e.layerInfo=i.data)});const l=await S({graphic:t,relatedInfos:r,layer:o},i);Object.keys(l).forEach(t=>{G(l[t]?.value,r.get(t.toString()))})}_configureRelatedInfo(t,e){const{relatedInfos:i}=this,r=q(t.fieldName||"");if(!r)return;const{layerId:s,fieldName:o}=r;if(!s)return;const a=i.get(s.toString())||H(s,e);a&&(z({relatedInfo:a,fieldName:o,fieldInfo:t}),this.relatedInfos.set(s,a))}};t([g()],K.prototype,"_error",void 0),t([g()],K.prototype,"_graphicChangedTask",void 0),t([g()],K.prototype,"_evaluateExpressionAttributesTask",void 0),t([g({readOnly:!0})],K.prototype,"_effectivePopupTemplate",null),t([g({readOnly:!0})],K.prototype,"_fieldInfoMap",null),t([g({readOnly:!0})],K.prototype,"_layer",null),t([g()],K.prototype,"abilities",void 0),t([y("abilities")],K.prototype,"castAbilities",null),t([g({readOnly:!0})],K.prototype,"content",void 0),t([g()],K.prototype,"description",void 0),t([g({type:Boolean})],K.prototype,"defaultPopupTemplateEnabled",void 0),t([g({readOnly:!0})],K.prototype,"isFeatureFromTable",null),t([g({readOnly:!0})],K.prototype,"state",null),t([g({readOnly:!0})],K.prototype,"formattedAttributes",void 0),t([g({type:e})],K.prototype,"graphic",void 0),t([g({readOnly:!0})],K.prototype,"lastEditInfo",void 0),t([g({type:v})],K.prototype,"location",void 0),t([g({readOnly:!0})],K.prototype,"relatedInfos",void 0),t([g({type:b})],K.prototype,"spatialReference",null),t([g()],K.prototype,"timeZone",null),t([g({readOnly:!0})],K.prototype,"title",void 0),t([g()],K.prototype,"map",null),t([g({readOnly:!0})],K.prototype,"waitingForContent",null),t([g()],K.prototype,"view",void 0),K=Q=t([_("esri.popup.Feature")],K);const V=K;export{V as default};
|
|
2
|
+
import{__decorate as t}from"tslib";import e from"../Graphic.js";import{FeatureSetQueryInterceptor as i}from"../arcade/featureset/support/FeatureSetQueryInterceptor.js";import r from"../core/Accessor.js";import{isSome as s}from"../core/arrayUtils.js";import{createTask as o}from"../core/asyncUtils.js";import{IdentifiableMixin as a}from"../core/Identifiable.js";import n from"../core/Logger.js";import{abortMaybe as l}from"../core/maybe.js";import{eachAlways as p,isAbortError as h,throwIfAborted as c}from"../core/promiseUtils.js";import{watch as u,initial as d,when as f}from"../core/reactiveUtils.js";import{throttle as m}from"../core/throttle.js";import{property as g,subclass as y}from"../core/accessorSupport/decorators.js";import _ from"../geometry/Point.js";import b from"../geometry/SpatialReference.js";import{getGraphicLayer as v}from"../graphic/graphicOriginUtils.js";import T from"./content/TextContent.js";import{compileExpressionInfos as I,formatArcadeValue as A}from"./support/arcadeFeatureUtils.js";import x from"./support/FeatureAbilities.js";import{preLayerQueryCallback as C,preRequestCallback as E,createFieldInfoMap as w,getAllFieldInfos as F,querySourceLayer as k,queryUpdatedFeature as j,isRelatableFeatureSupportedLayer as P,isAssociatedFeatureSupportedLayer as R,formatEditInfo as O,substituteFieldsInLinksAndAttributes as M,graphicCallback as Z,formatAttributes as U,isRelatedField as L}from"./support/featureUtils.js";import{queryLayerInfos as N,queryRelatedFeatures as S,setRelatedFeatures as G,getRelatedFieldInfo as q,createRelatedInfo as H,updateRelatedInfo as z}from"./support/relatedFeatureUtils.js";import{system as B}from"../time/constants.js";var Q;const D=1;let J=class extends(a(r)){static{Q=this}constructor(t){super(t),this._error=null,this._graphicChangedTask=null,this._evaluateExpressionAttributesTask=null,this._expressionAttributes=null,this._graphicExpressionAttributes=null,this.abilities=new x,this.content=null,this.description=null,this.defaultPopupTemplateEnabled=!1,this.formattedAttributes=null,this.graphic=null,this.lastEditInfo=null,this.location=null,this.relatedInfos=new Map,this.title="",this.view=null,this._graphicChangedThrottled=m(this._graphicChanged,()=>this.notifyChange("waitingForContent"),D,this),this._isAllowedContentType=t=>{const{abilities:e}=this;return"attachments"===t.type&&!!e.attachmentsContent||"custom"===t.type&&!!e.customContent||"fields"===t.type&&!!e.fieldsContent||"media"===t.type&&!!e.mediaContent||"text"===t.type&&!!e.textContent||"expression"===t.type&&!!e.expressionContent||"relationship"===t.type&&!!e.relationshipContent||"utility-network-associations"===t.type&&!!e.utilityNetworkAssociationsContent},this._evaluateExpressionAttributesThrottled=m(this._evaluateExpressionAttributes,()=>this.notifyChange("waitingForContent"),D,this),this.addHandles([u(()=>[this._effectivePopupTemplate,this.abilities.attachmentsContent,this.abilities.chartAnimation,this.abilities.customContent,this.abilities.expressionContent,this.abilities.fieldsContent,this.abilities.mediaContent,this.abilities.relationshipContent,this.abilities.textContent,this.abilities.utilityNetworkAssociationsContent,this.graphic,this.timeZone],()=>this._graphicChangedThrottled(),d),f(()=>{if(!this._graphicChangedTask?.finished||null==this._graphicChangedTask.value)return null;const t=this._graphicChangedTask.value,e=t?.expressionInfos?.dependencies;return[t,e?.has("view-scale")?this.view?.scale:null,e?.has("view-time-extent")?this.view?.timeExtent?.start:null,e?.has("view-time-extent")?this.view?.timeExtent?.end:null]},([t])=>this._evaluateExpressionAttributesThrottled(t))])}initialize(){this.addHandles([this._graphicChangedThrottled,this._evaluateExpressionAttributesThrottled])}destroy(){this._clear(),this._graphicChangedTask=l(this._graphicChangedTask),this._evaluateExpressionAttributesTask=l(this._evaluateExpressionAttributesTask),this._error=null,this.graphic=null,this.relatedInfos.clear()}static{this.interceptor=new i(C,E)}get _effectivePopupTemplate(){return null!=this.graphic?this.graphic.getEffectivePopupTemplate(this.defaultPopupTemplateEnabled):null}get _fieldInfoMap(){return w(F(this._effectivePopupTemplate),this._layer)}get _layer(){const{graphic:t}=this;return t?v(t):void 0}get isFeatureFromTable(){return this._layer?.isTable||!1}get state(){return this.graphic?this._error?"error":this.waitingForContent?"loading":"ready":"disabled"}get spatialReference(){return this.view?.spatialReference??null}set spatialReference(t){this._override("spatialReference",t)}get timeZone(){return this.view?.timeZone??B}set timeZone(t){this._overrideIfSome("timeZone",t)}get map(){return this.view?.map||null}set map(t){this._override("map",t)}get waitingForContent(){const{_graphicChangedThrottled:t,_evaluateExpressionAttributesThrottled:e,_graphicChangedTask:i,_evaluateExpressionAttributesTask:r}=this;return t.hasPendingUpdates()||e.hasPendingUpdates()||null!=i&&!i.finished||null!=r&&!r.finished}async updateGeometry(){const{graphic:t,spatialReference:e,_layer:i}=this;await(i?.load());const r=i?.objectIdField;if(!r||!t||!i)return;const s=t?.attributes?.[r];if(null==s)return;const o=[s];if(!t.geometry){const r=await k({layer:i,graphic:t,outFields:[],objectIds:o,returnGeometry:!0,spatialReference:e}),s=r?.geometry;s&&(t.geometry=s)}}_clear(){this._set("title",""),this._set("content",null),this._set("formattedAttributes",null)}_graphicChanged(){this._evaluateExpressionAttributesTask=l(this._evaluateExpressionAttributesTask),this._graphicChangedTask=l(this._graphicChangedTask),this._graphicChangedTask=o(async t=>{this._error=null,this._clear();const{graphic:e}=this;try{if(!e)return null;const{_layer:i,_effectivePopupTemplate:r}=this,s=this.spatialReference;await j({graphic:e,popupTemplate:r,layer:i,spatialReference:s},{signal:t});const[{value:o},{value:a}]=await p([this._getContent(),this._getTitle()]),[,{value:n}]=await p([this._checkForRelatedFeatures({signal:t}),I(r?.expressionInfos,e)]);return{expressionInfos:n,content:o,title:a}}catch(i){throw h(i)||(this._error=i,n.getLogger(this).error("error","The popupTemplate could not be displayed for this feature.",{error:i,graphic:e,popupTemplate:this._effectivePopupTemplate})),i}})}_compileContentElement(t){return"relationship"===t.type?P(this._layer)?t:void 0:"utility-network-associations"===t.type?R(this._layer)?t:void 0:t}_compileContent(t){if(this.graphic)return Array.isArray(t)?t.filter(this._isAllowedContentType).map(t=>this._compileContentElement(t)).filter(s):"string"==typeof t?new T({text:t}).text:t}_compileLastEditInfo(){const{_effectivePopupTemplate:t,_layer:e,graphic:i,timeZone:r}=this;if(!t)return;const{lastEditInfoEnabled:s}=t,o=e?.editFieldsInfo;return s&&o?O(o,i?.attributes,r,e):void 0}_compileTitle(t){const{_fieldInfoMap:e,_layer:i,graphic:r,_expressionAttributes:s}=this,o=r?.attributes??{},a=this.formattedAttributes?.global??{};return M({attributes:o,fieldInfoMap:e,globalAttributes:a,expressionAttributes:s,layer:i,text:t})}async _getTitle(){const{_effectivePopupTemplate:t,graphic:e}=this;return e?Z({type:"title",value:t?.title,event:{graphic:e}}):null}async _getContent(){const{_effectivePopupTemplate:t,graphic:e}=this;return e?Z({type:"content",value:t?.content,event:{graphic:e}}):null}_evaluateExpressionAttributes({title:t,content:e,expressionInfos:i}){this._evaluateExpressionAttributesTask=l(this._evaluateExpressionAttributesTask),this._evaluateExpressionAttributesTask=o(async r=>{const{graphic:s,map:o,view:a,spatialReference:l,location:p}=this;try{if(!s)return;let n;if(null!=i){const t=[];for(const[e,n]of i.expressions.entries())null!=n?t.push(n.evaluate({graphic:s,interceptor:Q.interceptor,location:p,map:o,options:{signal:r},spatialReference:l,view:a}).then(t=>[e,"string"==typeof t?A(t):t]).catch(()=>[e,void 0])):t.push(Promise.resolve([e,void 0]));n=Object.fromEntries(await Promise.all(t)),c(r)}this._expressionAttributes=n,this._graphicExpressionAttributes={...s.attributes,...n},this._set("formattedAttributes",this._createFormattedAttributes(e)),this._set("title",this._compileTitle(t)),this._set("lastEditInfo",this._compileLastEditInfo()||null),this._set("content",this._compileContent(e)||null)}catch(u){h(u)||(this._error=u,n.getLogger(this).error("error","The popupTemplate could not be displayed for this feature.",{error:u,graphic:s,popupTemplate:this._effectivePopupTemplate}))}})}_createMediaFormattedAttributes({contentElement:t,contentElementIndex:e,formattedAttributes:i}){const{_effectivePopupTemplate:r,graphic:s,relatedInfos:o,_layer:a,_fieldInfoMap:n,_graphicExpressionAttributes:l,timeZone:p}=this;i.content[e]=U({attributes:{...l,...t.attributes},fieldInfoMap:n,fieldInfos:r?.fieldInfos,graphic:s,layer:a,relatedInfos:o,timeZone:p})}_createFieldsFormattedAttributes({contentElement:t,contentElementIndex:e,formattedAttributes:i}){if(t.fieldInfos){const{graphic:r,relatedInfos:s,_layer:o,_fieldInfoMap:a,_graphicExpressionAttributes:n,timeZone:l}=this;i.content[e]=U({attributes:{...n,...t.attributes},fieldInfoMap:a,fieldInfos:t.fieldInfos,graphic:r,isContentFieldInfos:!0,layer:o,relatedInfos:s,timeZone:l})}}_createFormattedAttributes(t){const{_effectivePopupTemplate:e,graphic:i,relatedInfos:r,_layer:s,_fieldInfoMap:o,_graphicExpressionAttributes:a,timeZone:n}=this,l=e?.fieldInfos,p={global:U({attributes:a,fieldInfoMap:o,fieldInfos:l,graphic:i,layer:s,relatedInfos:r,timeZone:n}),content:[]};return Array.isArray(t)&&t.forEach((t,e)=>{"fields"===t.type&&this._createFieldsFormattedAttributes({contentElement:t,contentElementIndex:e,formattedAttributes:p}),"media"===t.type&&this._createMediaFormattedAttributes({contentElement:t,contentElementIndex:e,formattedAttributes:p})}),p}_checkForRelatedFeatures(t){const{graphic:e,_effectivePopupTemplate:i}=this;return this._queryRelatedInfos(e,F(i),t)}async _queryRelatedInfos(t,e,i){const{relatedInfos:r,_layer:s}=this;r.clear();const o=null!=s?.associatedLayer?await(s?.associatedLayer.load(i)):s;if(!o||!t)return;const a=e.filter(t=>!!t.fieldName&&L(t.fieldName));if(!a?.length)return;e.forEach(t=>this._configureRelatedInfo(t,o));const n=await N({relatedInfos:r,layer:o},i);Object.keys(n).forEach(t=>{const e=r.get(t.toString()),i=n[t]?.value;e&&i&&(e.layerInfo=i.data)});const l=await S({graphic:t,relatedInfos:r,layer:o},i);Object.keys(l).forEach(t=>{G(l[t]?.value,r.get(t.toString()))})}_configureRelatedInfo(t,e){const{relatedInfos:i}=this,r=q(t.fieldName||"");if(!r)return;const{layerId:s,fieldName:o}=r;if(!s)return;const a=i.get(s.toString())||H(s,e);a&&(z({relatedInfo:a,fieldName:o,fieldInfo:t}),this.relatedInfos.set(s,a))}};t([g()],J.prototype,"_error",void 0),t([g()],J.prototype,"_graphicChangedTask",void 0),t([g()],J.prototype,"_evaluateExpressionAttributesTask",void 0),t([g({readOnly:!0})],J.prototype,"_effectivePopupTemplate",null),t([g({readOnly:!0})],J.prototype,"_fieldInfoMap",null),t([g({readOnly:!0})],J.prototype,"_layer",null),t([g({type:x})],J.prototype,"abilities",void 0),t([g({readOnly:!0})],J.prototype,"content",void 0),t([g()],J.prototype,"description",void 0),t([g({type:Boolean})],J.prototype,"defaultPopupTemplateEnabled",void 0),t([g({readOnly:!0})],J.prototype,"isFeatureFromTable",null),t([g({readOnly:!0})],J.prototype,"state",null),t([g({readOnly:!0})],J.prototype,"formattedAttributes",void 0),t([g({type:e})],J.prototype,"graphic",void 0),t([g({readOnly:!0})],J.prototype,"lastEditInfo",void 0),t([g({type:_})],J.prototype,"location",void 0),t([g({readOnly:!0})],J.prototype,"relatedInfos",void 0),t([g({type:b})],J.prototype,"spatialReference",null),t([g()],J.prototype,"timeZone",null),t([g({readOnly:!0})],J.prototype,"title",void 0),t([g()],J.prototype,"map",null),t([g({readOnly:!0})],J.prototype,"waitingForContent",null),t([g()],J.prototype,"view",void 0),J=Q=t([y("esri.popup.Feature")],J);const K=J;export{K as default};
|