@arcgis/core 4.28.0-next.20230706 → 4.28.0-next.20230708
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/{cfd8b13bfabafc56d65d.js → 2c2cab197c47f080772a.js} +1 -1
- package/assets/esri/core/workers/chunks/{6d22060e5b6e0b11227a.js → 3a0e2535f6cdb2e65667.js} +1 -1
- package/assets/esri/core/workers/chunks/4e4e62462deec25e82ce.js +1 -0
- package/assets/esri/core/workers/chunks/fb7eff7f76386f81d57b.js +1 -0
- package/assets/esri/t9n/common.json +1 -1
- package/assets/esri/t9n/common_en.json +1 -1
- package/assets/esri/themes/base/widgets/_Feature.scss +3 -2
- package/assets/esri/themes/base/widgets/_UtilityNetworkAssociations.scss +69 -32
- package/assets/esri/themes/dark/main.css +1 -1
- package/assets/esri/themes/light/main.css +1 -1
- package/assets/esri/themes/light/view.css +1 -1
- package/assets/esri/widgets/UtilityNetworkAssociations/t9n/UtilityNetworkAssociations.json +1 -1
- package/assets/esri/widgets/UtilityNetworkAssociations/t9n/UtilityNetworkAssociations_en.json +1 -1
- package/chunks/BlendWeights.glsl.js +33 -35
- package/chunks/Blur.glsl.js +6 -9
- package/chunks/EdgeDetect.glsl.js +10 -10
- package/interfaces.d.ts +6 -300
- package/layers/WebTileLayer.js +1 -1
- package/layers/graphics/sources/FeatureLayerSource.js +1 -1
- package/layers/support/rasterDatasets/TIFFRaster.js +1 -1
- package/layers/support/rasterFormats/RasterCodec.js +1 -1
- package/layers/support/rasterFormats/TiffDecoder.js +1 -1
- package/layers/support/rasterFormats/pixelRangeUtils.js +1 -1
- package/networks/Network.js +1 -1
- package/networks/UtilityNetwork.js +1 -1
- package/package.json +1 -1
- package/rest/networks/support/ValidateNetworkTopologyResult.js +1 -1
- package/support/revision.js +1 -1
- package/views/3d/webgl-engine/lib/CompositingHelper.js +1 -1
- package/views/3d/webgl-engine/lib/OffscreenRendering.js +1 -1
- package/views/3d/webgl-engine/lib/SmaaRenderPass.js +1 -1
- package/views/3d/webgl-engine/shaders/BlendWeights.glsl.js +1 -1
- package/views/3d/webgl-engine/shaders/Blur.glsl.js +1 -1
- package/views/3d/webgl-engine/shaders/EdgeDetect.glsl.js +1 -1
- package/views/3d/webgl-engine/shaders/SMAAPassParameters.js +1 -1
- package/widgets/Editor/workflowUtils.js +1 -1
- package/widgets/Feature/resources.js +1 -1
- package/widgets/Feature.js +1 -1
- package/widgets/Print.js +1 -1
- package/widgets/UtilityNetworkAssociations/UtilityNetworkAssociationsViewModel.js +1 -1
- package/widgets/UtilityNetworkAssociations.js +1 -1
- package/widgets/Zoom/ZoomConditions2D.js +1 -1
- package/assets/esri/core/workers/chunks/6b579428c976011b8bcb.js +0 -1
- package/assets/esri/core/workers/chunks/7d9ad61c7896cafc19f7.js +0 -1
- package/layers/LinkChartLayer.d.ts +0 -4
package/layers/WebTileLayer.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.28/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../chunks/tslib.es6.js";import"../geometry.js";import t from"../request.js";import r from"../core/Error.js";import{MultiOriginJSONMixin as l}from"../core/MultiOriginJSONSupport.js";import{replace as o}from"../core/string.js";import{Url as s,isProtocolRelative as i,normalize as n}from"../core/urlUtils.js";import{property as a}from"../core/accessorSupport/decorators/property.js";import"../core/accessorSupport/ensureType.js";import"../core/arrayUtils.js";import"../core/has.js";import{reader as p}from"../core/accessorSupport/decorators/reader.js";import{subclass as u}from"../core/accessorSupport/decorators/subclass.js";import{writer as c}from"../core/accessorSupport/decorators/writer.js";import m from"./Layer.js";import{BlendLayer as f}from"./mixins/BlendLayer.js";import{OperationalLayer as y}from"./mixins/OperationalLayer.js";import{PortalLayer as h}from"./mixins/PortalLayer.js";import{RefreshableLayer as d}from"./mixins/RefreshableLayer.js";import{ScaleRangeLayer as v}from"./mixins/ScaleRangeLayer.js";import{createTileBitmap as w}from"./support/imageBitmapUtils.js";import g from"./support/LOD.js";import j from"./support/TileInfo.js";import{WMTSLayerInfo as T}from"./support/WMTSLayerInfo.js";import b from"../geometry/Extent.js";import
|
|
5
|
+
import{_ as e}from"../chunks/tslib.es6.js";import"../geometry.js";import t from"../request.js";import r from"../core/Error.js";import{MultiOriginJSONMixin as l}from"../core/MultiOriginJSONSupport.js";import{replace as o}from"../core/string.js";import{Url as s,isProtocolRelative as i,normalize as n}from"../core/urlUtils.js";import{property as a}from"../core/accessorSupport/decorators/property.js";import"../core/accessorSupport/ensureType.js";import"../core/arrayUtils.js";import"../core/has.js";import{reader as p}from"../core/accessorSupport/decorators/reader.js";import{subclass as u}from"../core/accessorSupport/decorators/subclass.js";import{writer as c}from"../core/accessorSupport/decorators/writer.js";import m from"./Layer.js";import{BlendLayer as f}from"./mixins/BlendLayer.js";import{OperationalLayer as y}from"./mixins/OperationalLayer.js";import{PortalLayer as h}from"./mixins/PortalLayer.js";import{RefreshableLayer as d}from"./mixins/RefreshableLayer.js";import{ScaleRangeLayer as v}from"./mixins/ScaleRangeLayer.js";import{createTileBitmap as w}from"./support/imageBitmapUtils.js";import g from"./support/LOD.js";import j from"./support/TileInfo.js";import{WMTSLayerInfo as T}from"./support/WMTSLayerInfo.js";import b from"../geometry/Extent.js";import S from"../geometry/SpatialReference.js";import R from"../geometry/Point.js";var x;let U=x=class extends(f(d(v(y(h(l(m))))))){constructor(...e){super(...e),this.copyright="",this.fullExtent=new b(-20037508.342787,-20037508.34278,20037508.34278,20037508.342787,S.WebMercator),this.legendEnabled=!1,this.isReference=null,this.popupEnabled=!1,this.spatialReference=S.WebMercator,this.subDomains=null,this.tileInfo=new j({size:[256,256],dpi:96,format:"png8",compressionQuality:0,origin:new R({x:-20037508.342787,y:20037508.342787,spatialReference:S.WebMercator}),spatialReference:S.WebMercator,lods:[new g({level:0,scale:591657527.591555,resolution:156543.033928}),new g({level:1,scale:295828763.795777,resolution:78271.5169639999}),new g({level:2,scale:147914381.897889,resolution:39135.7584820001}),new g({level:3,scale:73957190.948944,resolution:19567.8792409999}),new g({level:4,scale:36978595.474472,resolution:9783.93962049996}),new g({level:5,scale:18489297.737236,resolution:4891.96981024998}),new g({level:6,scale:9244648.868618,resolution:2445.98490512499}),new g({level:7,scale:4622324.434309,resolution:1222.99245256249}),new g({level:8,scale:2311162.217155,resolution:611.49622628138}),new g({level:9,scale:1155581.108577,resolution:305.748113140558}),new g({level:10,scale:577790.554289,resolution:152.874056570411}),new g({level:11,scale:288895.277144,resolution:76.4370282850732}),new g({level:12,scale:144447.638572,resolution:38.2185141425366}),new g({level:13,scale:72223.819286,resolution:19.1092570712683}),new g({level:14,scale:36111.909643,resolution:9.55462853563415}),new g({level:15,scale:18055.954822,resolution:4.77731426794937}),new g({level:16,scale:9027.977411,resolution:2.38865713397468}),new g({level:17,scale:4513.988705,resolution:1.19432856685505}),new g({level:18,scale:2256.994353,resolution:.597164283559817}),new g({level:19,scale:1128.497176,resolution:.298582141647617}),new g({level:20,scale:564.248588,resolution:.14929107082380833}),new g({level:21,scale:282.124294,resolution:.07464553541190416}),new g({level:22,scale:141.062147,resolution:.03732276770595208}),new g({level:23,scale:70.5310735,resolution:.01866138385297604})]}),this.type="web-tile",this.urlTemplate=null,this.wmtsInfo=null}normalizeCtorArgs(e,t){return"string"==typeof e?{urlTemplate:e,...t}:e}load(e){const t=this.loadFromPortal({supportedTypes:["WMTS"]},e).then((()=>{let e="";if(this.urlTemplate)if(this.spatialReference.equals(this.tileInfo.spatialReference)){const t=new s(this.urlTemplate);!(!!this.subDomains&&this.subDomains.length>0)&&t.authority?.includes("{subDomain}")&&(e="is missing 'subDomains' property")}else e="spatialReference must match tileInfo.spatialReference";else e="is missing the required 'urlTemplate' property value";if(e)throw new r("web-tile-layer:load",`WebTileLayer (title: '${this.title}', id: '${this.id}') ${e}`)}));return this.addResolvingPromise(t),Promise.resolve(this)}get levelValues(){const e=[];if(!this.tileInfo)return null;for(const t of this.tileInfo.lods)e[t.level]=t.levelValue||t.level;return e}readSpatialReference(e,t){return e||S.fromJSON(t.fullExtent?.spatialReference)}get tileServers(){if(!this.urlTemplate)return null;const e=[],{urlTemplate:t,subDomains:r}=this,l=new s(t),o=l.scheme?l.scheme+"://":"//",i=o+l.authority+"/",n=l.authority;if(n?.includes("{subDomain}")){if(r&&r.length>0&&n.split(".").length>1)for(const s of r)e.push(o+n.replaceAll(/\{subDomain\}/gi,s)+"/")}else e.push(i);return e.map((e=>("/"!==e.charAt(e.length-1)&&(e+="/"),e)))}get urlPath(){if(!this.urlTemplate)return null;const e=this.urlTemplate,t=new s(e),r=(t.scheme?t.scheme+"://":"//")+t.authority+"/";return e.substring(r.length)}readUrlTemplate(e,t){return e||t.templateUrl}writeUrlTemplate(e,t){e&&i(e)&&(e="https:"+e),e&&(e=e.replaceAll(/\{z\}/gi,"{level}").replaceAll(/\{x\}/gi,"{col}").replaceAll(/\{y\}/gi,"{row}"),e=n(e)),t.templateUrl=e}fetchTile(e,r,l,o={}){const{signal:s}=o,i=this.getTileUrl(e,r,l),n={responseType:"image",signal:s,query:{...this.refreshParameters}};return t(i,n).then((e=>e.data))}async fetchImageBitmapTile(e,r,l,o={}){const{signal:s}=o;if(this.fetchTile!==x.prototype.fetchTile){const t=await this.fetchTile(e,r,l,o);return w(t,e,r,l,s)}const i=this.getTileUrl(e,r,l),n={responseType:"blob",signal:s,query:{...this.refreshParameters}},{data:a}=await t(i,n);return w(a,e,r,l,s)}getTileUrl(e,t,r){const{levelValues:l,tileServers:s,urlPath:i}=this;if(!l||!s||!i)return"";const n=l[e];return s[t%s.length]+o(i,{level:n,z:n,col:r,x:r,row:t,y:t})}};e([a({type:String,value:"",json:{write:!0}})],U.prototype,"copyright",void 0),e([a({type:b,json:{write:!0},nonNullable:!0})],U.prototype,"fullExtent",void 0),e([a({readOnly:!0,json:{read:!1,write:!1}})],U.prototype,"legendEnabled",void 0),e([a({type:["show","hide"]})],U.prototype,"listMode",void 0),e([a({json:{read:!0,write:!0}})],U.prototype,"blendMode",void 0),e([a()],U.prototype,"levelValues",null),e([a({type:Boolean,json:{read:!1,write:{enabled:!0,overridePolicy:()=>({enabled:!1})}}})],U.prototype,"isReference",void 0),e([a({type:["WebTiledLayer"],value:"WebTiledLayer"})],U.prototype,"operationalLayerType",void 0),e([a({readOnly:!0,json:{read:!1,write:!1}})],U.prototype,"popupEnabled",void 0),e([a({type:S})],U.prototype,"spatialReference",void 0),e([p("spatialReference",["spatialReference","fullExtent.spatialReference"])],U.prototype,"readSpatialReference",null),e([a({type:[String],json:{write:!0}})],U.prototype,"subDomains",void 0),e([a({type:j,json:{write:!0}})],U.prototype,"tileInfo",void 0),e([a({readOnly:!0})],U.prototype,"tileServers",null),e([a({json:{read:!1}})],U.prototype,"type",void 0),e([a()],U.prototype,"urlPath",null),e([a({type:String,json:{origins:{"portal-item":{read:{source:"url"}}}}})],U.prototype,"urlTemplate",void 0),e([p("urlTemplate",["urlTemplate","templateUrl"])],U.prototype,"readUrlTemplate",null),e([c("urlTemplate",{templateUrl:{type:String}})],U.prototype,"writeUrlTemplate",null),e([a({type:T,json:{write:!0}})],U.prototype,"wmtsInfo",void 0),U=x=e([u("esri.layers.WebTileLayer")],U);const L=U;export{L as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.28/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../../../chunks/tslib.es6.js";import"../../../geometry.js";import t from"../../../Graphic.js";import{id as s}from"../../../kernel.js";import r from"../../../request.js";import a from"../../../TimeExtent.js";import{isSome as i}from"../../../core/arrayUtils.js";import o from"../../../core/Error.js";import has from"../../../core/has.js";import{JSONMap as n}from"../../../core/jsonMap.js";import u from"../../../core/Loadable.js";import l from"../../../core/Logger.js";import{setDeepValue as d}from"../../../core/object.js";import{debounce as c,after as p,throwIfAbortError as h}from"../../../core/promiseUtils.js";import{getMetersPerCartesianUnitForSR as y}from"../../../core/unitUtils.js";import{join as m,parseData as f}from"../../../core/urlUtils.js";import{generateBracedUUID as g}from"../../../core/uuid.js";import{property as R}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as S}from"../../../core/accessorSupport/decorators/subclass.js";import b from"../../../geometry/Extent.js";import{initializeProjection as w,project as F}from"../../../geometry/projection.js";import{fromJSON as E}from"../../../geometry/support/jsonUtils.js";import{toRelativeVertexSpace as q}from"../../../geometry/support/meshVertexSpaceUtils.js";import{isOriginalExternal as _}from"../../../geometry/support/meshUtils/External.js";import{isFeatureIdentifierArrayWithGlobalId as O,isFeatureIdentifierArrayWithObjectId as I}from"../editingSupport.js";import{createDrawingInfo as A}from"./support/clientSideDefaults.js";import j from"./support/QueryTask.js";import{isHostedAgolService as x}from"../../support/arcgisLayerUrl.js";import{ensureLayerCredential as T}from"../../support/featureLayerUtils.js";import{getAssetMapTable as N}from"../../support/infoFor3D.js";import{executeQueryJSON as v}from"../../../rest/query/executeQueryJSON.js";import{unapplyEditsZUnitScaling as J}from"../../../rest/query/operations/editsZScale.js";import M from"../../../rest/support/Query.js";import U from"../../../geometry/SpatialReference.js";const k=new n({originalAndCurrentFeatures:"original-and-current-features",none:"none"}),L=new Set(["Feature Layer","Oriented Imagery Layer","Table"]),C=new n({Started:"published",Publishing:"publishing",Stopped:"unavailable"});let Q=class extends u{constructor(){super(...arguments),this.type="feature-layer",this.refresh=c((async()=>{await this.load();const e=this.sourceJSON.editingInfo?.lastEditDate;if(null==e)return{dataChanged:!0,updates:{}};try{await this._fetchService(null)}catch{return{dataChanged:!0,updates:{}}}const t=e!==this.sourceJSON.editingInfo?.lastEditDate;return{dataChanged:t,updates:t?{editingInfo:this.sourceJSON.editingInfo,extent:this.sourceJSON.extent}:null}})),this._ongoingAssetUploads=new Map}load(e){const t=this.layer.sourceJSON,s=this._fetchService(t,{...e}).then((()=>this.layer.setUserPrivileges(this.sourceJSON.serviceItemId,e))).then((()=>this._ensureLatestMetadata(e)));return this.addResolvingPromise(s),Promise.resolve(this)}get queryTask(){const{capabilities:e,parsedUrl:t,dynamicDataSource:s,infoFor3D:r,gdbVersion:a,spatialReference:i,fieldsIndex:o}=this.layer,n=has("featurelayer-pbf")&&e?.query.supportsFormatPBF&&null==r,u=e?.operations?.supportsQueryAttachments??!1;return new j({url:t.path,pbfSupported:n,fieldsIndex:o,infoFor3D:r,dynamicDataSource:s,gdbVersion:a,sourceSpatialReference:i,queryAttachmentsSupported:u})}async addAttachment(e,t){await this.load();const{layer:s}=this;await T(s,"editing");const a=e.attributes[s.objectIdField],i=s.parsedUrl.path+"/"+a+"/addAttachment",o=this._getLayerRequestOptions(),n=this._getFormDataForAttachment(t,o.query);try{const e=await r(i,{body:n});return this._createFeatureEditResult(e.data.addAttachmentResult)}catch(u){throw this._createAttachmentErrorResult(a,u)}}async updateAttachment(e,t,s){await this.load();const{layer:a}=this;await T(a,"editing");const i=e.attributes[a.objectIdField],o=a.parsedUrl.path+"/"+i+"/updateAttachment",n=this._getLayerRequestOptions({query:{attachmentId:t}}),u=this._getFormDataForAttachment(s,n.query);try{const e=await r(o,{body:u});return this._createFeatureEditResult(e.data.updateAttachmentResult)}catch(l){throw this._createAttachmentErrorResult(i,l)}}async applyEdits(e,t){await this.load();const{layer:a}=this;await T(a,"editing");const o=a.infoFor3D,n=null!=o,u=n||(t?.globalIdUsed??!1),l=n?await this._uploadMeshesAndGetAssetMapEditsJSON(e):null,d=e.addFeatures?.map((e=>this._getFeatureJSON(e,o)))??[],c=(await Promise.all(d)).filter(i),p=e.updateFeatures?.map((e=>this._getFeatureJSON(e,o)))??[],h=(await Promise.all(p)).filter(i),y=this._getFeatureIds(e.deleteFeatures,u);J(c,h,a.spatialReference);const m=await this._getAttachmentEditsJSON(e),f=a.capabilities.editing.supportsAsyncApplyEdits&&n,g={gdbVersion:t?.gdbVersion||a.gdbVersion,rollbackOnFailure:t?.rollbackOnFailureEnabled,useGlobalIds:u,returnEditMoment:t?.returnEditMoment,usePreviousEditMoment:t?.usePreviousEditMoment,sessionId:t?.sessionId,async:f};t?.returnServiceEditsOption?(g.edits=JSON.stringify([{id:a.layerId,adds:c,updates:h,deletes:y,attachments:m,assetMaps:l}]),g.returnServiceEditsOption=k.toJSON(t?.returnServiceEditsOption),g.returnServiceEditsInSourceSR=t?.returnServiceEditsInSourceSR):(g.adds=c.length?JSON.stringify(c):null,g.updates=h.length?JSON.stringify(h):null,g.deletes=y.length?u?JSON.stringify(y):y.join(","):null,g.attachments=m&&JSON.stringify(m),g.assetMaps=null!=l?JSON.stringify(l):void 0);const R=this._getLayerRequestOptions({method:"post",query:g}),S=t?.returnServiceEditsOption?a.url:a.parsedUrl.path,b=f?await this._asyncApplyEdits(S+"/applyEdits",R):await r(S+"/applyEdits",R);if(!a.capabilities.operations?.supportsEditing&&a.effectiveCapabilities?.operations?.supportsEditing){const e=s?.findCredential(a.url);await(e?.refreshToken())}return this._createEditsResult(b)}async deleteAttachments(e,t){await this.load();const{layer:s}=this;await T(s,"editing");const a=e.attributes[s.objectIdField],i=s.parsedUrl.path+"/"+a+"/deleteAttachments";try{return(await r(i,this._getLayerRequestOptions({query:{attachmentIds:t.join(",")},method:"post"}))).data.deleteAttachmentResults.map(this._createFeatureEditResult)}catch(o){throw this._createAttachmentErrorResult(a,o)}}fetchRecomputedExtents(e={}){const t=e.signal;return this.load({signal:t}).then((async()=>{const t=this._getLayerRequestOptions({...e,query:{returnUpdates:!0}}),{layerId:s,url:i}=this.layer,{data:o}=await r(`${i}/${s}`,t),{id:n,extent:u,fullExtent:l,timeExtent:d}=o,c=u||l;return{id:n,fullExtent:c&&b.fromJSON(c),timeExtent:d&&a.fromJSON({start:d[0],end:d[1]})}}))}async queryAttachments(e,t={}){await this.load();const s=this._getLayerRequestOptions(t);return this.queryTask.executeAttachmentQuery(e,s)}async queryFeatures(e,t){await this.load();const s=await this.queryTask.execute(e,{...t,query:this._createRequestQueryOptions(t)});return e.outStatistics?.length&&s.features.length&&s.features.forEach((t=>{const s=t.attributes;e.outStatistics?.forEach((({outStatisticFieldName:e})=>{const t=e&&e.toLowerCase();t&&t in s&&e!==t&&(s[e]=s[t],delete s[t])}))})),s}async queryFeaturesJSON(e,t){return await this.load(),this.queryTask.executeJSON(e,{...t,query:this._createRequestQueryOptions(t)})}async queryObjectIds(e,t){return await this.load(),this.queryTask.executeForIds(e,{...t,query:this._createRequestQueryOptions(t)})}async queryFeatureCount(e,t){return await this.load(),this.queryTask.executeForCount(e,{...t,query:this._createRequestQueryOptions(t)})}async queryExtent(e,t){return await this.load(),this.queryTask.executeForExtent(e,{...t,query:this._createRequestQueryOptions(t)})}async queryRelatedFeatures(e,t){return await this.load(),this.queryTask.executeRelationshipQuery(e,{...t,query:this._createRequestQueryOptions(t)})}async queryRelatedFeaturesCount(e,t){return await this.load(),this.queryTask.executeRelationshipQueryForCount(e,{...t,query:this._createRequestQueryOptions(t)})}async queryTopFeatures(e,t){return await this.load(),this.queryTask.executeTopFeaturesQuery(e,{...t,query:this._createRequestQueryOptions(t)})}async queryTopObjectIds(e,t){return await this.load(),this.queryTask.executeForTopIds(e,{...t,query:this._createRequestQueryOptions(t)})}async queryTopExtents(e,t){return await this.load(),this.queryTask.executeForTopExtents(e,{...t,query:this._createRequestQueryOptions(t)})}async queryTopCount(e,t){return await this.load(),this.queryTask.executeForTopCount(e,{...t,query:this._createRequestQueryOptions(t)})}async fetchPublishingStatus(){if(!x(this.layer.url))return"unavailable";const e=m(this.layer.url,"status"),t=await r(e,{query:{f:"json"}});return C.fromJSON(t.data.status)}async uploadAssets(e,t){const{uploadAssets:s}=await import("./support/uploadAssets.js");return s(e,{layer:this.layer,ongoingUploads:this._ongoingAssetUploads},t)}async _asyncApplyEdits(e,t){const s=(await r(e,t)).data.statusUrl;for(;;){const e=(await r(s,{query:{f:"json"},responseType:"json"})).data;switch(e.status){case"Completed":return r(e.resultUrl,{query:{f:"json"},responseType:"json"});case"CompletedWithErrors":throw new o("async-applyEdits-failed","asynchronous applyEdits call failed.");case"Failed ImportChanges":case"InProgress":case"Pending":case"ExportAttachments":case"ExportChanges":case"ExportingData":case"ExportingSnapshot":case"ImportAttachments":case"ProvisioningReplica":case"UnRegisteringReplica":break;default:throw new o("async-applyEdits-failed","asynchronous applyEdits call failed (undefined response status)")}await p(D)}}_createRequestQueryOptions(e){const t={...this.layer.customParameters,token:this.layer.apiKey,...e?.query};return this.layer.datesInUnknownTimezone&&(t.timeReferenceUnknownClient=!0),t}async _fetchService(e,t){if(!e){const s={};has("featurelayer-advanced-symbols")&&(s.returnAdvancedSymbols=!0),t?.cacheBust&&(s._ts=Date.now());const{data:a}=await r(this.layer.parsedUrl.path,this._getLayerRequestOptions({query:s,signal:t?.signal}));e=a}this.sourceJSON=await this._patchServiceJSON(e,t?.signal);const s=e.type;if(!L.has(s))throw new o("feature-layer-source:unsupported-type",`Source type "${s}" is not supported`)}async _patchServiceJSON(e,t){if("Table"!==e.type&&e.geometryType&&!e?.drawingInfo?.renderer&&!e.defaultSymbol){const t=A(e.geometryType).renderer;d("drawingInfo.renderer",t,e)}if("esriGeometryMultiPatch"===e.geometryType&&e.infoFor3D&&(e.geometryType="mesh"),null==e.extent)try{const{data:s}=await r(this.layer.url,this._getLayerRequestOptions({signal:t}));s.spatialReference&&(e.extent={xmin:0,ymin:0,xmax:0,ymax:0,spatialReference:s.spatialReference})}catch(s){h(s)}return e}async _ensureLatestMetadata(e){if(this.layer.userHasUpdateItemPrivileges&&this.sourceJSON.cacheMaxAge>0)return this._fetchService(null,{...e,cacheBust:!0})}async _getFeatureJSON(e,t){const{geometry:s}=e,r={...e.attributes};if(null!=t&&"mesh"===s?.type){const{transformFieldRoles:e}=t,{origin:a,spatialReference:i,transform:o}=s,n=this.layer.spatialReference;await w(i,n);const u=F(a,n);if(r[e.originX]=u.x,r[e.originY]=u.y,r[e.originZ]=u.z??0,null!=o){const{translation:t,scale:a,rotation:u}=o,{vertexSpace:l}=s,d=l.isGeoreferenced?1:y(i)/y(n);r[e.translationX]=t[0]*d,r[e.translationY]=-t[2]*d,r[e.translationZ]=t[1]*d,r[e.scaleX]=a[0],r[e.scaleY]=a[2],r[e.scaleZ]=a[1],r[e.rotationX]=u[0],r[e.rotationY]=u[2],r[e.rotationZ]=u[1],r[e.rotationDeg]=u[3]}return{geometry:null,attributes:r}}return null==s?{attributes:r}:"mesh"===s.type||"extent"===s.type?null:{geometry:s.toJSON(),attributes:r}}async _getAttachmentEditsJSON(e){const t=await Promise.all((e.addAttachments??[]).map((e=>this._getAttachmentEditJSON(e)))),s=await Promise.all((e.updateAttachments??[]).map((e=>this._getAttachmentEditJSON(e)))),r=e.deleteAttachments??[];return t.length||s.length||r.length?{adds:t,updates:s,deletes:[...r]}:null}async _getAttachmentEditJSON(e){const{feature:t,attachment:s}=e,{globalId:r,name:a,contentType:i,data:o,uploadId:n}=s,u={globalId:r,parentGlobalId:null,contentType:null,name:null,uploadId:null,data:null};if(t&&(u.parentGlobalId="attributes"in t?t.attributes&&t.attributes[this.layer.globalIdField]:t.globalId),n)u.uploadId=n;else if(o){const e=await f(o);e&&(u.contentType=e.mediaType,u.data=e.data),o instanceof File&&(u.name=o.name)}return a&&(u.name=a),i&&(u.contentType=i),u}async _uploadMeshesAndGetAssetMapEditsJSON(e){const{addAssetFeatures:t}=e;if(!t?.length)return null;const s=await this._filterRedundantAssetMaps(t);if(!t?.length)return null;const r=new Array,a=new Map;for(const i of s){const{geometry:e}=i,{vertexSpace:t}=e;if(t.isRelative)r.push(e);else{const t=q(e);a.set(t,e),i.geometry=t,r.push(t)}}await this.uploadAssets(r);for(const[i,o]of a)o.addExternalSources(i.metadata.externalSources.items);return{adds:this._getAssetMapEditsJSON(s),updates:[],deletes:[]}}_getAssetMapEditsJSON(e){const t=new Array,s=this.layer.globalIdField,r=this.layer.parsedUrl;for(const a of e){const e=a.geometry,{metadata:i}=e,o=i.getExternalSourcesOnService(r),n=a.getAttribute(s);if(0===o.length){l.getLogger(this).error(`Skipping feature ${n}. The mesh it is associated with has not been uploaded to the service and cannot be mapped to it.`);continue}const{source:u}=o.find(_)??o[0],{vertexSpace:d}=e,c=d.isGeoreferenced?["PROJECT_VERTICES"]:[];for(const s of u)1===s.parts.length?t.push({globalId:g(),parentGlobalId:n,assetName:s.assetName,assetHash:s.parts[0].partHash,flags:c}):l.getLogger(this).error(`Skipping asset ${s.assetName}. It does not have exactly one part, so we cannot map it to a feature.`)}return t}_getFeatureIds(e,t){if(!e||0===e.length)return[];if(t&&O(e))return e.map((e=>e.globalId));if(I(e))return e.map((e=>e.objectId));const{layer:s}=this,r=t?s.globalIdField:s.objectIdField;return r?e.map((e=>e.getAttribute(r))):[]}_createEditsResult(e){const t=e.data,{layerId:s}=this.layer,r=[];let a=null;if(Array.isArray(t))for(const u of t)r.push({id:u.id,editedFeatures:u.editedFeatures}),u.id===s&&(a={addResults:u.addResults??[],updateResults:u.updateResults??[],deleteResults:u.deleteResults??[],attachments:u.attachments,editMoment:u.editMoment});else a=t;const i=a?.assetMaps;if(i){for(const e of i.addResults)e.success||l.getLogger(this).error(`Failed to map asset to feature with globalId ${e.globalId}.`);for(const e of i.updateResults)e.success||l.getLogger(this).error(`Failed to map asset to feature with globalId ${e.globalId}.`)}const o=a?.attachments,n={addFeatureResults:a?.addResults?.map(this._createFeatureEditResult,this)??[],updateFeatureResults:a?.updateResults?.map(this._createFeatureEditResult,this)??[],deleteFeatureResults:a?.deleteResults?.map(this._createFeatureEditResult,this)??[],addAttachmentResults:o&&o.addResults?o.addResults.map(this._createFeatureEditResult,this):[],updateAttachmentResults:o&&o.updateResults?o.updateResults.map(this._createFeatureEditResult,this):[],deleteAttachmentResults:o&&o.deleteResults?o.deleteResults.map(this._createFeatureEditResult,this):[]};if(a?.editMoment&&(n.editMoment=a.editMoment),r.length>0){n.editedFeatureResults=[];for(const e of r){const{editedFeatures:t}=e,s=t?.spatialReference?new U(t.spatialReference):null;n.editedFeatureResults.push({layerId:e.id,editedFeatures:{adds:t?.adds?.map((e=>this._createEditedFeature(e,s)))||[],updates:t?.updates?.map((e=>({original:this._createEditedFeature(e[0],s),current:this._createEditedFeature(e[1],s)})))||[],deletes:t?.deletes?.map((e=>this._createEditedFeature(e,s)))||[],spatialReference:s}})}}return n}_createEditedFeature(e,s){return new t({attributes:e.attributes,geometry:E({...e.geometry,spatialReference:s})})}_createFeatureEditResult(e){const t=!0===e.success?null:e.error||{code:void 0,description:void 0};return{objectId:e.objectId,globalId:e.globalId,error:t?new o("feature-layer-source:edit-failure",t.description,{code:t.code}):null}}_createAttachmentErrorResult(e,t){const s=t.details.messages&&t.details.messages[0]||t.message,r=t.details.httpStatus||t.details.messageCode;return{objectId:e,globalId:null,error:new o("feature-layer-source:attachment-failure",s,{code:r})}}_getFormDataForAttachment(e,t){const s=e instanceof FormData?e:e&&e.elements?new FormData(e):null;if(s)for(const r in t){const e=t[r];null!=e&&(s.set?s.set(r,e):s.append(r,e))}return s}_getLayerRequestOptions(e={}){const{parsedUrl:t,gdbVersion:s,dynamicDataSource:r}=this.layer;return{...e,query:{gdbVersion:s,layer:r?JSON.stringify({source:r}):void 0,...t.query,f:"json",...this._createRequestQueryOptions(e)},responseType:"json"}}async _filterRedundantAssetMaps(e){const{layer:t}=this,{globalIdField:s,infoFor3D:r,parsedUrl:a}=t;if(null==r||null==s)return e;const o=N(r);if(null==o)return e;const n=m(a.path,`../${o.id}`),u=new Array,l=new Array;for(const i of e)i.geometry.metadata.getExternalSourcesOnService(a).length>0?l.push(i):u.push(i);const d=l.map((e=>e.getAttribute(s))).filter(i);if(0===d.length)return e;const{assetMapFieldRoles:{parentGlobalId:c,assetHash:p}}=r,h=new M;h.where=`${c} IN (${d.map((e=>`'${e}'`))})`,h.outFields=[p,c],h.returnGeometry=!1;const y=await v(n,h),{features:f}=y;return 0===f.length?e:[...u,...l.filter((e=>{const t=e.getAttribute(s);if(!t)return!0;const{metadata:r}=e.geometry,i=f.filter((e=>e.getAttribute(c)===t));if(0===i.length)return!0;const o=i.map((e=>e.getAttribute(p)));return r.getExternalSourcesOnService(a).flatMap((({source:e})=>e.flatMap((e=>e.parts.map((e=>e.partHash)))))).some((e=>o.every((t=>e!==t))))}))]}};e([R()],Q.prototype,"type",void 0),e([R({constructOnly:!0})],Q.prototype,"layer",void 0),e([R({readOnly:!0})],Q.prototype,"queryTask",null),Q=e([S("esri.layers.graphics.sources.FeatureLayerSource")],Q);const D=1e3,P=Q;export{P as default};
|
|
5
|
+
import{_ as e}from"../../../chunks/tslib.es6.js";import"../../../geometry.js";import t from"../../../Graphic.js";import{id as s}from"../../../kernel.js";import r from"../../../request.js";import a from"../../../TimeExtent.js";import{isSome as i}from"../../../core/arrayUtils.js";import o from"../../../core/Error.js";import has from"../../../core/has.js";import{JSONMap as n}from"../../../core/jsonMap.js";import u from"../../../core/Loadable.js";import l from"../../../core/Logger.js";import{setDeepValue as d}from"../../../core/object.js";import{debounce as c,after as p,throwIfAbortError as h}from"../../../core/promiseUtils.js";import{getMetersPerCartesianUnitForSR as y}from"../../../core/unitUtils.js";import{join as m,parseData as f}from"../../../core/urlUtils.js";import{generateBracedUUID as g}from"../../../core/uuid.js";import{property as R}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import{subclass as S}from"../../../core/accessorSupport/decorators/subclass.js";import b from"../../../geometry/Extent.js";import{initializeProjection as w,project as F}from"../../../geometry/projection.js";import{fromJSON as E}from"../../../geometry/support/jsonUtils.js";import{toRelativeVertexSpace as q}from"../../../geometry/support/meshVertexSpaceUtils.js";import{isOriginalExternal as _}from"../../../geometry/support/meshUtils/External.js";import{isFeatureIdentifierArrayWithGlobalId as O,isFeatureIdentifierArrayWithObjectId as I}from"../editingSupport.js";import{createDrawingInfo as A}from"./support/clientSideDefaults.js";import j from"./support/QueryTask.js";import{isHostedAgolService as x}from"../../support/arcgisLayerUrl.js";import{ensureLayerCredential as T}from"../../support/featureLayerUtils.js";import{getAssetMapTable as N}from"../../support/infoFor3D.js";import{executeQueryJSON as v}from"../../../rest/query/executeQueryJSON.js";import{unapplyEditsZUnitScaling as J}from"../../../rest/query/operations/editsZScale.js";import M from"../../../rest/support/Query.js";import U from"../../../geometry/SpatialReference.js";const k=new n({originalAndCurrentFeatures:"original-and-current-features",none:"none"}),L=new Set(["Feature Layer","Oriented Imagery Layer","Table"]),C=new n({Started:"published",Publishing:"publishing",Stopped:"unavailable"});let Q=class extends u{constructor(){super(...arguments),this.type="feature-layer",this.refresh=c((async()=>{await this.load();const e=this.sourceJSON.editingInfo?.lastEditDate;if(null==e)return{dataChanged:!0,updates:{}};try{await this._fetchService(null)}catch{return{dataChanged:!0,updates:{}}}const t=e!==this.sourceJSON.editingInfo?.lastEditDate;return{dataChanged:t,updates:t?{editingInfo:this.sourceJSON.editingInfo,extent:this.sourceJSON.extent}:null}})),this._ongoingAssetUploads=new Map}load(e){const t=this.layer.sourceJSON,s=this._fetchService(t,{...e}).then((()=>this.layer.setUserPrivileges(this.sourceJSON.serviceItemId,e))).then((()=>this._ensureLatestMetadata(e)));return this.addResolvingPromise(s),Promise.resolve(this)}get queryTask(){const{capabilities:e,parsedUrl:t,dynamicDataSource:s,infoFor3D:r,gdbVersion:a,spatialReference:i,fieldsIndex:o}=this.layer,n=has("featurelayer-pbf")&&e?.query.supportsFormatPBF&&null==r,u=e?.operations?.supportsQueryAttachments??!1;return new j({url:t.path,pbfSupported:n,fieldsIndex:o,infoFor3D:r,dynamicDataSource:s,gdbVersion:a,sourceSpatialReference:i,queryAttachmentsSupported:u})}async addAttachment(e,t){await this.load();const{layer:s}=this;await T(s,"editing");const a=e.attributes[s.objectIdField],i=s.parsedUrl.path+"/"+a+"/addAttachment",o=this._getLayerRequestOptions(),n=this._getFormDataForAttachment(t,o.query);try{const e=await r(i,{body:n});return this._createFeatureEditResult(e.data.addAttachmentResult)}catch(u){throw this._createAttachmentErrorResult(a,u)}}async updateAttachment(e,t,s){await this.load();const{layer:a}=this;await T(a,"editing");const i=e.attributes[a.objectIdField],o=a.parsedUrl.path+"/"+i+"/updateAttachment",n=this._getLayerRequestOptions({query:{attachmentId:t}}),u=this._getFormDataForAttachment(s,n.query);try{const e=await r(o,{body:u});return this._createFeatureEditResult(e.data.updateAttachmentResult)}catch(l){throw this._createAttachmentErrorResult(i,l)}}async applyEdits(e,t){await this.load();const{layer:a}=this;await T(a,"editing");const o=a.infoFor3D,n=null!=o,u=n||(t?.globalIdUsed??!1),l=n?await this._uploadMeshesAndGetAssetMapEditsJSON(e):null,d=e.addFeatures?.map((e=>this._getFeatureJSON(e,o)))??[],c=(await Promise.all(d)).filter(i),p=e.updateFeatures?.map((e=>this._getFeatureJSON(e,o)))??[],h=(await Promise.all(p)).filter(i),y=this._getFeatureIds(e.deleteFeatures,u);J(c,h,a.spatialReference);const m=await this._getAttachmentEditsJSON(e),f=a.capabilities.editing.supportsAsyncApplyEdits&&n,g={gdbVersion:t?.gdbVersion||a.gdbVersion,rollbackOnFailure:t?.rollbackOnFailureEnabled,useGlobalIds:u,returnEditMoment:t?.returnEditMoment,usePreviousEditMoment:t?.usePreviousEditMoment,sessionId:t?.sessionId,async:f};t?.returnServiceEditsOption?(g.edits=JSON.stringify([{id:a.layerId,adds:c,updates:h,deletes:y,attachments:m,assetMaps:l}]),g.returnServiceEditsOption=k.toJSON(t?.returnServiceEditsOption),g.returnServiceEditsInSourceSR=t?.returnServiceEditsInSourceSR):(g.adds=c.length?JSON.stringify(c):null,g.updates=h.length?JSON.stringify(h):null,g.deletes=y.length?u?JSON.stringify(y):y.join(","):null,g.attachments=m&&JSON.stringify(m),g.assetMaps=null!=l?JSON.stringify(l):void 0);const R=this._getLayerRequestOptions({method:"post",query:g}),S=t?.returnServiceEditsOption?a.url:a.parsedUrl.path,b=f?await this._asyncApplyEdits(S+"/applyEdits",R):await r(S+"/applyEdits",R);if(!a.capabilities.operations?.supportsEditing&&a.effectiveCapabilities?.operations?.supportsEditing){const e=s?.findCredential(a.url);await(e?.refreshToken())}return this._createEditsResult(b)}async deleteAttachments(e,t){await this.load();const{layer:s}=this;await T(s,"editing");const a=e.attributes[s.objectIdField],i=s.parsedUrl.path+"/"+a+"/deleteAttachments";try{return(await r(i,this._getLayerRequestOptions({query:{attachmentIds:t.join(",")},method:"post"}))).data.deleteAttachmentResults.map(this._createFeatureEditResult)}catch(o){throw this._createAttachmentErrorResult(a,o)}}fetchRecomputedExtents(e={}){const t=e.signal;return this.load({signal:t}).then((async()=>{const t=this._getLayerRequestOptions({...e,query:{returnUpdates:!0}}),{layerId:s,url:i}=this.layer,{data:o}=await r(`${i}/${s}`,t),{id:n,extent:u,fullExtent:l,timeExtent:d}=o,c=u||l;return{id:n,fullExtent:c&&b.fromJSON(c),timeExtent:d&&a.fromJSON({start:d[0],end:d[1]})}}))}async queryAttachments(e,t={}){await this.load();const s=this._getLayerRequestOptions(t);return this.queryTask.executeAttachmentQuery(e,s)}async queryFeatures(e,t){await this.load();const s=await this.queryTask.execute(e,{...t,query:this._createRequestQueryOptions(t)});return e.outStatistics?.length&&s.features.length&&s.features.forEach((t=>{const s=t.attributes;e.outStatistics?.forEach((({outStatisticFieldName:e})=>{const t=e&&e.toLowerCase();t&&t in s&&e!==t&&(s[e]=s[t],delete s[t])}))})),s}async queryFeaturesJSON(e,t){return await this.load(),this.queryTask.executeJSON(e,{...t,query:this._createRequestQueryOptions(t)})}async queryObjectIds(e,t){return await this.load(),this.queryTask.executeForIds(e,{...t,query:this._createRequestQueryOptions(t)})}async queryFeatureCount(e,t){return await this.load(),this.queryTask.executeForCount(e,{...t,query:this._createRequestQueryOptions(t)})}async queryExtent(e,t){return await this.load(),this.queryTask.executeForExtent(e,{...t,query:this._createRequestQueryOptions(t)})}async queryRelatedFeatures(e,t){return await this.load(),this.queryTask.executeRelationshipQuery(e,{...t,query:this._createRequestQueryOptions(t)})}async queryRelatedFeaturesCount(e,t){return await this.load(),this.queryTask.executeRelationshipQueryForCount(e,{...t,query:this._createRequestQueryOptions(t)})}async queryTopFeatures(e,t){return await this.load(),this.queryTask.executeTopFeaturesQuery(e,{...t,query:this._createRequestQueryOptions(t)})}async queryTopObjectIds(e,t){return await this.load(),this.queryTask.executeForTopIds(e,{...t,query:this._createRequestQueryOptions(t)})}async queryTopExtents(e,t){return await this.load(),this.queryTask.executeForTopExtents(e,{...t,query:this._createRequestQueryOptions(t)})}async queryTopCount(e,t){return await this.load(),this.queryTask.executeForTopCount(e,{...t,query:this._createRequestQueryOptions(t)})}async fetchPublishingStatus(){if(!x(this.layer.url))return"unavailable";const e=m(this.layer.url,"status"),t=await r(e,{query:{f:"json"}});return C.fromJSON(t.data.status)}async uploadAssets(e,t){const{uploadAssets:s}=await import("./support/uploadAssets.js");return s(e,{layer:this.layer,ongoingUploads:this._ongoingAssetUploads},t)}async _asyncApplyEdits(e,t){const s=(await r(e,t)).data.statusUrl;for(;;){const e=(await r(s,{query:{f:"json"},responseType:"json"})).data;switch(e.status){case"Completed":return r(e.resultUrl,{query:{f:"json"},responseType:"json"});case"CompletedWithErrors":throw new o("async-applyEdits-failed","asynchronous applyEdits call failed.");case"Failed ImportChanges":case"InProgress":case"Pending":case"ExportAttachments":case"ExportChanges":case"ExportingData":case"ExportingSnapshot":case"ImportAttachments":case"ProvisioningReplica":case"UnRegisteringReplica":break;default:throw new o("async-applyEdits-failed","asynchronous applyEdits call failed (undefined response status)")}await p(D)}}_createRequestQueryOptions(e){const t={...this.layer.customParameters,token:this.layer.apiKey,...e?.query};return this.layer.datesInUnknownTimezone&&(t.timeReferenceUnknownClient=!0),t}async _fetchService(e,t){if(!e){const s={};has("featurelayer-advanced-symbols")&&(s.returnAdvancedSymbols=!0),t?.cacheBust&&(s._ts=Date.now());const{data:a}=await r(this.layer.parsedUrl.path,this._getLayerRequestOptions({query:s,signal:t?.signal}));e=a}this.sourceJSON=await this._patchServiceJSON(e,t?.signal);const s=e.type;if(!L.has(s))throw new o("feature-layer-source:unsupported-type",`Source type "${s}" is not supported`)}async _patchServiceJSON(e,t){if("Table"!==e.type&&e.geometryType&&!e?.drawingInfo?.renderer&&!e.defaultSymbol){const t=A(e.geometryType).renderer;d("drawingInfo.renderer",t,e)}if("esriGeometryMultiPatch"===e.geometryType&&e.infoFor3D&&(e.geometryType="mesh"),null==e.extent)try{const{data:s}=await r(this.layer.url,this._getLayerRequestOptions({signal:t}));s.spatialReference&&(e.extent={xmin:0,ymin:0,xmax:0,ymax:0,spatialReference:s.spatialReference})}catch(s){h(s)}return e}async _ensureLatestMetadata(e){if(this.layer.userHasUpdateItemPrivileges&&this.sourceJSON.cacheMaxAge>0)return this._fetchService(null,{...e,cacheBust:!0})}async _getFeatureJSON(e,t){const{geometry:s}=e,r={...e.attributes};if(null!=t&&"mesh"===s?.type){const{transformFieldRoles:e}=t,{origin:a,spatialReference:i,transform:o}=s,n=this.layer.spatialReference;await w(i,n);const u=F(a,n);if(r[e.originX]=u.x,r[e.originY]=u.y,r[e.originZ]=u.z??0,null!=o){const{translation:t,scale:a,rotation:u}=o,{vertexSpace:l}=s,d=l.isGeoreferenced?1:y(i)/y(n);r[e.translationX]=t[0]*d,r[e.translationY]=-t[2]*d,r[e.translationZ]=t[1]*d,r[e.scaleX]=a[0],r[e.scaleY]=a[2],r[e.scaleZ]=a[1],r[e.rotationX]=u[0],r[e.rotationY]=u[2],r[e.rotationZ]=u[1],r[e.rotationDeg]=u[3]}return{attributes:r}}return null==s?{attributes:r}:"mesh"===s.type||"extent"===s.type?null:{geometry:s.toJSON(),attributes:r}}async _getAttachmentEditsJSON(e){const t=await Promise.all((e.addAttachments??[]).map((e=>this._getAttachmentEditJSON(e)))),s=await Promise.all((e.updateAttachments??[]).map((e=>this._getAttachmentEditJSON(e)))),r=e.deleteAttachments??[];return t.length||s.length||r.length?{adds:t,updates:s,deletes:[...r]}:null}async _getAttachmentEditJSON(e){const{feature:t,attachment:s}=e,{globalId:r,name:a,contentType:i,data:o,uploadId:n}=s,u={globalId:r,parentGlobalId:null,contentType:null,name:null,uploadId:null,data:null};if(t&&(u.parentGlobalId="attributes"in t?t.attributes&&t.attributes[this.layer.globalIdField]:t.globalId),n)u.uploadId=n;else if(o){const e=await f(o);e&&(u.contentType=e.mediaType,u.data=e.data),o instanceof File&&(u.name=o.name)}return a&&(u.name=a),i&&(u.contentType=i),u}async _uploadMeshesAndGetAssetMapEditsJSON(e){const{addAssetFeatures:t}=e;if(!t?.length)return null;const s=await this._filterRedundantAssetMaps(t);if(!t?.length)return null;const r=new Array,a=new Map;for(const i of s){const{geometry:e}=i,{vertexSpace:t}=e;if(t.isRelative)r.push(e);else{const t=q(e);a.set(t,e),i.geometry=t,r.push(t)}}await this.uploadAssets(r);for(const[i,o]of a)o.addExternalSources(i.metadata.externalSources.items);return{adds:this._getAssetMapEditsJSON(s),updates:[],deletes:[]}}_getAssetMapEditsJSON(e){const t=new Array,s=this.layer.globalIdField,r=this.layer.parsedUrl;for(const a of e){const e=a.geometry,{metadata:i}=e,o=i.getExternalSourcesOnService(r),n=a.getAttribute(s);if(0===o.length){l.getLogger(this).error(`Skipping feature ${n}. The mesh it is associated with has not been uploaded to the service and cannot be mapped to it.`);continue}const{source:u}=o.find(_)??o[0],{vertexSpace:d}=e,c=d.isGeoreferenced?["PROJECT_VERTICES"]:[];for(const s of u)1===s.parts.length?t.push({globalId:g(),parentGlobalId:n,assetName:s.assetName,assetHash:s.parts[0].partHash,flags:c}):l.getLogger(this).error(`Skipping asset ${s.assetName}. It does not have exactly one part, so we cannot map it to a feature.`)}return t}_getFeatureIds(e,t){if(!e||0===e.length)return[];if(t&&O(e))return e.map((e=>e.globalId));if(I(e))return e.map((e=>e.objectId));const{layer:s}=this,r=t?s.globalIdField:s.objectIdField;return r?e.map((e=>e.getAttribute(r))):[]}_createEditsResult(e){const t=e.data,{layerId:s}=this.layer,r=[];let a=null;if(Array.isArray(t))for(const u of t)r.push({id:u.id,editedFeatures:u.editedFeatures}),u.id===s&&(a={addResults:u.addResults??[],updateResults:u.updateResults??[],deleteResults:u.deleteResults??[],attachments:u.attachments,editMoment:u.editMoment});else a=t;const i=a?.assetMaps;if(i){for(const e of i.addResults)e.success||l.getLogger(this).error(`Failed to map asset to feature with globalId ${e.globalId}.`);for(const e of i.updateResults)e.success||l.getLogger(this).error(`Failed to map asset to feature with globalId ${e.globalId}.`)}const o=a?.attachments,n={addFeatureResults:a?.addResults?.map(this._createFeatureEditResult,this)??[],updateFeatureResults:a?.updateResults?.map(this._createFeatureEditResult,this)??[],deleteFeatureResults:a?.deleteResults?.map(this._createFeatureEditResult,this)??[],addAttachmentResults:o&&o.addResults?o.addResults.map(this._createFeatureEditResult,this):[],updateAttachmentResults:o&&o.updateResults?o.updateResults.map(this._createFeatureEditResult,this):[],deleteAttachmentResults:o&&o.deleteResults?o.deleteResults.map(this._createFeatureEditResult,this):[]};if(a?.editMoment&&(n.editMoment=a.editMoment),r.length>0){n.editedFeatureResults=[];for(const e of r){const{editedFeatures:t}=e,s=t?.spatialReference?new U(t.spatialReference):null;n.editedFeatureResults.push({layerId:e.id,editedFeatures:{adds:t?.adds?.map((e=>this._createEditedFeature(e,s)))||[],updates:t?.updates?.map((e=>({original:this._createEditedFeature(e[0],s),current:this._createEditedFeature(e[1],s)})))||[],deletes:t?.deletes?.map((e=>this._createEditedFeature(e,s)))||[],spatialReference:s}})}}return n}_createEditedFeature(e,s){return new t({attributes:e.attributes,geometry:E({...e.geometry,spatialReference:s})})}_createFeatureEditResult(e){const t=!0===e.success?null:e.error||{code:void 0,description:void 0};return{objectId:e.objectId,globalId:e.globalId,error:t?new o("feature-layer-source:edit-failure",t.description,{code:t.code}):null}}_createAttachmentErrorResult(e,t){const s=t.details.messages&&t.details.messages[0]||t.message,r=t.details.httpStatus||t.details.messageCode;return{objectId:e,globalId:null,error:new o("feature-layer-source:attachment-failure",s,{code:r})}}_getFormDataForAttachment(e,t){const s=e instanceof FormData?e:e&&e.elements?new FormData(e):null;if(s)for(const r in t){const e=t[r];null!=e&&(s.set?s.set(r,e):s.append(r,e))}return s}_getLayerRequestOptions(e={}){const{parsedUrl:t,gdbVersion:s,dynamicDataSource:r}=this.layer;return{...e,query:{gdbVersion:s,layer:r?JSON.stringify({source:r}):void 0,...t.query,f:"json",...this._createRequestQueryOptions(e)},responseType:"json"}}async _filterRedundantAssetMaps(e){const{layer:t}=this,{globalIdField:s,infoFor3D:r,parsedUrl:a}=t;if(null==r||null==s)return e;const o=N(r);if(null==o)return e;const n=m(a.path,`../${o.id}`),u=new Array,l=new Array;for(const i of e)i.geometry.metadata.getExternalSourcesOnService(a).length>0?l.push(i):u.push(i);const d=l.map((e=>e.getAttribute(s))).filter(i);if(0===d.length)return e;const{assetMapFieldRoles:{parentGlobalId:c,assetHash:p}}=r,h=new M;h.where=`${c} IN (${d.map((e=>`'${e}'`))})`,h.outFields=[p,c],h.returnGeometry=!1;const y=await v(n,h),{features:f}=y;return 0===f.length?e:[...u,...l.filter((e=>{const t=e.getAttribute(s);if(!t)return!0;const{metadata:r}=e.geometry,i=f.filter((e=>e.getAttribute(c)===t));if(0===i.length)return!0;const o=i.map((e=>e.getAttribute(p)));return r.getExternalSourcesOnService(a).flatMap((({source:e})=>e.flatMap((e=>e.parts.map((e=>e.partHash)))))).some((e=>o.every((t=>e!==t))))}))]}};e([R()],Q.prototype,"type",void 0),e([R({constructOnly:!0})],Q.prototype,"layer",void 0),e([R({readOnly:!0})],Q.prototype,"queryTask",null),Q=e([S("esri.layers.graphics.sources.FeatureLayerSource")],Q);const D=1e3,P=Q;export{P as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.28/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../../../chunks/tslib.es6.js";import"../../../geometry.js";import{isSome as t}from"../../../core/arrayUtils.js";import r from"../../../core/Error.js";import i from"../../../core/Logger.js";import{property as s}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import"../../../core/has.js";import{subclass as a}from"../../../core/accessorSupport/decorators/subclass.js";import n from"../RasterInfo.js";import o from"../RasterStorageInfo.js";import f from"./BaseRaster.js";import l from"./DBFParser.js";import{parseSpatialReference as u,parsePAMInfo as p}from"./pamParser.js";import{parseSignature as c,getPyramidIFDs as h,getMaskIFDs as m,getImageInfo as d,parseIFD as y,parseFieldValues as g,isBSQConfig as T}from"../rasterFormats/TiffDecoder.js";import x from"../rasterFormats/TiffTags.js";import{estimateStatisticsFromHistograms as I}from"../rasterFunctions/stretchUtils.js";import w from"../rasterTransforms/PolynomialTransform.js";import R from"../../../rest/support/FeatureSet.js";import _ from"../../../geometry/SpatialReference.js";import b from"../../../geometry/Extent.js";import E from"../../../geometry/Point.js";const F=(e,t)=>e.get(t)?.values,S=(e,t)=>e.get(t)?.values?.[0];let P=class extends f{constructor(){super(...arguments),this._files=null,this._headerInfo=null,this._bufferSize=1048576,this.datasetFormat="TIFF"}async open(e){await this.init();const t=e?e.signal:null,{data:s}=await this.request(this.url,{range:{from:0,to:this._bufferSize},responseType:"array-buffer",signal:t});if(!s)throw new r("tiffraster:open","failed to open url "+this.url);this.datasetName=this.url.slice(this.url.lastIndexOf("/")+1,this.url.lastIndexOf("."));const{littleEndian:a,firstIFDPos:n,isBigTiff:o}=c(s),f=[];await this._readIFDs(f,s,a,n,0,o?8:4,t);const{imageInfo:l,rasterInfo:u}=this._parseIFDs(f),p=h(f),d=m(f);if(this._headerInfo={littleEndian:a,isBigTiff:o,ifds:f,pyramidIFDs:p,maskIFDs:d,...l},this._set("rasterInfo",u),!l.isSupported)throw new r("tiffraster:open","this tiff is not supported: "+l.message);if(!l.tileWidth)throw new r("tiffraster:open","none-tiled tiff is not optimized for access, convert to COG and retry.");u.isPseudoSpatialReference&&i.getLogger(this).warn("The spatial reference for this tiff is unsupported. Only EPSG spatial reference codes and Esri WKTs are supported.");const y=f[0].get("PREDICTOR")?.values?.[0],g=f[0].get("SAMPLEFORMAT")?.values?.[0];if(3===g&&2===y)throw new r("tiffraster:open","unsupported horizontal difference encoding. Predictor=3 is supported for floatting point data");const{skipExtensions:T=[]}=this.ioConfig;if(!T.includes("aux.xml")){const t=await this._fetchAuxiliaryMetaData(e);null!=t&&this._processPAMInfo(t,u)}T.includes("vat.dbf")||1!==u.bandCount||"u8"!==u.pixelType||(u.attributeTable=await this._fetchAuxiliaryTable(e),null!=u.attributeTable&&(u.keyProperties.DataType="thematic")),this.updateTileInfo()}async fetchRawTile(e,t,r,i={}){if(!this._headerInfo?.isSupported||this.isBlockOutside(e,t,r))return null;const s=await this._fetchRawTiffTile(e,t,r,!1,i);if(null!=s&&this._headerInfo.hasMaskBand){const a=await this._fetchRawTiffTile(e,t,r,!0,i);null!=a&&a.pixels[0]instanceof Uint8Array&&(s.mask=a.pixels[0])}return s}_parseIFDs(e){const t=d(e),{width:r,height:i,tileWidth:s,tileHeight:a,planes:f,pixelType:l,compression:p,firstPyramidLevel:c,maximumPyramidLevel:h,pyramidBlockWidth:m,pyramidBlockHeight:y,tileBoundary:g,affine:T,metadata:x}=t,I=t.extent.spatialReference?.wkt||t.extent.spatialReference?.wkid;let R=u(I),P=!!t.isPseudoGeographic;null==R&&(P=!0,R=new _({wkid:3857}));const v=new b({...t.extent,spatialReference:R}),D=new E(v?{x:v.xmin,y:v.ymax,spatialReference:R}:{x:0,y:0}),k=new o({blockWidth:s,blockHeight:a,pyramidBlockWidth:m,pyramidBlockHeight:y,compression:p,origin:D,firstPyramidLevel:c,maximumPyramidLevel:h,blockBoundary:g}),O=new E({x:(v.xmax-v.xmin)/r,y:(v.ymax-v.ymin)/i,spatialReference:R}),j=x?{BandProperties:x.bandProperties,DataType:x.dataType}:{};let L=null;const B=S(e[0],"PHOTOMETRICINTERPRETATION"),A=F(e[0],"COLORMAP");if(B<=3&&A?.length>3&&A.length%3==0){L=[];const e=A.length/3;for(let t=0;t<e;t++)L.push([t,A[t]>>>8,A[t+e]>>>8,A[t+2*e]>>>8])}const z=new n({width:r,height:i,bandCount:f,pixelType:l,pixelSize:O,storageInfo:k,spatialReference:R,isPseudoSpatialReference:P,keyProperties:j,extent:v,colormap:L,statistics:x?x.statistics:null});return T?.length&&(z.nativeExtent=new b({xmin:-.5,ymin:.5-i,xmax:r-.5,ymax:.5,spatialReference:R}),z.transform=new w({polynomialOrder:1,forwardCoefficients:[T[2]+T[0]/2,T[5]-T[3]/2,T[0],T[3],-T[1],-T[4]]}),z.extent=z.transform.forwardTransform(z.nativeExtent),z.pixelSize=new E({x:(v.xmax-v.xmin)/r,y:(v.ymax-v.ymin)/i,spatialReference:R}),k.origin.x=-.5,k.origin.y=.5),{imageInfo:t,rasterInfo:z}}_processPAMInfo(e,t){if(t.statistics=e.statistics??t.statistics,t.histograms=e.histograms,e.histograms&&null==t.statistics&&(t.statistics=I(e.histograms)),e.transform&&null==t.transform){t.transform=e.transform,t.nativeExtent=t.extent;const r=t.transform.forwardTransform(t.nativeExtent);t.pixelSize=new E({x:(r.xmax-r.xmin)/t.width,y:(r.ymax-r.ymin)/t.height,spatialReference:t.spatialReference}),t.extent=r}t.isPseudoSpatialReference&&e.spatialReference&&(t.spatialReference=e.spatialReference,t.extent.spatialReference=t.nativeExtent.spatialReference=t.storageInfo.origin.spatialReference=t.spatialReference)}async _readIFDs(e,t,r,i,s,a=4,n){if(!i)return null;if(i>=t.byteLength||i<0){t=(await this.request(this.url,{range:{from:i+s,to:i+s+this._bufferSize},responseType:"array-buffer",signal:n})).data,s=i+s,i=0}const o=await this._readIFD(t,r,i,s,x.TIFF_TAGS,a,n);if(e.push(o.ifd),!o.nextIFD)return null;await this._readIFDs(e,t,r,o.nextIFD-s,s,a,n)}async _readIFD(e,r,i,s,a=x.TIFF_TAGS,n=4,o){if(!e)return null;const f=y(e,r,i,s,a,n);if(f.success){const i=[];if(f.ifd?.forEach((e=>{e.values||i.push(e)})),i.length>0){const a=i.map((e=>e.offlineOffsetSize)).filter(t),n=Math.min.apply(null,a.map((e=>e[0])));if(Math.min.apply(null,a.map((e=>e[0]+e[1])))-n<=this._bufferSize){const{data:t}=await this.request(this.url,{range:{from:n,to:n+this._bufferSize},responseType:"array-buffer",signal:o});e=t,s=n,i.forEach((t=>g(e,r,t,s)))}}if(f.ifd?.has("GEOKEYDIRECTORY")){const t=f.ifd.get("GEOKEYDIRECTORY"),i=t?.values;if(i&&i.length>4){const a=i[0]+"."+i[1]+"."+i[2],n=await this._readIFD(e,r,t.valueOffset+6-s,s,x.GEO_KEYS,2,o);t.data=n.ifd,t.data&&t.data.set("GEOTIFFVersion",{id:0,type:2,valueCount:1,valueOffset:null,values:[a]})}}return f}if(f.requiredBufferSize&&f.requiredBufferSize!==e.byteLength){const t=await this.request(this.url,{range:{from:s,to:s+f.requiredBufferSize+4},responseType:"array-buffer",signal:o});return(e=t.data).byteLength<f.requiredBufferSize?null:this._readIFD(e,r,0,s,x.TIFF_TAGS,4,o)}}async _fetchRawTiffTile(e,t,r,i,s={}){const a=this._getTileLocation(e,t,r,i);if(!a)return null;const{ranges:n,actualTileWidth:o,actualTileHeight:f,ifd:l}=a,u=n.map((e=>this.request(this.url,{range:e,responseType:"array-buffer",signal:s.signal}))),p=await Promise.all(u),c=p.map((e=>e.data.byteLength)).reduce(((e,t)=>e+t)),h=1===p.length?p[0].data:new ArrayBuffer(c),m=[0],d=[0];if(p.length>1){const e=new Uint8Array(h);for(let t=0,r=0;t<p.length;t++){const i=p[t].data;e.set(new Uint8Array(i),r),m[t]=r,r+=i.byteLength,d[t]=i.byteLength}}const{blockWidth:y,blockHeight:g}=this.getBlockWidthHeight(e),T=await this.decodePixelBlock(h,{format:"tiff",customOptions:{headerInfo:this._headerInfo,ifd:l,offsets:m,sizes:d},width:y,height:g,planes:null,pixelType:null});if(null==T)return null;let x,I,w;if(o!==y||f!==g){let e=T.mask;if(e)for(x=0;x<g;x++)if(w=x*y,x<f)for(I=o;I<y;I++)e[w+I]=0;else for(I=0;I<y;I++)e[w+I]=0;else for(e=new Uint8Array(y*g),T.mask=e,x=0;x<f;x++)for(w=x*y,I=0;I<o;I++)e[w+I]=1}return T}_getTileLocation(e,t,r,i=!1){const{firstPyramidLevel:s,blockBoundary:a}=this.rasterInfo.storageInfo,n=0===e?0:e-(s-1),{_headerInfo:o}=this;if(!o)return null;const f=i?o.maskIFDs[n]:0===n?o?.ifds[0]:o?.pyramidIFDs[n-1];if(!f)return null;const l=T(f,o),u=F(f,"TILEOFFSETS");if(void 0===u)return null;const p=F(f,"TILEBYTECOUNTS"),{minRow:c,minCol:h,maxRow:m,maxCol:d}=a[n];if(t>m||r>d||t<c||r<h)return null;const y=S(f,"IMAGEWIDTH"),g=S(f,"IMAGELENGTH"),x=S(f,"TILEWIDTH"),I=S(f,"TILELENGTH"),w=[];if(l){const{bandCount:e}=this.rasterInfo;for(let i=0;i<e;i++){const e=i*(m+1)*(d+1)+t*(d+1)+r;w[i]={from:u[e],to:u[e]+p[e]-1}}}else{const e=t*(d+1)+r;w.push({from:u[e],to:u[e]+p[e]-1})}for(let T=0;T<w.length;T++)if(null==w[T].from||!w[T].to)return null;return{ranges:w,ifd:f,actualTileWidth:r===d&&y%x||x,actualTileHeight:t===m&&g%I||I}}async _fetchAuxiliaryMetaData(e){try{const{data:t}=await this.request(this.url+".aux.xml",{responseType:"xml",signal:e?.signal});return p(t)}catch{return null}}async _fetchAuxiliaryTable(e){try{const{data:t}=await this.request(this.url+".vat.dbf",{responseType:"array-buffer",signal:e?.signal}),r=l.parse(t);return r?.recordSet?R.fromJSON(r.recordSet):null}catch{return null}}};e([s()],P.prototype,"_files",void 0),e([s()],P.prototype,"_headerInfo",void 0),e([s()],P.prototype,"_bufferSize",void 0),e([s({type:String,json:{write:!0}})],P.prototype,"datasetFormat",void 0),P=e([a("esri.layers.support.rasterDatasets.TIFFRaster")],P);const v=P;export{v as default};
|
|
5
|
+
import{_ as e}from"../../../chunks/tslib.es6.js";import"../../../geometry.js";import{isSome as t}from"../../../core/arrayUtils.js";import r from"../../../core/Error.js";import i from"../../../core/Logger.js";import{property as s}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import"../../../core/has.js";import{subclass as a}from"../../../core/accessorSupport/decorators/subclass.js";import n from"../RasterInfo.js";import o from"../RasterStorageInfo.js";import f from"./BaseRaster.js";import l from"./DBFParser.js";import{parseSpatialReference as u,parsePAMInfo as p}from"./pamParser.js";import{parseSignature as c,getPyramidIFDs as h,getMaskIFDs as m,getImageInfo as d,parseIFD as y,parseFieldValues as g,isBSQConfig as T}from"../rasterFormats/TiffDecoder.js";import x from"../rasterFormats/TiffTags.js";import{estimateStatisticsFromHistograms as I}from"../rasterFunctions/stretchUtils.js";import w from"../rasterTransforms/PolynomialTransform.js";import R from"../../../rest/support/FeatureSet.js";import _ from"../../../geometry/SpatialReference.js";import b from"../../../geometry/Extent.js";import E from"../../../geometry/Point.js";const F=(e,t)=>e.get(t)?.values,S=(e,t)=>e.get(t)?.values?.[0];let P=class extends f{constructor(){super(...arguments),this._files=null,this._headerInfo=null,this._bufferSize=1048576,this.datasetFormat="TIFF"}async open(e){await this.init();const t=e?e.signal:null,{data:s}=await this.request(this.url,{range:{from:0,to:this._bufferSize},responseType:"array-buffer",signal:t});if(!s)throw new r("tiffraster:open","failed to open url "+this.url);this.datasetName=this.url.slice(this.url.lastIndexOf("/")+1,this.url.lastIndexOf("."));const{littleEndian:a,firstIFDPos:n,isBigTiff:o}=c(s),f=[];await this._readIFDs(f,s,a,n,0,o?8:4,t);const{imageInfo:l,rasterInfo:u}=this._parseIFDs(f),p=h(f),d=m(f);if(this._headerInfo={littleEndian:a,isBigTiff:o,ifds:f,pyramidIFDs:p,maskIFDs:d,...l},this._set("rasterInfo",u),!l.isSupported)throw new r("tiffraster:open","this tiff is not supported: "+l.message);if(!l.tileWidth)throw new r("tiffraster:open","none-tiled tiff is not optimized for access, convert to COG and retry.");u.isPseudoSpatialReference&&i.getLogger(this).warn("The spatial reference for this tiff is unsupported. Only EPSG spatial reference codes and Esri WKTs are supported.");const y=f[0].get("PREDICTOR")?.values?.[0],g=f[0].get("SAMPLEFORMAT")?.values?.[0];if(3===g&&2===y)throw new r("tiffraster:open","unsupported horizontal difference encoding. Predictor=3 is supported for floatting point data");const{skipExtensions:T=[]}=this.ioConfig;if(!T.includes("aux.xml")){const t=await this._fetchAuxiliaryMetaData(e);null!=t&&this._processPAMInfo(t,u)}T.includes("vat.dbf")||1!==u.bandCount||"u8"!==u.pixelType||(u.attributeTable=await this._fetchAuxiliaryTable(e),null!=u.attributeTable&&(u.keyProperties.DataType="thematic")),this.updateTileInfo()}async fetchRawTile(e,t,r,i={}){if(!this._headerInfo?.isSupported||this.isBlockOutside(e,t,r))return null;const s=await this._fetchRawTiffTile(e,t,r,!1,i);if(null!=s&&this._headerInfo.hasMaskBand){const a=await this._fetchRawTiffTile(e,t,r,!0,i);null!=a&&a.pixels[0]instanceof Uint8Array&&(s.mask=a.pixels[0])}return s}_parseIFDs(e){const t=d(e),{width:r,height:i,tileWidth:s,tileHeight:a,planes:f,pixelType:l,compression:p,firstPyramidLevel:c,maximumPyramidLevel:h,pyramidBlockWidth:m,pyramidBlockHeight:y,tileBoundary:g,affine:T,metadata:x}=t,I=t.extent.spatialReference?.wkt||t.extent.spatialReference?.wkid;let R=u(I),P=!!t.isPseudoGeographic;null==R&&(P=!0,R=new _({wkid:3857}));const v=new b({...t.extent,spatialReference:R}),D=new E(v?{x:v.xmin,y:v.ymax,spatialReference:R}:{x:0,y:0}),k=new o({blockWidth:s,blockHeight:a,pyramidBlockWidth:m,pyramidBlockHeight:y,compression:p,origin:D,firstPyramidLevel:c,maximumPyramidLevel:h,blockBoundary:g}),O=new E({x:(v.xmax-v.xmin)/r,y:(v.ymax-v.ymin)/i,spatialReference:R}),j=x?{BandProperties:x.bandProperties,DataType:x.dataType}:{};let L=null;const B=S(e[0],"PHOTOMETRICINTERPRETATION"),A=F(e[0],"COLORMAP");if(B<=3&&A?.length>3&&A.length%3==0){L=[];const e=A.length/3;for(let t=0;t<e;t++)L.push([t,A[t]>>>8,A[t+e]>>>8,A[t+2*e]>>>8])}const z=new n({width:r,height:i,bandCount:f,pixelType:l,pixelSize:O,storageInfo:k,spatialReference:R,isPseudoSpatialReference:P,keyProperties:j,extent:v,colormap:L,statistics:x?x.statistics:null});return T?.length&&(z.nativeExtent=new b({xmin:-.5,ymin:.5-i,xmax:r-.5,ymax:.5,spatialReference:R}),z.transform=new w({polynomialOrder:1,forwardCoefficients:[T[2]+T[0]/2,T[5]-T[3]/2,T[0],T[3],-T[1],-T[4]]}),z.extent=z.transform.forwardTransform(z.nativeExtent),z.pixelSize=new E({x:(v.xmax-v.xmin)/r,y:(v.ymax-v.ymin)/i,spatialReference:R}),k.origin.x=-.5,k.origin.y=.5),{imageInfo:t,rasterInfo:z}}_processPAMInfo(e,t){if(t.statistics=e.statistics??t.statistics,t.histograms=e.histograms,e.histograms&&null==t.statistics&&(t.statistics=I(e.histograms)),e.transform&&null==t.transform){t.transform=e.transform,t.nativeExtent=t.extent;const r=t.transform.forwardTransform(t.nativeExtent);t.pixelSize=new E({x:(r.xmax-r.xmin)/t.width,y:(r.ymax-r.ymin)/t.height,spatialReference:t.spatialReference}),t.extent=r}t.isPseudoSpatialReference&&e.spatialReference&&(t.spatialReference=e.spatialReference,t.extent.spatialReference=t.nativeExtent.spatialReference=t.storageInfo.origin.spatialReference=t.spatialReference)}async _readIFDs(e,t,r,i,s,a=4,n){if(!i)return null;if(i>=t.byteLength||i<0){t=(await this.request(this.url,{range:{from:i+s,to:i+s+this._bufferSize},responseType:"array-buffer",signal:n})).data,s=i+s,i=0}const o=await this._readIFD(t,r,i,s,x.TIFF_TAGS,a,n);if(e.push(o.ifd),!o.nextIFD)return null;await this._readIFDs(e,t,r,o.nextIFD-s,s,a,n)}async _readIFD(e,r,i,s,a=x.TIFF_TAGS,n=4,o){if(!e)return null;const f=y(e,r,i,s,a,n);if(f.success){const i=[];if(f.ifd?.forEach((e=>{e.values||i.push(e)})),i.length>0){const a=i.map((e=>e.offlineOffsetSize)).filter(t),n=Math.min.apply(null,a.map((e=>e[0])));if(Math.min.apply(null,a.map((e=>e[0]+e[1])))-n<=this._bufferSize){const{data:t}=await this.request(this.url,{range:{from:n,to:n+this._bufferSize},responseType:"array-buffer",signal:o});e=t,s=n,i.forEach((t=>g(e,r,t,s)))}}if(f.ifd?.has("GEOKEYDIRECTORY")){const t=f.ifd.get("GEOKEYDIRECTORY"),i=t?.values;if(i&&i.length>4){const a=i[0]+"."+i[1]+"."+i[2],n=await this._readIFD(e,r,t.valueOffset+6-s,s,x.GEO_KEYS,2,o);t.data=n.ifd,t.data&&t.data.set("GEOTIFFVersion",{id:0,type:2,valueCount:1,valueOffset:null,values:[a]})}}return f}if(f.requiredBufferSize&&f.requiredBufferSize!==e.byteLength){const t=await this.request(this.url,{range:{from:s,to:s+f.requiredBufferSize+4},responseType:"array-buffer",signal:o});return(e=t.data).byteLength<f.requiredBufferSize?null:this._readIFD(e,r,0,s,x.TIFF_TAGS,4,o)}}async _fetchRawTiffTile(e,t,r,i,s={}){const a=this._getTileLocation(e,t,r,i);if(!a)return null;const{ranges:n,actualTileWidth:o,actualTileHeight:f,ifd:l}=a,u=n.map((e=>this.request(this.url,{range:e,responseType:"array-buffer",signal:s.signal}))),p=await Promise.all(u),c=p.map((e=>e.data.byteLength)).reduce(((e,t)=>e+t)),h=1===p.length?p[0].data:new ArrayBuffer(c),m=[0],d=[0];if(p.length>1){const e=new Uint8Array(h);for(let t=0,r=0;t<p.length;t++){const i=p[t].data;e.set(new Uint8Array(i),r),m[t]=r,r+=i.byteLength,d[t]=i.byteLength}}const{blockWidth:y,blockHeight:g}=this.getBlockWidthHeight(e),T=await this.decodePixelBlock(h,{format:"tiff",customOptions:{headerInfo:this._headerInfo,ifd:l,offsets:m,sizes:d},width:y,height:g,planes:null,pixelType:null});if(null==T)return null;let x,I,w;if(o!==y||f!==g){let e=T.mask;if(e)for(x=0;x<g;x++)if(w=x*y,x<f)for(I=o;I<y;I++)e[w+I]=0;else for(I=0;I<y;I++)e[w+I]=0;else for(e=new Uint8Array(y*g),T.mask=e,x=0;x<f;x++)for(w=x*y,I=0;I<o;I++)e[w+I]=1}return T}_getTileLocation(e,t,r,i=!1){const{firstPyramidLevel:s,blockBoundary:a}=this.rasterInfo.storageInfo,n=0===e?0:e-(s-1),{_headerInfo:o}=this;if(!o)return null;const f=i?o.maskIFDs[n]:0===n?o?.ifds[0]:o?.pyramidIFDs[n-1];if(!f)return null;const l=T(f,o),u=F(f,"TILEOFFSETS");if(void 0===u)return null;const p=F(f,"TILEBYTECOUNTS"),{minRow:c,minCol:h,maxRow:m,maxCol:d}=a[n];if(t>m||r>d||t<c||r<h)return null;const y=S(f,"IMAGEWIDTH"),g=S(f,"IMAGELENGTH"),x=S(f,"TILEWIDTH"),I=S(f,"TILELENGTH"),w=[];if(l){const{bandCount:e}=this.rasterInfo;for(let i=0;i<e;i++){const e=i*(m+1)*(d+1)+t*(d+1)+r;w[i]={from:u[e],to:u[e]+p[e]-1}}}else{const e=t*(d+1)+r;w.push({from:u[e],to:u[e]+p[e]-1})}for(let T=0;T<w.length;T++)if(null==w[T].from||!w[T].to||w[T].to<0)return null;return{ranges:w,ifd:f,actualTileWidth:r===d&&y%x||x,actualTileHeight:t===m&&g%I||I}}async _fetchAuxiliaryMetaData(e){try{const{data:t}=await this.request(this.url+".aux.xml",{responseType:"xml",signal:e?.signal});return p(t)}catch{return null}}async _fetchAuxiliaryTable(e){try{const{data:t}=await this.request(this.url+".vat.dbf",{responseType:"array-buffer",signal:e?.signal}),r=l.parse(t);return r?.recordSet?R.fromJSON(r.recordSet):null}catch{return null}}};e([s()],P.prototype,"_files",void 0),e([s()],P.prototype,"_headerInfo",void 0),e([s()],P.prototype,"_bufferSize",void 0),e([s({type:String,json:{write:!0}})],P.prototype,"datasetFormat",void 0),P=e([a("esri.layers.support.rasterDatasets.TIFFRaster")],P);const v=P;export{v as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.28/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import t from"../../../core/Error.js";import{assertIsSome as e}from"../../../core/maybe.js";import a from"../PixelBlock.js";import 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{Z as c}from"../../../chunks/Zlib.js";import l from"./Raw.js";import{decodeTileOrStrip as p,decode as d}from"./TiffDecoder.js";import{isPlatformLittleEndian as u}from"./utils.js";var f=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,g,w,y,x,b,k,T,I,C;if(null==t&&(t=this.imgData),0===t.length)return new Uint8Array(0);for(t=(t=new c(t)).getBytes(),w=(u=this.pixelBitlength/8)*this.width,f=new Uint8Array(w*this.height),n=t.length,g=0,m=0,a=0;m<n;){switch(t[m++]){case 0:for(s=b=0;b<w;s=b+=1)f[a++]=t[m++];break;case 1:for(s=k=0;k<w;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<w;s=T+=1)e=t[m++],i=(s-s%u)/u,y=g&&f[(g-1)*w+i*u+s%u],f[a++]=(y+e)%256;break;case 3:for(s=I=0;I<w;s=I+=1)e=t[m++],i=(s-s%u)/u,r=s<u?0:f[a-u],y=g&&f[(g-1)*w+i*u+s%u],f[a++]=(e+Math.floor((r+y)/2))%256;break;case 4:for(s=C=0;C<w;s=C+=1)e=t[m++],i=(s-s%u)/u,r=s<u?0:f[a-u],0===g?y=x=0:(y=f[(g-1)*w+i*u+s%u],x=i&&f[(g-1)*w+(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])}g++}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 m=new Set(["jpg","png","bmp","gif"]);async function g(e,i){if(!u)throw new t("rasterCoded:decode","lerc decoder is not supported on big endian platform");await r();const{offset:s}=i,{width:o,height:h,pixelType:c,statistics:l,depthCount:p,noDataValues:d,bandMasks:f,pixels:m,mask:g}=n(e,{inputOffset:s,returnInterleaved:i.returnInterleaved});return new a({width:o,height:h,pixelType:c.toLowerCase(),pixels:m,mask:g,statistics:l,bandMasks:f,depthCount:p,noDataValues:d})}async function w(t,i){const s=await d(t,{...i,noDataValue:null});e(s);const r=new a({width:s.width,height:s.height,pixels:s.pixels,pixelType:s.pixelType.toLowerCase(),mask:s.mask,statistics:null});return r.updateStatistics(),r}async function y(t,e){const i=await p(t,e.customOptions),s=new a({width:i.width,height:i.height,pixels:i.pixels,pixelType:i.pixelType.toLowerCase(),mask:i.mask,statistics:null});return s.updateStatistics(),s}function x(t,e){const i=e.pixelType||"u8",s=a.getPixelArrayConstructor(i),r="u8"===i?t:new s(t.buffer),n=[],o=e.planes||1;if(1===o)n.push(r);else for(let a=0;a<o;a++){const i=(e.width||1)*(e.height||t.length),h=new s(i);for(let t=0;t<i;t++)h[t]=r[t*o+a];n.push(h)}const h=new a({width:e.width||1,height:e.height||t.length,pixels:n,pixelType:i,statistics:null});return h.updateStatistics(),h}function b(t,e){return x(new c(new Uint8Array(t)).getBytes(),e)}function k(t,e){return x(o(t,e.offset,e.eof,!e.isInputBigEndian),e)}function T(t,e,i){const{pixelTypeCtor:s}=D(e.pixelType),r=(0,l.decode)(t,{width:e.width,height:e.height,pixelType:s,format:i}),n=new a({width:e.width,height:e.height,pixels:r.pixels,pixelType:e.pixelType,mask:r.mask,statistics:null});return n.updateStatistics(),n}function I(t,e){const i=s.decode(t,e.hasNoZlibMask??void 0),r=new a({width:i.width,height:i.height,pixels:i.pixels,pixelType:"U8",mask:i.mask,statistics:null});return r.updateStatistics(),r}function C(t,e){const i=new Uint8Array(t),s=new f(i),{width:r,height:n}=e,o=r*n,h=s.decode();let c,l=0,p=0;const d=new Uint8Array(o);for(l=0;l<o;l++)d[l]=h[4*l+3];const u=new a({width:r,height:n,pixels:[],pixelType:"U8",mask:d,statistics:[]});for(l=0;l<3;l++){for(c=new Uint8Array(o),p=0;p<o;p++)c[p]=h[4*p+l];u.addData({pixels:c})}return u.updateStatistics(),u}async function v(t,e,s,r){const n=new i,o={applyJpegMask:!1,format:e,...s},h=await n.decode(t,o,r),c=new a(h);return c.updateStatistics(),c}function U(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":String.fromCharCode.apply(null,a).toLowerCase().includes("error")&&(i="error"),i}function A(e){let a=null;switch(e){case"lerc":case"lerc2":a=g;break;case"jpg":a=I;break;case"png":a=C;break;case"bsq":case"bip":a=(t,a)=>T(t,a,e);break;case"tiff":a=w;break;case"deflate":a=b;break;case"lzw":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 D(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 O(t,e=1){if(!t)return;const{pixels:i,width:s,height:r,mask:n}=t;if(!i||0===i.length)return;const o=i.length,h=s-1,c=r-1,l=[];let p,d,u,f,m,g,w=null;const y=a.getPixelArrayConstructor(t.pixelType);if(0===e){for(p=0;p<o;p++){for(m=i[p],g=new y(h*c),d=0;d<c;d++)for(f=d*s,u=0;u<h;u++)g[d*h+u]=m[f+u];l.push(g)}if(null!=n)for(w=new Uint8Array(h*c),d=0;d<c;d++)for(f=d*s,u=0;u<h;u++)w[d*h+u]=n[f+u]}else{for(p=0;p<o;p++){for(m=i[p],g=new y(h*c),d=0;d<c;d++)for(f=d*s,u=0;u<h;u++)g[d*h+u]=(m[f+u]+m[f+u+1]+m[f+s+u]+m[f+s+u+1])/4;l.push(g)}if(n)for(w=new Uint8Array(h*c),d=0;d<c;d++)for(f=d*s,u=0;u<h;u++)w[d*h+u]=Math.min.apply(null,[n[f+u],n[f+u+1],n[f+s+u],n[f+s+u+1]])}t.width=h,t.height=c,t.mask=w,t.pixels=l}function P(t){let e=U(t);return"lerc2"===e?e="lerc":"error"===e&&(e=""),e}async function j(e,a={},i){if(null==e)throw new t("rasterCodec:decode","missing encodeddata parameter.");let s=a.format&&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 y(e,a);if((!s||"bsq"!==s&&"bip"!==s&&"deflate"!==s&&"lzw"!==s)&&(s=U(e)),a.useCanvas&&m.has(s))return v(e,s,a,i);const r=A(s);a.isPoint&&(null!=(a={...a}).width&&a.width++,null!=a.height&&a.height++);const n=await r(e,a);return n?("jpg"!==s&&null!=a.noDataValue&&1===n.depthCount&&h(n,a.noDataValue,{customFloatTolerance:a.tolerance}),a.isPoint&&O(n),n):n}export{j as decode,P as getFormat};
|
|
5
|
+
import t from"../../../core/Error.js";import{assertIsSome as e}from"../../../core/maybe.js";import a from"../PixelBlock.js";import 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{Z as c}from"../../../chunks/Zlib.js";import l from"./Raw.js";import{decodeTileOrStrip as p,decode as d}from"./TiffDecoder.js";import{isPlatformLittleEndian as u}from"./utils.js";var f=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,g,w,y,b,x,k,T,I,C;if(null==t&&(t=this.imgData),0===t.length)return new Uint8Array(0);for(t=(t=new c(t)).getBytes(),w=(u=this.pixelBitlength/8)*this.width,f=new Uint8Array(w*this.height),n=t.length,g=0,m=0,a=0;m<n;){switch(t[m++]){case 0:for(s=x=0;x<w;s=x+=1)f[a++]=t[m++];break;case 1:for(s=k=0;k<w;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<w;s=T+=1)e=t[m++],i=(s-s%u)/u,y=g&&f[(g-1)*w+i*u+s%u],f[a++]=(y+e)%256;break;case 3:for(s=I=0;I<w;s=I+=1)e=t[m++],i=(s-s%u)/u,r=s<u?0:f[a-u],y=g&&f[(g-1)*w+i*u+s%u],f[a++]=(e+Math.floor((r+y)/2))%256;break;case 4:for(s=C=0;C<w;s=C+=1)e=t[m++],i=(s-s%u)/u,r=s<u?0:f[a-u],0===g?y=b=0:(y=f[(g-1)*w+i*u+s%u],b=i&&f[(g-1)*w+(i-1)*u+s%u]),o=r+y-b,h=Math.abs(o-r),p=Math.abs(o-y),d=Math.abs(o-b),l=h<=p&&h<=d?r:p<=d?y:b,f[a++]=(e+l)%256;break;default:throw new Error("Invalid filter algorithm: "+t[m-1])}g++}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 m=new Set(["jpg","png","bmp","gif"]);async function g(e,i){if(!u)throw new t("rasterCoded:decode","lerc decoder is not supported on big endian platform");await r();const{offset:s}=i,{width:o,height:h,pixelType:c,statistics:l,depthCount:p,noDataValues:d,bandMasks:f,pixels:m,mask:g}=n(e,{inputOffset:s,returnInterleaved:i.returnInterleaved});return new a({width:o,height:h,pixelType:c.toLowerCase(),pixels:m,mask:g,statistics:l,bandMasks:f,depthCount:p,noDataValues:d})}async function w(t,i){const s=await d(t,{...i,noDataValue:null});e(s);const r=new a({width:s.width,height:s.height,pixels:s.pixels,pixelType:s.pixelType.toLowerCase(),mask:s.mask,bandMasks:s.bandMasks,statistics:null});return r.updateStatistics(),r}async function y(t,e){const i=await p(t,e.customOptions),s=new a({width:i.width,height:i.height,pixels:i.pixels,pixelType:i.pixelType.toLowerCase(),mask:i.mask,statistics:null});return s.updateStatistics(),s}function b(t,e){const i=e.pixelType||"u8",s=a.getPixelArrayConstructor(i),r="u8"===i?t:new s(t.buffer),n=[],o=e.planes||1;if(1===o)n.push(r);else for(let a=0;a<o;a++){const i=(e.width||1)*(e.height||t.length),h=new s(i);for(let t=0;t<i;t++)h[t]=r[t*o+a];n.push(h)}const h=new a({width:e.width||1,height:e.height||t.length,pixels:n,pixelType:i,statistics:null});return h.updateStatistics(),h}function x(t,e){return b(new c(new Uint8Array(t)).getBytes(),e)}function k(t,e){return b(o(t,e.offset,e.eof,!e.isInputBigEndian),e)}function T(t,e,i){const{pixelTypeCtor:s}=D(e.pixelType),r=(0,l.decode)(t,{width:e.width,height:e.height,pixelType:s,format:i}),n=new a({width:e.width,height:e.height,pixels:r.pixels,pixelType:e.pixelType,mask:r.mask,statistics:null});return n.updateStatistics(),n}function I(t,e){const i=s.decode(t,e.hasNoZlibMask??void 0),r=new a({width:i.width,height:i.height,pixels:i.pixels,pixelType:"U8",mask:i.mask,statistics:null});return r.updateStatistics(),r}function C(t,e){const i=new Uint8Array(t),s=new f(i),{width:r,height:n}=e,o=r*n,h=s.decode();let c,l=0,p=0;const d=new Uint8Array(o);for(l=0;l<o;l++)d[l]=h[4*l+3];const u=new a({width:r,height:n,pixels:[],pixelType:"U8",mask:d,statistics:[]});for(l=0;l<3;l++){for(c=new Uint8Array(o),p=0;p<o;p++)c[p]=h[4*p+l];u.addData({pixels:c})}return u.updateStatistics(),u}async function v(t,e,s,r){const n=new i,o={applyJpegMask:!1,format:e,...s},h=await n.decode(t,o,r),c=new a(h);return c.updateStatistics(),c}function U(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":String.fromCharCode.apply(null,a).toLowerCase().includes("error")&&(i="error"),i}function A(e){let a=null;switch(e){case"lerc":case"lerc2":a=g;break;case"jpg":a=I;break;case"png":a=C;break;case"bsq":case"bip":a=(t,a)=>T(t,a,e);break;case"tiff":a=w;break;case"deflate":a=x;break;case"lzw":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 D(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 O(t,e=1){if(!t)return;const{pixels:i,width:s,height:r,mask:n}=t;if(!i||0===i.length)return;const o=i.length,h=s-1,c=r-1,l=[];let p,d,u,f,m,g,w=null;const y=a.getPixelArrayConstructor(t.pixelType);if(0===e){for(p=0;p<o;p++){for(m=i[p],g=new y(h*c),d=0;d<c;d++)for(f=d*s,u=0;u<h;u++)g[d*h+u]=m[f+u];l.push(g)}if(null!=n)for(w=new Uint8Array(h*c),d=0;d<c;d++)for(f=d*s,u=0;u<h;u++)w[d*h+u]=n[f+u]}else{for(p=0;p<o;p++){for(m=i[p],g=new y(h*c),d=0;d<c;d++)for(f=d*s,u=0;u<h;u++)g[d*h+u]=(m[f+u]+m[f+u+1]+m[f+s+u]+m[f+s+u+1])/4;l.push(g)}if(n)for(w=new Uint8Array(h*c),d=0;d<c;d++)for(f=d*s,u=0;u<h;u++)w[d*h+u]=Math.min.apply(null,[n[f+u],n[f+u+1],n[f+s+u],n[f+s+u+1]])}t.width=h,t.height=c,t.mask=w,t.pixels=l}function P(t){let e=U(t);return"lerc2"===e?e="lerc":"error"===e&&(e=""),e}async function j(e,a={},i){if(null==e)throw new t("rasterCodec:decode","missing encodeddata parameter.");let s=a.format&&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 y(e,a);if((!s||"bsq"!==s&&"bip"!==s&&"deflate"!==s&&"lzw"!==s)&&(s=U(e)),a.useCanvas&&m.has(s))return v(e,s,a,i);const r=A(s);a.isPoint&&(null!=(a={...a}).width&&a.width++,null!=a.height&&a.height++);const n=await r(e,a);return n?("jpg"!==s&&null!=a.noDataValue&&1===n.depthCount&&h(n,a.noDataValue,{customFloatTolerance:a.tolerance}),a.isPoint&&O(n),n):n}export{j as decode,P as getFormat};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.28/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{bytesToUTF8 as e}from"../rasterDatasets/byteStreamUtils.js";import{J as t}from"../../../chunks/Jpg.js";import{load as n,decode as a}from"./Lerc.js";import{decode as i}from"./Lzw.js";import{convertNoDataToMask as s}from"./pixelRangeUtils.js";import r from"./TiffTags.js";import{isPlatformLittleEndian as l}from"./utils.js";import{Z as o}from"../../../chunks/Zlib.js";const f=[0,1,1,2,4,8,1,1,2,4,8,4,8,-1,-1,-1,8,8,8],u=4294967296,c=new Set([1,5,6,7,8,34712,34887]);function h(e,t){let n="unknown";return 3===e?n=64===t?"f64":"f32":1===e?1===t?n="u1":2===t?n="u2":4===t?n="u4":t<=8?n="u8":t<=16?n="u16":t<=32&&(n="u32"):2===e&&(t<=8?n="s8":t<=16?n="s16":t<=32&&(n="s32")),n}function g(e){let t=null;switch(e?e.toLowerCase():"f32"){case"u1":case"u2":case"u4":case"u8":t=Uint8Array;break;case"u16":t=Uint16Array;break;case"u32":t=Uint32Array;break;case"s8":t=Int8Array;break;case"s16":t=Int16Array;break;case"s32":t=Int32Array;break;case"f64":t=Float64Array;break;default:t=Float32Array}return t}function E(e,t){return{x:t[0]*e.x+t[1]*e.y+t[2],y:t[3]*e.x+t[4]*e.y+t[5]}}function T(e,t){return e.get(t)?.values}function I(e,t){return e.get(t)?.values}function w(e,t){return e.get(t)?.values?.[0]}function p(e,t){return e.get(t)?.values?.[0]}function d(e,t,n,a=0,i=r.TIFF_TAGS,s=4){const l=8===s,o=l?k(new DataView(e,n,8),0,t):new DataView(e,n,2).getUint16(0,t),f=4+2*s,u=l?8:2,c=u+o*f;if(n+c>e.byteLength)return{success:!1,ifd:null,nextIFD:null,requiredBufferSize:c};const h=n+c+4<=e.byteLength?C(new DataView(e,n+c,8===s?8:4),0,t,8===s):null,g=n+u,E=new Map;let T,I,w,p,d,S=0,y=0;for(let m=0;m<o;m++){I=new DataView(e,g+f*m,f),w=I.getUint16(0,t),d=I.getUint16(2,t),p=r.getTagName(w,i);const n=[];2===s?(S=I.getUint16(4,t),y=I.getUint16(6,t)):4===s?(S=I.getUint32(4,t),y=I.getUint32(8,t)):8===s&&(S=C(I,4,t,!0),y=C(I,12,t,!0),n.push(I.getUint32(12,t)),n.push(I.getUint32(16,t))),T={id:w,type:d,valueCount:S,valueOffset:y,valueOffsets:n,values:null},L(e,t,T,a,!1,s),E.set(p,T)}return{success:!0,ifd:E,nextIFD:h,requiredBufferSize:c}}const S=(e,t)=>a(e,{inputOffset:t}).pixels[0];function y(e,t){if(1!==t&&2!==t&&4!==t)return e;const n=new Uint8Array(e),a=8/t,i=new Uint8Array(e.byteLength*a);let s=0;const r=2**t-1;for(let l=0;l<n.length;l++){const e=n[l];for(let n=0;n<a;n++)i[s++]=e<<t*n>>>8-t&r}return i.buffer}function m(e,n,a){const i=new t;i.parse(e),i.colorTransform=6===a?-1:0;const s=i.getData(i.width,i.height,1!==n&&4!==n);return new Uint8Array(s.buffer)}function A(e){const t=new o(e).getBytes(),n=new ArrayBuffer(t.length),a=new Uint8Array(n);return a.set(t),a}async function M(e,t,a,s,r){const o=l===t,f=p(a,"BITSPERSAMPLE"),u=p(a,"SAMPLESPERPIXEL")??1,c=p(a,"PHOTOMETRICINTERPRETATION"),E=p(a,"SAMPLEFORMAT")??1,T=h(E,f),I=p(a,"COMPRESSION")??1,w=g(T);let d,M,P;if(34887===I)return await n(),S(e,s);if(1===I)d=e.slice(s,s+r),M=new Uint8Array(d);else if(8===I||32946===I)M=new Uint8Array(e,s,r),M=A(M),d=M.buffer;else if(6===I)M=new Uint8Array(e,s,r),M=m(M,u,c),d=M.buffer;else if(7===I){const t=a.get("JPEGTABLES").values,n=t.length-2;M=new Uint8Array(n+r-2);for(let e=0;e<n;e++)M[e]=t[e];const i=new Uint8Array(e,s+2,r-2);for(let e=0;e<i.length;e++)M[n+e]=i[e];M=m(M,u,c),d=M.buffer}else{if(5!==I)throw new Error("tiff-decode: unsupport compression "+I);M=i(e,s,r,t),d=M.buffer}if(d=y(d,f),"u8"===T||"s8"===T||o)P=new w(d);else{d=new ArrayBuffer(M.length);const e=new Uint8Array(d);switch(T){case"u16":case"s16":for(let t=0;t<M.length;t+=2)e[t]=M[t+1],e[t+1]=M[t];break;case"u32":case"s32":case"f32":for(let t=0;t<M.length;t+=4)e[t]=M[t+3],e[t+1]=M[t+2],e[t+2]=M[t+1],e[t+3]=M[t]}P=new w(d)}const O=p(a,"PREDICTOR")??1,b=p(a,"TILEWIDTH"),x=p(a,"TILELENGTH");if(O>1&&(5===I||8===I||32946===I)&&b&&x){const e=D(a),t=new w(P.length);t.set(P),P=W(t,x,b,3===E&&3===O,e?1:u)}return P}async function P(e,t,n){const a=I(n,"TILEOFFSETS");if(void 0===a)return null;const i=I(n,"TILEBYTECOUNTS"),{width:s,height:r,pixelType:l,tileWidth:o,tileHeight:f}=R([n]),u=D(n,t),c=p(n,"SAMPLESPERPIXEL")||t.planes,h=s*r,E=p(n,"BITSPERSAMPLE"),T=34887===(p(n,"COMPRESSION")??1),w=g(l),d=[];for(let g=0;g<c;g++)d.push(new w(h));let S,y,m,A,P,O,b,x,L,U,N,G,k;const F=Math.ceil(s/o);if(E%8==0)if(T&&u&&c>1){const l=Math.round(a.length/c);for(S=0;S<l;S++){O=Math.floor(S/F)*f,b=S%F*o,x=O*s+b;for(let l=0;l<c;l++){const u=S*c+l;if(0!==i[u])for(m=await M(e,t.littleEndian,n,a[u],i[u]),U=0,L=x,G=Math.min(o,s-b),N=Math.min(f,r-O),k=d[l],A=0;A<N;A++)for(L=x+A*s,U=A*o,P=0;P<G;P++,L++,U++)k[L]=m[U]}}}else for(S=0;S<a.length;S++)if(0!==i[S])for(O=Math.floor(S/F)*f,b=S%F*o,x=O*s+b,m=await M(e,t.littleEndian,n,a[S],i[S]),U=0,L=x,G=Math.min(o,s-b),N=Math.min(f,r-O),y=0;y<c;y++)if(k=d[y],u||T)for(A=0;A<N;A++)for(L=x+A*s,U=o*f*y+A*o,P=0;P<G;P++,L++,U++)k[L]=m[U];else for(A=0;A<N;A++)for(L=x+A*s,U=A*o*c+y,P=0;P<G;P++,L++,U+=c)k[L]=m[U];return{width:s,height:r,pixelType:l,pixels:d}}const O=(e,t,n)=>{const a=l===t.littleEndian,s=I(n,"STRIPOFFSETS");if(void 0===s)return null;const{width:r,height:o,pixelType:f}=R([n]),u=p(n,"SAMPLESPERPIXEL")||t.planes,c=p(n,"PHOTOMETRICINTERPRETATION"),h=r*o,E=p(n,"BITSPERSAMPLE"),T=g(f),w=new T(h*u),d=I(n,"STRIPBYTECOUNTS"),S=p(n,"ROWSPERSTRIP"),M=p(n,"COMPRESSION")??1;let P,O,b,x,L,D,U,N,G,k=S;if(E%8==0)for(P=0;P<s.length;P++){if(L=P*(S*r)*u,k=(P+1)*S>o?o-P*S:S,"u8"===f||"s8"===f||a)8===M||32946===M?(U=new Uint8Array(e,s[P],d[P]),U=A(U),D=U.buffer):6===M?(U=new Uint8Array(e,s[P],d[P]),U=m(U,u,c),D=U.buffer):5===M?(U=i(e,s[P],d[P],t.littleEndian),D=U.buffer):(d[P]!==k*r*u*E/8&&console.log("strip byte counts is different than expected"),D=e.slice(s[P],s[P]+d[P])),D=y(D,E),x=new T(D);else{switch(6===M||8===M||32946===M?(U=new Uint8Array(e,s[P],d[P]),N=A(U),D=N.buffer):(d[P]!==k*r*u*E/8&&console.log("strip byte counts is different than expected"),D=new ArrayBuffer(d[P]),U=new Uint8Array(e,s[P],d[P]),N=new Uint8Array(D)),f){case"u16":case"s16":for(b=0;b<U.length;b+=2)N[b]=U[b+1],N[b+1]=U[b];break;case"u32":case"s32":case"f32":for(b=0;b<U.length;b+=4)N[b]=U[b+3],N[b+1]=U[b+2],N[b+2]=U[b+1],N[b+3]=U[b]}D=y(D,E),x=new T(D)}w.set(x,L)}const F=[];if(1===u)F.push(w);else for(P=0;P<u;P++){for(G=new T(h),O=0;O<h;O++)G[O]=w[O*u+P];F.push(G)}return{width:r,height:o,pixelType:f,pixels:F}},b=(e,t,n)=>{if(!(e&&e.length>0&&t&&n))return null;let a,i,s;const r=e[0].length,l=e.length,o=new Uint8Array(r);for(let f=0;f<l;f++)if(a=e[f],i=t[f],s=n[f],0===f)for(let e=0;e<r;e++)o[e]=a[e]<i||a[e]>s?0:1;else for(let e=0;e<r;e++)o[e]&&(o[e]=a[e]<i||a[e]>s?0:1);return o},x=e=>{if(!e)return null;const t=e.match(/<Item(.*?)Item>/gi);if(!t||0===t.length)return null;const n=new Map;let a,i,s,r,l;for(let w=0;w<t.length;w++)a=t[w],i=a.slice(6,a.indexOf(">")),r=a.indexOf("sample="),r>-1&&(l=a.slice(r+8,a.indexOf('"',r+8))),r=a.indexOf("name="),r>-1&&(i=a.slice(r+6,a.indexOf('"',r+6))),i&&(s=a.slice(a.indexOf(">")+1,a.indexOf("</Item>")).trim(),null!=l?n.has(i)?n.get(i)[l]=s:n.set(i,[s]):n.set(i,s)),l=null;const o=n.get("STATISTICS_MINIMUM"),f=n.get("STATISTICS_MAXIMUM"),u=n.get("STATISTICS_MEAN"),c=n.get("STATISTICS_STDDEV");let h=null;if(o&&f){h=[];for(let e=0;e<o.length;e++)h.push({min:parseFloat(o[e]),max:parseFloat(f[e]),avg:u&&parseFloat(u[e]),stddev:c&&parseFloat(c[e])})}const g=n.get("BandName"),E=n.get("WavelengthMin"),T=n.get("WavelengthMax");let I=null;if(g){I=[];for(let e=0;e<g.length;e++)I.push({BandName:g[e],WavelengthMin:E&&parseFloat(E[e]),WavelengthMax:T&&parseFloat(T[e])})}return{statistics:h,bandProperties:I,dataType:n.get("DataType"),rawMetadata:n}};function L(e,t,n,a=0,i=!1,s=4){if(n.values)return!0;const r=n.type,l=n.valueCount;let o=n.valueOffset,c=[];const h=f[r],g=8*h,E=l*h,T=l*f[r]*8;let I,w;const p=8===s?64:32,d=n.valueOffsets;if(T>p){if(E>(i?e.byteLength:e?e.byteLength-o+a:0))return n.offlineOffsetSize=[o,E],n.values=null,!1}if(T<=p){if(!t)if(p<=32)o>>>=32-T;else{const e=d?.length?d[0]:o>>>0,t=d?.length?d[1]:Math.round((o-e)/u);T<=32?(o=e>>>32-T,d[0]=o):(o=e*2**(32-T)+(t>>>32-T),d[0]=e,d[1]=t>>>32-T)}if(1===l&&g===p)c=[o];else if(64===p){const e=d?.length?d[0]:o>>>0,t=d?.length?d[1]:Math.round((o-e)/u);let n=e,a=32;for(w=1;w<=l;w++){const e=32-g*w%32;if(a<g){const i=n<<e>>>32-a,s=t<<32-a>>>32-a;n=t,c.push(i+s*2**(g-a)),a-=32-(g-a)}else c.push(n<<e>>>32-g),a-=g;0===a&&(a=32,n=t)}}else for(w=1;w<=l;w++){const e=32-g*w;c.push(o<<e>>>32-g)}}else{o-=a,i&&(o=0);for(let n=o;n<o+E;n+=h){switch(r){case 1:case 2:case 7:I=new DataView(e,n,1).getUint8(0);break;case 3:I=new DataView(e,n,2).getUint16(0,t);break;case 4:case 13:I=new DataView(e,n,4).getUint32(0,t);break;case 5:I=new DataView(e,n,4).getUint32(0,t)/new DataView(e,n+4,4).getUint32(0,t);break;case 6:I=new DataView(e,n,1).getInt8(0);break;case 8:I=new DataView(e,n,2).getInt16(0,t);break;case 9:I=new DataView(e,n,4).getInt32(0,t);break;case 10:I=new DataView(e,n,4).getInt32(0,t)/new DataView(e,n+4,4).getInt32(0,t);break;case 11:I=new DataView(e,n,4).getFloat32(0,t);break;case 12:I=new DataView(e,n,8).getFloat64(0,t);break;case 16:case 18:I=k(new DataView(e,n,8),0,t);break;case 17:I=F(new DataView(e,n,8),0,t);break;default:I=null}c.push(I)}}if(2===r){let e="";const t=c;for(c=[],w=0;w<t.length;w++)0===t[w]&&""!==e?(c.push(e),e=""):e+=String.fromCharCode(t[w]);""===e&&0!==c.length||c.push(e)}return n.values=c,!0}function R(e){const t=e[0],n=p(t,"TILEWIDTH"),a=p(t,"TILELENGTH"),i=p(t,"IMAGEWIDTH"),s=p(t,"IMAGELENGTH"),r=p(t,"BITSPERSAMPLE"),l=p(t,"SAMPLESPERPIXEL"),o=p(t,"SAMPLEFORMAT")??1,f=h(o,r),u=D(t),g=T(t,"GDAL_NODATA");let d=null;g?.length&&(d=g.map((e=>parseFloat(e))),d.some((e=>isNaN(e)))&&(d=null));const S=p(t,"COMPRESSION")??1;let y;switch(S){case 1:y="NONE";break;case 2:case 3:case 4:case 32771:y="CCITT";break;case 5:y="LZW";break;case 6:case 7:y="JPEG";break;case 32773:y="PACKBITS";break;case 8:case 32946:y="DEFLATE";break;case 34712:y="JPEG2000";break;case 34887:y="LERC";break;default:y=String(S)}let m=!0,A="";c.has(S)||(m=!1,A+="unsupported tag compression "+S),o>3&&(m=!1,A+="unsupported tag sampleFormat "+o),1!==r&&2!==r&&4!==r&&r%8!=0&&(m=!1,A+="unsupported tag bitsPerSample "+r);const M=w(t,"GEOASCIIPARAMS");let P;if(M){const e=M.split("|").find((e=>e.includes("ESRI PE String = "))),t=e?e.replace("ESRI PE String = ",""):"";P=t.startsWith("COMPD_CS")||t.startsWith("PROJCS")||t.startsWith("GEOGCS")?{wkid:null,wkt:t}:null}const O=I(t,"GEOTIEPOINTS"),b=I(t,"GEOPIXELSCALE"),L=I(t,"GEOTRANSMATRIX"),R=t.has("GEOKEYDIRECTORY")?t.get("GEOKEYDIRECTORY").data:null;let G,k,F=!1,C=!1;if(R){F=2===p(R,"GTRasterTypeGeoKey");const e=p(R,"GTModelTypeGeoKey");if(2===e){const e=p(R,"GeographicTypeGeoKey");e>=1024&&e<=32766&&(P={wkid:e}),P||32767!==e||(C=!0,P={wkid:4326})}else if(1===e){const e=p(R,"ProjectedCSTypeGeoKey");e>=1024&&e<=32766&&(P={wkid:e})}}if(b&&O&&O.length>=6?(G=[b[0],0,O[3]-O[0]*b[0],0,-Math.abs(b[1]),O[4]-O[1]*b[1]],F&&(G[2]-=.5*G[0]+.5*G[1],G[5]-=.5*G[3]+.5*G[4])):L&&16===L.length&&(G=F?[L[0],L[1],L[3]-.5*L[0],L[4],L[5],L[7]-.5*L[5]]:[L[0],L[1],L[3],L[4],L[5],L[7]]),G){const e=[{x:0,y:s},{x:0,y:0},{x:i,y:s},{x:i,y:0}];let t,n=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;for(let i=0;i<e.length;i++)t=E(e[i],G),n=t.x>n?n:t.x,r=t.x<r?r:t.x,a=t.y>a?a:t.y,l=t.y<l?l:t.y;k={xmin:n,xmax:r,ymin:a,ymax:l,spatialReference:P}}else k={xmin:-.5,ymin:.5-s,xmax:i-.5,ymax:.5,spatialReference:P};C&&(k.xmax-k.xmin>400||Math.max(Math.abs(k.xmin),Math.abs(k.xmax))>361)&&(P=null,k.spatialReference=null);const v=U(e);let B,W,H,Y,_;if(v.length>0){H=Math.round(Math.log(i/p(v[0],"IMAGEWIDTH"))/Math.LN2);const e=v[v.length-1];Y=Math.round(Math.log(i/p(e,"IMAGEWIDTH"))/Math.LN2),B=p(e,"TILEWIDTH"),W=p(e,"TILELENGTH")}B=null!=Y&&Y>0?B||n:null,W=null!=Y&&Y>0?W||a:null,n&&(_=[{maxCol:Math.ceil(i/n)-1,maxRow:Math.ceil(s/a)-1,minRow:0,minCol:0}],v.forEach((e=>{_.push({maxCol:Math.ceil(p(e,"IMAGEWIDTH")/p(e,"TILEWIDTH"))-1,maxRow:Math.ceil(p(e,"IMAGELENGTH")/p(e,"TILELENGTH"))-1,minRow:0,minCol:0})})));const K=w(e[0],"GDAL_METADATA"),X=x(K);A+=" "+V({width:i,height:s,tileWidth:n,tileHeight:a,planes:l,ifds:e});return{width:i,height:s,tileWidth:n,tileHeight:a,planes:l,isBSQ:u,pixelType:f,compression:y,noData:d,hasMaskBand:N(e).length===v.length+1,isSupported:m,message:A,extent:k,isPseudoGeographic:C,affine:b?null:G,firstPyramidLevel:H,maximumPyramidLevel:Y,pyramidBlockWidth:B,pyramidBlockHeight:W,tileBoundary:_,metadata:X}}function D(e,t){const n=T(e,"PLANARCONFIGURATION");return n?2===n[0]:!!t&&t.isBSQ}function U(e){return e.filter((e=>1===p(e,"NEWSUBFILETYPE")))}function N(e){return e.filter((e=>{const t=4==(4&(p(e,"NEWSUBFILETYPE")??0)),n=4===p(e,"PHOTOMETRICINTERPRETATION");return t&&n}))}function G(e){const{littleEndian:t,isBigTiff:n,firstIFDPos:a}=v(e);let i=a;const s=[];do{const a=B(e,t,i,0,r.TIFF_TAGS,n?8:4);if(!a.success)break;s.push(a.ifd),i=a.nextIFD}while(i>0);return{...R(s),littleEndian:t,isBigTiff:n,ifds:s,pyramidIFDs:U(s),maskIFDs:N(s)}}function k(e,t,n){const a=e.getUint32(t,n),i=e.getUint32(t+4,n);return n?i*u+a:a*u+i}function F(e,t,n){let a=n?e.getInt32(t,n):e.getUint32(t,n),i=n?e.getUint32(t+4,n):e.getInt32(t+4,n);const s=(n?a:i)>=0?1:-1;n?a*=s:i*=s;return s*(n?i*u+a:a*u+i)}function C(e,t,n,a){return a?k(e,t,n):e.getUint32(t,n)}function v(e){const t=new DataView(e,0,16),n=t.getUint16(0,!1);let a=null;if(18761===n)a=!0;else{if(19789!==n)throw new Error("unexpected endianess byte");a=!1}const i=t.getUint16(2,a);if(42!==i&&43!==i)throw new Error("unexpected tiff identifier");let s=4;const r=43===i;if(r){const e=t.getUint16(s,a);if(s+=2,8!==e)throw new Error("unsupported bigtiff version");if(0!==t.getUint16(s,a))throw new Error("unsupported bigtiff version");s+=2}return{littleEndian:a,isBigTiff:r,firstIFDPos:C(t,s,a,r)}}function B(t,n,a,i=0,s=r.TIFF_TAGS,l=4){const o=d(t,n,a,i,s,l);let f;const u=o.ifd;if(u){if(r.ifdTags.forEach(((e,a)=>{u.has(a)&&(f=u.get(a),f.data=d(t,n,f.valueOffset-i,i,e).ifd)})),u.has("GEOKEYDIRECTORY")){f=u.get("GEOKEYDIRECTORY");const e=f.values;if(e&&e.length>4){const a=e[0]+"."+e[1]+"."+e[2];f.data=d(t,n,f.valueOffset+6-i,i,r.GEO_KEYS,2).ifd,f.data&&f.data.set("GEOTIFFVersion",{id:0,type:2,valueCount:1,valueOffset:null,values:[a]})}}if(u.has("XMP")){f=u.get("XMP");const t=f.values;"number"==typeof t[0]&&7===f.type&&(f.values=[e(new Uint8Array(t))])}}return o}function V(e){const{width:t,height:n,tileHeight:a,tileWidth:i}=e,s=e.planes,r=i?i*a:t*n,l=p(e.ifds[0],"BITSPERSAMPLE");let o="";return r*s>2**30/(l>8?l/8:1)&&(o=i?"tiled tiff exceeding 1 gigabits per tile is not supported":"scanline tiff exceeding 1 gigabits is not supported"),o}function W(e,t,n,a,i){const s=a?4:1,r=n*s*i;a&&(e=new Uint8Array(e.buffer));for(let f=0;f<t;f++){const t=f*r;for(let n=i;n<r;n++)e[t+n]+=e[t+n-i]}if(!a)return e;const l=new Uint8Array(e.length),o=n*i;for(let f=0;f<t;f++){const t=f*r;for(let n=0;n<o;n++)for(let a=0;a<s;a++)l[t+n*s+a]=e[t+n+(s-a-1)*o]}return new Float32Array(l.buffer)}async function H(e,t){const{headerInfo:n,ifd:a,offsets:i,sizes:r}=t,l=[];for(let s=0;s<i.length;s++){const t=await M(e,n.littleEndian,a,i[s],r[s]||e.byteLength);l.push(t)}const o=D(a,n),f=p(a,"BITSPERSAMPLE"),u=h(p(a,"SAMPLEFORMAT")??1,f),c=p(a,"SAMPLESPERPIXEL")||n.planes,E=g(u),T=p(a,"TILEWIDTH"),I=p(a,"TILELENGTH"),w=p(a,"COMPRESSION")??1,d=T*I;let S;const y=[];let m=l[0];const A=34887===w;for(let s=0;s<c;s++){if(S=new E(d),l.length===c)m=l[s],m.length===d&&(S=m);else if(m.length)if(o||A)S=m.length===d?m:m.slice(d*s,d*(s+1));else for(let e=0;e<d;e++)S[e]=m[e*c+s];y.push(S)}const P=n.noData?n.noData[0]:t.noDataValue,O=n.metadata?n.metadata.statistics:null,x=O?O.map((e=>e.min)):null,L=O?O.map((e=>e.max)):null,R={pixelType:u,width:T,height:I,pixels:y,noDataValue:P};return null!=P?s(R,P):x&&L&&t.applyMinMaxConstraint&&(R.mask=b(y,x,L)),R}async function Y(e,t={}){const n=t.pyramidLevel||0,a=t.headerInfo||G(e),{ifds:i,noData:r}=a;if(0===i.length)throw new Error("no valid image file directory");const l=V(a);if(l)throw l;let o=null;const f=-1===n?i[i.length-1]:i[n],u=r??t.noDataValue;return o=a.tileWidth?await P(e,a,f):await O(e,a,f),o?(null!=u&&s(o,u),o):o}export{Y as decode,H as decodeTileOrStrip,R as getImageInfo,N as getMaskIFDs,U as getPyramidIFDs,D as isBSQConfig,L as parseFieldValues,G as parseHeader,B as parseIFD,v as parseSignature};
|
|
5
|
+
import{bytesToUTF8 as e}from"../rasterDatasets/byteStreamUtils.js";import{J as t}from"../../../chunks/Jpg.js";import{load as n,decode as a}from"./Lerc.js";import{decode as i}from"./Lzw.js";import{convertNoDataToMask as r}from"./pixelRangeUtils.js";import s from"./TiffTags.js";import{isPlatformLittleEndian as l}from"./utils.js";import{Z as o}from"../../../chunks/Zlib.js";const f=[0,1,1,2,4,8,1,1,2,4,8,4,8,-1,-1,-1,8,8,8],u=4294967296,c=new Set([1,5,6,7,8,34712,34887]);function h(e,t){let n="unknown";return 3===e?n=64===t?"f64":"f32":1===e?1===t?n="u1":2===t?n="u2":4===t?n="u4":t<=8?n="u8":t<=16?n="u16":t<=32&&(n="u32"):2===e&&(t<=8?n="s8":t<=16?n="s16":t<=32&&(n="s32")),n}function g(e){let t=null;switch(e?e.toLowerCase():"f32"){case"u1":case"u2":case"u4":case"u8":t=Uint8Array;break;case"u16":t=Uint16Array;break;case"u32":t=Uint32Array;break;case"s8":t=Int8Array;break;case"s16":t=Int16Array;break;case"s32":t=Int32Array;break;case"f64":t=Float64Array;break;default:t=Float32Array}return t}function E(e,t){return{x:t[0]*e.x+t[1]*e.y+t[2],y:t[3]*e.x+t[4]*e.y+t[5]}}function T(e,t){return e.get(t)?.values}function I(e,t){return e.get(t)?.values}function w(e,t){return e.get(t)?.values?.[0]}function d(e,t){return e.get(t)?.values?.[0]}function p(e,t,n,a=0,i=s.TIFF_TAGS,r=4){const l=8===r,o=l?G(new DataView(e,n,8),0,t):new DataView(e,n,2).getUint16(0,t),f=4+2*r,u=l?8:2,c=u+o*f;if(n+c>e.byteLength)return{success:!1,ifd:null,nextIFD:null,requiredBufferSize:c};const h=n+c+4<=e.byteLength?C(new DataView(e,n+c,8===r?8:4),0,t,8===r):null,g=n+u,E=new Map;let T,I,w,d,p,y=0,S=0;for(let m=0;m<o;m++){I=new DataView(e,g+f*m,f),w=I.getUint16(0,t),p=I.getUint16(2,t),d=s.getTagName(w,i);const n=[];2===r?(y=I.getUint16(4,t),S=I.getUint16(6,t)):4===r?(y=I.getUint32(4,t),S=I.getUint32(8,t)):8===r&&(y=C(I,4,t,!0),S=C(I,12,t,!0),n.push(I.getUint32(12,t)),n.push(I.getUint32(16,t))),T={id:w,type:p,valueCount:y,valueOffset:S,valueOffsets:n,values:null},L(e,t,T,a,!1,r),E.set(d,T)}return{success:!0,ifd:E,nextIFD:h,requiredBufferSize:c}}const y=(e,t)=>a(e,{inputOffset:t}).pixels[0];function S(e,t){if(1!==t&&2!==t&&4!==t)return e;const n=new Uint8Array(e),a=8/t,i=new Uint8Array(e.byteLength*a);let r=0;const s=2**t-1;for(let l=0;l<n.length;l++){const e=n[l];for(let n=0;n<a;n++)i[r++]=e<<t*n>>>8-t&s}return i.buffer}function m(e,n,a){const i=new t;i.parse(e),i.colorTransform=6===a?-1:0;const r=i.getData(i.width,i.height,1!==n&&4!==n);return new Uint8Array(r.buffer)}function A(e){const t=new o(e).getBytes(),n=new ArrayBuffer(t.length),a=new Uint8Array(n);return a.set(t),a}async function M(e,t,a,r,s){const o=l===t,f=d(a,"BITSPERSAMPLE"),u=d(a,"SAMPLESPERPIXEL")??1,c=d(a,"PHOTOMETRICINTERPRETATION"),E=d(a,"SAMPLEFORMAT")??1,T=h(E,f),I=d(a,"COMPRESSION")??1,w=g(T);let p,M,P;if(34887===I)return await n(),y(e,r);if(1===I)p=e.slice(r,r+s),M=new Uint8Array(p);else if(8===I||32946===I)M=new Uint8Array(e,r,s),M=A(M),p=M.buffer;else if(6===I)M=new Uint8Array(e,r,s),M=m(M,u,c),p=M.buffer;else if(7===I){const t=a.get("JPEGTABLES").values,n=t.length-2;M=new Uint8Array(n+s-2);for(let e=0;e<n;e++)M[e]=t[e];const i=new Uint8Array(e,r+2,s-2);for(let e=0;e<i.length;e++)M[n+e]=i[e];M=m(M,u,c),p=M.buffer}else{if(5!==I)throw new Error("tiff-decode: unsupport compression "+I);M=i(e,r,s,t),p=M.buffer}if(p=S(p,f),"u8"===T||"s8"===T||o)P=new w(p);else{p=new ArrayBuffer(M.length);const e=new Uint8Array(p);switch(T){case"u16":case"s16":for(let t=0;t<M.length;t+=2)e[t]=M[t+1],e[t+1]=M[t];break;case"u32":case"s32":case"f32":for(let t=0;t<M.length;t+=4)e[t]=M[t+3],e[t+1]=M[t+2],e[t+2]=M[t+1],e[t+3]=M[t]}P=new w(p)}const O=d(a,"PREDICTOR")??1,b=d(a,"TILEWIDTH"),x=d(a,"TILELENGTH");if(O>1&&(5===I||8===I||32946===I)&&b&&x){const e=D(a),t=new w(P.length);t.set(P),P=W(t,x,b,3===E&&3===O,e?1:u)}return P}async function P(e,t,n){const a=I(n,"TILEOFFSETS");if(void 0===a)return null;const i=I(n,"TILEBYTECOUNTS"),{width:r,height:s,pixelType:l,tileWidth:o,tileHeight:f}=R([n]),u=D(n,t),c=d(n,"SAMPLESPERPIXEL")||t.planes,h=r*s,E=d(n,"BITSPERSAMPLE"),T=34887===(d(n,"COMPRESSION")??1),w=g(l),p=[];for(let g=0;g<c;g++)p.push(new w(h));let y,S,m,A,P,O,b,x,L,U,N,k,G;const F=Math.ceil(r/o),C=new Uint8Array(h).fill(255);let v=!1;if(E%8==0)if(T&&u&&c>1){const l=Math.round(a.length/c);for(y=0;y<l;y++){O=Math.floor(y/F)*f,b=y%F*o,x=O*r+b;for(let l=0;l<c;l++){const u=y*c+l;for(0===i[u]?(m=null,v=!0):m=await M(e,t.littleEndian,n,a[u],i[u]),U=0,L=x,k=Math.min(o,r-b),N=Math.min(f,s-O),G=p[l],A=0;A<N;A++)for(L=x+A*r,U=A*o,P=0;P<k;P++,L++,U++)m?G[L]=m[U]:C[L]=0}}}else for(y=0;y<a.length;y++)for(O=Math.floor(y/F)*f,b=y%F*o,x=O*r+b,0===i[y]?(m=null,v=!0):m=await M(e,t.littleEndian,n,a[y],i[y]),U=0,L=x,k=Math.min(o,r-b),N=Math.min(f,s-O),S=0;S<c;S++)if(G=p[S],u||T)for(A=0;A<N;A++)for(L=x+A*r,U=o*f*S+A*o,P=0;P<k;P++,L++,U++)m?G[L]=m[U]:C[L]=0;else for(A=0;A<N;A++)for(L=x+A*r,U=A*o*c+S,P=0;P<k;P++,L++,U+=c)m?G[L]=m[U]:C[L]=0;return{width:r,height:s,pixelType:l,pixels:p,mask:v?C:void 0}}const O=(e,t,n)=>{const a=l===t.littleEndian,r=I(n,"STRIPOFFSETS");if(void 0===r)return null;const{width:s,height:o,pixelType:f}=R([n]),u=d(n,"SAMPLESPERPIXEL")||t.planes,c=d(n,"PHOTOMETRICINTERPRETATION"),h=s*o,E=d(n,"BITSPERSAMPLE"),T=g(f),w=new T(h*u),p=I(n,"STRIPBYTECOUNTS"),y=d(n,"ROWSPERSTRIP"),M=d(n,"COMPRESSION")??1;let P,O,b,x,L,D,U,N,k,G=y;if(E%8==0)for(P=0;P<r.length;P++){if(L=P*(y*s)*u,G=(P+1)*y>o?o-P*y:y,"u8"===f||"s8"===f||a)8===M||32946===M?(U=new Uint8Array(e,r[P],p[P]),U=A(U),D=U.buffer):6===M?(U=new Uint8Array(e,r[P],p[P]),U=m(U,u,c),D=U.buffer):5===M?(U=i(e,r[P],p[P],t.littleEndian),D=U.buffer):(p[P]!==G*s*u*E/8&&console.log("strip byte counts is different than expected"),D=e.slice(r[P],r[P]+p[P])),D=S(D,E),x=new T(D);else{switch(6===M||8===M||32946===M?(U=new Uint8Array(e,r[P],p[P]),N=A(U),D=N.buffer):(p[P]!==G*s*u*E/8&&console.log("strip byte counts is different than expected"),D=new ArrayBuffer(p[P]),U=new Uint8Array(e,r[P],p[P]),N=new Uint8Array(D)),f){case"u16":case"s16":for(b=0;b<U.length;b+=2)N[b]=U[b+1],N[b+1]=U[b];break;case"u32":case"s32":case"f32":for(b=0;b<U.length;b+=4)N[b]=U[b+3],N[b+1]=U[b+2],N[b+2]=U[b+1],N[b+3]=U[b]}D=S(D,E),x=new T(D)}w.set(x,L)}const F=[];if(1===u)F.push(w);else for(P=0;P<u;P++){for(k=new T(h),O=0;O<h;O++)k[O]=w[O*u+P];F.push(k)}return{width:s,height:o,pixelType:f,pixels:F}},b=(e,t,n)=>{if(!(e&&e.length>0&&t&&n))return null;let a,i,r;const s=e[0].length,l=e.length,o=new Uint8Array(s);for(let f=0;f<l;f++)if(a=e[f],i=t[f],r=n[f],0===f)for(let e=0;e<s;e++)o[e]=a[e]<i||a[e]>r?0:1;else for(let e=0;e<s;e++)o[e]&&(o[e]=a[e]<i||a[e]>r?0:1);return o},x=e=>{if(!e)return null;const t=e.match(/<Item(.*?)Item>/gi);if(!t||0===t.length)return null;const n=new Map;let a,i,r,s,l;for(let w=0;w<t.length;w++)a=t[w],i=a.slice(6,a.indexOf(">")),s=a.indexOf("sample="),s>-1&&(l=a.slice(s+8,a.indexOf('"',s+8))),s=a.indexOf("name="),s>-1&&(i=a.slice(s+6,a.indexOf('"',s+6))),i&&(r=a.slice(a.indexOf(">")+1,a.indexOf("</Item>")).trim(),null!=l?n.has(i)?n.get(i)[l]=r:n.set(i,[r]):n.set(i,r)),l=null;const o=n.get("STATISTICS_MINIMUM"),f=n.get("STATISTICS_MAXIMUM"),u=n.get("STATISTICS_MEAN"),c=n.get("STATISTICS_STDDEV");let h=null;if(o&&f){h=[];for(let e=0;e<o.length;e++)h.push({min:parseFloat(o[e]),max:parseFloat(f[e]),avg:u&&parseFloat(u[e]),stddev:c&&parseFloat(c[e])})}const g=n.get("BandName"),E=n.get("WavelengthMin"),T=n.get("WavelengthMax");let I=null;if(g){I=[];for(let e=0;e<g.length;e++)I.push({BandName:g[e],WavelengthMin:E&&parseFloat(E[e]),WavelengthMax:T&&parseFloat(T[e])})}return{statistics:h,bandProperties:I,dataType:n.get("DataType"),rawMetadata:n}};function L(e,t,n,a=0,i=!1,r=4){if(n.values)return!0;const s=n.type,l=n.valueCount;let o=n.valueOffset,c=[];const h=f[s],g=8*h,E=l*h,T=l*f[s]*8;let I,w;const d=8===r?64:32,p=n.valueOffsets;if(T>d){if(E>(i?e.byteLength:e?e.byteLength-o+a:0))return n.offlineOffsetSize=[o,E],n.values=null,!1}if(T<=d){if(!t)if(d<=32)o>>>=32-T;else{const e=p?.length?p[0]:o>>>0,t=p?.length?p[1]:Math.round((o-e)/u);T<=32?(o=e>>>32-T,p[0]=o):(o=e*2**(32-T)+(t>>>32-T),p[0]=e,p[1]=t>>>32-T)}if(1===l&&g===d)c=[o];else if(64===d){const e=p?.length?p[0]:o>>>0,t=p?.length?p[1]:Math.round((o-e)/u);let n=e,a=32;for(w=1;w<=l;w++){const e=32-g*w%32;if(a<g){const i=n<<e>>>32-a,r=t<<32-a>>>32-a;n=t,c.push(i+r*2**(g-a)),a-=32-(g-a)}else c.push(n<<e>>>32-g),a-=g;0===a&&(a=32,n=t)}}else for(w=1;w<=l;w++){const e=32-g*w;c.push(o<<e>>>32-g)}}else{o-=a,i&&(o=0);for(let n=o;n<o+E;n+=h){switch(s){case 1:case 2:case 7:I=new DataView(e,n,1).getUint8(0);break;case 3:I=new DataView(e,n,2).getUint16(0,t);break;case 4:case 13:I=new DataView(e,n,4).getUint32(0,t);break;case 5:I=new DataView(e,n,4).getUint32(0,t)/new DataView(e,n+4,4).getUint32(0,t);break;case 6:I=new DataView(e,n,1).getInt8(0);break;case 8:I=new DataView(e,n,2).getInt16(0,t);break;case 9:I=new DataView(e,n,4).getInt32(0,t);break;case 10:I=new DataView(e,n,4).getInt32(0,t)/new DataView(e,n+4,4).getInt32(0,t);break;case 11:I=new DataView(e,n,4).getFloat32(0,t);break;case 12:I=new DataView(e,n,8).getFloat64(0,t);break;case 16:case 18:I=G(new DataView(e,n,8),0,t);break;case 17:I=F(new DataView(e,n,8),0,t);break;default:I=null}c.push(I)}}if(2===s){let e="";const t=c;for(c=[],w=0;w<t.length;w++)0===t[w]&&""!==e?(c.push(e),e=""):e+=String.fromCharCode(t[w]);""===e&&0!==c.length||c.push(e)}return n.values=c,!0}function R(e){const t=e[0],n=d(t,"TILEWIDTH"),a=d(t,"TILELENGTH"),i=d(t,"IMAGEWIDTH"),r=d(t,"IMAGELENGTH"),s=d(t,"BITSPERSAMPLE"),l=d(t,"SAMPLESPERPIXEL"),o=d(t,"SAMPLEFORMAT")??1,f=h(o,s),u=D(t),g=T(t,"GDAL_NODATA");let p=null;g?.length&&(p=g.map((e=>parseFloat(e))),p.some((e=>isNaN(e)))&&(p=null));const y=d(t,"COMPRESSION")??1;let S;switch(y){case 1:S="NONE";break;case 2:case 3:case 4:case 32771:S="CCITT";break;case 5:S="LZW";break;case 6:case 7:S="JPEG";break;case 32773:S="PACKBITS";break;case 8:case 32946:S="DEFLATE";break;case 34712:S="JPEG2000";break;case 34887:S="LERC";break;default:S=String(y)}let m=!0,A="";c.has(y)||(m=!1,A+="unsupported tag compression "+y),o>3&&(m=!1,A+="unsupported tag sampleFormat "+o),1!==s&&2!==s&&4!==s&&s%8!=0&&(m=!1,A+="unsupported tag bitsPerSample "+s);const M=w(t,"GEOASCIIPARAMS");let P;if(M){const e=M.split("|").find((e=>e.includes("ESRI PE String = "))),t=e?e.replace("ESRI PE String = ",""):"";P=t.startsWith("COMPD_CS")||t.startsWith("PROJCS")||t.startsWith("GEOGCS")?{wkid:null,wkt:t}:null}const O=I(t,"GEOTIEPOINTS"),b=I(t,"GEOPIXELSCALE"),L=I(t,"GEOTRANSMATRIX"),R=t.has("GEOKEYDIRECTORY")?t.get("GEOKEYDIRECTORY").data:null;let k,G,F=!1,C=!1;if(R){F=2===d(R,"GTRasterTypeGeoKey");const e=d(R,"GTModelTypeGeoKey");if(2===e){const e=d(R,"GeographicTypeGeoKey");e>=1024&&e<=32766&&(P={wkid:e}),P||32767!==e||(C=!0,P={wkid:4326})}else if(1===e){const e=d(R,"ProjectedCSTypeGeoKey");e>=1024&&e<=32766&&(P={wkid:e})}}if(b&&O&&O.length>=6?(k=[b[0],0,O[3]-O[0]*b[0],0,-Math.abs(b[1]),O[4]-O[1]*b[1]],F&&(k[2]-=.5*k[0]+.5*k[1],k[5]-=.5*k[3]+.5*k[4])):L&&16===L.length&&(k=F?[L[0],L[1],L[3]-.5*L[0],L[4],L[5],L[7]-.5*L[5]]:[L[0],L[1],L[3],L[4],L[5],L[7]]),k){const e=[{x:0,y:r},{x:0,y:0},{x:i,y:r},{x:i,y:0}];let t,n=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;for(let i=0;i<e.length;i++)t=E(e[i],k),n=t.x>n?n:t.x,s=t.x<s?s:t.x,a=t.y>a?a:t.y,l=t.y<l?l:t.y;G={xmin:n,xmax:s,ymin:a,ymax:l,spatialReference:P}}else G={xmin:-.5,ymin:.5-r,xmax:i-.5,ymax:.5,spatialReference:P};C&&(G.xmax-G.xmin>400||Math.max(Math.abs(G.xmin),Math.abs(G.xmax))>361)&&(P=null,G.spatialReference=null);const v=U(e);let B,W,H,Y,_;if(v.length>0){H=Math.round(Math.log(i/d(v[0],"IMAGEWIDTH"))/Math.LN2);const e=v[v.length-1];Y=Math.round(Math.log(i/d(e,"IMAGEWIDTH"))/Math.LN2),B=d(e,"TILEWIDTH"),W=d(e,"TILELENGTH")}B=null!=Y&&Y>0?B||n:null,W=null!=Y&&Y>0?W||a:null,n&&(_=[{maxCol:Math.ceil(i/n)-1,maxRow:Math.ceil(r/a)-1,minRow:0,minCol:0}],v.forEach((e=>{_.push({maxCol:Math.ceil(d(e,"IMAGEWIDTH")/d(e,"TILEWIDTH"))-1,maxRow:Math.ceil(d(e,"IMAGELENGTH")/d(e,"TILELENGTH"))-1,minRow:0,minCol:0})})));const K=w(e[0],"GDAL_METADATA"),X=x(K);A+=" "+V({width:i,height:r,tileWidth:n,tileHeight:a,planes:l,ifds:e});return{width:i,height:r,tileWidth:n,tileHeight:a,planes:l,isBSQ:u,pixelType:f,compression:S,noData:p,hasMaskBand:N(e).length===v.length+1,isSupported:m,message:A,extent:G,isPseudoGeographic:C,affine:b?null:k,firstPyramidLevel:H,maximumPyramidLevel:Y,pyramidBlockWidth:B,pyramidBlockHeight:W,tileBoundary:_,metadata:X}}function D(e,t){const n=T(e,"PLANARCONFIGURATION");return n?2===n[0]:!!t&&t.isBSQ}function U(e){return e.filter((e=>1===d(e,"NEWSUBFILETYPE")))}function N(e){return e.filter((e=>{const t=4==(4&(d(e,"NEWSUBFILETYPE")??0)),n=4===d(e,"PHOTOMETRICINTERPRETATION");return t&&n}))}function k(e){const{littleEndian:t,isBigTiff:n,firstIFDPos:a}=v(e);let i=a;const r=[];do{const a=B(e,t,i,0,s.TIFF_TAGS,n?8:4);if(!a.success)break;r.push(a.ifd),i=a.nextIFD}while(i>0);return{...R(r),littleEndian:t,isBigTiff:n,ifds:r,pyramidIFDs:U(r),maskIFDs:N(r)}}function G(e,t,n){const a=e.getUint32(t,n),i=e.getUint32(t+4,n);return n?i*u+a:a*u+i}function F(e,t,n){let a=n?e.getInt32(t,n):e.getUint32(t,n),i=n?e.getUint32(t+4,n):e.getInt32(t+4,n);const r=(n?a:i)>=0?1:-1;n?a*=r:i*=r;return r*(n?i*u+a:a*u+i)}function C(e,t,n,a){return a?G(e,t,n):e.getUint32(t,n)}function v(e){const t=new DataView(e,0,16),n=t.getUint16(0,!1);let a=null;if(18761===n)a=!0;else{if(19789!==n)throw new Error("unexpected endianess byte");a=!1}const i=t.getUint16(2,a);if(42!==i&&43!==i)throw new Error("unexpected tiff identifier");let r=4;const s=43===i;if(s){const e=t.getUint16(r,a);if(r+=2,8!==e)throw new Error("unsupported bigtiff version");if(0!==t.getUint16(r,a))throw new Error("unsupported bigtiff version");r+=2}return{littleEndian:a,isBigTiff:s,firstIFDPos:C(t,r,a,s)}}function B(t,n,a,i=0,r=s.TIFF_TAGS,l=4){const o=p(t,n,a,i,r,l);let f;const u=o.ifd;if(u){if(s.ifdTags.forEach(((e,a)=>{u.has(a)&&(f=u.get(a),f.data=p(t,n,f.valueOffset-i,i,e).ifd)})),u.has("GEOKEYDIRECTORY")){f=u.get("GEOKEYDIRECTORY");const e=f.values;if(e&&e.length>4){const a=e[0]+"."+e[1]+"."+e[2];f.data=p(t,n,f.valueOffset+6-i,i,s.GEO_KEYS,2).ifd,f.data&&f.data.set("GEOTIFFVersion",{id:0,type:2,valueCount:1,valueOffset:null,values:[a]})}}if(u.has("XMP")){f=u.get("XMP");const t=f.values;"number"==typeof t[0]&&7===f.type&&(f.values=[e(new Uint8Array(t))])}}return o}function V(e){const{width:t,height:n,tileHeight:a,tileWidth:i}=e,r=e.planes,s=i?i*a:t*n,l=d(e.ifds[0],"BITSPERSAMPLE");let o="";return s*r>2**30/(l>8?l/8:1)&&(o=i?"tiled tiff exceeding 1 gigabits per tile is not supported":"scanline tiff exceeding 1 gigabits is not supported"),o}function W(e,t,n,a,i){const r=a?4:1,s=n*r*i;a&&(e=new Uint8Array(e.buffer));for(let f=0;f<t;f++){const t=f*s;for(let n=i;n<s;n++)e[t+n]+=e[t+n-i]}if(!a)return e;const l=new Uint8Array(e.length),o=n*i;for(let f=0;f<t;f++){const t=f*s;for(let n=0;n<o;n++)for(let a=0;a<r;a++)l[t+n*r+a]=e[t+n+(r-a-1)*o]}return new Float32Array(l.buffer)}async function H(e,t){const{headerInfo:n,ifd:a,offsets:i,sizes:s}=t,l=[];for(let r=0;r<i.length;r++){s[r];const t=await M(e,n.littleEndian,a,i[r],s[r]||e.byteLength);l.push(t)}const o=D(a,n),f=d(a,"BITSPERSAMPLE"),u=h(d(a,"SAMPLEFORMAT")??1,f),c=d(a,"SAMPLESPERPIXEL")||n.planes,E=g(u),T=d(a,"TILEWIDTH"),I=d(a,"TILELENGTH"),w=d(a,"COMPRESSION")??1,p=T*I;let y;const S=[];let m=l[0];const A=34887===w;for(let r=0;r<c;r++){if(y=new E(p),l.length===c)m=l[r],m.length===p&&(y=m);else if(m.length)if(o||A)y=m.length===p?m:m.slice(p*r,p*(r+1));else for(let e=0;e<p;e++)y[e]=m[e*c+r];S.push(y)}const P=n.noData?n.noData[0]:t.noDataValue,O=n.metadata?n.metadata.statistics:null,x=O?O.map((e=>e.min)):null,L=O?O.map((e=>e.max)):null,R={pixelType:u,width:T,height:I,pixels:S,noDataValue:P};return null!=P?r(R,P):x&&L&&t.applyMinMaxConstraint&&(R.mask=b(S,x,L)),R}async function Y(e,t={}){const n=t.pyramidLevel||0,a=t.headerInfo||k(e),{ifds:i,noData:s}=a;if(0===i.length)throw new Error("no valid image file directory");const l=V(a);if(l)throw l;let o=null;const f=-1===n?i[i.length-1]:i[n],u=s??t.noDataValue;return o=a.tileWidth?await P(e,a,f):await O(e,a,f),o?(null!=u&&r(o,u),o):o}export{Y as decode,H as decodeTileOrStrip,R as getImageInfo,N as getMaskIFDs,U as getPyramidIFDs,D as isBSQConfig,L as parseFieldValues,k as parseHeader,B as parseIFD,v as parseSignature};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.28/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
const
|
|
5
|
+
const e=9999999e31,t=2e-7,n={u1:[0,1],u2:[0,3],u4:[0,15],u8:[0,255],s8:[-128,127],u16:[0,65535],s16:[-32768,32767],u32:[0,4294967295],s32:[-2147483648,2147483647],f32:[-34028234663852886e22,34028234663852886e22],f64:[-Number.MAX_VALUE,Number.MAX_VALUE],unknown:void 0,c64:void 0,c128:void 0};function s(e){return n[e]??[-34028234663852886e22,34028234663852886e22]}function u(n,u,a){if(n.depthCount&&n.depthCount>1)return;const{pixels:i,statistics:l,pixelType:o}=n,c=i[0].length,r=n.bandMasks??[],f=n.mask??new Uint8Array(c).fill(255),b="f32"===o||"f64"===o,m=s(o);let d=!1;for(let s=0;s<i.length;s++){const n="number"==typeof u?u:u[s];if(null==n)continue;const c=l?.[s].minValue??m[0],h=l?.[s].maxValue??m[1];if(c>n+Number.EPSILON||h<n-Number.EPSILON)continue;const p=r[s]||f.slice(),M=i[s],N=a?.customFloatTolerance;if(b&&0!==N){let s=N;s||(s=Math.abs(n)>=e?t*Math.abs(n):"f32"===o?2**-23:Number.EPSILON);for(let e=0;e<M.length;e++)p[e]&&Math.abs(M[e]-n)<s&&(M[e]=0,p[e]=0,f[e]=0,d=!0)}else for(let e=0;e<M.length;e++)p[e]&&M[e]===n&&(M[e]=0,p[e]=0,f[e]=0,d=!0);r[s]=p}d&&(n.bandMasks=n.bandMasks||n.pixels.length>1?r:null,n.mask=f),d&&"updateStatistics"in n&&n.updateStatistics()}export{u as convertNoDataToMask,s as getPixelValueRange};
|
package/networks/Network.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.28/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../chunks/tslib.es6.js";import"../geometry.js";import t from"../Graphic.js";import r from"../request.js";import o from"../core/Error.js";import a from"../core/Loadable.js";import s from"../core/Logger.js";import{MultiOriginJSONMixin as i}from"../core/MultiOriginJSONSupport.js";import{isAbortError as n}from"../core/promiseUtils.js";import{urlToObject as l}from"../core/urlUtils.js";import{property as d}from"../core/accessorSupport/decorators/property.js";import"../core/accessorSupport/ensureType.js";import"../core/arrayUtils.js";import"../core/has.js";import{subclass as u}from"../core/accessorSupport/decorators/subclass.js";import p from"../geometry/Extent.js";import{fromJSON as c}from"../geometry/support/jsonUtils.js";import{emitApplyEditsEvent as m}from"../layers/mixins/EditBusLayer.js";import{parse as y}from"../layers/support/arcgisLayerUrl.js";import f from"./support/TopologyValidationJobInfo.js";import{networkFromPortalItem as h}from"./support/utils.js";import g from"../rest/networks/support/QueryNamedTraceConfigurationsParameters.js";import w from"../geometry/SpatialReference.js";let v=class extends(i(a)){static fromPortalItem(e){return h(e)}constructor(e){super(e),this.id=null,this.title=null,this.layerUrl=null,this.dataElement=null,this.fullExtent=null,this.spatialReference=null,this.type=null,this.sourceJSON=null}initialize(){this.when().catch((e=>{n(e)||s.getLogger(this).error("#load()",`Failed to load layer (title: '${this.title??"no title"}', id: '${this.id??"no id"}')`,{error:e})}))}get datasetName(){return this.dataElement?.name??null}get owner(){return this.dataElement?.userIdentity??null}get schemaGeneration(){return this.dataElement?.schemaGeneration??null}get parsedUrl(){return l(this.layerUrl)}get featureServiceUrl(){
|
|
5
|
+
import{_ as e}from"../chunks/tslib.es6.js";import"../geometry.js";import t from"../Graphic.js";import r from"../request.js";import o from"../core/Error.js";import a from"../core/Loadable.js";import s from"../core/Logger.js";import{MultiOriginJSONMixin as i}from"../core/MultiOriginJSONSupport.js";import{isAbortError as n}from"../core/promiseUtils.js";import{urlToObject as l}from"../core/urlUtils.js";import{property as d}from"../core/accessorSupport/decorators/property.js";import"../core/accessorSupport/ensureType.js";import"../core/arrayUtils.js";import"../core/has.js";import{subclass as u}from"../core/accessorSupport/decorators/subclass.js";import p from"../geometry/Extent.js";import{fromJSON as c}from"../geometry/support/jsonUtils.js";import{emitApplyEditsEvent as m}from"../layers/mixins/EditBusLayer.js";import{parse as y}from"../layers/support/arcgisLayerUrl.js";import f from"./support/TopologyValidationJobInfo.js";import{networkFromPortalItem as h}from"./support/utils.js";import g from"../rest/networks/support/QueryNamedTraceConfigurationsParameters.js";import w from"../geometry/SpatialReference.js";let v=class extends(i(a)){static fromPortalItem(e){return h(e)}constructor(e){super(e),this.id=null,this.title=null,this.layerUrl=null,this.dataElement=null,this.fullExtent=null,this.spatialReference=null,this.type=null,this.sourceJSON=null}initialize(){this.when().catch((e=>{n(e)||s.getLogger(this).error("#load()",`Failed to load layer (title: '${this.title??"no title"}', id: '${this.id??"no id"}')`,{error:e})}))}get datasetName(){return this.dataElement?.name??null}get owner(){return this.dataElement?.userIdentity??null}get schemaGeneration(){return this.dataElement?.schemaGeneration??null}get parsedUrl(){return l(this.layerUrl)}get featureServiceUrl(){return y(this.parsedUrl.path).url.path}get networkServiceUrl(){return this.featureServiceUrl.replace(/\/FeatureServer/i,"/UtilityNetworkServer")}get layerId(){return y(this.parsedUrl.path).sublayer}get networkSystemLayers(){return null}async load(e){return this.addResolvingPromise(this._fetchDataElement(this.featureServiceUrl,this.layerId.toString(),e)),this.addResolvingPromise(this._fetchLayerMetaData(this.layerUrl,e)),this}getLayerIdBySourceId(e){if(this.dataElement){const t=this.dataElement.domainNetworks;for(const r of t){for(const t of r.edgeSources??[])if(t.sourceId===e)return t.layerId;for(const t of r.junctionSources??[])if(t.sourceId===e)return t.layerId}return null}return null}async queryNamedTraceConfigurations(e,t){const{queryNamedTraceConfigurations:r}=await import("../rest/networks/queryNamedTraceConfigurations.js"),o=this.networkServiceUrl,a=new g({...e});return(await r(o,a,{...t}))?.namedTraceConfigurations??null}async validateTopology(e,t){if(!e.validateArea)throw new o("network:undefined-validateArea","the network must have validateArea defined in the validate network topology parameters.");const[{validateNetworkTopology:r},{default:a}]=await Promise.all([import("../rest/networks/validateNetworkTopology.js"),import("../rest/networks/support/ValidateNetworkTopologyParameters.js")]),s=a.from(e),i=this.networkServiceUrl,n=this.featureServiceUrl,l=m(n,null,null,!0),d=await r(i,s,{...t});if(d?.serviceEdits){const e=[];for(const t of d.serviceEdits){const{editedFeatures:r}=t,o=r?.spatialReference?new w(r.spatialReference):null;e.push({layerId:t.layerId,editedFeatures:{adds:r?.adds?.map((e=>this._createEditedFeature(e,o)))||[],updates:r?.updates?.map((e=>({original:this._createEditedFeature(e[0],o),current:this._createEditedFeature(e[1],o)})))||[],deletes:r?.deletes?.map((e=>this._createEditedFeature(e,o)))||[],spatialReference:o}})}l.resolve({edits:null,addedFeatures:[],updatedFeatures:[],deletedFeatures:[],addedAttachments:[],updatedAttachments:[],deletedAttachments:[],editedFeatures:e,exceededTransferLimit:!1,historicMoment:d.moment})}return d}async submitTopologyValidationJob(e,t){if(!e.validateArea)throw new o("network:undefined-validateArea","the network must have validateArea defined in the validate network topology parameters.");if(!e.gdbVersion)throw new o("network:undefined-gdb-version","version must be defined");const[{submitValidateNetworkTopologyJob:r},{default:a}]=await Promise.all([import("../rest/networks/validateNetworkTopology.js"),import("../rest/networks/support/ValidateNetworkTopologyParameters.js")]),s=a.from(e),i=this.networkServiceUrl,n=this.featureServiceUrl?m(this.featureServiceUrl,null,null,!0):void 0,l=await r(i,s,{...t});return new f({statusUrl:l,editsResolver:n})}_createEditedFeature(e,r){return new t({attributes:e.attributes,geometry:c({...e.geometry,spatialReference:r})})}async _fetchLayerMetaData(e,t){const o=await r(e,{responseType:"json",query:{f:"json"},...t});this.sourceJSON=o.data,this.read(o.data,{origin:"service"})}async _fetchDataElement(e,t,o){if(this.dataElement)return;const a=await r(`${e}/queryDataElements`,{responseType:"json",query:{layers:JSON.stringify([t]),f:"json"},...o}).then((e=>e.data.layerDataElements?.[0]));a&&this.read(a,{origin:"service"})}};e([d({type:String,nonNullable:!0,json:{origins:{"web-map":{read:!0,write:{isRequired:!0}},service:{read:!0}},read:!1}})],v.prototype,"id",void 0),e([d({type:String,nonNullable:!0,json:{origins:{"web-map":{read:!0,write:{isRequired:!0}},service:{read:{source:"name"}}},read:!1}})],v.prototype,"title",void 0),e([d({type:String,nonNullable:!0,json:{origins:{"web-map":{read:{source:"url"},write:{target:"url",isRequired:!0}}},read:!1}})],v.prototype,"layerUrl",void 0),e([d({type:Object,json:{origins:{service:{read:!0}},read:!1}})],v.prototype,"dataElement",void 0),e([d({type:p,json:{origins:{service:{read:{source:"extent"}}},read:!1}})],v.prototype,"fullExtent",void 0),e([d({type:w,json:{origins:{service:{read:{source:"extent.spatialReference"}}},read:!1}})],v.prototype,"spatialReference",void 0),e([d({type:["utility","trace"],readOnly:!0,json:{read:!1,write:!1}})],v.prototype,"type",void 0),e([d({readOnly:!0})],v.prototype,"datasetName",null),e([d({readOnly:!0})],v.prototype,"owner",null),e([d({readOnly:!0})],v.prototype,"schemaGeneration",null),e([d({readOnly:!0})],v.prototype,"parsedUrl",null),e([d({readOnly:!0})],v.prototype,"featureServiceUrl",null),e([d({readOnly:!0})],v.prototype,"networkServiceUrl",null),e([d({readOnly:!0})],v.prototype,"layerId",null),e([d()],v.prototype,"sourceJSON",void 0),e([d({readOnly:!0})],v.prototype,"networkSystemLayers",null),v=e([u("esri.networks.Network")],v);const j=v;export{j as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.28/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../chunks/tslib.es6.js";import{
|
|
5
|
+
import{_ as e}from"../chunks/tslib.es6.js";import{property as t}from"../core/accessorSupport/decorators/property.js";import"../core/accessorSupport/ensureType.js";import"../core/arrayUtils.js";import"../core/has.js";import{subclass as r}from"../core/accessorSupport/decorators/subclass.js";import s from"../layers/FeatureLayer.js";import{queryAllJSON as a}from"../layers/support/featureQueryAll.js";import o from"./Network.js";import n from"./RulesTable.js";import i from"./support/NamedTraceConfiguration.js";import u from"./support/NetworkSystemLayers.js";import l from"./support/TerminalConfiguration.js";import m from"./support/TraceJobInfo.js";import{RuleType as d}from"./support/typeUtils.js";import c from"../rest/support/Query.js";let p=class extends o{constructor(e){super(e),this.sharedNamedTraceConfigurations=[],this.type="utility"}get serviceTerritoryFeatureLayerId(){return this.dataElement?.serviceTerritoryFeatureLayerId??null}get networkSystemLayers(){return new u({rulesTableId:this.sourceJSON?.systemLayers.rulesTableId,rulesTableUrl:this.sourceJSON?`${this.featureServiceUrl}/${this.sourceJSON?.systemLayers.rulesTableId}`:null,subnetworksTableId:this.sourceJSON?.systemLayers.subnetworksTableId,subnetworksTableUrl:this.sourceJSON?`${this.featureServiceUrl}/${this.sourceJSON?.systemLayers.subnetworksTableId}`:null,dirtyAreasLayerId:this.sourceJSON?.systemLayers.dirtyAreasLayerId,dirtyAreasLayerUrl:this.sourceJSON?`${this.featureServiceUrl}/${this.sourceJSON?.systemLayers.dirtyAreasLayerId}`:null})}get terminalConfigurations(){return this.dataElement?.terminalConfigurations.map((e=>l.fromJSON(e)))||[]}get domainNetworkNames(){return this.dataElement?.domainNetworks.map((e=>e.domainNetworkName))||[]}get _utilityLayerList(){const e=new Set;return this.dataElement?.domainNetworks?.map((t=>{t.edgeSources.map((t=>{e.add(t.layerId)})),t.junctionSources.map((t=>{e.add(t.layerId)}))})),e}async load(e){return this.addResolvingPromise(super.load(e)),this.addResolvingPromise(this._loadNamedTraceConfigurationsFromNetwork(e)),this}getTerminalConfiguration(e){let t=null,r=null;const s=e.layer;let a=null;if("feature"===s?.type){if(a=s.layerId,null===a)return null}else{if("subtype-sublayer"!==s?.type)return null;if(a=s?.parent?.layerId??null,null===a)return null}const o=e.attributes;if(null==o)return null;for(const u of Object.keys(o))"ASSETGROUP"===u.toUpperCase()&&(t=e.getAttribute(u)),"ASSETTYPE"===u.toUpperCase()&&(r=e.getAttribute(u));if(!this.dataElement)return null;let n=null;const i=this.dataElement.domainNetworks;for(const u of i){const e=u.junctionSources?.find((e=>e.layerId===a));if(e){const s=e.assetGroups?.find((e=>e.assetGroupCode===t));if(s){const e=s.assetTypes?.find((e=>e.assetTypeCode===r));if(e){n=e.terminalConfigurationId;break}}}}if(null!=n){const e=this.dataElement.terminalConfigurations,t=e?.find((e=>e.terminalConfigurationId===n));return t?l.fromJSON(t):null}return null}getTierNames(e){const t=this.dataElement?.domainNetworks.find((t=>t.domainNetworkName===e));return t?.tiers.map((e=>e.name))||[]}async getRulesTable(){return this._createRulesTable()}isUtilityLayer(e){return this._utilityLayerList.has(e.layerId)}async trace(e){const[{trace:t},{default:r}]=await Promise.all([import("../rest/networks/trace.js"),import("../rest/networks/support/TraceParameters.js")]),s=r.from(e);return t(this.networkServiceUrl,s)}async submitTraceJob(e){const[{submitTraceJob:t},{default:r}]=await Promise.all([import("../rest/networks/trace.js"),import("../rest/networks/support/TraceParameters.js")]),s=r.from(e),a=await t(this.networkServiceUrl,s);return new m({statusUrl:a})}async _loadNamedTraceConfigurationsFromNetwork(e){if(0===this.sharedNamedTraceConfigurations?.length)return;const t=this.sharedNamedTraceConfigurations.map((e=>e.globalId)),r=await this.queryNamedTraceConfigurations({globalIds:t},e);for(const s of this.sharedNamedTraceConfigurations){const e=r?.find((e=>e.globalId===s.globalId));if(e){const t=e.write({},{origin:"service"});s.read(t,{origin:"service"})}}}async _createRulesTable(){const e=this.networkSystemLayers.rulesTableUrl,t=new s({url:e});await t.load();const r=this.dataElement?.domainNetworks;if(!r)return null;const a=r.flatMap((e=>[...e.edgeSources,...e.junctionSources])),o=(await this._queryRulesTable(t)).map((e=>this._hydrateRuleInfo(t,a,e)));return new n({layer:t,rules:o})}async _queryRulesTable(e){const t=new c({where:"1=1",outFields:["*"]});return(await a(e,t)).features}_hydrateRuleInfo(e,t,r){const s=e.fieldsIndex,a=s.get("RULETYPE"),o=s.get("CREATIONDATE"),n=s.get("FROMNETWORKSOURCEID"),i=s.get("FROMASSETGROUP"),u=s.get("FROMASSETTYPE"),l=s.get("FROMTERMINALID"),m=s.get("TONETWORKSOURCEID"),c=s.get("TOASSETGROUP"),p=s.get("TOASSETTYPE"),y=s.get("TOTERMINALID"),f=s.get("VIANETWORKSOURCEID"),T=s.get("VIAASSETGROUP"),g=s.get("VIAASSETTYPE"),I=s.get("VIATERMINALID"),h=r.attributes[a.name],b=new Date(r.attributes[o.name]),S=[{networkSourceId:r.attributes[n.name],assetGroupId:r.attributes[i.name],assetTypeId:r.attributes[u.name],terminalId:r.attributes[l.name]},{networkSourceId:r.attributes[m.name],assetGroupId:r.attributes[c.name],assetTypeId:r.attributes[p.name],terminalId:r.attributes[y.name]},{networkSourceId:r.attributes[f.name],assetGroupId:r.attributes[T.name],assetTypeId:r.attributes[g.name],terminalId:r.attributes[I.name]}];let w;!function(e){e[e.from=0]="from",e[e.to=1]="to",e[e.via=2]="via"}(w||(w={}));const N={ruleType:h,creationDate:b};for(const k of[w.from,w.to,w.via]){if(h!==d.RTEdgeJunctionEdgeConnectivity&&k===w.via)continue;const e=S[k],r=t.find((t=>t.sourceId===e.networkSourceId)),s=r?.assetGroups.find((t=>t.assetGroupCode===e.assetGroupId)),a=s?.assetTypes.find((t=>t.assetTypeCode===e.assetTypeId));let o=this._getTerminal(h,a,e);h!==d.RTContainment&&h!==d.RTAttachment||(o=null);let n="";switch(k){case w.from:n="from";break;case w.to:n="to";break;case w.via:n="via"}N[`${n}NetworkSource`]=r,N[`${n}AssetGroup`]=s,N[`${n}AssetType`]=a,N[`${n}Terminal`]=o?.toJSON()}return N}_getTerminal(e,t,r){if(e===d.RTAttachment||e===d.RTContainment)return null;const s=t?.terminalConfigurationId,a=this.terminalConfigurations?.find((e=>e.id===s));return a?.terminals?.find((e=>e.id===r.terminalId))??null}};e([t({type:[i],json:{origins:{"web-map":{read:{source:"traceConfigurations"},write:{target:"traceConfigurations"}},service:{read:{source:"traceConfigurations"}}},read:!1}})],p.prototype,"sharedNamedTraceConfigurations",void 0),e([t({type:["utility"],readOnly:!0,json:{read:!1,write:!1}})],p.prototype,"type",void 0),e([t({readOnly:!0})],p.prototype,"serviceTerritoryFeatureLayerId",null),e([t({readOnly:!0})],p.prototype,"networkSystemLayers",null),e([t({readOnly:!0})],p.prototype,"terminalConfigurations",null),e([t({readOnly:!0})],p.prototype,"domainNetworkNames",null),p=e([r("esri.networks.UtilityNetwork")],p);const y=p;export{y as default};
|
package/package.json
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.28/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as e}from"../../../chunks/tslib.es6.js";import{JSONSupport as t}from"../../../core/JSONSupport.js";import{property as o}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import"../../../core/arrayUtils.js";import"../../../core/has.js";import{subclass as r}from"../../../core/accessorSupport/decorators/subclass.js";let s=class extends t{constructor(e){super(e),this.moment=null,this.fullUpdate=!1,this.validateErrorsCreated=!1,this.dirtyAreaCount=null,this.exceededTransferLimit=null,this.serviceEdits=null}};e([o({type:Date,json:{type:Number,write:{writer:(e,t)=>{t.moment=e?e.getTime():null}}}})],s.prototype,"moment",void 0),e([o({type:Boolean,json:{write:!0}})],s.prototype,"fullUpdate",void 0),e([o({type:Boolean,json:{write:!0}})],s.prototype,"validateErrorsCreated",void 0),e([o({type:Number,json:{write:!0}})],s.prototype,"dirtyAreaCount",void 0),e([o({type:Boolean,json:{write:!0}})],s.prototype,"exceededTransferLimit",void 0),e([o({type:[Object],json:{write:!0}})],s.prototype,"serviceEdits",void 0),s=e([r("esri.rest.networks.support.ValidateNetworkTopologyResult")],s);const
|
|
5
|
+
import{_ as e}from"../../../chunks/tslib.es6.js";import{JSONSupport as t}from"../../../core/JSONSupport.js";import{property as o}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import"../../../core/arrayUtils.js";import"../../../core/has.js";import{subclass as r}from"../../../core/accessorSupport/decorators/subclass.js";let s=class extends t{constructor(e){super(e),this.moment=null,this.fullUpdate=!1,this.validateErrorsCreated=!1,this.dirtyAreaCount=null,this.exceededTransferLimit=null,this.serviceEdits=null,this.discoveredSubnetworks=null}};e([o({type:Date,json:{type:Number,write:{writer:(e,t)=>{t.moment=e?e.getTime():null}}}})],s.prototype,"moment",void 0),e([o({type:Boolean,json:{write:!0}})],s.prototype,"fullUpdate",void 0),e([o({type:Boolean,json:{write:!0}})],s.prototype,"validateErrorsCreated",void 0),e([o({type:Number,json:{write:!0}})],s.prototype,"dirtyAreaCount",void 0),e([o({type:Boolean,json:{write:!0}})],s.prototype,"exceededTransferLimit",void 0),e([o({type:[Object],json:{write:!0}})],s.prototype,"serviceEdits",void 0),e([o({type:[Object],json:{write:!0}})],s.prototype,"discoveredSubnetworks",void 0),s=e([r("esri.rest.networks.support.ValidateNetworkTopologyResult")],s);const i=s;export{i as default};
|
package/support/revision.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.28/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
const
|
|
5
|
+
const b="20230708",e="b898d4d18b7efb1436e338128b02169a23c8f104";export{b as buildDate,e as commitHash};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.28/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{disposeMaybe as e}from"../../../../core/maybe.js";import{ChapmanAtmosphereTechniqueConfiguration as t}from"../../environment/ChapmanAtmosphereTechniqueConfiguration.js";import{
|
|
5
|
+
import{disposeMaybe as e}from"../../../../core/maybe.js";import{ChapmanAtmosphereTechniqueConfiguration as t}from"../../environment/ChapmanAtmosphereTechniqueConfiguration.js";import{BlendWeightsTechnique as s}from"./BlendWeightsTechnique.js";import{BlurTechnique as r}from"./BlurTechnique.js";import{EdgeDetectTechnique as i}from"./EdgeDetectTechnique.js";import{createScreenSizeTriangleVAO as a}from"./glUtil3D.js";import{A as o}from"../../../../chunks/AtmosphereCompositing.glsl.js";import{AtmosphereCompositingTechnique as h}from"../shaders/AtmosphereCompositingTechnique.js";import{C as m}from"../../../../chunks/Compositing.glsl.js";import{CompositingTechnique as n}from"../shaders/CompositingTechnique.js";import{CompositingTechniqueConfiguration as c,AlphaMode as u}from"../shaders/CompositingTechniqueConfiguration.js";import{H as _}from"../../../../chunks/HUDCompositing.glsl.js";import{HUDCompositingTechnique as p}from"../shaders/HUDCompositingTechnique.js";import{O as l}from"../../../../chunks/OITCompositing.glsl.js";import{OITCompositingTechnique as d}from"../shaders/OITCompositingTechnique.js";import{O as q}from"../../../../chunks/OverlayCompositing.glsl.js";import{OverlayCompositingTechnique as P}from"../shaders/OverlayCompositingTechnique.js";import{SMAAPassParameters as g}from"../shaders/SMAAPassParameters.js";import{PrimitiveType as f}from"../../../webgl/enums.js";class T{constructor(e,s){this._rctx=e,this._techniqueRepository=s,this._configuration=new c,this._atmosphereConfiguration=new t,this._passParameters=new m,this._atmosphereParameters=new o,this._oitParameters=new l,this._hudParameters=new _,this._overlayParameters=new q,this._smaaParameters=new g}destroy(){this._vao=e(this._vao)}compositeOIT(e,t,s,r){this._oitParameters.colorTexture=t,this._oitParameters.alphaTexture=s,this._oitParameters.frontFaceTexture=r;const i=this._techniqueRepository.acquire(d);this._rctx.bindTechnique(i,this._oitParameters,e),this._draw(),i.release()}compositeHUD(e,t){this._hudParameters.texture=t;const s=this._techniqueRepository.acquire(p);this._rctx.bindTechnique(s,this._hudParameters,e),this._draw(),s.release()}compositeOverlay(e,t,s,r){this._overlayParameters.texture=t,this._overlayParameters.opacity=s,this._overlayParameters.overlayIndex=r;const i=this._techniqueRepository.acquire(P);this._rctx.bindTechnique(i,this._overlayParameters,e),this._draw(),i.release()}compositeAtmosphere(e,t,s,r){this._atmosphereParameters.color=t,this._atmosphereParameters.depth=s,this._atmosphereConfiguration.haze=r;const i=this._techniqueRepository.acquire(h,this._atmosphereConfiguration);this._rctx.bindTechnique(i,this._atmosphereParameters,e),this._draw(),i.release()}composite(e,t,s=u.None,r=1){this._configuration.alphaMode=s,this._configuration.hasOpacityFactor=1!==r,this._passParameters.texture=t,this._passParameters.opacity=r;const i=this._techniqueRepository.acquire(n,this._configuration);this._rctx.bindTechnique(i,this._passParameters,e),this._draw(),i.release()}compositeSMAAEdgeDetect(e){this._smaaParameters.color=e;const t=this._techniqueRepository.acquire(i);this._rctx.bindTechnique(t,this._smaaParameters,null),this._draw(),t.release()}compositeSMAABlendWeights(e,t,r){this._smaaParameters.inputTexture=e,this._smaaParameters.areaTexture=t,this._smaaParameters.searchTexture=r;const i=this._techniqueRepository.acquire(s);this._rctx.bindTechnique(i,this._smaaParameters,null),this._draw(),i.release()}compositeSMAABlur(e){this._smaaParameters.inputTexture=e;const t=this._techniqueRepository.acquire(r);this._rctx.bindTechnique(t,this._smaaParameters,null),this._draw(),t.release()}_draw(){const e=this._ensureVAO();this._rctx.bindVAO(e),this._rctx.drawArrays(f.TRIANGLES,0,3)}_ensureVAO(){return null==this._vao&&(this._vao=a(this._rctx)),this._vao}}export{T as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.28/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import"../../../../core/has.js";import{releaseMaybe as t}from"../../../../core/maybe.js";import{c as e}from"../../../../chunks/vec4.js";import{f as r}from"../../../../chunks/vec4f64.js";import{ColorFormat as i,DepthFormat as h}from"../core/FBOCache.js";import{TransparencyPassType as s}from"./TransparencyPassType.js";import{ClearBufferBit as o}from"../../../webgl/enums.js";import{ensureAttachmentMaxSize as c}from"../../../webgl/FramebufferObject.js";class a{constructor(t,e){this._fbos=t,this.
|
|
5
|
+
import"../../../../core/has.js";import{releaseMaybe as t}from"../../../../core/maybe.js";import{c as e}from"../../../../chunks/vec4.js";import{f as r}from"../../../../chunks/vec4f64.js";import{ColorFormat as i,DepthFormat as h}from"../core/FBOCache.js";import{TransparencyPassType as s}from"./TransparencyPassType.js";import{ClearBufferBit as o}from"../../../webgl/enums.js";import{ensureAttachmentMaxSize as c}from"../../../webgl/FramebufferObject.js";class a{constructor(t,e){this._fbos=t,this.compositingHelper=e,this.width=4,this.height=4,this._backgroundColor=r(0,0,0,1)}dispose(){this.releaseBuffers()}get backgroundColor(){return this._backgroundColor}set backgroundColor(t){e(this._backgroundColor,t)}get framebuffer(){return this.color.detachDepth(),this.color.attachDepth(this.depth),this.color.fbo}get colorTexture(){return this.color.colorTexture}get depthTexture(){return this.depth.attachment}swapColorBuffer(){const t=this.color;return this._color=null,t}initializeFrame(t){const e=this._fbos.rctx;this.width=t.fullWidth,this.height=t.fullHeight,c(this,e.parameters.maxTextureSize),this.releaseBuffers(),this.bindFbo(),e.setClearStencil(0);const r=this._backgroundColor;e.setClearColor(r[0]*r[3],r[1]*r[3],r[2]*r[3],r[3]),e.clearSafe(o.COLOR_BUFFER_BIT|o.DEPTH_BUFFER_BIT|o.STENCIL_BUFFER_BIT)}releaseBuffers(){this._color?.detachDepth(),this._color=t(this._color),this._depth=t(this._depth)}compositeAtmosphereToMain(t,e,r,i){this._bindTarget(this.color),this.compositingHelper.compositeAtmosphere(t,r,i,e),this._bindTarget(this.color,this.depth)}renderHUDVisibility(t,e,r){return t?.fbo.width===this.width&&t?.fbo.height===this.height||(t?.release(),t=this._fbos.acquire(i.RGBA4,this.width,this.height)),t.attachDepth(r||this.depth),this._fbos.rctx.bindFramebuffer(t.fbo),this.renderToFBO(e,b),t.detachDepth(),t}compositeToHUDVisibility(t,e){this._fbos.rctx.bindFramebuffer(t.hudVisibility?.fbo),this.compositingHelper.compositeHUD(t,e)}renderOITPass(t,e,r){let o,c;switch(e){case s.Color:o=this._fbos.acquire(i.RGBA16F,this.width,this.height),c=[0,0,0,0];break;case s.Alpha:o=this._fbos.acquire(i.R16F,this.width,this.height),c=[1,1,1,1];break;case s.FrontFace:o=this._fbos.acquire(i.RGBA,this.width,this.height),c=[0,0,0,0]}return r?(o.acquireDepth(h.DEPTH16_BUFFER),this._fbos.rctx.bindFramebuffer(o.fbo),this.renderToFBO(t,c,!0,!0),o.releaseDepth()):(o.attachDepth(this.depth),this._fbos.rctx.bindFramebuffer(o.fbo),this.renderToFBO(t,c),o.detachDepth()),o}compositeToFramebuffer(t,e,r,i){this.bindFbo(),this.compositingHelper.composite(t,e,r,i)}compositeTransparentOntoOpaque(t,e,r,i,h){h?(this._fbos.rctx.bindFramebuffer(h.fbo),this._fbos.rctx.setClearColor(0,0,0,1e-13),this._fbos.rctx.clearSafe(o.COLOR_BUFFER_BIT)):this.bindFbo(),this.compositingHelper.compositeOIT(t,e.colorTexture,r.colorTexture,i.colorTexture)}renderDepthDetached(t){this._bindTarget(this.color),t(),this._bindTarget(this.color,this.depth)}renderToCachedFBO(e,r,s,o=i.RGBA,c=h.DEPTH16_BUFFER,a=this.width,b=this.height){return e?.fbo.width===a&&e?.fbo.height===b||(e=t(e)),e=e??this._fbos.acquire(o,a,b),null!=c&&e.acquireDepth(c),this._fbos.rctx.bindFramebuffer(e.fbo),this.renderToFBO(r,s,!0,!0),e}renderToFBO(t,e,r=!1,i=!1){const h=this._fbos.rctx;let s=0;if(e){const t=1e-13,r=Math.max(t,e[3]);h.setClearColor(e[0],e[1],e[2],r),s|=o.COLOR_BUFFER_BIT}r&&(s|=o.DEPTH_BUFFER_BIT),!1===i?i=0:(!0===i&&(i=255),s|=o.STENCIL_BUFFER_BIT),s&&h.clearSafe(s,i),t(),h.gl.flush()}renderToTargets(t,e,r,i,h=!1,s=!1){this._bindTarget(e,r),this.renderToFBO(t,i,h,s),e.detachDepth()}bindFbo(){this._bindTarget(this.color,this.depth)}_bindTarget(t,e){t.detachDepth(),t.attachDepth(e),this._fbos.rctx.bindFramebuffer(t.fbo)}get gpuMemoryUsage(){return(this._color?.colorTexture?.gpuMemoryUsage??0)+(this._depth?.memoryUsage??0)}get color(){return this._color||(this._color=this._fbos.acquire(i.RGBA,this.width,this.height)),this._color}get depth(){return this._depth||(this._depth=this._fbos.acquireDepth(h.DEPTH_STENCIL_TEXTURE,this.width,this.height)),this._depth}}const b=[0,1,0,1];export{a as OffscreenRendering};
|