@arcgis/core 5.1.0-next.44 → 5.1.0-next.46
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/applications/Components/featureUtils.d.ts +11 -7
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/{9aa1ad8b436b5b0dd5f5.js → 08d76c600926d7642a8b.js} +1 -1
- package/assets/esri/core/workers/chunks/{54db91c0a3bd1946e026.js → 0d59f5cd3fdd7d6fd693.js} +1 -1
- package/assets/esri/core/workers/chunks/128799741dd3c6fc69b9.js +1 -0
- package/assets/esri/core/workers/chunks/13eb0162d95b4d27389c.js +1 -0
- package/assets/esri/core/workers/chunks/1a481f3ae3146682eb00.js +1 -0
- package/assets/esri/core/workers/chunks/1cce2f8837ad765acf44.js +1 -0
- package/assets/esri/core/workers/chunks/{288082ae7b19837a3d38.js → 20e715e3aeb1c3265901.js} +1 -1
- package/assets/esri/core/workers/chunks/2379c64b0ca30814a815.js +1 -0
- package/assets/esri/core/workers/chunks/23a9070e9362b8439770.js +1 -0
- package/assets/esri/core/workers/chunks/2b3a8a53cd68f666676b.js +1 -0
- package/assets/esri/core/workers/chunks/{4d16b6ac52e25bd7e6aa.js → 32a51ce8e1a362115c89.js} +1 -1
- package/assets/esri/core/workers/chunks/{392941013107bbd96503.js → 365ad1ffd496ed86637b.js} +1 -1
- package/assets/esri/core/workers/chunks/{45cf181c1945e6c77a4b.js → 3a7c02616d942c81257d.js} +1 -1
- package/assets/esri/core/workers/chunks/3e9700445518b8f9ae1b.js +1 -0
- package/assets/esri/core/workers/chunks/{eab74d830c2eaa9d133b.js → 4869e2f35aaf6b058281.js} +1 -1
- package/assets/esri/core/workers/chunks/4b3545965b11a54184d4.js +2 -0
- package/assets/esri/core/workers/chunks/{10941b50f5933d168df6.js → 521a671182b0f79e3624.js} +1 -1
- package/assets/esri/core/workers/chunks/{c2f3fc1b34a6782b431f.js → 5351e71ce7839636d06d.js} +1 -1
- package/assets/esri/core/workers/chunks/569e4479707bc6881d97.js +1 -0
- package/assets/esri/core/workers/chunks/5b515b5741733bcb4645.js +1 -0
- package/assets/esri/core/workers/chunks/{1669f1bf959c4e3083da.js → 5c0b3c76a7bc971c61dc.js} +1 -1
- package/assets/esri/core/workers/chunks/{5f81f9e586b3ba0c34d4.js → 5c830cce32710d70dfa6.js} +1 -1
- package/assets/esri/core/workers/chunks/5e9bd5ed6ecee5b15127.js +1 -0
- package/assets/esri/core/workers/chunks/617328964d480d4a3a45.js +1 -0
- package/assets/esri/core/workers/chunks/650614a9e4871714c42e.js +1 -0
- package/assets/esri/core/workers/chunks/66baacbef23291eab853.js +1 -0
- package/assets/esri/core/workers/chunks/{c9f5d72b86ecb2a30587.js → 6c49ac7888679b9f7823.js} +1 -1
- package/assets/esri/core/workers/chunks/7278cc37e85f0242f19b.js +1 -0
- package/assets/esri/core/workers/chunks/{3c597d8ef898627b8f93.js → 768bbc910be6c65ac107.js} +1 -1
- package/assets/esri/core/workers/chunks/{a1f36240a31057f998da.js → 79dc7045d9a2d43ba8df.js} +1 -1
- package/assets/esri/core/workers/chunks/{4140d4c8b6b122fc2cd4.js → 7b48c102a44606291f82.js} +1 -1
- package/assets/esri/core/workers/chunks/{f9da5c81535eaffc8b9c.js → 7f07f490c6fcc794c8d9.js} +1 -1
- package/assets/esri/core/workers/chunks/{2b386374330d96387aec.js → 851fc5290497991ba001.js} +1 -1
- package/assets/esri/core/workers/chunks/{30cdb2d1d9f018f1642d.js → 9032c040b214b5af775b.js} +1 -1
- package/assets/esri/core/workers/chunks/{ff8ec6369c8a1bee9bb4.js → 908f171b9c512d738dea.js} +1 -1
- package/assets/esri/core/workers/chunks/{c7799ba861ac5af08e6a.js → 92d4e962284e13ba2fc5.js} +1 -1
- package/assets/esri/core/workers/chunks/970d971551e42f7ae08d.js +1 -0
- package/assets/esri/core/workers/chunks/9802770413ad814dab29.js +1 -0
- package/assets/esri/core/workers/chunks/{6cc5c37d6bdaf5483bd4.js → a422cfe1e2afe0722acd.js} +1 -1
- package/assets/esri/core/workers/chunks/{6e8cfe69617876ee0dac.js → a69f1879735a031f62e9.js} +1 -1
- package/assets/esri/core/workers/chunks/{af804beb43d4d10c54d9.js → a9f35127c3f5bf42036b.js} +1 -1
- package/assets/esri/core/workers/chunks/{fb69a0bb025b7a5ec588.js → b45fdc04d399d2849d63.js} +1 -1
- package/assets/esri/core/workers/chunks/{c0cc4ca138db47052845.js → b49b608c0d58a9b55fa2.js} +1 -1
- package/assets/esri/core/workers/chunks/b744b950999b92393e37.js +1 -0
- package/assets/esri/core/workers/chunks/beb53b372d356800f333.js +1 -0
- package/assets/esri/core/workers/chunks/c2aa3b1344b42a904234.js +1 -0
- package/assets/esri/core/workers/chunks/cdeb6aec578a1c07d663.js +1 -0
- package/assets/esri/core/workers/chunks/{1a3f874700f86b750390.js → ce0a6bc9df30af778ac9.js} +2 -2
- package/assets/esri/core/workers/chunks/cf5e4cf9b1aa37eeb6b0.js +1 -0
- package/assets/esri/core/workers/chunks/d0adf059085ddf7151dd.js +1 -0
- package/assets/esri/core/workers/chunks/d2af5342fbe80e2d8c60.js +1 -0
- package/assets/esri/core/workers/chunks/e4e0c5a45cf32973d5d5.js +1 -0
- package/assets/esri/core/workers/chunks/{465cc0e00f03cdb640b2.js → e7402dfd683f82878360.js} +1 -1
- package/assets/esri/core/workers/chunks/{8838ff9668b472af16a1.js → ef0eae13408cbf83a64f.js} +1 -1
- package/assets/esri/core/workers/chunks/f1767b8ba82fdd9bd947.js +1 -0
- package/assets/esri/core/workers/chunks/{b86cb84c03b76e824213.js → f9fe89ced41b49608667.js} +1 -1
- package/assets/esri/core/workers/chunks/{3c7ee71f0d8582e6d78f.js → ff75fb0fce51ac12e656.js} +1 -1
- package/assets/esri/libs/lyr3d/lyr3DMain.wasm +0 -0
- package/assets/esri/libs/lyr3d/lyr3DWorker.wasm +0 -0
- package/assets/esri/libs/vxl/vxlLayer.wasm +0 -0
- package/assets/esri/themes/base/widgets/_Grid.scss +5 -0
- 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/chunks/GaussianSplat.glsl.js +2 -2
- package/chunks/HUDMaterial.glsl.js +1 -1
- package/chunks/Jpg.js +1 -1
- package/chunks/LineCallout.glsl.js +1 -1
- package/chunks/PointRenderer.glsl.js +1 -1
- package/chunks/Terrain.glsl.js +4 -4
- package/chunks/Zlib.js +1 -1
- package/chunks/lyr3DMain.js +1 -1
- package/chunks/lyr3DWorker.js +1 -1
- package/chunks/vxlLayer.js +1 -1
- package/config.js +1 -1
- package/geometry/support/zscale.js +1 -1
- package/kernel.js +1 -1
- package/layers/IntegratedMesh3DTilesLayer.d.ts +2 -1
- package/layers/IntegratedMesh3DTilesLayer.js +1 -1
- package/layers/Lyr3DWasmPerSceneView.js +1 -1
- package/layers/graphics/featureConversionUtils.js +1 -1
- package/layers/knowledgeGraph/dataModelVisualizationUtils.js +1 -1
- package/layers/ogc/ogcFeatureUtils.js +1 -1
- package/layers/raster/formats/ImageCanvasDecoder.js +1 -1
- package/layers/raster/formats/JpgPlus.js +1 -1
- package/layers/raster/formats/RasterCodec.js +1 -1
- package/layers/raster/formats/TiffDecoder.js +1 -1
- package/layers/save/featureLayerUtils.js +1 -1
- package/layers/save/groupLayerUtils.js +1 -1
- package/layers/save/mapImageLayerUtils.js +1 -1
- package/layers/support/SubtypeSublayer.js +1 -1
- package/layers/support/layerUtils.js +1 -1
- package/layers/support/schemaValidator.js +1 -1
- package/libs/ajv/ajv.bundle-wrapper.js +2 -0
- package/package.json +3 -3
- package/renderers/visualVariables/SizeVariable.js +1 -1
- package/rest/locator/locationToAddress.js +1 -1
- package/rest/query/operations/pbfFeatureSetUtils.js +1 -1
- package/rest/query/operations/pbfFlatFeatureSet.js +1 -1
- package/rest/query/operations/pbfOptimizedFeatureSet.js +1 -1
- package/rest/support/LocationToAddressParameters.d.ts +62 -2
- package/rest/support/types.d.ts +6 -0
- package/support/revision.js +1 -1
- package/third-party-notices.txt +2 -2
- package/views/2d/analysis/AreaMeasurement/AreaMeasurementTool.js +1 -1
- package/views/2d/engine/ManagedCanvas.js +1 -1
- package/views/2d/engine/vectorTiles/Placement.js +1 -1
- package/views/2d/engine/vectorTiles/VTLPainter3D.js +1 -1
- package/views/2d/engine/webgl/shaders/sources/shaderRepository.js +1 -1
- package/views/2d/layers/FeatureLikeLayerView2D.js +1 -1
- package/views/2d/layers/TileLayerView2D.js +1 -1
- package/views/2d/layers/features/FeaturePipelineWorker.js +1 -1
- package/views/2d/layers/features/Processor.js +1 -1
- package/views/2d/layers/features/processor/AProcessorStrategy.js +1 -1
- package/views/2d/layers/features/processor/ClusterStrategy.js +1 -1
- package/views/2d/layers/imagery/BaseImageryTileSubView2D.js +1 -1
- package/views/3d/layers/GaussianSplatLayerView3D.js +1 -1
- package/views/3d/layers/i3s/I3SClientMaterialUtil.js +1 -1
- package/views/3d/terrain/OverlayRenderer.js +1 -1
- package/views/3d/terrain/TerrainRenderer.js +1 -1
- package/views/3d/terrain/TileCompositor.js +1 -1
- package/views/3d/webgl-engine/collections/Component/ComponentDrawParameters.js +1 -1
- package/views/3d/webgl-engine/core/renderPasses/RenderPassManager.js +1 -1
- package/views/3d/webgl-engine/core/shaderLibrary/Slice.glsl.js +3 -3
- package/views/3d/webgl-engine/effects/WeatherFader.js +1 -1
- package/views/3d/webgl-engine/effects/debug/RenderNodeVisualizerNode.js +1 -1
- package/views/3d/webgl-engine/effects/highlight/ShadowHighlight.js +1 -1
- package/views/3d/webgl-engine/lib/BindParameters.js +1 -1
- package/views/3d/webgl-engine/lib/GaussianSplatRenderNode.js +1 -1
- package/views/3d/webgl-engine/lib/RenderContext.js +1 -1
- package/views/3d/webgl-engine/lib/Renderer.js +1 -1
- package/views/3d/webgl-engine/lib/ShadowAccumulator.js +1 -1
- package/views/3d/webgl-engine/shaders/GaussianSplat.glsl.js +1 -1
- package/views/3d/webgl-engine/shaders/GaussianSplatTechniqueConfiguration.js +1 -1
- package/views/3d/webgl-engine/shaders/OutputColorHighlightOLID.glsl.js +1 -1
- package/views/interactive/GraphicManipulator.js +1 -1
- package/views/webgl/InstanceCounter.js +1 -1
- package/webscene/support/schemaValidator.js +1 -1
- package/widgets/AreaMeasurement2D/AreaMeasurement2DTool.js +1 -1
- package/widgets/DistanceMeasurement2D/DistanceMeasurement2DTool.js +1 -1
- package/widgets/Editor/EditorViewModel.d.ts +1 -1
- package/widgets/Editor/workflowUtils.js +1 -1
- package/widgets/Editor.d.ts +2 -1
- package/widgets/FeatureTable/FeatureTableViewModel.js +1 -1
- package/widgets/FeatureTable.js +1 -1
- package/widgets/Sketch/SketchViewModel.js +1 -1
- package/widgets/Sketch/support/PluginManager.js +1 -1
- package/assets/esri/core/workers/chunks/02a0a58ca5916db1db19.js +0 -1
- package/assets/esri/core/workers/chunks/03c8453ae72a4e190252.js +0 -1
- package/assets/esri/core/workers/chunks/0e669a04999feb9f98c9.js +0 -1
- package/assets/esri/core/workers/chunks/244dd7a948ca8a7dc6ef.js +0 -1
- package/assets/esri/core/workers/chunks/26cafd20c8d03c274389.js +0 -1
- package/assets/esri/core/workers/chunks/2cd0934163cb627ce251.js +0 -1
- package/assets/esri/core/workers/chunks/2fa86dacc8a12a6a6c43.js +0 -1
- package/assets/esri/core/workers/chunks/385f1bb9164b2d488b2d.js +0 -1
- package/assets/esri/core/workers/chunks/3e26f9af6b8c75bad97a.js +0 -1
- package/assets/esri/core/workers/chunks/5a6a6e7151085a3cd3dd.js +0 -1
- package/assets/esri/core/workers/chunks/5eb9fdb076488de9cd83.js +0 -1
- package/assets/esri/core/workers/chunks/65865c25487d23dd2e31.js +0 -1
- package/assets/esri/core/workers/chunks/65ea5028eb12457a3aeb.js +0 -1
- package/assets/esri/core/workers/chunks/73d7337ac9efdbad14a4.js +0 -1
- package/assets/esri/core/workers/chunks/8333561a938bcdf6c2e6.js +0 -1
- package/assets/esri/core/workers/chunks/848c6989a6a222c7a1d8.js +0 -2
- package/assets/esri/core/workers/chunks/91718795fc4ca6516ac7.js +0 -1
- package/assets/esri/core/workers/chunks/9b80569819cd1c72a9ff.js +0 -1
- package/assets/esri/core/workers/chunks/a4a2e7bc3369434c5cfa.js +0 -1
- package/assets/esri/core/workers/chunks/b056b4c79bcd542dd1d2.js +0 -1
- package/assets/esri/core/workers/chunks/b553264db0f10bb8c5f7.js +0 -1
- package/assets/esri/core/workers/chunks/c4f64195e44986644993.js +0 -1
- package/assets/esri/core/workers/chunks/ca6012135929b028ea1b.js +0 -1
- package/assets/esri/core/workers/chunks/de79645e559a2d1ffa67.js +0 -1
- package/assets/esri/core/workers/chunks/df5788d42787ee8bf523.js +0 -1
- package/assets/esri/core/workers/chunks/f0e6a26a3625068b08ab.js +0 -1
- package/assets/esri/core/workers/chunks/f36a234ef35faf8ca04d.js +0 -1
- package/chunks/ajv.bundle.js +0 -2
- /package/assets/esri/core/workers/chunks/{848c6989a6a222c7a1d8.js.LICENSE.txt → 4b3545965b11a54184d4.js.LICENSE.txt} +0 -0
package/config.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
-
import"./core/has.js";import{deepMerge as e}from"./core/object.js";const s={apiKey:void 0,apiKeys:{scopes:[]},applicationName:"",applicationUrl:globalThis.location?.href,assetsPath:"",fontsUrl:"https://static.arcgis.com/fonts",geometryServiceUrl:"https://utility.arcgisonline.com/arcgis/rest/services/Geometry/GeometryServer",geoRSSServiceUrl:"https://utility.arcgis.com/sharing/rss",kmlServiceUrl:"https://utility.arcgis.com/sharing/kml",userPrivilegesApplied:!0,portalUrl:"https://www.arcgis.com",respectPrefersReducedMotion:!0,routeServiceUrl:"https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World",workers:{loaderConfig:{has:{},paths:{},map:{},packages:[]}},request:{crossOriginNoCorsDomains:null,httpsDomains:["arcgis.com","arcgisonline.com","esrikr.com","premiumservices.blackbridge.com","esripremium.accuweather.com","gbm.digitalglobe.com","firstlook.digitalglobe.com","msi.digitalglobe.com"],interceptors:[],internalInterceptors:[],maxUrlLength:2e3,priority:"high",proxyRules:[],proxyUrl:null,timeout:62e3,trustedServers:[],useIdentity:!0},log:{interceptors:[],level:null}};if(globalThis.esriConfig&&(e(s,globalThis.esriConfig,!0),delete s.has),!s.assetsPath){{const e="5.1.0-next.
|
|
2
|
+
import"./core/has.js";import{deepMerge as e}from"./core/object.js";const s={apiKey:void 0,apiKeys:{scopes:[]},applicationName:"",applicationUrl:globalThis.location?.href,assetsPath:"",fontsUrl:"https://static.arcgis.com/fonts",geometryServiceUrl:"https://utility.arcgisonline.com/arcgis/rest/services/Geometry/GeometryServer",geoRSSServiceUrl:"https://utility.arcgis.com/sharing/rss",kmlServiceUrl:"https://utility.arcgis.com/sharing/kml",userPrivilegesApplied:!0,portalUrl:"https://www.arcgis.com",respectPrefersReducedMotion:!0,routeServiceUrl:"https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World",workers:{loaderConfig:{has:{},paths:{},map:{},packages:[]}},request:{crossOriginNoCorsDomains:null,httpsDomains:["arcgis.com","arcgisonline.com","esrikr.com","premiumservices.blackbridge.com","esripremium.accuweather.com","gbm.digitalglobe.com","firstlook.digitalglobe.com","msi.digitalglobe.com"],interceptors:[],internalInterceptors:[],maxUrlLength:2e3,priority:"high",proxyRules:[],proxyUrl:null,timeout:62e3,trustedServers:[],useIdentity:!0},log:{interceptors:[],level:null}};if(globalThis.esriConfig&&(e(s,globalThis.esriConfig,!0),delete s.has),!s.assetsPath){{const e="5.1.0-next.46";s.assetsPath=`https://cdn.jsdelivr.net/npm/@arcgis/core@${e}/assets`}s.defaultAssetsPath=s.assetsPath}export{s as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
-
import{getMetersPerVerticalUnitForSR as
|
|
2
|
+
import{getMetersPerVerticalUnitForSR as n}from"../../core/units.js";import{isSphericalPCPF as o}from"../ellipsoidUtils.js";import{equals as t}from"./spatialReferenceUtils.js";import{getEndpoint as e}from"./curves/curveUtils.js";function r(n,o,t){const e=i(o,t);if(1!==e)switch(n){case"point":case"esriGeometryPoint":return n=>s(n,e);case"polyline":case"esriGeometryPolyline":return n=>f(n,e);case"polygon":case"esriGeometryPolygon":return n=>c(n,e);case"multipoint":case"esriGeometryMultipoint":return n=>l(n,e);case"extent":case"esriGeometryEnvelope":return n=>u(n,e);default:return}}function i(e,r){if(null==e||null==r||(e.vcsWkid??null)!==(r.vcsWkid??null)||t(e,r)||o(e)||o(r))return 1;return n(e)/n(r)}function s(n,o){null!=n?.z&&(n.z*=o)}function c(n,o){if(n){if(n.curveRings)for(const t of n.curveRings)for(const n of t){const t=e(n);t.length>2&&(t[2]*=o)}if(n.rings)for(const t of n.rings)for(const n of t)n.length>2&&(n[2]*=o)}}function f(n,o){if(n){if(n.curvePaths)for(const t of n.curvePaths)for(const n of t){const t=e(n);t.length>2&&(t[2]*=o)}if(n.paths)for(const t of n.paths)for(const n of t)n.length>2&&(n[2]*=o)}}function l(n,o){if(n)for(const t of n.points)t.length>2&&(t[2]*=o)}function u(n,o){n&&null!=n.zmin&&null!=n.zmax&&(n.zmin*=o,n.zmax*=o)}export{r as getGeometryZScaler,i as zScale};
|
package/kernel.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
-
import has from"./core/has.js";import{addQueryParameter as o}from"./core/urlUtils.js";export{buildDate,commitHash as revision}from"./support/revision.js";Symbol.dispose??=Symbol("Symbol.dispose"),Symbol.asyncDispose??=Symbol("Symbol.asyncDispose");const e="5.1";let s,r=e;function i(o){s=o}function t(e){const r=s?.findCredential(e);return r?.token?o(e,"token",r.token):e}r="5.1.0-next.
|
|
2
|
+
import has from"./core/has.js";import{addQueryParameter as o}from"./core/urlUtils.js";export{buildDate,commitHash as revision}from"./support/revision.js";Symbol.dispose??=Symbol("Symbol.dispose"),Symbol.asyncDispose??=Symbol("Symbol.asyncDispose");const e="5.1";let s,r=e;function i(o){s=o}function t(e){const r=s?.findCredential(e);return r?.token?o(e,"token",r.token):e}r="5.1.0-next.46",has("host-webworker")||globalThis.$arcgis||Object.defineProperty(globalThis,"$arcgis",{configurable:!1,enumerable:!0,writable:!1,value:{}}),has("host-webworker");export{t as addTokenParameter,r as fullVersion,s as id,i as setId,e as version};
|
|
@@ -2,6 +2,7 @@ import type SpatialReference from "../geometry/SpatialReference.js";
|
|
|
2
2
|
import type Layer from "./Layer.js";
|
|
3
3
|
import type SceneModifications from "./support/SceneModifications.js";
|
|
4
4
|
import type ElevationInfo from "../symbols/support/ElevationInfo.js";
|
|
5
|
+
import type { ClonableMixin } from "../core/Clonable.js";
|
|
5
6
|
import type { MultiOriginJSONSupportMixin } from "../core/MultiOriginJSONSupport.js";
|
|
6
7
|
import type { APIKeyMixin, APIKeyMixinProperties } from "./mixins/APIKeyMixin.js";
|
|
7
8
|
import type { CustomParametersMixin, CustomParametersMixinProperties } from "./mixins/CustomParametersMixin.js";
|
|
@@ -185,4 +186,4 @@ export default class IntegratedMesh3DTilesLayer extends IntegratedMesh3DTilesLay
|
|
|
185
186
|
/** The URL of the root json file. */
|
|
186
187
|
accessor url: string | null | undefined;
|
|
187
188
|
}
|
|
188
|
-
declare const IntegratedMesh3DTilesLayerSuperclass: typeof Layer & typeof APIKeyMixin & typeof CustomParametersMixin & typeof MultiOriginJSONSupportMixin & typeof ScaleRangeLayer & typeof PortalLayer & typeof OperationalLayer
|
|
189
|
+
declare const IntegratedMesh3DTilesLayerSuperclass: typeof Layer & typeof ClonableMixin & typeof APIKeyMixin & typeof CustomParametersMixin & typeof MultiOriginJSONSupportMixin & typeof ScaleRangeLayer & typeof PortalLayer & typeof OperationalLayer
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
-
import{__decorate as e}from"tslib";import t from"../request.js";import o from"../core/Error.js";import has from"../core/has.js";import
|
|
2
|
+
import{__decorate as e}from"tslib";import t from"../request.js";import{ClonableMixin as o}from"../core/Clonable.js";import r from"../core/Error.js";import has from"../core/has.js";import i from"../core/Logger.js";import{MultiOriginJSONSupportMixin as s}from"../core/MultiOriginJSONSupport.js";import{throwIfAbortError as a}from"../core/promiseUtils.js";import{on as n,sync as l}from"../core/reactiveUtils.js";import{property as p,subclass as m}from"../core/accessorSupport/decorators.js";import{persistable as c}from"../core/accessorSupport/decorators/persistable.js";import d from"../geometry/Extent.js";import u from"../geometry/SpatialReference.js";import h from"./Layer.js";import{APIKeyMixin as f}from"./mixins/APIKeyMixin.js";import{ArcGISService as y}from"./mixins/ArcGISService.js";import{CustomParametersMixin as g}from"./mixins/CustomParametersMixin.js";import{OperationalLayer as S}from"./mixins/OperationalLayer.js";import{PortalLayer as _}from"./mixins/PortalLayer.js";import{ScaleRangeLayer as j}from"./mixins/ScaleRangeLayer.js";import{elevationInfo as v,url as T}from"./support/commonProperties.js";import w from"./support/SceneModifications.js";import{default3DTilesSpatialReference as b,default3DTilesFullExtent as L,initFullExtent as x}from"./support/tiles3DUtils.js";import P from"../portal/Portal.js";import{logInvalidElevationInfoWarning as I,elevationModeRequiredMessage as k,featureExpressionUnsupportedMessage as R}from"../support/elevationInfoUtils.js";import{f as D}from"../chunks/persistableUrlUtils.js";import{isBasemap as U}from"../support/userTypeGuards/isBasemap.js";import{initialize as E,switchMeshModificationPolygonVCSSync as O}from"../views/3d/layers/Lyr3DWorker.js";import{toWasmModification as M,fromWasmModification as q}from"../views/3d/layers/SceneLayerWorkerHandle.js";import{reader as A}from"../core/accessorSupport/decorators/reader.js";let G=class extends(y(S(_(j(s(g(f(o(h))))))))){readModifications(e,t,o){this._modificationsSource={url:D(e,o),context:o}}initialize(){this.addHandles(n(()=>this.modifications,"after-changes",()=>this.modifications=this.modifications,l))}constructor(e){super(e),this.operationalLayerType="IntegratedMesh3DTilesLayer",this.modifications=null,this._modificationsSource=null,this.spatialReference=b,this.fullExtent=L,this.url=null,this.type="integrated-mesh-3dtiles",this.path=null,this.minScale=0,this.maxScale=0,this._rootTilesetJSON=null,this._rootTileset=null,this._key=null,this._session=null,this._rootRequestPromise=null,this.queryElevationCallback=null}set elevationInfo(e){null!=e&&"absolute-height"!==e.mode||this._set("elevationInfo",e),this._validateElevationInfo(e)}async load(e){return this.addResolvingPromise(this._doLoad(e)),this}get rootTilesetJSON(){return this._rootTilesetJSON}get rootTileset(){return this._rootTileset}get key(){return this._key}get session(){return this._session}_findSessionParameter(e){const t=[e];for(;t?.length>0;){const e=t.pop();if(!e)return;for(const[r,i]of Object.entries(e)){if("uri"===r)try{const e=new URL("https://tmp"+i).searchParams.get("session");if(e)return e}catch(o){}"object"==typeof i&&null!==i&&t.push(i)}}return null}async requestRootAndSession(e){const o=(e,t)=>new r("3dtiles-init:"+e,t);return this._rootRequestPromise||(this._rootRequestPromise=new Promise((r,s)=>{this.url||s(o("url-missing","Layer url missing")),this._key=this.customParameters?this.customParameters.key:null;new Promise((e,r)=>{if(this.replacesTerrain&&!this._key){const i=this.portalItem?.portal||this.parent?.portalItem?.portal||P.getDefault();i.signIn().then(()=>{i.g3dTilesEnabled?t(i.restUrl+"/portals/self/modules/g3dtiles",{responseType:"json",query:{f:"json"}}).then(t=>{this._key=t.data.keyString,e()},()=>r(o("g3dtiles-key-error","Error fetching Google 3D Tiles key from portal"))):r(o("g3dTilesEnabled-false","Google 3D Tiles are not enabled on Portal "+i.url))},()=>r(o("sign-in-failed","Error signing in to Portal")))}else e()}).then(()=>{t(this.url,{query:this._key?{key:this._key,token:this.apiKey}:{token:this.apiKey},responseType:"array-buffer",signal:e}).then(e=>{try{this._rootTilesetJSON=JSON.parse((new TextDecoder).decode(e.data))}catch(t){return void s(o("root-parse-failed","Error parsing root tile, details: "+t))}this._rootTilesetJSON?(this._session=this._findSessionParameter(this._rootTilesetJSON),this._rootTileset=e.data,this.fullExtent=x(this._rootTilesetJSON),r(),this._rootRequestPromise=null):s(o("root-is-null","Root tile is null."))},e=>{a(e),s(o("root-load-failed","Error loading root tile")),this._rootRequestPromise=null,i.getLogger("IntegratedMesh3DTilesLayer").error("Layer loading failed",e)})},e=>s(e))})),this._rootRequestPromise}async _doLoad(e){const t=null!=e?e.signal:null;if(this.isUsedAsGroundLayer&&!has("enable-feature:basemap-groundlayers"))throw new r("3dtiles-init:not-supported-in-groundlayers","Layer is not supported in basemap.");try{await this.loadFromPortal({supportedTypes:["3DTiles Service"],validateItem:e=>{if(e.typeKeywords?.includes("IntegratedMesh"))return!0;throw new r("portal:invalid-layer-item-type","Invalid layer item, expected '${expectedType}' ",{expectedType:"3DTiles Service containing IntegratedMesh"})}},e)}catch(o){a(o)}if(null!=this._modificationsSource){const t=await w.fromUrl(this._modificationsSource.url,this.spatialReference,e);if(t&&t.length>0){await E();try{const e=M(null,t.toArray(),this.spatialReference),o=O({modifications:e,inVCS:115700});o.success&&o.modifications&&q(o.modifications,t)}catch(s){i.getLogger(this).error("convert-mesh-modification-z-error","Error when converting:",s)}null!=this._modificationsSource&&this.setAtOrigin("modifications",t,this._modificationsSource.context.origin),this._modificationsSource=null}}await this.requestRootAndSession(t)}async beforeSave(){if(null==this._modificationsSource){const{modifications:e}=this;return void(e&&e.length>0&&await E())}await this.load().then(()=>{},()=>{})}get hasAttributionData(){return!1}_validateElevationInfo(e){const t="Integrated mesh 3d tiles layers";I(i.getLogger(this),k(t,"absolute-height",e)),I(i.getLogger(this),R(t,e))}get replacesTerrain(){return!!has("enable-feature:basemap-groundlayers")&&this.hasGoogleUrl&&this.isUsedAsGroundLayer}get isUsedAsGroundLayer(){return U(this.parent)}get hasGoogleUrl(){return!!this.url?.match(/.+\.googleapis.com/)}};e([p({type:["IntegratedMesh3DTilesLayer"]})],G.prototype,"operationalLayerType",void 0),e([p({type:w,clonable:e=>e?.clone()??null}),c({origins:["web-scene","portal-item"],type:"resource",prefix:"modifications"})],G.prototype,"modifications",void 0),e([A(["web-scene","portal-item"],"modifications")],G.prototype,"readModifications",null),e([p({type:u})],G.prototype,"spatialReference",void 0),e([p({type:d})],G.prototype,"fullExtent",void 0),e([p(v)],G.prototype,"elevationInfo",null),e([p({type:["show","hide"]})],G.prototype,"listMode",void 0),e([p(T)],G.prototype,"url",void 0),e([p({readOnly:!0})],G.prototype,"type",void 0),e([p({type:String,json:{origins:{"web-scene":{read:!0,write:!0},"portal-item":{read:!0,write:!0}},read:!1}})],G.prototype,"path",void 0),e([p({type:Number,json:{name:"layerDefinition.minScale",write:!0,origins:{service:{read:!1,write:!1}}}})],G.prototype,"minScale",void 0),e([p({type:Number,json:{name:"layerDefinition.maxScale",write:!0,origins:{service:{read:!1,write:!1}}}})],G.prototype,"maxScale",void 0),e([p({readOnly:!0})],G.prototype,"hasAttributionData",null),e([p()],G.prototype,"replacesTerrain",null),e([p()],G.prototype,"isUsedAsGroundLayer",null),e([p()],G.prototype,"hasGoogleUrl",null),G=e([m("esri.layers.IntegratedMesh3DTilesLayer")],G);const N=G;export{N as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
-
import{__decorate as e}from"tslib";import i from"../request.js";import t from"../core/Accessor.js";import s from"../core/Error.js";import r from"../core/Logger.js";import{createAbortError as a,isAborted as n,isAbortError as o}from"../core/promiseUtils.js";import{watch as l}from"../core/reactiveUtils.js";import{addFrameTask as d}from"../core/scheduling.js";import{property as h,subclass as _}from"../core/accessorSupport/decorators.js";import y from"../geometry/SpatialReference.js";import{isGeographic as c}from"../geometry/support/spatialReferenceUtils.js";import u from"../geometry/support/WKIDUnitConversion.js";import{wasmFailedToInit as m,elevQueriesFull as g,elevQueriesGenericFail as w,invalidLayerView as p}from"./ILyr3DWasmPerSceneView.js";import{Lyr3DWorkerHandle as b}from"./Lyr3DWorkerHandle.js";import{getVCSFromHeightModelInfo as f}from"./support/tiles3DUtils.js";import{loadLyr3DMainWASM as v}from"../libs/lyr3d/Lyr3DModule.js";import{getElevationOffsetInMeters as D}from"../support/elevationInfoUtils.js";import{makeScheduleFunction as M}from"../views/3d/layers/support/makeScheduleFunction.js";const L=3857,k=32662,R=4326,S=5773,C=115700;let W=class extends t{constructor(e){super(e),this._lyr3DMainPromise=null,this._lyr3DMain=null,this._layers=new Map,this._viewSR=null,this._lyr3DBusyCount=0,this._lyr3DInternalMemoryBytes=0,this._isTerrainReady=!1,this._hasLayerThatReplacesTerrain=!1,this._elevationQueries=new Map,this._debugFlags=new Set,this._debugLevel=0,this._wasmNotLoaded="method requiring WASM was called when WASM isn't loaded",this._pulseTaskHandle=null,this._cameraElevationDirty=!0,this._debugFlags.add(0),this._debugFlags.add(1),this._debugFlags.add(2)}_debugLog(e,i,t,s=!0){if(this._debugFlags.has(e)&&this._debugLevel>=i){const e=s?`[js] ${t}`:`${t}`;0===i||1===i?r.getLogger(this).error(e):2===i&&r.getLogger(this).warn(e),r.getLogger(this).info(e)}}get lyr3DInternalMemoryBytes(){return this._lyr3DInternalMemoryBytes}initialize(){this._debugLevel>2&&(r.getLogger(this).level="info"),this._debugLog(0,3,"Lyr3DWasmPerSceneView.initialize()"),this.addHandles([l(()=>this.view.state?.contentCamera,()=>this._updateWasmCamera()),l(()=>this.view.state?.contentCamera.relativeElevation,()=>{this._cameraElevationDirty=!0,this._markAllLayerViewsUpdating()})]),this._pulseTaskHandle=d({preRender:()=>this._pulseTask()})}destroy(){this._debugLog(0,3,"Lyr3DWasmPerSceneView.destroy()"),this._lyr3DMain&&(this._layers.forEach(e=>{e.abortController.abort()}),this._elevationQueries.forEach((e,i)=>{this._lyr3DMain.cancel_elevation_query(i),e.rejectCallback(a())}),this._elevationQueries.clear(),this._lyr3DMain.uninitialize_lyr3d_wasm(),this._lyr3DMain=null);const e=this._workerHandle;e&&e.destroyWasm().then(()=>{this._workerHandle?.destroy(),this._workerHandle=null}),this._pulseTaskHandle?.remove(),this._pulseTaskHandle=null}addLayerView(e){return this._lyr3DMain?this._addLayerView(e):(this._debugLog(0,1,"Lyr3DWasmPerSceneView.add3DTilesLayerView() called when WASM wasn't initialized"),{wasmLayerId:m})}removeLayerView(e){if(!this._lyr3DMain)return this._debugLog(0,1,this._wasmNotLoaded),0;this._doRemoveLayerView(e);const i=this._layers.size;return 0===i&&(this._debugLog(0,3,"Lyr3DWasmPerSceneView.remove3DTilesLayerView() no Lyr3D layers left after removing a layer, destroying"),this.destroy()),i}getValidLayerViewCount(){if(!this._lyr3DMain)return this._debugLog(0,1,this._wasmNotLoaded),0;let e=0;return this._layers.forEach(i=>{i.layerView.wasmLayerId>=0&&++e}),e}setEnabled(e,i){if(!this._lyr3DMain)return void this._debugLog(0,1,this._wasmNotLoaded);const t=this._layers.get(e.wasmLayerId);if(t){this._lyr3DMain.set_enabled(e.wasmLayerId,i),t.needMemoryUsageUpdate=!0;const s=this._isUpdating(t);t.needFrame=!0,s||t.layerView.updatingFlagChanged()}}setLayerOffset(e,i){if(!this._lyr3DMain)return void this._debugLog(0,1,this._wasmNotLoaded);this._layers.get(e.wasmLayerId)&&this._lyr3DMain.set_carto_offset_z(e.wasmLayerId,i)}getAttributionText(){if(!this._lyr3DMain)return this._debugLog(0,1,this._wasmNotLoaded),[];return this._lyr3DMain.get_current_attribution_text().split("|")}onRenderableEvicted(e,i,t){if(!this._lyr3DMain)return void this._debugLog(0,1,this._wasmNotLoaded);this._layers.get(e.wasmLayerId)&&this._lyr3DMain.on_renderable_evicted(e.wasmLayerId,i,t)}setMeshModifications(e,i){if(!this._lyr3DMain)return void this._debugLog(0,1,this._wasmNotLoaded);const t=this._layers.get(e.wasmLayerId);if(t){const s=this._lyr3DMain._malloc(8*i.length),r=new Float64Array(this._lyr3DMain.HEAPF64.buffer,s,i.length);for(let e=0;e<i.length;++e)r[e]=i[e];this._lyr3DMain.set_mesh_modification_polygons(e.wasmLayerId,s,i.length),this._lyr3DMain._free(s);const a=this._isUpdating(t);t.needFrame=!0,a||t.layerView.updatingFlagChanged()}}isUpdating(e){if(!this._lyr3DMain&&this._lyr3DMainPromise)return!0;const i=this._layers.get(e);return!!i&&(i.outstandingJobCount>0||i.outstandingRenderableCount>0||i.needFrame||this._lyr3DBusyCount>0)}initializeWasm(e,i){return this._lyr3DMain?Promise.resolve():this.view.renderSpatialReference?(this._debugLog(0,3,"Lyr3DWasmPerSceneView.initializeWasm()"),this._lyr3DMainPromise||(this._lyr3DMainPromise=v().then(t=>{this._lyr3DMain=t,this._lyr3DMainPromise=null;const s=this._lyr3DMain.addFunction(this._onNewJob.bind(this),"v"),r=this._lyr3DMain.addFunction(this._onNewRenderable.bind(this),"v"),a=this._lyr3DMain.addFunction(this._freeRenderables.bind(this),"viii"),n=this._lyr3DMain.addFunction(this._setRenderableVisibility.bind(this),"viiii"),o=this._lyr3DMain.addFunction(this._onWasmError.bind(this),"viiii"),l=this._lyr3DMain.addFunction(this._onElevQueryComplete.bind(this),"vi");if(!this.view.renderSpatialReference)return void(this._lyr3DMain=null);this._viewSR=this.view.renderSpatialReference?.toJSON();const d="global"===this.view.viewingMode?5:3;if(5===d)this._viewSR.wkid=this._viewSR.latestWkid=R,this._viewSR.vcsWkid=this._viewSR.latestVcsWkid=S;else if(this.view.renderSpatialReference?.isWebMercator)this._viewSR.wkid=this._viewSR.latestWkid=L,this._viewSR.vcsWkid=this._viewSR.latestVcsWkid=S;else if(this.view.renderSpatialReference?.wkid===k)this._viewSR.wkid=this._viewSR.latestWkid=R,this._viewSR.vcsWkid=this._viewSR.latestVcsWkid=S;else if(!this._viewSR.latestVcsWkid&&!this._viewSR.vcsWkid){const e=f(this.view.heightModelInfo);if(e)this._viewSR.vcsWkid=this._viewSR.latestVcsWkid=e;else{const e=this.view.heightModelInfo?.heightModel,i=!e||"gravity-related-height"===e;this._viewSR.vcsWkid=this._viewSR.latestVcsWkid=i?S:C}}return this._lyr3DMain.initialize_lyr3d_wasm(o,s,r,a,n,l,e,i,d,this._cleanUpSR(this._makeSRWasmSerializable(this._viewSR)),Math.max(this._debugLevel,0),16)?(this._workerHandle=new b(M(this.view.resourceController)),this._workerHandle.promise?this._workerHandle.promise:void 0):(this._lyr3DMain=null,void this._debugLog(0,0,"Lyr3d Main WASM failed to initialize",!1))}).catch(e=>{this._debugLog(0,0,`Lyr3d WASM failed to download error = ${e}`,!1)})),this._lyr3DMainPromise):Promise.reject()}get isTerrainReady(){return this._isTerrainReady}setLodPixelThreshold(e,i){this._lyr3DMain?.set_lod_pixel_threshold(i);const t=this._layers.get(e.wasmLayerId);t&&(t.needFrame=!0)}setMaximumGaussianSplatCount(e){this._lyr3DMain.set_maximum_splat_count(e),this._layers.forEach(e=>{"gaussian-splat-3d"===e.layerView.type&&(e.needFrame=!0)})}queryElevation(e,i,t){if(!this._lyr3DMain)return Promise.reject(this._wasmNotLoaded);if(0===i.coordinates.length)return Promise.reject("no coordinates for elevation query");const s="global"===this.view.viewingMode?y.WGS84:this._viewSR.wkid===L?y.WebMercator:y.PlateCarree,r=i.projectSync(s);r&&(i=r);const a=2*i.coordinates.length,n=this._lyr3DMain._malloc(8*a),o=new Float64Array(this._lyr3DMain.HEAPF64.buffer,n,a);for(let y=0;y<i.coordinates.length;++y){const e=i.coordinates[y];o[2*y]=e.x,o[2*y+1]=e.y}const l=t?.maxGeometricError??0,d=this._lyr3DMain.create_elevation_query(e.wasmLayerId,l,n,a);if(this._lyr3DMain._free(n),d===g)return Promise.reject("max mesh elevation query limit exceeded");if(d===w)return Promise.reject("elevation query failed");const h={descriptor:i,signal:t?.signal,resolveCallback:null,rejectCallback:null},_=new Promise((e,i)=>{h.resolveCallback=e,h.rejectCallback=i});return this._elevationQueries.set(d,h),_}_checkForAbortedElevationQueries(){const e=[];this._elevationQueries.forEach((i,t)=>{n(i.signal)&&(this._lyr3DMain.cancel_elevation_query(t),i.rejectCallback(a()),e.push(t))});for(let i=0;i<e.length;++i)this._elevationQueries.delete(e[i])}_pulseTask(){if(this._lyr3DMain){if(this._cameraElevationDirty){const e=this.view.state?.contentCamera.relativeElevation;this._lyr3DMain.set_camera_elevation(e)}this._checkForAbortedElevationQueries();let e=0,i=0;this._layers.forEach(t=>{e+=t.layerView.usedMemory,i+=t.layerView.cachedMemory}),e/=1048576,i/=1048576;const t=this.view.resourceController.memoryController,s=t.usedMemory*t.maxMemory-e-this._lyr3DInternalMemoryBytes/1048576;this._lyr3DBusyCount=this._lyr3DMain.frame_pulse(t.memoryFactor,e,i,s,t.maxMemory),this._lyr3DInternalMemoryBytes=this._lyr3DMain.get_index_memory_bytes(),this._layers.forEach(e=>{this._cameraElevationDirty||(e.needFrame=!1),e.layerView.updatingFlagChanged()}),this._hasLayerThatReplacesTerrain&&!this._isTerrainReady&&(this._isTerrainReady=this._lyr3DMain.is_terrain_ready(),this._isTerrainReady&&this.notifyChange("isTerrainReady")),this._cameraElevationDirty=!1}}_isUpdating(e){return e.outstandingJobCount>0||e.outstandingRenderableCount>0||e.needFrame||this._lyr3DBusyCount>0}_incrementJobCount(e,i){if(i.isForElevationQuery)return;const t=this._isUpdating(e);e.outstandingJobCount+=1,t||e.layerView.updatingFlagChanged()}_decrementJobCount(e,i){if(i.isForElevationQuery)return;const t=this._isUpdating(e);e.outstandingJobCount-=1;t!==this._isUpdating(e)&&e.layerView.updatingFlagChanged()}_incrementRenderableCount(e){const i=this._isUpdating(e);e.outstandingRenderableCount+=1,i||e.layerView.updatingFlagChanged()}_decrementRenderableCount(e){const i=this._isUpdating(e);e.outstandingRenderableCount-=1;i!==this._isUpdating(e)&&e.layerView.updatingFlagChanged()}_onJobFailed(e,i,t){i.error.length&&this._debugLog(1,1,i.error,!1),this._lyr3DMain&&this._lyr3DMain.on_job_failed(t.jobId,t.desc),this._decrementJobCount(e,t)}_onJobSucceeded(e,i,t){if(this._lyr3DMain){if(e.layerView.destroyed)return void this._lyr3DMain.on_job_failed(t.jobId,t.desc);const s=i.data.byteLength,r=this._lyr3DMain._malloc(s);new Uint8Array(this._lyr3DMain.HEAPU8.buffer,r,s).set(i.data),this._lyr3DMain.on_job_completed(t.jobId,i.jobDescJson,r,s),this._lyr3DMain._free(r)}this._decrementJobCount(e,t)}_getRequestPromises(e,t,s,r){const a=[];for(const n of e){const e=new URL(n);if("integrated-mesh-3dtiles"===r.type){if(e.origin===s.origin&&e.pathname===s.pathname){if(r.rootTileset){a.push(Promise.resolve(r.rootTileset.slice()));continue}}else r.session&&e.searchParams.set("session",r.session)}a.push(i(e.toString(),t).then(e=>e.data))}return a}_getInitialPromise(e,i,t,s,r,a,n){const l=this._getRequestPromises(e.urls,i,t,s);return Promise.all(l).then(e=>(r.inputs=e,this._workerHandle.invoke(r,a))).then(e=>e).catch(i=>{let t=1;return o(i)?this._debugLog(1,2,`job ${e.jobId} was cancelled.`):n&&400===i.details?.httpStatus?(t=3,this._debugLog(1,2,"Session expired, trying to create new Session.")):this._debugLog(1,1,`job ${e.jobId} failed with error ${i}.`),{status:t,error:"",jobDescJson:"",data:new Uint8Array(0),missingInputUrls:[],inputs:[]}})}async _onNewJob(){const e=this._lyr3DMain.get_next_job(),i=this._layers.get(e.layerId);if(!i)return;this._incrementJobCount(i,e);const t=i.abortController.signal,s=i.layerView.layer,r="integrated-mesh-3dtiles"===s.type?s.key:null,a="integrated-mesh-3dtiles"===s.type?s.session:null,n={responseType:"array-buffer",signal:t,query:{...i.customParameters,token:i.apiKey,key:r}},l={id:e.jobId,inputs:[],jobDescJson:e.desc.slice(),isMissingResourceCase:!1},d=new URL(s.url),h=r=>{if(1===r.status)this._onJobFailed(i,r,e);else if(0===r.status)this._onJobSucceeded(i,r,e);else if(2===r.status){const a=this._getRequestPromises(r.missingInputUrls,n,d,s);Promise.all(a).then(e=>{l.jobDescJson=r.jobDescJson,r.originalInputs?l.inputs=r.originalInputs:l.inputs=[],l.isMissingResourceCase=!0;for(const i of e)l.inputs.push(i);return this._workerHandle.invoke(l,t)}).then(t=>{1===t.status?this._onJobFailed(i,t,e):0===t.status&&this._onJobSucceeded(i,t,e)}).catch(t=>{this._decrementJobCount(i,e),o(t)?this._debugLog(1,2,`job ${e.jobId} was cancelled.`):this._debugLog(1,1,`job ${e.jobId} failed with error ${t}.`),this._lyr3DMain&&this._lyr3DMain.on_job_failed(e.jobId,e.desc)})}};try{const i=await this._getInitialPromise(e,n,d,s,l,t,a);if(3===i.status&&"integrated-mesh-3dtiles"===s.type){a===s.session&&null!==s.session&&await s.requestRootAndSession(t);h(await this._getInitialPromise(e,n,d,s,l,t,s.session))}else h(i)}catch(_){_&&this._debugLog(1,1,_.toString(),!1),this._lyr3DMain&&this._lyr3DMain.on_job_failed(e.jobId,e.desc),this._decrementJobCount(i,e)}}_onNewRenderable(){const e=this._lyr3DMain.get_next_renderable(),{meshData:i}=e;i.data&&i.data.byteLength>0&&(i.data=i.data.slice());const t=this._layers.get(e.layerId);t&&(this._incrementRenderableCount(t),t.layerView.createRenderable(e).then(i=>{const s=i.numGaussians??0;this._lyr3DMain?.on_renderable_created(!0,e.layerId,e.handle,i.memUsageBytes,s),this._decrementRenderableCount(t)}).catch(i=>{o(i)||this._debugLog(2,1,`createRenderable failed with error ${i}.`),this._lyr3DMain?.on_renderable_created(!1,e.layerId,e.handle,0,0),this._decrementRenderableCount(t)}))}_freeRenderables(e,i,t){if(t<1)return;const s=this._layers.get(e);if(!s)return;const r=s.layerView,a=[],n=new Uint32Array(this._lyr3DMain.HEAPU32.buffer,i,t);for(let o=0;o<t;++o)a.push(n[o]);for(let o=0;o<t;++o)r.freeRenderable(a[o])}_setRenderableVisibility(e,i,t,s){if(s<1)return;const r=this._layers.get(e);if(!r)return;const a=r.layerView,n=[],o=[],l=new Uint32Array(this._lyr3DMain.HEAPU32.buffer,i,s),d=new Uint8Array(this._lyr3DMain.HEAPU8.buffer,t,s);for(let h=0;h<s;++h)n.push(l[h]),o.push(!!(1&d[h]));a.setRenderableVisibility(n,o,s)}_onWasmError(e,i,t,s){this._lyr3DMain&&this._debugLog(t,s,this._lyr3DMain.UTF8ToString(e,i),!1)}_onElevQueryComplete(e){const i=this._elevationQueries.get(e),t=this._lyr3DMain.get_elevation_query_result(e);if(i)if(t.succeeded&&t.zs){const s=t.zs.slice(),r=i.descriptor.clone();for(let e=0;e<s.length;++e)r.coordinates[e].z=s[e];this._debugLog(2,3,`Success EQ ${e}, number points ${s.length}.`),i.resolveCallback(r),this._elevationQueries.delete(e)}else i.rejectCallback(new s("elevation-query:error",t?.error??"Elevation query failed")),this._elevationQueries.delete(e);else this._debugLog(2,1,`_onElevQueryComplete called for unknown queryId ${e}.`)}_doRemoveLayerView(e){const i=this._layers.get(e.wasmLayerId);return!!i&&(i.abortController.abort(),this._lyr3DMain.remove_layer(e.wasmLayerId),this._is3DTilesIMLayerView(e)&&e.layer.replacesTerrain&&(this._hasLayerThatReplacesTerrain=!1,this._isTerrainReady=!1,this.notifyChange("isTerrainReady")),this._layers.delete(e.wasmLayerId),!0)}_is3DTilesIMLayerView(e){return"integrated-mesh-3dtiles"===e.layer.type}_isGaussianSplatLayerView(e){return"gaussian-splat"===e.layer.type}_isGaussianSplatLayer(e){return"gaussian-splat"===e.type}_toWasmQuality(e){switch(e){case"low":return 1;case"medium":return 2;case"high":return 3}}_addLayerView(e){const i=e.layer;if(!i.url||!i.rootTilesetJSON)return{wasmLayerId:p};const t="integrated-mesh-3dtiles"===i.type?0:2,s=this._lyr3DMain.validate_root_tileset(JSON.stringify(i.rootTilesetJSON),t);if(0!==s.errorCode)return{wasmLayerId:p,check:s};const a=this._lyr3DMain.get_next_layer_id(),n=new AbortController;this._layers.set(a,{layerView:e,abortController:n,needMemoryUsageUpdate:!1,outstandingJobCount:0,outstandingRenderableCount:0,customParameters:i.customParameters,apiKey:i.apiKey,needFrame:!0});const o=D(i.elevationInfo),l=this._toWasmQuality(this.view?.qualityProfile),d=e=>r.getLogger(this).error("add-spatial-reference-error","Error when adding SR:",e);let h=!1;if(this._isGaussianSplatLayerView(e)&&this._isGaussianSplatLayer(i)){let t=i.spatialReference;if(e.useEsriCrs&&i.esriCrsSpatialReference){t=i.esriCrsSpatialReference;const s=c(t);let r=1,a=1;!s&&t.wkid&&-1!==t.wkid&&(r=u.values[u[t.wkid]],a=e.metersPerVCSUnit),this._workerHandle.addSpatialReferenceInfo(this._cleanUpSR(this._makeSRWasmSerializable(t)),s,r,a).catch(d),t.vcsWkid&&this._viewSR.vcsWkid&&this._viewSR.vcsWkid!==t.vcsWkid&&this._workerHandle.addSpatialReferenceInfo(this._cleanUpSR(this._makeSRWasmSerializable(this._viewSR)),!1,1,1).catch(d)}h=this._lyr3DMain.add_gaussian_splat_layer(l,i.url,a,o)}else this._is3DTilesIMLayerView(e)&&(h=this._lyr3DMain.add_3dtiles_layer(l,i.url,a,o,e.layer.replacesTerrain),h&&e.layer.replacesTerrain&&(this._hasLayerThatReplacesTerrain=!0,this._isTerrainReady=!1,this.notifyChange("isTerrainReady")));return h?(this._updateWasmCamera(),e.updatingFlagChanged(),{wasmLayerId:a}):(this._layers.delete(a),{wasmLayerId:p})}_updateWasmCamera(){const e=this.view.state?.contentCamera;if(!e||!this._lyr3DMain)return;const{eye:i,center:t,up:s,near:r,far:a,fovY:n}=e,o=[e.viewport[2],e.viewport[3]],l=e.width/e.height;this._lyr3DMain.set_camera_parameters({eye:i,center:t,up:s,near:r,far:a,fov:n,aspectRatio:l,viewport:o}),this._markAllLayerViewsUpdating()}_markAllLayerViewsUpdating(){this._layers.forEach(e=>{const i=this._isUpdating(e);e.needFrame=!0,i||e.layerView.updatingFlagChanged()})}_makeSRWasmSerializable(e){return{wkid:e?.wkid??-1,latestWkid:e?.latestWkid??-1,vcsWkid:e?.vcsWkid??-1,latestVcsWkid:e?.latestVcsWkid??-1,wkt:e?.wkt??""}}_cleanUpSR(e){return-1===e?.wkid&&e.latestWkid&&-1!==e.latestWkid?e.wkid=e.latestWkid:-1===e?.latestWkid&&e.wkid&&-1!==e.wkid&&(e.latestWkid=e.wkid),-1===e?.vcsWkid&&e.latestVcsWkid&&-1!==e.latestVcsWkid?e.vcsWkid=e.latestVcsWkid:-1===e?.latestVcsWkid&&e.vcsWkid&&-1!==e.vcsWkid&&(e.latestVcsWkid=e.vcsWkid),e}};e([h({constructOnly:!0})],W.prototype,"view",void 0),e([h({readOnly:!0})],W.prototype,"isTerrainReady",null),W=e([_("esri.layers.Lyr3DWasmPerSceneView")],W);const V=W;export{V as default};
|
|
2
|
+
import{__decorate as e}from"tslib";import i from"../request.js";import{has}from"../applications/Components/baUtils.js";import t from"../core/Accessor.js";import s from"../core/Error.js";import r from"../core/Logger.js";import{createAbortError as a,isAborted as n,isAbortError as o}from"../core/promiseUtils.js";import{watch as l}from"../core/reactiveUtils.js";import{addFrameTask as d}from"../core/scheduling.js";import{property as h,subclass as _}from"../core/accessorSupport/decorators.js";import y from"../geometry/SpatialReference.js";import{isGeographic as c}from"../geometry/support/spatialReferenceUtils.js";import u from"../geometry/support/WKIDUnitConversion.js";import{wasmFailedToInit as m,elevQueriesFull as g,elevQueriesGenericFail as w,invalidLayerView as p}from"./ILyr3DWasmPerSceneView.js";import{Lyr3DWorkerHandle as b}from"./Lyr3DWorkerHandle.js";import{getVCSFromHeightModelInfo as f}from"./support/tiles3DUtils.js";import{loadLyr3DMainWASM as v}from"../libs/lyr3d/Lyr3DModule.js";import{getElevationOffsetInMeters as D}from"../support/elevationInfoUtils.js";import{makeScheduleFunction as M}from"../views/3d/layers/support/makeScheduleFunction.js";const L=3857,k=32662,R=4326,S=5773,C=115700;let W=class extends t{constructor(e){super(e),this._lyr3DMainPromise=null,this._lyr3DMain=null,this._layers=new Map,this._viewSR=null,this._lyr3DBusyCount=0,this._lyr3DInternalMemoryBytes=0,this._isTerrainReady=!1,this._hasLayerThatReplacesTerrain=!1,this._elevationQueries=new Map,this._debugFlags=new Set,this._debugLevel=0,this._wasmNotLoaded="method requiring WASM was called when WASM isn't loaded",this._pulseTaskHandle=null,this._cameraElevationDirty=!0,this._debugFlags.add(0),this._debugFlags.add(1),this._debugFlags.add(2)}_debugLog(e,i,t,s=!0){if(this._debugFlags.has(e)&&this._debugLevel>=i){const e=s?`[js] ${t}`:`${t}`;0===i||1===i?r.getLogger(this).error(e):2===i&&r.getLogger(this).warn(e),r.getLogger(this).info(e)}}get lyr3DInternalMemoryBytes(){return this._lyr3DInternalMemoryBytes}initialize(){this._debugLevel>2&&(r.getLogger(this).level="info"),this._debugLog(0,3,"Lyr3DWasmPerSceneView.initialize()"),this.addHandles([l(()=>this.view.state?.contentCamera,()=>this._updateWasmCamera()),l(()=>this.view.state?.contentCamera.relativeElevation,()=>{this._cameraElevationDirty=!0,this._markAllLayerViewsUpdating()})]),this._pulseTaskHandle=d({preRender:()=>this._pulseTask()})}destroy(){this._debugLog(0,3,"Lyr3DWasmPerSceneView.destroy()"),this._lyr3DMain&&(this._layers.forEach(e=>{e.abortController.abort()}),this._elevationQueries.forEach((e,i)=>{this._lyr3DMain.cancel_elevation_query(i),e.rejectCallback(a())}),this._elevationQueries.clear(),this._lyr3DMain.uninitialize_lyr3d_wasm(),this._lyr3DMain=null);const e=this._workerHandle;e&&e.destroyWasm().then(()=>{this._workerHandle?.destroy(),this._workerHandle=null}),this._pulseTaskHandle?.remove(),this._pulseTaskHandle=null}addLayerView(e){return this._lyr3DMain?this._addLayerView(e):(this._debugLog(0,1,"Lyr3DWasmPerSceneView.add3DTilesLayerView() called when WASM wasn't initialized"),{wasmLayerId:m})}removeLayerView(e){if(!this._lyr3DMain)return this._debugLog(0,1,this._wasmNotLoaded),0;this._doRemoveLayerView(e);const i=this._layers.size;return 0===i&&(this._debugLog(0,3,"Lyr3DWasmPerSceneView.remove3DTilesLayerView() no Lyr3D layers left after removing a layer, destroying"),this.destroy()),i}getValidLayerViewCount(){if(!this._lyr3DMain)return this._debugLog(0,1,this._wasmNotLoaded),0;let e=0;return this._layers.forEach(i=>{i.layerView.wasmLayerId>=0&&++e}),e}setEnabled(e,i){if(!this._lyr3DMain)return void this._debugLog(0,1,this._wasmNotLoaded);const t=this._layers.get(e.wasmLayerId);if(t){this._lyr3DMain.set_enabled(e.wasmLayerId,i),t.needMemoryUsageUpdate=!0;const s=this._isUpdating(t);t.needFrame=!0,s||t.layerView.updatingFlagChanged()}}setLayerOffset(e,i){if(!this._lyr3DMain)return void this._debugLog(0,1,this._wasmNotLoaded);this._layers.get(e.wasmLayerId)&&this._lyr3DMain.set_carto_offset_z(e.wasmLayerId,i)}getAttributionText(){if(!this._lyr3DMain)return this._debugLog(0,1,this._wasmNotLoaded),[];return this._lyr3DMain.get_current_attribution_text().split("|")}onRenderableEvicted(e,i,t){if(!this._lyr3DMain)return void this._debugLog(0,1,this._wasmNotLoaded);this._layers.get(e.wasmLayerId)&&this._lyr3DMain.on_renderable_evicted(e.wasmLayerId,i,t)}setMeshModifications(e,i){if(!this._lyr3DMain)return void this._debugLog(0,1,this._wasmNotLoaded);const t=this._layers.get(e.wasmLayerId);if(t){const s=this._lyr3DMain._malloc(8*i.length),r=new Float64Array(this._lyr3DMain.HEAPF64.buffer,s,i.length);for(let e=0;e<i.length;++e)r[e]=i[e];this._lyr3DMain.set_mesh_modification_polygons(e.wasmLayerId,s,i.length),this._lyr3DMain._free(s);const a=this._isUpdating(t);t.needFrame=!0,a||t.layerView.updatingFlagChanged()}}isUpdating(e){if(!this._lyr3DMain&&this._lyr3DMainPromise)return!0;const i=this._layers.get(e);return!!i&&(i.outstandingJobCount>0||i.outstandingRenderableCount>0||i.needFrame||this._lyr3DBusyCount>0)}initializeWasm(e,i){return this._lyr3DMain?Promise.resolve():this.view.renderSpatialReference?(this._debugLog(0,3,"Lyr3DWasmPerSceneView.initializeWasm()"),this._lyr3DMainPromise||(this._lyr3DMainPromise=v().then(t=>{this._lyr3DMain=t,this._lyr3DMainPromise=null;const s=this._lyr3DMain.addFunction(this._onNewJob.bind(this),"v"),r=this._lyr3DMain.addFunction(this._onNewRenderable.bind(this),"v"),a=this._lyr3DMain.addFunction(this._freeRenderables.bind(this),"viii"),n=this._lyr3DMain.addFunction(this._setRenderableVisibility.bind(this),"viiii"),o=this._lyr3DMain.addFunction(this._onWasmError.bind(this),"viiii"),l=this._lyr3DMain.addFunction(this._onElevQueryComplete.bind(this),"vi");if(!this.view.renderSpatialReference)return void(this._lyr3DMain=null);this._viewSR=this.view.renderSpatialReference?.toJSON();const d="global"===this.view.viewingMode?5:3;if(5===d)this._viewSR.wkid=this._viewSR.latestWkid=R,this._viewSR.vcsWkid=this._viewSR.latestVcsWkid=S;else if(this.view.renderSpatialReference?.isWebMercator)this._viewSR.wkid=this._viewSR.latestWkid=L,this._viewSR.vcsWkid=this._viewSR.latestVcsWkid=S;else if(this.view.renderSpatialReference?.wkid===k)this._viewSR.wkid=this._viewSR.latestWkid=R,this._viewSR.vcsWkid=this._viewSR.latestVcsWkid=S;else if(!this._viewSR.latestVcsWkid&&!this._viewSR.vcsWkid){const e=f(this.view.heightModelInfo);if(e)this._viewSR.vcsWkid=this._viewSR.latestVcsWkid=e;else{const e=this.view.heightModelInfo?.heightModel,i=!e||"gravity-related-height"===e;this._viewSR.vcsWkid=this._viewSR.latestVcsWkid=i?S:C}}const h=has("esri-lyr3D-max-concurrent-requests")??16;return this._lyr3DMain.initialize_lyr3d_wasm(o,s,r,a,n,l,e,i,d,this._cleanUpSR(this._makeSRWasmSerializable(this._viewSR)),Math.max(this._debugLevel,0),h)?(this._workerHandle=new b(M(this.view.resourceController)),this._workerHandle.promise?this._workerHandle.promise:void 0):(this._lyr3DMain=null,void this._debugLog(0,0,"Lyr3d Main WASM failed to initialize",!1))}).catch(e=>{this._debugLog(0,0,`Lyr3d WASM failed to download error = ${e}`,!1)})),this._lyr3DMainPromise):Promise.reject()}get isTerrainReady(){return this._isTerrainReady}setLodPixelThreshold(e,i){this._lyr3DMain?.set_lod_pixel_threshold(i);const t=this._layers.get(e.wasmLayerId);t&&(t.needFrame=!0)}setMaximumGaussianSplatCount(e){this._lyr3DMain.set_maximum_splat_count(e),this._layers.forEach(e=>{"gaussian-splat-3d"===e.layerView.type&&(e.needFrame=!0)})}queryElevation(e,i,t){if(!this._lyr3DMain)return Promise.reject(this._wasmNotLoaded);if(0===i.coordinates.length)return Promise.reject("no coordinates for elevation query");const s="global"===this.view.viewingMode?y.WGS84:this._viewSR.wkid===L?y.WebMercator:y.PlateCarree,r=i.projectSync(s);r&&(i=r);const a=2*i.coordinates.length,n=this._lyr3DMain._malloc(8*a),o=new Float64Array(this._lyr3DMain.HEAPF64.buffer,n,a);for(let y=0;y<i.coordinates.length;++y){const e=i.coordinates[y];o[2*y]=e.x,o[2*y+1]=e.y}const l=t?.maxGeometricError??0,d=this._lyr3DMain.create_elevation_query(e.wasmLayerId,l,n,a);if(this._lyr3DMain._free(n),d===g)return Promise.reject("max mesh elevation query limit exceeded");if(d===w)return Promise.reject("elevation query failed");const h={descriptor:i,signal:t?.signal,resolveCallback:null,rejectCallback:null},_=new Promise((e,i)=>{h.resolveCallback=e,h.rejectCallback=i});return this._elevationQueries.set(d,h),_}_checkForAbortedElevationQueries(){const e=[];this._elevationQueries.forEach((i,t)=>{n(i.signal)&&(this._lyr3DMain.cancel_elevation_query(t),i.rejectCallback(a()),e.push(t))});for(let i=0;i<e.length;++i)this._elevationQueries.delete(e[i])}_pulseTask(){if(this._lyr3DMain){if(this._cameraElevationDirty){const e=this.view.state?.contentCamera.relativeElevation;this._lyr3DMain.set_camera_elevation(e)}this._checkForAbortedElevationQueries();let e=0,i=0;this._layers.forEach(t=>{e+=t.layerView.usedMemory,i+=t.layerView.cachedMemory}),e/=1048576,i/=1048576;const t=this.view.resourceController.memoryController,s=t.usedMemory*t.maxMemory-e-this._lyr3DInternalMemoryBytes/1048576;this._lyr3DBusyCount=this._lyr3DMain.frame_pulse(t.memoryFactor,e,i,s,t.maxMemory),this._lyr3DInternalMemoryBytes=this._lyr3DMain.get_index_memory_bytes(),this._layers.forEach(e=>{this._cameraElevationDirty||(e.needFrame=!1),e.layerView.updatingFlagChanged()}),this._hasLayerThatReplacesTerrain&&!this._isTerrainReady&&(this._isTerrainReady=this._lyr3DMain.is_terrain_ready(),this._isTerrainReady&&this.notifyChange("isTerrainReady")),this._cameraElevationDirty=!1}}_isUpdating(e){return e.outstandingJobCount>0||e.outstandingRenderableCount>0||e.needFrame||this._lyr3DBusyCount>0}_incrementJobCount(e,i){if(i.isForElevationQuery)return;const t=this._isUpdating(e);e.outstandingJobCount+=1,t||e.layerView.updatingFlagChanged()}_decrementJobCount(e,i){if(i.isForElevationQuery)return;const t=this._isUpdating(e);e.outstandingJobCount-=1;t!==this._isUpdating(e)&&e.layerView.updatingFlagChanged()}_incrementRenderableCount(e){const i=this._isUpdating(e);e.outstandingRenderableCount+=1,i||e.layerView.updatingFlagChanged()}_decrementRenderableCount(e){const i=this._isUpdating(e);e.outstandingRenderableCount-=1;i!==this._isUpdating(e)&&e.layerView.updatingFlagChanged()}_onJobFailed(e,i,t){i.error.length&&this._debugLog(1,1,i.error,!1),this._lyr3DMain&&this._lyr3DMain.on_job_failed(t.jobId,t.desc),this._decrementJobCount(e,t)}_onJobSucceeded(e,i,t){if(this._lyr3DMain){if(e.layerView.destroyed)return void this._lyr3DMain.on_job_failed(t.jobId,t.desc);const s=i.data.byteLength,r=this._lyr3DMain._malloc(s);new Uint8Array(this._lyr3DMain.HEAPU8.buffer,r,s).set(i.data),this._lyr3DMain.on_job_completed(t.jobId,i.jobDescJson,r,s),this._lyr3DMain._free(r)}this._decrementJobCount(e,t)}_getRequestPromises(e,t,s,r){const a=[];for(const n of e){const e=new URL(n);if("integrated-mesh-3dtiles"===r.type){if(e.origin===s.origin&&e.pathname===s.pathname){if(r.rootTileset){a.push(Promise.resolve(r.rootTileset.slice()));continue}}else r.session&&e.searchParams.set("session",r.session)}a.push(i(e.toString(),t).then(e=>e.data))}return a}_getInitialPromise(e,i,t,s,r,a,n){const l=this._getRequestPromises(e.urls,i,t,s);return Promise.all(l).then(e=>(r.inputs=e,this._workerHandle.invoke(r,a))).then(e=>e).catch(i=>{let t=1;return o(i)?this._debugLog(1,2,`job ${e.jobId} was cancelled.`):n&&400===i.details?.httpStatus?(t=3,this._debugLog(1,2,"Session expired, trying to create new Session.")):this._debugLog(1,1,`job ${e.jobId} failed with error ${i}.`),{status:t,error:"",jobDescJson:"",data:new Uint8Array(0),missingInputUrls:[],inputs:[]}})}async _onNewJob(){const e=this._lyr3DMain.get_next_job(),i=this._layers.get(e.layerId);if(!i)return;this._incrementJobCount(i,e);const t=i.abortController.signal,s=i.layerView.layer,r="integrated-mesh-3dtiles"===s.type?s.key:null,a="integrated-mesh-3dtiles"===s.type?s.session:null,n={responseType:"array-buffer",signal:t,query:{...i.customParameters,token:i.apiKey,key:r}},l={id:e.jobId,inputs:[],jobDescJson:e.desc.slice(),isMissingResourceCase:!1},d=new URL(s.url),h=r=>{if(1===r.status)this._onJobFailed(i,r,e);else if(0===r.status)this._onJobSucceeded(i,r,e);else if(2===r.status){const a=this._getRequestPromises(r.missingInputUrls,n,d,s);Promise.all(a).then(e=>{l.jobDescJson=r.jobDescJson,r.originalInputs?l.inputs=r.originalInputs:l.inputs=[],l.isMissingResourceCase=!0;for(const i of e)l.inputs.push(i);return this._workerHandle.invoke(l,t)}).then(t=>{1===t.status?this._onJobFailed(i,t,e):0===t.status&&this._onJobSucceeded(i,t,e)}).catch(t=>{this._decrementJobCount(i,e),o(t)?this._debugLog(1,2,`job ${e.jobId} was cancelled.`):this._debugLog(1,1,`job ${e.jobId} failed with error ${t}.`),this._lyr3DMain&&this._lyr3DMain.on_job_failed(e.jobId,e.desc)})}};try{const i=await this._getInitialPromise(e,n,d,s,l,t,a);if(3===i.status&&"integrated-mesh-3dtiles"===s.type){a===s.session&&null!==s.session&&await s.requestRootAndSession(t);h(await this._getInitialPromise(e,n,d,s,l,t,s.session))}else h(i)}catch(_){_&&this._debugLog(1,1,_.toString(),!1),this._lyr3DMain&&this._lyr3DMain.on_job_failed(e.jobId,e.desc),this._decrementJobCount(i,e)}}_onNewRenderable(){const e=this._lyr3DMain.get_next_renderable(),{meshData:i}=e;i.data&&i.data.byteLength>0&&(i.data=i.data.slice());const t=this._layers.get(e.layerId);t&&(this._incrementRenderableCount(t),t.layerView.createRenderable(e).then(i=>{const s=i.numGaussians??0;this._lyr3DMain?.on_renderable_created(!0,e.layerId,e.handle,i.memUsageBytes,s),this._decrementRenderableCount(t)}).catch(i=>{o(i)||this._debugLog(2,1,`createRenderable failed with error ${i}.`),this._lyr3DMain?.on_renderable_created(!1,e.layerId,e.handle,0,0),this._decrementRenderableCount(t)}))}_freeRenderables(e,i,t){if(t<1)return;const s=this._layers.get(e);if(!s)return;const r=s.layerView,a=[],n=new Uint32Array(this._lyr3DMain.HEAPU32.buffer,i,t);for(let o=0;o<t;++o)a.push(n[o]);for(let o=0;o<t;++o)r.freeRenderable(a[o])}_setRenderableVisibility(e,i,t,s){if(s<1)return;const r=this._layers.get(e);if(!r)return;const a=r.layerView,n=[],o=[],l=new Uint32Array(this._lyr3DMain.HEAPU32.buffer,i,s),d=new Uint8Array(this._lyr3DMain.HEAPU8.buffer,t,s);for(let h=0;h<s;++h)n.push(l[h]),o.push(!!(1&d[h]));a.setRenderableVisibility(n,o,s)}_onWasmError(e,i,t,s){this._lyr3DMain&&this._debugLog(t,s,this._lyr3DMain.UTF8ToString(e,i),!1)}_onElevQueryComplete(e){const i=this._elevationQueries.get(e),t=this._lyr3DMain.get_elevation_query_result(e);if(i)if(t.succeeded&&t.zs){const s=t.zs.slice(),r=i.descriptor.clone();for(let e=0;e<s.length;++e)r.coordinates[e].z=s[e];this._debugLog(2,3,`Success EQ ${e}, number points ${s.length}.`),i.resolveCallback(r),this._elevationQueries.delete(e)}else i.rejectCallback(new s("elevation-query:error",t?.error??"Elevation query failed")),this._elevationQueries.delete(e);else this._debugLog(2,1,`_onElevQueryComplete called for unknown queryId ${e}.`)}_doRemoveLayerView(e){const i=this._layers.get(e.wasmLayerId);return!!i&&(i.abortController.abort(),this._lyr3DMain.remove_layer(e.wasmLayerId),this._is3DTilesIMLayerView(e)&&e.layer.replacesTerrain&&(this._hasLayerThatReplacesTerrain=!1,this._isTerrainReady=!1,this.notifyChange("isTerrainReady")),this._layers.delete(e.wasmLayerId),!0)}_is3DTilesIMLayerView(e){return"integrated-mesh-3dtiles"===e.layer.type}_isGaussianSplatLayerView(e){return"gaussian-splat"===e.layer.type}_isGaussianSplatLayer(e){return"gaussian-splat"===e.type}_toWasmQuality(e){switch(e){case"low":return 1;case"medium":return 2;case"high":return 3}}_addLayerView(e){const i=e.layer;if(!i.url||!i.rootTilesetJSON)return{wasmLayerId:p};const t="integrated-mesh-3dtiles"===i.type?0:2,s=this._lyr3DMain.validate_root_tileset(JSON.stringify(i.rootTilesetJSON),t);if(0!==s.errorCode)return{wasmLayerId:p,check:s};const a=this._lyr3DMain.get_next_layer_id(),n=new AbortController;this._layers.set(a,{layerView:e,abortController:n,needMemoryUsageUpdate:!1,outstandingJobCount:0,outstandingRenderableCount:0,customParameters:i.customParameters,apiKey:i.apiKey,needFrame:!0});const o=D(i.elevationInfo),l=this._toWasmQuality(this.view?.qualityProfile),d=e=>r.getLogger(this).error("add-spatial-reference-error","Error when adding SR:",e);let h=!1;if(this._isGaussianSplatLayerView(e)&&this._isGaussianSplatLayer(i)){let t=i.spatialReference;if(e.useEsriCrs&&i.esriCrsSpatialReference){t=i.esriCrsSpatialReference;const s=c(t);let r=1,a=1;!s&&t.wkid&&-1!==t.wkid&&(r=u.values[u[t.wkid]],a=e.metersPerVCSUnit),this._workerHandle.addSpatialReferenceInfo(this._cleanUpSR(this._makeSRWasmSerializable(t)),s,r,a).catch(d),t.vcsWkid&&this._viewSR.vcsWkid&&this._viewSR.vcsWkid!==t.vcsWkid&&this._workerHandle.addSpatialReferenceInfo(this._cleanUpSR(this._makeSRWasmSerializable(this._viewSR)),!1,1,1).catch(d)}h=this._lyr3DMain.add_gaussian_splat_layer(l,i.url,a,o)}else this._is3DTilesIMLayerView(e)&&(h=this._lyr3DMain.add_3dtiles_layer(l,i.url,a,o,e.layer.replacesTerrain),h&&e.layer.replacesTerrain&&(this._hasLayerThatReplacesTerrain=!0,this._isTerrainReady=!1,this.notifyChange("isTerrainReady")));return h?(this._updateWasmCamera(),e.updatingFlagChanged(),{wasmLayerId:a}):(this._layers.delete(a),{wasmLayerId:p})}_updateWasmCamera(){const e=this.view.state?.contentCamera;if(!e||!this._lyr3DMain)return;const{eye:i,center:t,up:s,near:r,far:a,fovY:n}=e,o=[e.viewport[2],e.viewport[3]],l=e.width/e.height;this._lyr3DMain.set_camera_parameters({eye:i,center:t,up:s,near:r,far:a,fov:n,aspectRatio:l,viewport:o}),this._markAllLayerViewsUpdating()}_markAllLayerViewsUpdating(){this._layers.forEach(e=>{const i=this._isUpdating(e);e.needFrame=!0,i||e.layerView.updatingFlagChanged()})}_makeSRWasmSerializable(e){return{wkid:e?.wkid??-1,latestWkid:e?.latestWkid??-1,vcsWkid:e?.vcsWkid??-1,latestVcsWkid:e?.latestVcsWkid??-1,wkt:e?.wkt??""}}_cleanUpSR(e){return-1===e?.wkid&&e.latestWkid&&-1!==e.latestWkid?e.wkid=e.latestWkid:-1===e?.latestWkid&&e.wkid&&-1!==e.wkid&&(e.latestWkid=e.wkid),-1===e?.vcsWkid&&e.latestVcsWkid&&-1!==e.latestVcsWkid?e.vcsWkid=e.latestVcsWkid:-1===e?.latestVcsWkid&&e.vcsWkid&&-1!==e.vcsWkid&&(e.latestVcsWkid=e.vcsWkid),e}};e([h({constructOnly:!0})],W.prototype,"view",void 0),e([h({readOnly:!0})],W.prototype,"isTerrainReady",null),W=e([_("esri.layers.Lyr3DWasmPerSceneView")],W);const V=W;export{V as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
-
import t from"../../core/Error.js";import e from"../../core/Logger.js";import{assertIsSome as r}from"../../core/maybe.js";import{is as n,fromRectValues as o}from"../../geometry/support/aaBoundingBox.js";import{fromValues as s}from"../../geometry/support/aaBoundingRect.js";import{isPoint as u,isPolygon as c,isPolyline as i,isMultipoint as l,isGeometryWithZ as f,isGeometryWithM as a}from"../../geometry/support/jsonTypeUtils.js";import{OptimizedFeature as h}from"./OptimizedFeature.js";import m from"./OptimizedFeatureSet.js";import g from"./OptimizedGeometry.js";import{createFeatureId as d}from"./data/createFeatureId.js";const y=()=>e.getLogger("esri.layers.graphics.featureConversionUtils"),p={esriGeometryPoint:0,esriGeometryPolyline:2,esriGeometryPolygon:3,esriGeometryMultipoint:0,esriGeometryMultiPatch:3,esriGeometryEnvelope:0};function M({scale:t,translate:e},r){return Math.round((r-e[0])/t[0])}function I({scale:t,translate:e},r){return Math.round((e[1]-r)/t[1])}function w({scale:t,translate:e},r){return Math.round((r-e[0])/t[0])}function G({scale:t,translate:e},r){return Math.round((r-e[1])/t[1])}function b(t,e){return N(t,e,0)}function T(t,e){return N(t,-e,1)}function N({scale:t,translate:e},r,n){return r*t[n]+e[n]}function P(t,e,r){return e&&(t.hasZ=!0),r&&(t.hasM=!0),t}function Z(t,e,r,n){if(e&&n&&t!==r)return(e,r,n,o)=>{n[o++]=e[r++],n[o++]=e[r++],t?r++:n[o++]=0,n[o++]=e[r++]??0};const o=2+(r?1:0)+(n?1:0),s=o-((!t&&r?1:0)+(!e&&n?1:0));return(t,e,r,n)=>{for(let u=0;u<o;++u)r[n++]=u<s?t[e++]??0:0}}function x(t,e,r){if(!t)return null;const{coords:n,hasZ:o,hasM:s}=t,[u,c]=n,i=o?n[2]:0,l=s?n[2+(o?1:0)]:0;return{x:u,y:c,z:e?i:void 0,m:r?l:void 0}}function E(t,e,r,n){for(const{geometry:o,attributes:s}of e)t.push({attributes:s,geometry:x(o,r,n)});return t}function F(t,e,r,n,o){for(const s of e){const{geometry:e,attributes:u,centroid:c}=s,i=f(e),l=a(e);t.push(new h(e?j(e,r&&i,n&&l):null,u,c?j(c,!1,!1):null,d(s,o)))}return t}function j(t,e=f(t),r=a(t)){const{x:n,y:o,z:s,m:u}=t,c=[n,o];return e&&c.push(s??0),r&&c.push(u??0),new g([],c,e,r)}function v(t,e,r,n){for(const{geometry:o,attributes:s}of e)t.push({geometry:o&&k(o,r,n),attributes:s});return t}function k(t,e,r){if(null==t)return null;const{coords:n,stride:o,hasZ:s,hasM:u}=t,c=Z(s,u,e,r),i=[];for(let l=0;l<n.length;l+=o){const t=[];c(n,l,t,0),i.push(t)}return P({points:i},e,r)}function V(t,e,r,n,o){for(const s of e){const{geometry:e,attributes:u}=s,c=f(e),i=a(e);t.push(new h(e?Y(e,r&&c,n&&i):null,u,null,d(s,o)))}return t}function Y(t,e=f(t),r=a(t)){const{points:n,hasZ:o,hasM:s}=t,u=new g([n.length],[],e,r),{coords:c,stride:i}=u;let l=0;const h=Z(o??!1,s??!1,e,r);for(const f of n)h(f,0,c,l),l+=i;return u}function _(t,e,r,n){for(const{geometry:o,attributes:s}of e)t.push({geometry:o&&L(o,r,n),attributes:s});return t}function L(t,e,r){if(!t)return null;const{coords:n,lengths:o,stride:s,hasZ:u,hasM:c}=t;let i=0;const l=Z(u,c,e,r),f=[];for(const a of o){const t=[];for(let e=0;e<a;e++){const e=[];l(n,i,e,0),i+=s,t.push(e)}f.push(t)}return P({paths:f},e,r)}function O(t,e,r,n,o){for(const s of e){const{geometry:e,attributes:u,centroid:c}=s,i=f(e),l=a(e);t.push(new h(e?S(e,r&&i,n&&l):null,u,c?j(c,!1,!1):null,d(s,o)))}return t}function S(t,e=f(t),r=a(t)){const{paths:n,hasZ:o,hasM:s}=t,u=Z(o??!1,s??!1,e,r),c=new g([],[],e,r),{lengths:i,coords:l,stride:h}=c;let m=0;for(const f of n){for(const t of f)u(t,0,l,m),m+=h;i.push(f.length)}return c}function U(t,e,r,n){for(const{geometry:o,attributes:s,centroid:u}of e){const e=z(o,r,n),c=x(u,!1,!1);t.push(u?{geometry:e,attributes:s,centroid:c}:{geometry:e,attributes:s})}return t}function z(t,e,r){if(!t)return null;const{coords:n,lengths:o,stride:s,hasZ:u,hasM:c}=t;let i=0;const l=Z(u,c,e,r),f=[];for(const a of o){const t=[];for(let e=0;e<a;e++){const e=[];l(n,i,e,0),i+=s,t.push(e)}f.push(t)}return P({rings:f},e,r)}function R(t,e,r,n,o){for(const s of e){const{geometry:e,attributes:u,centroid:c}=s,i=f(e),l=a(e);t.push(new h(e?A(e,r&&i,n&&l):null,u,c?j(c,!1,!1):null,d(s,o)))}return t}function A(t,e=f(t),r=a(t)){const{rings:n,hasZ:o,hasM:s}=t,u=new g([],[],e,r),{lengths:c,coords:i,stride:l}=u;let h=0;const m=Z(o??!1,s??!1,e,r);for(const f of n){for(const t of f)m(t,0,i,h),h+=l;c.push(f.length)}return u}const $=[],q=[];function B(t,e,r,n,o){$[0]=t;const[s]=C(q,$,e,r,n,o);return gt($),gt(q),s}function C(e,r,n,o,s,u){if(gt(e),!n){for(const t of r){const r=d(t,u);e.push(new h(null,t.attributes,null,r))}return e}switch(n){case"esriGeometryPoint":return F(e,r,o,s,u);case"esriGeometryMultipoint":return V(e,r,o,s,u);case"esriGeometryPolyline":return O(e,r,o,s,u);case"esriGeometryPolygon":case"esriGeometryMultiPatch":return R(e,r,o,s,u);default:y().error("convertToFeatureSet:unknown-geometry",new t("internal:geometry",`Unable to parse unknown geometry type '${n}'`)),gt(e)}return e}function D(t,e,r,n){q[0]=t,Q($,q,e,r,n);const o=$[0];return gt($),gt(q),o}function H(e,r=f(e),n=a(e)){return null==e?null:u(e)?j(e,r,n):c(e)?A(e,r,n):i(e)?S(e,r,n):l(e)?Y(e,r,n):void y().error("convertFromGeometry:unknown-geometry",new t("internal:geometry",`Unable to parse unknown geometry type '${e}'`))}function J(e,r,n,o){if(null==e)return null;const s="coords"in e?e:e.geometry;if(null==s)return null;switch(r){case"esriGeometryPoint":return x(s,n,o);case"esriGeometryMultipoint":return k(s,n,o);case"esriGeometryPolyline":return L(s,n,o);case"esriGeometryPolygon":return z(s,n,o);default:return y().error("convertToGeometry:unknown-geometry",new t("internal:geometry",`Unable to parse unknown geometry type '${r}'`)),null}}function K(t,e){for(const r of e)t.push({attributes:r.attributes});return t}function Q(e,r,n,o,s){if(gt(e),null==n)return K(e,r);switch(n){case"esriGeometryPoint":return E(e,r,o,s);case"esriGeometryMultipoint":return v(e,r,o,s);case"esriGeometryPolyline":return _(e,r,o,s);case"esriGeometryPolygon":return U(e,r,o,s);default:y().error("convertToFeatureSet:unknown-geometry",new t("internal:geometry",`Unable to parse unknown geometry type '${n}'`))}return e}function W(t){const{spatialReference:e,transform:r,fields:n,hasM:o,hasZ:s,features:u,geometryType:c,exceededTransferLimit:i,queryGeometry:l,queryGeometryType:f}=t,a={features:Q([],u,c,s,o),fields:n,geometryType:c,spatialReference:e,queryGeometry:J(l,f,s,o)};return r&&(a.transform=r),i&&(a.exceededTransferLimit=i),o&&(a.hasM=o),s&&(a.hasZ=s),a}function X(t,e){const r=new m,{hasM:n,hasZ:o,features:s,spatialReference:u,geometryType:c,exceededTransferLimit:i,transform:l,fields:f}=t;return f&&(r.fields=f),r.geometryType=c??null,r.spatialReference=u??null,s&&C(r.features,s,c,o,n,e),i&&(r.exceededTransferLimit=i),n&&(r.hasM=n),o&&(r.hasZ=o),l&&(r.transform=l),r}function tt(t){const{transform:e,features:r}=t;if(!e)return t;for(const n of r)null!=n.geometry&&it(n.geometry,e),null!=n.centroid&&it(n.centroid,e);return t.transform=null,t}function et(t,e){const{geometryType:r,features:n}=e;if(!t)return e;for(let o=0;o<n.length;o++){const e=n[o],s=e.weakClone();s.geometry=rt(e.geometry,r,t),s.centroid=rt(e.centroid,"esriGeometryPoint",t),n[o]=s}return e.transform=t,e}function rt(t,e,r,n,o){if(null==t)return null;if(!t?.coords.length)return null;const s=p[e],{coords:u,lengths:c,stride:i,hasZ:l,hasM:f}=t;n??=l,o??=f;const a=new g([],[],n,o),h=a.stride,m=Z(l,f,n,o);let d=0;const y=[0,0,0,0].slice(h);function w(){m(u,d,y,0),d+=i,y[0]=M(r,y[0]),y[1]=I(r,y[1])}if(t.isPoint)return w(),a.coords.push(...y),a;let G=0;for(const g of c){if(g<s)continue;let t=1;w(),a.coords.push(...y);let[e,r]=y;for(let n=1;n<g;n++){w();const[n,o]=y;e===n&&r===o||(y[0]-=e,y[1]-=r,a.coords.push(...y),e=n,r=o,t++)}t>=s?(a.lengths.push(t),G=a.coords.length):gt(a.coords,G)}return gt(a.coords,G),a.coords.length?a:null}function nt(t,e,r,n=t.hasZ,o=t.hasM){if(!t.coords.length)return null;const s=p[e],{coords:u,lengths:c,stride:i,hasZ:l,hasM:f}=t,a=new g([],[],n,o),h=a.stride,m=Z(l,f,n,o);if(t.isPoint)return m(u,0,a.coords,0),a;let d=0;const y=r*r;for(const g of c){if(g<s){d+=g*i;continue}const t=a.coords.length/h,e=d,r=d+(g-1)*i;m(u,e,a.coords,a.coords.length),st(a.coords,u,i,y,m,e,r),m(u,r,a.coords,a.coords.length);const n=a.coords.length/h-t;n>=s?a.lengths.push(n):gt(a.coords,t*h),d+=g*i}return a.coords.length?a:null}function ot(t,e,r,n){const o=t[e],s=t[e+1],u=t[r],c=t[r+1],i=t[n],l=t[n+1];let f=u,a=c,h=i-f,m=l-a;if(0!==h||0!==m){const t=((o-f)*h+(s-a)*m)/(h*h+m*m);t>1?(f=i,a=l):t>0&&(f+=h*t,a+=m*t)}return h=o-f,m=s-a,h*h+m*m}function st(t,e,r,n,o,s,u){let c,i=n,l=0;for(let f=s+r;f<u;f+=r)c=ot(e,f,s,u),c>i&&(l=f,i=c);i>n&&(l-s>r&&st(t,e,r,n,o,s,l),o(e,l,t,t.length),u-l>r&&st(t,e,r,n,o,l,u))}function ut(t,e){if(!e?.coords?.length)return null;let r=Number.POSITIVE_INFINITY,u=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;const{coords:l,stride:f}=e;for(let n=0;n<l.length;n+=f){const t=l[n],e=l[n+1];r=Math.min(r,t),c=Math.max(c,t),u=Math.min(u,e),i=Math.max(i,e)}return n(t)?o(t,r,u,c,i):s(r,u,c,i,t),t}function ct(t,e){const{lengths:r,coords:n,stride:o}=e;let s=Number.POSITIVE_INFINITY,u=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY,l=0;for(const f of r){let t=n[l],e=n[l+1];s=Math.min(t,s),u=Math.min(e,u),c=Math.max(t,c),i=Math.max(e,i),l+=o;for(let r=1;r<f;r++,l+=o){const r=n[l],o=n[l+1];t+=r,e+=o,r<0&&(s=Math.min(s,t)),r>0&&(c=Math.max(c,t)),o<0?u=Math.min(u,e):o>0&&(i=Math.max(i,e))}}return t[0]=s,t[1]=u,t[2]=c,t[3]=i,t}function it(t,e){const{coords:n,lengths:o,stride:s}=t;if(!n.length)return void(o.length=0);r(e);const{originPosition:u,scale:c,translate:i}=e,l=dt;l.originPosition=u;const f=l.scale;f[0]=c[0]??1,f[1]=-(c[1]??1),f[2]=c[2]??1,f[3]=c[3]??1;const a=l.translate;if(a[0]=i[0]??0,a[1]=i[1]??0,a[2]=i[2]??0,a[3]=i[3]??0,!o.length){for(let t=0;t<s;++t)n[t]=N(l,n[t],t);return void(o.length=0)}let h=0;for(let r=0;r<o.length;r++){const t=o[r];o[r]=t;for(let r=0;r<s;++r)n[h+r]=N(l,n[h+r],r);let e=n[h],u=n[h+1];h+=s;for(let r=1;r<t;r++,h+=s){e+=n[h]*f[0],u+=n[h+1]*f[1],n[h]=e,n[h+1]=u;for(let t=2;t<s;++t)n[h+t]=N(l,n[h+t],t)}}}function lt(t,e){if(!t?.coords?.length)return null;const r=p[e],{coords:n,lengths:o,stride:s,hasZ:u,hasM:c}=t,i=Z(u,c,u,c),l=new g([],[],u,c);let f=0,a=0,h=0,m=0;for(const g of o){a=m,i(n,f,l.coords,a),f+=s,a+=s;let t=n[f],e=n[f+1];for(let r=1;r<g;r++){const o=n[f+s],u=n[f+s+1];t*u-e*o===0&&r!==g-1||(i(n,f,l.coords,a),l.coords[a]=t,l.coords[a+1]=e,a+=s,t=e=0),t+=o,e+=u,f+=s}const o=(a-m)/s;o>=r&&(l.lengths[h]=o,m=a,h++)}return l.coords.length>m&&(l.coords.length=m),l.lengths.length>h&&(l.lengths.length=h),l.coords.length&&l.lengths.length?l:null}function ft(t,e,r,n){let o=0,s=t[n*e],u=t[n*(e+1)];for(let c=1;c<r;c++){const r=s+t[n*(e+c)],i=u+t[n*(e+c)+1],l=(r-s)*(i+u);s=r,u=i,o+=l}return.5*o}function at(t,e){const{coords:r,lengths:n}=t;let o=0,s=0;for(let u=0;u<n.length;u++){const t=n[u];s+=ft(r,o,t,e),o+=t}return Math.abs(s)}function ht(t,e,r,n){return 0===t*n-r*e&&t*r+e*n>0}function mt(t,e,r){const{stride:n}=t;if(t.isPoint){if(t.coords.length<2)return null;const[r,n]=t.coords,o=w(e,r),s=G(e,n);return new g([],[o,s])}const o=new g([],[0,0]),s=p[r],u="esriGeometryPolygon"===r||"esriGeometryPolyline"===r;let c=0,i=0;for(let l=0;l<t.lengths.length;l++){const r=t.lengths[l],f=i;let a=w(e,t.coords[n*c]),h=G(e,t.coords[n*c+1]);o.coords[i++]=a,o.coords[i++]=h;let m=0,g=0,d=1;for(let s=1;s<r;s++){const r=w(e,t.coords[n*(s+c)]),l=G(e,t.coords[n*(s+c)+1]);if(r!==a||l!==h){const t=r-a,e=l-h;u&&ht(m,g,t,e)?(o.coords[i-2]+=t,o.coords[i-1]+=e,a+=t,h+=e):(o.coords[i++]=r,o.coords[i++]=l,a=r,h=l,m=t,g=e,d+=1)}}d<s?i=f:o.lengths.push(d),c+=r}return 0===o.lengths.length?null:o}function gt(t,e=0){t.length!==e&&(t.length=e)}const dt={originPosition:"lowerLeft",scale:[1,1,1,1],translate:[0,0,0,0]};export{B as convertFromFeature,X as convertFromFeatureSet,C as convertFromFeatures,H as convertFromGeometry,Y as convertFromMultipoint,V as convertFromMultipointFeatures,j as convertFromPoint,F as convertFromPointFeatures,A as convertFromPolygon,S as convertFromPolyline,O as convertFromPolylineFeatures,D as convertToFeature,W as convertToFeatureSet,Q as convertToFeatures,J as convertToGeometry,k as convertToMultipoint,v as convertToMultipointFeatures,x as convertToPoint,z as convertToPolygon,L as convertToPolyline,nt as generalizeOptimizedGeometry,ut as getBoundsOptimizedGeometry,at as getQuantizedArea,ct as getQuantizedBoundsOptimizedGeometry,ft as getSignedQuantizedRingArea,mt as quantizeForDisplay,et as quantizeOptimizedFeatureSet,rt as quantizeOptimizedGeometry,M as quantizeX,I as quantizeY,lt as removeCollinearVertices,tt as unquantizeOptimizedFeatureSetInPlace,it as unquantizeOptimizedGeometryInPlace,N as unquantizeValue,b as unquantizeX,T as unquantizeY};
|
|
2
|
+
import t from"../../core/Error.js";import e from"../../core/Logger.js";import{assertIsSome as r}from"../../core/maybe.js";import{is as n,fromRectValues as o}from"../../geometry/support/aaBoundingBox.js";import{fromValues as s}from"../../geometry/support/aaBoundingRect.js";import{isPoint as u,isPolygon as c,isPolyline as l,isMultipoint as i,isGeometryWithZ as f,isGeometryWithM as a}from"../../geometry/support/jsonTypeUtils.js";import{OptimizedFeature as h}from"./OptimizedFeature.js";import m from"./OptimizedFeatureSet.js";import d from"./OptimizedGeometry.js";import{createFeatureId as g}from"./data/createFeatureId.js";const y=()=>e.getLogger("esri.layers.graphics.featureConversionUtils"),p={esriGeometryPoint:0,esriGeometryPolyline:2,esriGeometryPolygon:3,esriGeometryMultipoint:0,esriGeometryMultiPatch:3,esriGeometryEnvelope:0};function I({scale:t,translate:e},r){return Math.round((r-e[0])/t[0])}function M({scale:t,translate:e},r){return Math.round((e[1]-r)/t[1])}function b({scale:t,translate:e},r){return Math.round((r-e[0])/t[0])}function w({scale:t,translate:e},r){return Math.round((r-e[1])/t[1])}function G(t,e){return T(t,e,0)}function N(t,e){return T(t,-e,1)}function T({scale:t,translate:e},r,n){return r*t[n]+e[n]}function P(t,e,r){return e&&(t.hasZ=!0),r&&(t.hasM=!0),t}function F(t,e,r,n){if(e&&n&&t!==r)return(e,r,n,o)=>{n[o++]=e[r++],n[o++]=e[r++],t?r++:n[o++]=0,n[o++]=e[r++]??0};const o=2+(r?1:0)+(n?1:0),s=o-((!t&&r?1:0)+(!e&&n?1:0));return(t,e,r,n)=>{for(let u=0;u<o;++u)r[n++]=u<s?t[e++]??0:0}}function Z(t,e,r){if(!t)return null;const{coords:n,hasZ:o,hasM:s}=t,[u,c]=n,l=o?n[2]:0,i=s?n[2+(o?1:0)]:0;return{x:u,y:c,z:e?l:void 0,m:r?i:void 0}}function x(t,e,r,n){for(const{geometry:o,attributes:s}of e)t.push({attributes:s,geometry:Z(o,r,n)});return t}function E(t,e,r,n,o){for(const s of e){const{geometry:e,attributes:u,centroid:c}=s,l=f(e),i=a(e);t.push(new h(e?j(e,r&&l,n&&i):null,u,c?j(c,!1,!1):null,g(s,o)))}return t}function j(t,e=f(t),r=a(t)){const{x:n,y:o,z:s,m:u}=t,c=[n,o];return e&&c.push(s??0),r&&c.push(u??0),new d([],c,e,r)}function v(t,e,r,n){for(const{geometry:o,attributes:s}of e)t.push({geometry:o&&k(o,r,n),attributes:s});return t}function k(t,e,r){if(null==t)return null;const{coords:n,stride:o,hasZ:s,hasM:u}=t,c=F(s,u,e,r),l=[];for(let i=0;i<n.length;i+=o){const t=[];c(n,i,t,0),l.push(t)}return P({points:l},e,r)}function V(t,e,r,n,o){for(const s of e){const{geometry:e,attributes:u}=s,c=f(e),l=a(e);t.push(new h(e?Y(e,r&&c,n&&l):null,u,null,g(s,o)))}return t}function Y(t,e=f(t),r=a(t)){const{points:n,hasZ:o,hasM:s}=t,u=new d([n.length],[],e,r),{coords:c,stride:l}=u;let i=0;const h=F(o??!1,s??!1,e,r);for(const f of n)h(f,0,c,i),i+=l;return u}function _(t,e,r,n){for(const{geometry:o,attributes:s}of e)t.push({geometry:o&&L(o,r,n),attributes:s});return t}function L(t,e,r){if(!t)return null;const{coords:n,lengths:o,stride:s,hasZ:u,hasM:c}=t;let l=0;const i=F(u,c,e,r),f=[];for(const a of o){const t=[];for(let e=0;e<a;e++){const e=[];i(n,l,e,0),l+=s,t.push(e)}f.push(t)}return P({paths:f},e,r)}function O(t,e,r,n,o){for(const s of e){const{geometry:e,attributes:u,centroid:c}=s,l=f(e),i=a(e);t.push(new h(e?S(e,r&&l,n&&i):null,u,c?j(c,!1,!1):null,g(s,o)))}return t}function S(t,e=f(t),r=a(t)){const{paths:n,hasZ:o,hasM:s}=t,u=F(o??!1,s??!1,e,r),c=new d([],[],e,r),{lengths:l,coords:i,stride:h}=c;let m=0;for(const f of n){for(const t of f)u(t,0,i,m),m+=h;l.push(f.length)}return c}function U(t,e,r,n){for(const{geometry:o,attributes:s,centroid:u}of e){const e=z(o,r,n),c=Z(u,!1,!1);t.push(u?{geometry:e,attributes:s,centroid:c}:{geometry:e,attributes:s})}return t}function z(t,e,r){if(!t)return null;const{coords:n,lengths:o,stride:s,hasZ:u,hasM:c}=t;let l=0;const i=F(u,c,e,r),f=[];for(const a of o){const t=[];for(let e=0;e<a;e++){const e=[];i(n,l,e,0),l+=s,t.push(e)}f.push(t)}return P({rings:f},e,r)}function R(t,e,r,n,o){for(const s of e){const{geometry:e,attributes:u,centroid:c}=s,l=f(e),i=a(e);t.push(new h(e?A(e,r&&l,n&&i):null,u,c?j(c,!1,!1):null,g(s,o)))}return t}function A(t,e=f(t),r=a(t)){const{rings:n,hasZ:o,hasM:s}=t,u=new d([],[],e,r),{lengths:c,coords:l,stride:i}=u;let h=0;const m=F(o??!1,s??!1,e,r);for(const f of n){for(const t of f)m(t,0,l,h),h+=i;c.push(f.length)}return u}const $=[],q=[];function B(t,e,r,n,o){$[0]=t;const[s]=C(q,$,e,r,n,o);return dt($),dt(q),s}function C(e,r,n,o,s,u){if(dt(e),!n){for(const t of r){const r=g(t,u);e.push(new h(null,t.attributes,null,r))}return e}switch(n){case"esriGeometryPoint":return E(e,r,o,s,u);case"esriGeometryMultipoint":return V(e,r,o,s,u);case"esriGeometryPolyline":return O(e,r,o,s,u);case"esriGeometryPolygon":case"esriGeometryMultiPatch":return R(e,r,o,s,u);default:y().error("convertToFeatureSet:unknown-geometry",new t("internal:geometry",`Unable to parse unknown geometry type '${n}'`)),dt(e)}return e}function D(t,e,r,n){q[0]=t,Q($,q,e,r,n);const o=$[0];return dt($),dt(q),o}function H(e,r=f(e),n=a(e)){return null==e?null:u(e)?j(e,r,n):c(e)?A(e,r,n):l(e)?S(e,r,n):i(e)?Y(e,r,n):void y().error("convertFromGeometry:unknown-geometry",new t("internal:geometry",`Unable to parse unknown geometry type '${e}'`))}function J(e,r,n,o){if(null==e)return null;const s="coords"in e?e:e.geometry;if(null==s)return null;switch(r){case"esriGeometryPoint":return Z(s,n,o);case"esriGeometryMultipoint":return k(s,n,o);case"esriGeometryPolyline":return L(s,n,o);case"esriGeometryPolygon":return z(s,n,o);default:return y().error("convertToGeometry:unknown-geometry",new t("internal:geometry",`Unable to parse unknown geometry type '${r}'`)),null}}function K(t,e){for(const r of e)t.push({attributes:r.attributes});return t}function Q(e,r,n,o,s){if(dt(e),null==n)return K(e,r);switch(n){case"esriGeometryPoint":return x(e,r,o,s);case"esriGeometryMultipoint":return v(e,r,o,s);case"esriGeometryPolyline":return _(e,r,o,s);case"esriGeometryPolygon":return U(e,r,o,s);default:y().error("convertToFeatureSet:unknown-geometry",new t("internal:geometry",`Unable to parse unknown geometry type '${n}'`))}return e}function W(t){const{spatialReference:e,transform:r,fields:n,hasM:o,hasZ:s,features:u,geometryType:c,exceededTransferLimit:l,queryGeometry:i,queryGeometryType:f}=t,a={features:Q([],u,c,s,o),fields:n,geometryType:c,spatialReference:e,queryGeometry:J(i,f,s,o)};return r&&(a.transform=r),l&&(a.exceededTransferLimit=l),o&&(a.hasM=o),s&&(a.hasZ=s),a}function X(t,e){const r=new m,{hasM:n,hasZ:o,features:s,spatialReference:u,geometryType:c,exceededTransferLimit:l,transform:i,fields:f,globalIdFieldName:a}=t;return f&&(r.fields=f),r.geometryType=c??null,r.spatialReference=u??null,s&&C(r.features,s,c,o,n,e),l&&(r.exceededTransferLimit=l),n&&(r.hasM=n),o&&(r.hasZ=o),i&&(r.transform=i),a&&(r.globalIdFieldName=a),r}function tt(t){const{transform:e,features:r}=t;if(!e)return t;for(const n of r)null!=n.geometry&<(n.geometry,e),null!=n.centroid&<(n.centroid,e);return t.transform=null,t}function et(t,e){const{geometryType:r,features:n}=e;if(!t)return e;for(let o=0;o<n.length;o++){const e=n[o],s=e.weakClone();s.geometry=rt(e.geometry,r,t),s.centroid=rt(e.centroid,"esriGeometryPoint",t),n[o]=s}return e.transform=t,e}function rt(t,e,r,n,o){if(null==t)return null;if(!t?.coords.length)return null;const s=p[e],{coords:u,lengths:c,stride:l,hasZ:i,hasM:f}=t;n??=i,o??=f;const a=new d([],[],n,o),h=a.stride,m=F(i,f,n,o);let g=0;const y=[0,0,0,0].slice(h);function b(){m(u,g,y,0),g+=l,y[0]=I(r,y[0]),y[1]=M(r,y[1])}if(t.isPoint)return b(),a.coords.push(...y),a;let w=0;for(const d of c){if(d<s)continue;let t=1;b(),a.coords.push(...y);let[e,r]=y;for(let n=1;n<d;n++){b();const[n,o]=y;e===n&&r===o||(y[0]-=e,y[1]-=r,a.coords.push(...y),e=n,r=o,t++)}t>=s?(a.lengths.push(t),w=a.coords.length):dt(a.coords,w)}return dt(a.coords,w),a.coords.length?a:null}function nt(t,e,r,n=t.hasZ,o=t.hasM){if(!t.coords.length)return null;const s=p[e],{coords:u,lengths:c,stride:l,hasZ:i,hasM:f}=t,a=new d([],[],n,o),h=a.stride,m=F(i,f,n,o);if(t.isPoint)return m(u,0,a.coords,0),a;let g=0;const y=r*r;for(const d of c){if(d<s){g+=d*l;continue}const t=a.coords.length/h,e=g,r=g+(d-1)*l;m(u,e,a.coords,a.coords.length),st(a.coords,u,l,y,m,e,r),m(u,r,a.coords,a.coords.length);const n=a.coords.length/h-t;n>=s?a.lengths.push(n):dt(a.coords,t*h),g+=d*l}return a.coords.length?a:null}function ot(t,e,r,n){const o=t[e],s=t[e+1],u=t[r],c=t[r+1],l=t[n],i=t[n+1];let f=u,a=c,h=l-f,m=i-a;if(0!==h||0!==m){const t=((o-f)*h+(s-a)*m)/(h*h+m*m);t>1?(f=l,a=i):t>0&&(f+=h*t,a+=m*t)}return h=o-f,m=s-a,h*h+m*m}function st(t,e,r,n,o,s,u){let c,l=n,i=0;for(let f=s+r;f<u;f+=r)c=ot(e,f,s,u),c>l&&(i=f,l=c);l>n&&(i-s>r&&st(t,e,r,n,o,s,i),o(e,i,t,t.length),u-i>r&&st(t,e,r,n,o,i,u))}function ut(t,e){if(!e?.coords?.length)return null;let r=Number.POSITIVE_INFINITY,u=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;const{coords:i,stride:f}=e;for(let n=0;n<i.length;n+=f){const t=i[n],e=i[n+1];r=Math.min(r,t),c=Math.max(c,t),u=Math.min(u,e),l=Math.max(l,e)}return n(t)?o(t,r,u,c,l):s(r,u,c,l,t),t}function ct(t,e){const{lengths:r,coords:n,stride:o}=e;let s=Number.POSITIVE_INFINITY,u=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY,i=0;for(const f of r){let t=n[i],e=n[i+1];s=Math.min(t,s),u=Math.min(e,u),c=Math.max(t,c),l=Math.max(e,l),i+=o;for(let r=1;r<f;r++,i+=o){const r=n[i],o=n[i+1];t+=r,e+=o,r<0&&(s=Math.min(s,t)),r>0&&(c=Math.max(c,t)),o<0?u=Math.min(u,e):o>0&&(l=Math.max(l,e))}}return t[0]=s,t[1]=u,t[2]=c,t[3]=l,t}function lt(t,e){const{coords:n,lengths:o,stride:s}=t;if(!n.length)return void(o.length=0);r(e);const{originPosition:u,scale:c,translate:l}=e,i=gt;i.originPosition=u;const f=i.scale;f[0]=c[0]??1,f[1]=-(c[1]??1),f[2]=c[2]??1,f[3]=c[3]??1;const a=i.translate;if(a[0]=l[0]??0,a[1]=l[1]??0,a[2]=l[2]??0,a[3]=l[3]??0,!o.length){for(let t=0;t<s;++t)n[t]=T(i,n[t],t);return void(o.length=0)}let h=0;for(let r=0;r<o.length;r++){const t=o[r];o[r]=t;for(let r=0;r<s;++r)n[h+r]=T(i,n[h+r],r);let e=n[h],u=n[h+1];h+=s;for(let r=1;r<t;r++,h+=s){e+=n[h]*f[0],u+=n[h+1]*f[1],n[h]=e,n[h+1]=u;for(let t=2;t<s;++t)n[h+t]=T(i,n[h+t],t)}}}function it(t,e){if(!t?.coords?.length)return null;const r=p[e],{coords:n,lengths:o,stride:s,hasZ:u,hasM:c}=t,l=F(u,c,u,c),i=new d([],[],u,c);let f=0,a=0,h=0,m=0;for(const d of o){a=m,l(n,f,i.coords,a),f+=s,a+=s;let t=n[f],e=n[f+1];for(let r=1;r<d;r++){const o=n[f+s],u=n[f+s+1];t*u-e*o===0&&r!==d-1||(l(n,f,i.coords,a),i.coords[a]=t,i.coords[a+1]=e,a+=s,t=e=0),t+=o,e+=u,f+=s}const o=(a-m)/s;o>=r&&(i.lengths[h]=o,m=a,h++)}return i.coords.length>m&&(i.coords.length=m),i.lengths.length>h&&(i.lengths.length=h),i.coords.length&&i.lengths.length?i:null}function ft(t,e,r,n){let o=0,s=t[n*e],u=t[n*(e+1)];for(let c=1;c<r;c++){const r=s+t[n*(e+c)],l=u+t[n*(e+c)+1],i=(r-s)*(l+u);s=r,u=l,o+=i}return.5*o}function at(t,e){const{coords:r,lengths:n}=t;let o=0,s=0;for(let u=0;u<n.length;u++){const t=n[u];s+=ft(r,o,t,e),o+=t}return Math.abs(s)}function ht(t,e,r,n){return 0===t*n-r*e&&t*r+e*n>0}function mt(t,e,r){const{stride:n}=t;if(t.isPoint){if(t.coords.length<2)return null;const[r,n]=t.coords,o=b(e,r),s=w(e,n);return new d([],[o,s])}const o=new d([],[0,0]),s=p[r],u="esriGeometryPolygon"===r||"esriGeometryPolyline"===r;let c=0,l=0;for(let i=0;i<t.lengths.length;i++){const r=t.lengths[i],f=l;let a=b(e,t.coords[n*c]),h=w(e,t.coords[n*c+1]);o.coords[l++]=a,o.coords[l++]=h;let m=0,d=0,g=1;for(let s=1;s<r;s++){const r=b(e,t.coords[n*(s+c)]),i=w(e,t.coords[n*(s+c)+1]);if(r!==a||i!==h){const t=r-a,e=i-h;u&&ht(m,d,t,e)?(o.coords[l-2]+=t,o.coords[l-1]+=e,a+=t,h+=e):(o.coords[l++]=r,o.coords[l++]=i,a=r,h=i,m=t,d=e,g+=1)}}g<s?l=f:o.lengths.push(g),c+=r}return 0===o.lengths.length?null:o}function dt(t,e=0){t.length!==e&&(t.length=e)}const gt={originPosition:"lowerLeft",scale:[1,1,1,1],translate:[0,0,0,0]};export{B as convertFromFeature,X as convertFromFeatureSet,C as convertFromFeatures,H as convertFromGeometry,Y as convertFromMultipoint,V as convertFromMultipointFeatures,j as convertFromPoint,E as convertFromPointFeatures,A as convertFromPolygon,S as convertFromPolyline,O as convertFromPolylineFeatures,D as convertToFeature,W as convertToFeatureSet,Q as convertToFeatures,J as convertToGeometry,k as convertToMultipoint,v as convertToMultipointFeatures,Z as convertToPoint,z as convertToPolygon,L as convertToPolyline,nt as generalizeOptimizedGeometry,ut as getBoundsOptimizedGeometry,at as getQuantizedArea,ct as getQuantizedBoundsOptimizedGeometry,ft as getSignedQuantizedRingArea,mt as quantizeForDisplay,et as quantizeOptimizedFeatureSet,rt as quantizeOptimizedGeometry,I as quantizeX,M as quantizeY,it as removeCollinearVertices,tt as unquantizeOptimizedFeatureSetInPlace,lt as unquantizeOptimizedGeometryInPlace,T as unquantizeValue,G as unquantizeX,N as unquantizeY};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
-
import e from"../../Graphic.js";import n from"../../WebLinkChart.js";import o from"../../core/Collection.js";import t from"../../core/Logger.js";import r from"../../geometry/Extent.js";import a from"../../geometry/Point.js";import i from"../../geometry/Polyline.js";import s from"../GraphicsLayer.js";import l from"../LinkChartLayer.js";import{loadRecordsIntoLocalCache as m}from"./supportUtils.js";import p from"../support/LabelClass.js";import y from"../support/LabelExpressionInfo.js";import d from"../../renderers/visualVariables/SizeVariable.js";import c from"../../renderers/visualVariables/support/SizeStop.js";import{executeQueryStreaming as f}from"../../rest/knowledgeGraphService.js";import u from"../../rest/knowledgeGraph/Entity.js";import w from"../../rest/knowledgeGraph/GraphQueryStreaming.js";import h from"../../rest/knowledgeGraph/Relationship.js";import g from"../../symbols/SimpleLineSymbol.js";import b from"../../symbols/SimpleMarkerSymbol.js";import T from"../../symbols/TextSymbol.js";import x from"../../views/LinkChartView.js";const j="ESRI__DM__ENTITY__",E="ESRI__DM__RELATIONSHIP__",S=e=>`${j}${e}`,v=(e,n,o)=>`${E}${n}--${e}--${o}`,I=async(e,n)=>{const o=e.dataModel.entityTypes.map(({name:e})=>`MATCH (n:${e}) RETURN "${S(e)}" as typename LIMIT 1`),r=[];for(const t of e.dataModel.relationshipTypes)for(const{originEntityType:e,destinationEntityType:n}of t.endPoints)r.push(`MATCH (n:${e})-[r:${t.name}]->(m:${n}) RETURN "${v(e,t.name,n)}" as typename LIMIT 1`);const a=new Set,i=o.concat(r).join(" UNION ALL ");let s=!1;try{const{resultRowsStream:o}=await f(e,new w({openCypherQuery:i}),{signal:n}),t=o.getReader();for(;;){const{done:e,value:n}=await t.read();if(e)break;for(const[o]of n)a.add(o)}}catch(l){n.aborted||t.getLogger("esri.layers.knowledgeGraph.dataModelVisualizationUtils.generateDataModelView").error("Failed to fetch entity and relationship counts for data model visualization:",l),s=!0}return s?null:a},L=e=>{const n=[],o={generateAllSublayers:!0,namedTypeDefinitions:new Map},t=[];return e.dataModel.entityTypes.forEach(e=>{n.push(new u({typeName:e.name,id:S(e.name),properties:e.properties.reduce((e,n)=>({...e,[n.name]:null}),{})})),o.namedTypeDefinitions.set(e.name,{useAllData:!1,members:new Map([[S(e.name),{id:S(e.name)}]])})}),e.dataModel.relationshipTypes.forEach(e=>{const r=new Map;o.namedTypeDefinitions.set(e.name,{useAllData:!1,members:r}),e.endPoints.length||t.push(e.name);for(const{originEntityType:o,destinationEntityType:t}of e.endPoints)n.push(new h({typeName:e.name,id:v(o,e.name,t),originId:S(o),destinationId:S(t),properties:e.properties.reduce((e,n)=>({...e,[n.name]:null}),{})})),r.set(v(o,e.name,t),{id:v(o,e.name,t)})}),{records:n,inclusionDefinition:o,unobservedRelationshipTypes:t}},M=(e,n)=>{const o=n?`\n var typeCount = {\n ${Array.from(n).map(e=>`${JSON.stringify(e)}: 1`).join(",\n")}\n };\n\n var countText = "";\n if (!HasKey(typeCount, $feature.ESRI__ID)) {\n countText = " (0)"
|
|
2
|
+
import e from"../../Graphic.js";import n from"../../WebLinkChart.js";import o from"../../core/Collection.js";import t from"../../core/Logger.js";import r from"../../geometry/Extent.js";import a from"../../geometry/Point.js";import i from"../../geometry/Polyline.js";import s from"../GraphicsLayer.js";import l from"../LinkChartLayer.js";import{loadRecordsIntoLocalCache as m}from"./supportUtils.js";import p from"../support/LabelClass.js";import y from"../support/LabelExpressionInfo.js";import d from"../../renderers/visualVariables/SizeVariable.js";import c from"../../renderers/visualVariables/support/SizeStop.js";import{executeQueryStreaming as f}from"../../rest/knowledgeGraphService.js";import u from"../../rest/knowledgeGraph/Entity.js";import w from"../../rest/knowledgeGraph/GraphQueryStreaming.js";import h from"../../rest/knowledgeGraph/Relationship.js";import g from"../../symbols/SimpleLineSymbol.js";import b from"../../symbols/SimpleMarkerSymbol.js";import T from"../../symbols/TextSymbol.js";import x from"../../views/LinkChartView.js";const j="ESRI__DM__ENTITY__",E="ESRI__DM__RELATIONSHIP__",S=e=>`${j}${e}`,v=(e,n,o)=>`${E}${n}--${e}--${o}`,I=async(e,n)=>{const o=e.dataModel.entityTypes.map(({name:e})=>`MATCH (n:${e}) RETURN "${S(e)}" as typename LIMIT 1`),r=[];for(const t of e.dataModel.relationshipTypes)for(const{originEntityType:e,destinationEntityType:n}of t.endPoints)r.push(`MATCH (n:${e})-[r:${t.name}]->(m:${n}) RETURN "${v(e,t.name,n)}" as typename LIMIT 1`);const a=new Set,i=o.concat(r).join(" UNION ALL ");let s=!1;try{const{resultRowsStream:o}=await f(e,new w({openCypherQuery:i}),{signal:n}),t=o.getReader();for(;;){const{done:e,value:n}=await t.read();if(e)break;for(const[o]of n)a.add(o)}}catch(l){n.aborted||t.getLogger("esri.layers.knowledgeGraph.dataModelVisualizationUtils.generateDataModelView").error("Failed to fetch entity and relationship counts for data model visualization:",l),s=!0}return s?null:a},L=e=>{const n=[],o={generateAllSublayers:!0,namedTypeDefinitions:new Map},t=[];return e.dataModel.entityTypes.forEach(e=>{n.push(new u({typeName:e.name,id:S(e.name),properties:e.properties.reduce((e,n)=>({...e,[n.name]:null}),{})})),o.namedTypeDefinitions.set(e.name,{useAllData:!1,members:new Map([[S(e.name),{id:S(e.name)}]])})}),e.dataModel.relationshipTypes.forEach(e=>{const r=new Map;o.namedTypeDefinitions.set(e.name,{useAllData:!1,members:r}),e.endPoints.length||t.push(e.name);for(const{originEntityType:o,destinationEntityType:t}of e.endPoints)n.push(new h({typeName:e.name,id:v(o,e.name,t),originId:S(o),destinationId:S(t),properties:e.properties.reduce((e,n)=>({...e,[n.name]:null}),{})})),r.set(v(o,e.name,t),{id:v(o,e.name,t)})}),{records:n,inclusionDefinition:o,unobservedRelationshipTypes:t}},M=(e,n)=>{const o=n?`\n var typeCount = {\n ${Array.from(n).map(e=>`${JSON.stringify(e)}: 1`).join(",\n")}\n };\n\n var countText = "";\n if (!HasKey(typeCount, $feature.ESRI__ID)) {\n countText = " (0)";\n }\n\n return ${JSON.stringify(e.objectType.name)} + countText;\n `:`${JSON.stringify(e.objectType.name)}`;return"entity"===e.graphType?[new p({labelExpressionInfo:new y({expression:o}),labelPlacement:"above-center",symbol:new T({color:[255,255,255,255],font:{family:"arial-unicode-ms",size:10,weight:"bold"},haloColor:[0,0,0,255],haloSize:.7})})]:[new p({labelExpressionInfo:new y({expression:o}),labelPlacement:"above-along",repeatLabel:!1,symbol:new T({color:[80,80,80],haloColor:[255,255,255],haloSize:.7,font:{size:10,weight:"normal"},yoffset:"2px"}),deconflictionStrategy:"none"})]},$=e=>"entity"===e.graphType?[new d({valueExpression:"$view.scale",stops:[new c({size:30,value:0}),new c({size:6,value:1e3})]})]:[new d({valueExpression:"$view.scale",stops:[new c({size:20,value:0}),new c({size:8,value:1e3})]})],z=(n,o,t)=>{const l=5e-5,m=15e-5,p=8e-6,y=new s,d=new s({minScale:1e3,maxScale:0});let c=t.ymin;const f=t.xmin,u=f+m;for(const r of o){const o=n.layers.find(e=>e.objectType.name===r);c-=l;const t=("simple"===o?.renderer?.type?o.renderer.symbol?.clone():null)||new g({type:"simple-line",color:"gray",width:2}),s=new e({geometry:new i({paths:[[[f,c],[u,c]]]}),symbol:t});y.add(s);for(const n of[f,u]){const o=new e({geometry:new a({x:n,y:c}),symbol:new b({color:"white",outline:{color:"gray",width:1},size:6})});y.add(o)}const m=new e({geometry:new a({x:(f+u)/2,y:c+p}),symbol:new T({text:r+" (0)",color:[80,80,80],haloColor:[255,255,255],haloSize:.7,font:{size:10,weight:"normal"},yoffset:"2px"})});d.add(m)}return{graphicsLayers:[y,d],graphicsExtent:new r({xmin:f,xmax:u,ymin:c,ymax:t.ymin,spatialReference:t.spatialReference})}},C=({container:e,kg:t})=>{const r=new AbortController,{records:a,inclusionDefinition:i,unobservedRelationshipTypes:s}=L(t),p=I(t,r.signal);m(a,t.dataModel);const y=new l({title:"Data Model Visualization Layer",url:t.url,initializationInclusionModeDefinition:i,dataPreloadedInLocalCache:!0}),d=new n({layers:new o([y])}),c=new x({map:d,container:e}),f=new Promise((e,n)=>{c.when(()=>y.load().then(async()=>{if(y.layers.forEach(e=>{e.labelsVisible=!0,e.visible=!0,e.labelingInfo=M(e,null),p.then(n=>{n&&(e.labelingInfo=M(e,n))}),e.renderer&&"heatmap"!==e.renderer.type&&(e.renderer.visualVariables=$(e))}),d.diagramNodesExtent){let n=null;if(s.length>0){const{graphicsExtent:e,graphicsLayers:o}=z(y,s,d.diagramNodesExtent);d.addMany(o),n=e}const o=n?d.diagramNodesExtent.union(n):d.diagramNodesExtent;c.goTo(o.expand(1.4)).finally(()=>e())}},n),n)});return{_view:c,load:()=>f,destroy:()=>{c.destroy(),r.abort()}}};export{S as entityTypeToRecordId,C as generateDataModelView,L as generateRecordsForDataModelView,I as getExistingEntitiesAndRelationshipTriples,M as getLabellingInfoForLayer,z as getUnobservedRelationshipGraphics,$ as getVisualVariablesForLayer,v as relationshipTripleToRecordId};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
-
import e from"../../request.js";import t from"../../core/Error.js";import n from"../../core/Logger.js";import{makeAbsolute as i,addQueryParameters as r,urlToObject as o}from"../../core/urlUtils.js";import a from"../../geometry/SpatialReference.js";import{wgs84 as s}from"../../geometry/support/spatialReferenceUtils.js";import{project as l}from"../../geometry/support/webMercatorUtils.js";import{convertToFeatureSet as c,convertToGeometry as u,convertFromGeometry as
|
|
2
|
+
import e from"../../request.js";import t from"../../core/Error.js";import n from"../../core/Logger.js";import{makeAbsolute as i,addQueryParameters as r,urlToObject as o}from"../../core/urlUtils.js";import a from"../../geometry/SpatialReference.js";import{wgs84 as s}from"../../geometry/support/spatialReferenceUtils.js";import{project as l}from"../../geometry/support/webMercatorUtils.js";import{convertToFeatureSet as c,convertToGeometry as u,convertFromGeometry as f}from"../graphics/featureConversionUtils.js";import d from"../graphics/OptimizedFeatureSet.js";import{validateGeoJSON as p,inferLayerProperties as m,createOptimizedFeatures as g}from"../graphics/sources/geojson/geojson.js";import{createDrawingInfo as y}from"../graphics/sources/support/clientSideDefaults.js";import{mixAttributes as w}from"../graphics/sources/support/sourceUtils.js";import h from"../support/FieldsIndex.js";import{kebabDict as b}from"../support/fieldType.js";import{utc as j}from"../../time/constants.js";const F=()=>n.getLogger("esri.layers.ogc.ogcFeatureUtils"),I="startindex",T=new Set([I,"offset"]),k="http://www.opengis.net/def/crs/",x=`${k}OGC/1.3/CRS84`;async function S(n,o,a={},s=5){const{links:l}=n,c=A(l);if(!c)throw new t("ogc-feature-layer:missing-items-page","Missing items url");const{apiKey:u,customParameters:f,signal:d}=a,g=i(c.href,n.landingPage.url),w={limit:s,...f,token:u},T=r(g,w),k={accept:"application/geo+json"},{data:x}=await e(T,{signal:d,headers:k}),S=E(T,s,x.links)??I;p(x);const v=x.numberMatched,O=m(x,{geometryType:o.geometryType}),P=o.fields||O.fields||[],q=null!=o.hasZ?o.hasZ:O.hasZ,C=O.geometryType,N=o.objectIdField||O.objectIdFieldName||"OBJECTID";let R=o.timeInfo;const W=P.find(({name:e})=>e===N);if(W)W.editable=!1,W.nullable=!1;else{if(!O.objectIdFieldType)throw new t("ogc-feature-layer:missing-feature-id","Collection geojson require a feature id as a unique identifier");P.unshift({name:N,alias:N,type:"number"===O.objectIdFieldType?"esriFieldTypeOID":"esriFieldTypeString",editable:!1,nullable:!1})}if(N!==O.objectIdFieldName){const e=P.find(({name:e})=>e===O.objectIdFieldName);e&&(e.type="esriFieldTypeInteger")}P===O.fields&&O.unknownFields.length>0&&F().warn({name:"ogc-feature-layer:unknown-field-types",message:"Some fields types couldn't be inferred from the features and were dropped",details:{unknownFields:O.unknownFields}});for(const e of P){if(e.name??=e.alias,e.alias??=e.name,"esriFieldTypeOID"!==e.type&&"esriFieldTypeGlobalID"!==e.type&&(e.editable??=!0,e.nullable??=!0),!e.name)throw new t("ogc-feature-layer:invalid-field-name","field name is missing",{field:e});if(!b.jsonValues.includes(e.type))throw new t("ogc-feature-layer:invalid-field-type",`invalid type for field "${e.name}"`,{field:e})}if(R){const e=new h(P);if(R.startTimeField){const t=e.get(R.startTimeField);t?(R.startTimeField=t.name,t.type="esriFieldTypeDate"):R.startTimeField=null}if(R.endTimeField){const t=e.get(R.endTimeField);t?(R.endTimeField=t.name,t.type="esriFieldTypeDate"):R.endTimeField=null}if(R.trackIdField){const t=e.get(R.trackIdField);t?R.trackIdField=t.name:(R.trackIdField=null,F().warn({name:"ogc-feature-layer:invalid-timeInfo-trackIdField",message:"trackIdField is missing",details:{timeInfo:R}}))}R.timeReference||={timeZoneIANA:j},R.startTimeField||R.endTimeField||(F().warn({name:"ogc-feature-layer:invalid-timeInfo",message:"startTimeField and endTimeField are missing",details:{timeInfo:R}}),R=void 0)}return{drawingInfo:C?y(C):null,extent:U(n),geometryType:C,fields:P,hasZ:!!q,objectIdField:N,paginationParameter:S,timeInfo:R,featureCount:v}}async function v(n,r={}){const{links:o,url:a}=n,s=L(o);if(!s)throw new t("ogc-feature-layer:missing-collections-page","Missing collections url");const{apiKey:l,customParameters:c,signal:u}=r,f=i(s.href,a),{data:d}=await e(f,{signal:u,headers:{accept:"application/json"},query:{...c,token:l}});for(const e of d.collections)e.landingPage=n;return d}async function O(n,r={}){const{links:o,url:a}=n,s=K(o);if(!s)throw new t("ogc-feature-layer:missing-conformance-page","Missing conformance url");const{apiKey:l,customParameters:c,signal:u}=r,f=i(s.href,a),{data:d}=await e(f,{signal:u,headers:{accept:"application/json"},query:{...c,token:l}});return d}async function P(t,n={}){const{apiKey:i,customParameters:r,signal:o}=n,{data:a}=await e(t,{signal:o,headers:{accept:"application/json"},query:{...r,token:i}});return a.url=t,a}async function q(t,n={}){const{links:r,url:o}=t,a=J(r,"service-desc","application/vnd.oai.openapi+json;version=3.0");if(!a)return F().warn("ogc-feature-layer:missing-openapi-page","The OGC API-Features server does not have an OpenAPI page."),null;const{apiKey:s,customParameters:l,signal:c}=n,u=i(a.href,o),{data:f}=await e(u,{signal:c,headers:{accept:"application/vnd.oai.openapi+json;version=3.0"},query:{...l,token:s}});return f}function C(e){const t=/^http:\/\/www\.opengis.net\/def\/crs\/(?<authority>.*)\/(?<version>.*)\/(?<code>.*)$/i.exec(e),n=t?.groups;if(!n)return null;const{authority:i,code:r}=n;switch(i.toLowerCase()){case"ogc":switch(r.toLowerCase()){case"crs27":return a.GCS_NAD_1927.wkid;case"crs83":return 4269;case"crs84":case"crs84h":return a.WGS84.wkid;default:return null}case"esri":case"epsg":{const e=Number.parseInt(r,10);return Number.isNaN(e)?null:e}default:return null}}async function N(e,t,n){const i=await R(e,t,n);return c(i)}async function R(n,r,o){const{collection:{links:c,landingPage:{url:p}},layerDefinition:m,maxRecordCount:y,queryParameters:{apiKey:b,customParameters:j},spatialReference:F,supportedCrs:I}=n,T=A(c);if(!T)throw new t("ogc-feature-layer:missing-items-page","Missing items url");const{geometry:k,num:x,start:S,timeExtent:v,where:O}=r;if(r.objectIds)throw new t("ogc-feature-layer:query-by-objectids-not-supported","Queries with object ids are not supported");const P=a.fromJSON(F),q=r.outSpatialReference??P,C=q.isWGS84?null:$(q,I),N=Z(k,I),R=M(v),W=D(O),G=x??(null==S?y:10),K=0===S?void 0:S,{fields:L,geometryType:U,hasZ:J,objectIdField:E,paginationParameter:_}=m,B=i(T.href,p),{data:Q}=await e(B,{...o,query:{...j,...N,crs:C,datetime:R,query:W,limit:G,[_]:K,token:b},headers:{accept:"application/geo+json"}}),V=g(Q,{geometryType:U,hasZ:J,objectIdField:E}),H=V.length===G&&!!z(Q.links??[]),X=new h(L);for(const e of V){const t={};w(X,t,e.attributes,!0);for(const e of X.fields)e.nullable&&!(e.name in t)&&(t[e.name]=null);t[E]=e.attributes[E],e.attributes=t}if(!C&&q.isWebMercator)for(const e of V)if(null!=e.geometry&&null!=U){const t=u(e.geometry,U,J,!1);t.spatialReference=a.WGS84,e.geometry=f(l(t,q))}for(const e of V)e.objectId=e.attributes[E];const Y=C||!C&&q.isWebMercator?q.toJSON():s,ee=new d;return ee.exceededTransferLimit=H,ee.features=V,ee.fields=L,ee.geometryType=U,ee.hasZ=J,ee.spatialReference=Y,ee}function W(e){return null!=e&&"extent"===e.type}function $(e,t){const{isWebMercator:n,wkid:i,latestWkid:r}=e;if(!i&&!r)return null;const o=n?t[3857]??t[102100]??t[102113]??t[900913]:i&&t[i]||r&&t[r];return o?`${k}${o}`:null}function G(e){if(!e)return"";const{xmin:t,ymin:n,xmax:i,ymax:r}=e;return`${t},${n},${i},${r}`}function M(e){if(!e)return null;const{start:t,end:n}=e;return`${null!=t?t.toISOString():".."}/${null!=n?n.toISOString():".."}`}function D(e){return e&&"1=1"!==e?e:null}function Z(e,t){if(!W(e))return null;const{spatialReference:n}=e;if(!n||n.isWGS84)return{bbox:G(e)};const i=$(n,t);return null!=i?{bbox:G(e),"bbox-crs":i}:n.isWebMercator?{bbox:G(l(e,a.WGS84))}:null}function K(e){return J(e,"conformance","application/json")??J(e,"http://www.opengis.net/def/rel/ogc/1.0/conformance","application/json")}function L(e){return J(e,"data","application/json")??J(e,"http://www.opengis.net/def/rel/ogc/1.0/data","application/json")}function U(e){const t=e.extent?.spatial;if(!t)return null;const n=t.bbox[0],i=4===n.length,[r,o]=n,s=i?void 0:n[2];return{xmin:r,ymin:o,xmax:i?n[2]:n[3],ymax:i?n[3]:n[4],zmin:s,zmax:i?void 0:n[5],spatialReference:a.WGS84.toJSON()}}function A(e){return J(e,"items","application/geo+json","http://www.opengis.net/def/profile/ogc/0/rfc7946")??J(e,"http://www.opengis.net/def/rel/ogc/1.0/items","application/geo+json","http://www.opengis.net/def/profile/ogc/0/rfc7946")}function J(e,t,n,i){return i?e.find(({rel:e,type:r,profile:o})=>e===t&&r===n&&o?.includes(i))??e.find(({rel:e,type:i,profile:r})=>e===t&&i===n&&!r):e.find(({rel:e,type:i})=>e===t&&i===n)??e.find(({rel:e,type:n})=>e===t&&!n)}function z(e){return J(e,"next","application/geo+json")}function E(e,t,n){if(!n)return;const i=z(n),r=o(i?.href)?.query;if(!r)return;const a=o(e).query,s=Object.keys(a??{}),l=Object.entries(r).filter(([e])=>!s.includes(e)).find(([e,n])=>T.has(e.toLowerCase())&&Number.parseInt(n,10)===t),c=l?.[0];return c}export{x as crsDefault,k as crsPrefix,S as getCollectionDefinition,A as getItemsLink,v as getServerCollectionsPage,O as getServerConformance,P as getServerLandingPage,q as getServerOpenApi,C as getSpatialReferenceWkid,N as queryFeatureSetJSON,R as queryOptimizedFeatureSet};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
-
import t from"../../../core/Error.js";import{isAborted as e,createAbortError as a}from"../../../core/promiseUtils.js";import{
|
|
2
|
+
import t from"../../../core/Error.js";import{isAborted as e,createAbortError as a}from"../../../core/promiseUtils.js";import{F as n}from"../../../chunks/Zlib.js";class i{constructor(t){this._canvas=null,this._ctx=null,t&&(this._canvas=t.canvas,this._ctx=t.ctx||t.canvas&&t.canvas.getContext("2d"))}decode(n,s,r){if(!n||n.byteLength<10)throw new t("imagecanvasdecoder: decode","required a valid encoded data as input.");let{width:c=0,height:h=0,format:o}=s;const{applyJpegMask:l}=s;if(l&&(!c||!h))throw new t("imagecanvasdecoder: decode","image width and height are needed to apply jpeg mask directly to canvas");return new Promise((t,d)=>{let g=null;"jpg"===o&&l&&(g=i._getMask(n,{width:c,height:h}));const w=new Blob([new Uint8Array(n)],{type:"image/"+o=="jpg"?"jpeg":o}),v=URL.createObjectURL(w),m=new Image;m.src=v,m.onload=()=>{if(URL.revokeObjectURL(v),e(r))return void d(a());c=m.width,h=m.height,this._canvas&&this._ctx?(this._canvas.width===c&&this._canvas.height===h||(this._canvas.width=c,this._canvas.height=h),this._ctx.clearRect(0,0,c,h)):(this._canvas=document.createElement("canvas"),this._canvas.width=c,this._canvas.height=h,this._ctx=this._canvas.getContext("2d")),this._ctx.drawImage(m,0,0);const n=this._ctx.getImageData(0,0,c,h),i=n.data;if(s.renderOnCanvas){if(g)for(let t=0;t<g.length;t++)g[t]?i[4*t+3]=255:i[4*t+3]=0;return this._ctx.putImageData(n,0,0),void t(null)}const o=c*h,l=new Uint8Array(o),w=new Uint8Array(o),_=new Uint8Array(o);if(g)for(let t=0;t<o;t++)l[t]=i[4*t],w[t]=i[4*t+1],_[t]=i[4*t+2];else{g=new Uint8Array(o);for(let t=0;t<o;t++)l[t]=i[4*t],w[t]=i[4*t+1],_[t]=i[4*t+2],g[t]=i[4*t+3]}t({width:c,height:h,pixels:[l,w,_],mask:g,pixelType:"u8"})},m.onerror=()=>{URL.revokeObjectURL(v),d("cannot load image")}})}static _getMask(t,e){let a=null;try{const i=new Uint8Array(t),s=Math.ceil(i.length/2);let r=0;const c=i.length-2;for(r=s;r<c&&(255!==i[r]||217!==i[r+1]);r++);if(r+=2,r<i.length-1){const t=new n(i.subarray(r)).getBytes();a=new Uint8Array(e.width*e.height);let s=0;for(let e=0;e<t.length;e++)for(let n=7;n>=0;n--)a[s++]=t[e]>>n&1}}catch(i){}return a}}export{i as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
-
import{J as t}from"../../../chunks/Jpg.js";import{
|
|
2
|
+
import{J as t}from"../../../chunks/Jpg.js";import{F as e}from"../../../chunks/Zlib.js";class r{static decode(r,n=!1){const s=new Uint8Array(r),l=new t;l.parse(s);const{width:o,height:a,numComponents:i,eof:f}=l,h=l.getData(o,a,!0),c=o*a;let u,g=null;if(!n&&f<s.length-1)try{const t=new e(s.subarray(f)).getBytes();g=new Uint8Array(c);let r=0;for(let e=0;e<t.length;e++)for(let n=7;n>=0;n--)g[r++]=t[e]>>n&1}catch{}if(1===i&&h.length===o*a){const t=new Uint8Array(h.buffer);u=[t,t,t]}else{u=[];for(let e=0;e<3;e++)u.push(new Uint8Array(c));let t=0;for(let e=0;e<c;e++)for(let r=0;r<3;r++)u[r][e]=h[t++]}return{width:o,height:a,pixels:u,mask:g}}}export{r as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
-
import t from"../../../core/Error.js";import{assertIsSome as e}from"../../../core/maybe.js";import a from"./ImageCanvasDecoder.js";import i from"./JpgPlus.js";import{load as s,decode as r}from"./Lerc.js";import{decode as n}from"./Lzw.js";import{convertNoDataToMask as o}from"./pixelRangeUtils.js";import{Z as h}from"../../../chunks/Zlib.js";import{load as c,decode as l}from"./Qb3.js";import p from"./Raw.js";import{decodeTileOrStrip as d,decode as u}from"./TiffDecoder.js";import{isPlatformLittleEndian as f}from"./utils.js";import m from"../../support/PixelBlock.js";import w from"../../support/SimpleBandStatistics.js";var g=function(t){var e,a,i,s,r,n;function o(t){var e,a,i,s,r,n,o,h,c,l,p,d,u;for(this.data=t,this.pos=8,this.palette=[],this.imgData=[],this.transparency={},this.animation=null,this.text={},r=null;;){switch(e=this.readUInt32(),h=function(){var t,e;for(e=[],t=0;t<4;++t)e.push(String.fromCharCode(this.data[this.pos++]));return e}.call(this).join(""),h){case"IHDR":this.width=this.readUInt32(),this.height=this.readUInt32(),this.bits=this.data[this.pos++],this.colorType=this.data[this.pos++],this.compressionMethod=this.data[this.pos++],this.filterMethod=this.data[this.pos++],this.interlaceMethod=this.data[this.pos++];break;case"acTL":this.animation={numFrames:this.readUInt32(),numPlays:this.readUInt32()||1/0,frames:[]};break;case"PLTE":this.palette=this.read(e);break;case"fcTL":r&&this.animation.frames.push(r),this.pos+=4,r={width:this.readUInt32(),height:this.readUInt32(),xOffset:this.readUInt32(),yOffset:this.readUInt32()},s=this.readUInt16(),i=this.readUInt16()||100,r.delay=1e3*s/i,r.disposeOp=this.data[this.pos++],r.blendOp=this.data[this.pos++],r.data=[];break;case"IDAT":case"fdAT":for("fdAT"===h&&(this.pos+=4,e-=4),t=(null!=r?r.data:void 0)||this.imgData,p=0;0<=e?p<e:p>e;0<=e?++p:--p)t.push(this.data[this.pos++]);break;case"tRNS":switch(this.transparency={},this.colorType){case 3:if(this.transparency.indexed=this.read(e),(c=255-this.transparency.indexed.length)>0)for(d=0;0<=c?d<c:d>c;0<=c?++d:--d)this.transparency.indexed.push(255);break;case 0:this.transparency.grayscale=this.read(e)[0];break;case 2:this.transparency.rgb=this.read(e)}break;case"tEXt":n=(l=this.read(e)).indexOf(0),o=String.fromCharCode.apply(String,l.slice(0,n)),this.text[o]=String.fromCharCode.apply(String,l.slice(n+1));break;case"IEND":return r&&this.animation.frames.push(r),this.colors=function(){switch(this.colorType){case 0:case 3:case 4:return 1;case 2:case 6:return 3}}.call(this),this.hasAlphaChannel=4===(u=this.colorType)||6===u,a=this.colors+(this.hasAlphaChannel?1:0),this.pixelBitlength=this.bits*a,this.colorSpace=function(){switch(this.colors){case 1:return"DeviceGray";case 3:return"DeviceRGB"}}.call(this),void(this.imgData=new Uint8Array(this.imgData));default:this.pos+=e}if(this.pos+=4,this.pos>this.data.length)throw new Error("Incomplete or corrupt PNG file")}}return o.load=function(t,e,a){var i;return"function"==typeof e&&(a=e),(i=new XMLHttpRequest).open("GET",t,!0),i.responseType="arraybuffer",i.onload=function(){var t;return t=new o(new Uint8Array(i.response||i.mozResponseArrayBuffer)),"function"==typeof(null!=e?e.getContext:void 0)&&t.render(e),"function"==typeof a?a(t):void 0},i.send(null)},a=1,i=2,e=0,o.prototype.read=function(t){var e,a;for(a=[],e=0;0<=t?e<t:e>t;0<=t?++e:--e)a.push(this.data[this.pos++]);return a},o.prototype.readUInt32=function(){return this.data[this.pos++]<<24|this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++]},o.prototype.readUInt16=function(){return this.data[this.pos++]<<8|this.data[this.pos++]},o.prototype.decodePixels=function(t){var e,a,i,s,r,n,o,c,l,p,d,u,f,m,w,g,y,x,b,k,T,C,I;if(null==t&&(t=this.imgData),0===t.length)return new Uint8Array(0);for(t=(t=new h(t)).getBytes(),g=(u=this.pixelBitlength/8)*this.width,f=new Uint8Array(g*this.height),n=t.length,w=0,m=0,a=0;m<n;){switch(t[m++]){case 0:for(s=b=0;b<g;s=b+=1)f[a++]=t[m++];break;case 1:for(s=k=0;k<g;s=k+=1)e=t[m++],r=s<u?0:f[a-u],f[a++]=(e+r)%256;break;case 2:for(s=T=0;T<g;s=T+=1)e=t[m++],i=(s-s%u)/u,y=w&&f[(w-1)*g+i*u+s%u],f[a++]=(y+e)%256;break;case 3:for(s=C=0;C<g;s=C+=1)e=t[m++],i=(s-s%u)/u,r=s<u?0:f[a-u],y=w&&f[(w-1)*g+i*u+s%u],f[a++]=(e+Math.floor((r+y)/2))%256;break;case 4:for(s=I=0;I<g;s=I+=1)e=t[m++],i=(s-s%u)/u,r=s<u?0:f[a-u],0===w?y=x=0:(y=f[(w-1)*g+i*u+s%u],x=i&&f[(w-1)*g+(i-1)*u+s%u]),o=r+y-x,c=Math.abs(o-r),p=Math.abs(o-y),d=Math.abs(o-x),l=c<=p&&c<=d?r:p<=d?y:x,f[a++]=(e+l)%256;break;default:throw new Error("Invalid filter algorithm: "+t[m-1])}w++}return f},o.prototype.decodePalette=function(){var t,e,a,i,s,r,n,o,h;for(a=this.palette,r=this.transparency.indexed||[],s=new Uint8Array((r.length||0)+a.length),i=0,a.length,t=0,e=n=0,o=a.length;n<o;e=n+=3)s[i++]=a[e],s[i++]=a[e+1],s[i++]=a[e+2],s[i++]=null!=(h=r[t++])?h:255;return s},o.prototype.copyToImageData=function(t,e){var a,i,s,r,n,o,h,c,l,p,d;if(i=this.colors,l=null,a=this.hasAlphaChannel,this.palette.length&&(l=null!=(d=this._decodedPalette)?d:this._decodedPalette=this.decodePalette(),i=4,a=!0),c=(s=t.data||t).length,n=l||e,r=o=0,1===i)for(;r<c;)h=l?4*e[r/4]:o,p=n[h++],s[r++]=p,s[r++]=p,s[r++]=p,s[r++]=a?n[h++]:this.transparency.grayscale&&this.transparency.grayscale===p?0:255,o=h;else for(;r<c;)h=l?4*e[r/4]:o,s[r++]=n[h++],s[r++]=n[h++],s[r++]=n[h++],s[r++]=a?n[h++]:this.transparency.rgb&&this.transparency.rgb[1]===n[h-3]&&this.transparency.rgb[3]===n[h-2]&&this.transparency.rgb[5]===n[h-1]?0:255,o=h},o.prototype.decode=function(){var t;return t=new Uint8Array(this.width*this.height*4),this.copyToImageData(t,this.decodePixels()),t},r=t.document&&t.document.createElement("canvas"),n=r&&r.getContext("2d"),s=function(t){var e;return n.width=t.width,n.height=t.height,n.clearRect(0,0,t.width,t.height),n.putImageData(t,0,0),(e=new Image).src=r.toDataURL(),e},o.prototype.decodeFrames=function(t){var e,a,i,r,n,o,h,c;if(this.animation){for(c=[],a=n=0,o=(h=this.animation.frames).length;n<o;a=++n)e=h[a],i=t.createImageData(e.width,e.height),r=this.decodePixels(new Uint8Array(e.data)),this.copyToImageData(i,r),e.imageData=i,c.push(e.image=s(i));return c}},o.prototype.renderFrame=function(t,s){var r,n,o;return r=(n=this.animation.frames)[s],o=n[s-1],0===s&&t.clearRect(0,0,this.width,this.height),(null!=o?o.disposeOp:void 0)===a?t.clearRect(o.xOffset,o.yOffset,o.width,o.height):(null!=o?o.disposeOp:void 0)===i&&t.putImageData(o.imageData,o.xOffset,o.yOffset),r.blendOp===e&&t.clearRect(r.xOffset,r.yOffset,r.width,r.height),t.drawImage(r.image,r.xOffset,r.yOffset)},o.prototype.animate=function(t){var e,a,i,s,r,n,o=this;return a=0,n=this.animation,s=n.numFrames,i=n.frames,r=n.numPlays,(e=function(){var n,h;if(n=a++%s,h=i[n],o.renderFrame(t,n),s>1&&a/s<r)return o.animation._timeout=setTimeout(e,h.delay)})()},o.prototype.stopAnimation=function(){var t;return clearTimeout(null!=(t=this.animation)?t._timeout:void 0)},o.prototype.render=function(t){var e,a;return t._png&&t._png.stopAnimation(),t._png=this,t.width=this.width,t.height=this.height,e=t.getContext("2d"),this.animation?(this.decodeFrames(e),this.animate(e)):(a=e.createImageData(this.width,this.height),this.copyToImageData(a,this.decodePixels()),e.putImageData(a,0,0))},o}(self);const y=new Set(["jpg","png","bmp","gif"]);async function x(e,a){if(!f)throw new t("rasterCoded:decode","lerc decoder is not supported on big endian platform");await s();const{offset:i}=a,{width:n,height:o,pixelType:h,statistics:c,depthCount:l,noDataValues:p,bandMasks:d,pixels:u,mask:g}=r(e,{inputOffset:i,returnInterleaved:a.returnInterleaved}),y=new m({width:n,height:o,pixelType:h.toLowerCase(),pixels:u,mask:g,statistics:c.map(({minValue:t,maxValue:e})=>new w(t,e)),bandMasks:d,depthCount:l,noDataValues:p});return c?.length||y.updateStatistics(),y}async function b(e,a){await c();const i=l(e);if(!i)throw new t("rasterCodec:decode","failed to decode the input data.");const{width:s,height:r,pixels:n,pixelType:o}=i,h=new m({width:s,height:r,pixelType:o,pixels:n});return h.updateStatistics(),h}async function k(t,a){const i=await u(t,{...a,noDataValue:a.tiffNoDataValue,matchAllNoData:a.matchAllNoData});e(i);const s=new m({width:i.width,height:i.height,pixels:i.pixels,pixelType:i.pixelType.toLowerCase(),mask:i.mask,bandMasks:i.bandMasks,statistics:null});return s.updateStatistics(),s}async function T(t,e){const a=await d(t,e.customOptions),i=new m({width:a.width,height:a.height,pixels:a.pixels,pixelType:a.pixelType.toLowerCase(),mask:a.mask,statistics:null});return i.updateStatistics(),i}function C(t,e){const a=e.pixelType||"u8",i=m.getPixelArrayConstructor(a),s="u8"===a?t:new i(t.buffer),r=[],n=e.planes||1;if(1===n)r.push(s);else for(let h=0;h<n;h++){const a=(e.width||1)*(e.height||t.length),o=new i(a);for(let t=0;t<a;t++)o[t]=s[t*n+h];r.push(o)}const o=new m({width:e.width||1,height:e.height||t.length,pixels:r,pixelType:a,statistics:null});return o.updateStatistics(),o}function I(t,e){return C(new h(new Uint8Array(t)).getBytes(),e)}function A(t,e){return C(n(t,e.offset,e.eof,!e.isInputBigEndian),e)}function v(t,e,a){const{pixelTypeCtor:i}=P(e.pixelType),s=(0,p.decode)(t,{width:e.width,height:e.height,pixelType:i,format:a}),r=new m({width:e.width,height:e.height,pixels:s.pixels,pixelType:e.pixelType,mask:s.mask,statistics:null});return r.updateStatistics(),r}function D(t,e){const a=i.decode(t,e.hasNoZlibMask??void 0),s=new m({width:a.width,height:a.height,pixels:a.pixels,pixelType:"u8",mask:a.mask,statistics:null});return s.updateStatistics(),s}function U(t,e){const a=new Uint8Array(t),i=new g(a),{width:s,height:r}=e,n=s*r,o=i.decode();let h,c=0,l=0;const p=new Uint8Array(n);for(c=0;c<n;c++)p[c]=o[4*c+3];const d=new m({width:s,height:r,pixels:[],pixelType:"u8",mask:p,statistics:[]});for(c=0;c<3;c++){for(h=new Uint8Array(n),l=0;l<n;l++)h[l]=o[4*l+c];d.addData({pixels:h})}return d.updateStatistics(),d}async function S(t,e,i,s){const r=new a,n={applyJpegMask:!1,format:e,...i},o=await r.decode(t,n,s),h=new m(o);return h.updateStatistics(),h}function j(e){if(null==e)throw new t("rasterCodec:decode","parameter encodeddata is required.");const a=new Uint8Array(e,0,10);let i="";return 255===a[0]&&216===a[1]?i="jpg":137===a[0]&&80===a[1]&&78===a[2]&&71===a[3]?i="png":67===a[0]&&110===a[1]&&116===a[2]&&90===a[3]&&73===a[4]&&109===a[5]&&97===a[6]&&103===a[7]&&101===a[8]&&32===a[9]?i="lerc":76===a[0]&&101===a[1]&&114===a[2]&&99===a[3]&&50===a[4]&&32===a[5]?i="lerc2":73===a[0]&&73===a[1]&&42===a[2]&&0===a[3]||77===a[0]&&77===a[1]&&0===a[2]&&42===a[3]||73===a[0]&&73===a[1]&&43===a[2]&&0===a[3]||77===a[0]&&77===a[1]&&0===a[2]&&43===a[3]?i="tiff":71===a[0]&&73===a[1]&&70===a[2]?i="gif":66===a[0]&&77===a[1]?i="bmp":81===a[0]&&66===a[1]&&51===a[2]?i="qb3":String.fromCharCode.apply(null,a).toLowerCase().includes("error")&&(i="error"),i}function O(e){let a=null;switch(e){case"lerc":case"lerc2":a=x;break;case"jpg":a=D;break;case"png":a=U;break;case"bsq":case"bip":a=(t,a)=>v(t,a,e);break;case"tiff":a=k;break;case"deflate":a=I;break;case"lzw":a=A;break;case"qb3":a=b;break;case"error":a=()=>{throw new t("rasterCodec:decode","input data contains error")};break;default:a=()=>{throw new t("rasterCodec:decode","unsupported raster format")}}return a}function P(t){let e=null,a=null;switch(t?t.toLowerCase():"f32"){case"u1":case"u2":case"u4":case"u8":a=255,e=Uint8Array;break;case"u16":a=a||65535,e=Uint16Array;break;case"u32":a=a||2**32-1,e=Uint32Array;break;case"s8":a=a||-128,e=Int8Array;break;case"s16":a=a||-32768,e=Int16Array;break;case"s32":a=a||0-2**31,e=Int32Array;break;default:e=Float32Array}return{pixelTypeCtor:e,noDataValue:a}}function M(t,e=1){if(!t)return;const{pixels:a,width:i,height:s,mask:r}=t;if(!a||0===a.length)return;const n=i-1,o=s-1,h=[];let c=null;const l=m.getPixelArrayConstructor(t.pixelType);if(0===e){for(const t of a){const e=new l(n*o);for(let a=0;a<o;a++){const s=a*i;for(let i=0;i<n;i++)e[a*n+i]=t[s+i]}h.push(e)}if(null!=r){c=new Uint8Array(n*o);for(let t=0;t<o;t++){const e=t*i;for(let a=0;a<n;a++)c[t*n+a]=r[e+a]}}}else{for(const t of a){const e=new l(n*o);for(let a=0;a<o;a++){const s=a*i;for(let r=0;r<n;r++)e[a*n+r]=(t[s+r]+t[s+r+1]+t[s+i+r]+t[s+i+r+1])/4}h.push(e)}if(r){c=new Uint8Array(n*o);for(let t=0;t<o;t++){const e=t*i;for(let a=0;a<n;a++)c[t*n+a]=Math.min.apply(null,[r[e+a],r[e+a+1],r[e+i+a],r[e+i+a+1]])}}}t.width=n,t.height=o,t.mask=c,t.pixels=h}function L(t){let e=j(t);return"lerc2"===e?e="lerc":"error"===e&&(e=""),e}async function R(e,a={},i){if(null==e)throw new t("rasterCodec:decode","missing encodeddata parameter.");let s=a.format?.toLowerCase();if(!("bsq"!==s&&"bip"!==s||null!=a.width&&null!=a.height))throw new t("rasterCodec:decode","requires width and height in options parameter.");if("tiff"===s&&a.customOptions)return T(e,a);if((!s||"bsq"!==s&&"bip"!==s&&"deflate"!==s&&"lzw"!==s)&&(s=j(e)),a.useCanvas&&y.has(s))return S(e,s,a,i);const r=O(s);let n;a.isPoint&&(null!=(a={...a}).width&&a.width++,null!=a.height&&a.height++);const{offsets:h}=a;if(h&&h.length>1){const t=h.map((t,i)=>r(e.slice(t,h[i+1]),a)),i=await Promise.all(t);n=i[0],n.pixels=i.map(t=>t.pixels[0]);const s=i.map(t=>t.mask);i.some(t=>null!=t)&&(s.forEach((t,e)=>{null==t&&(s[e]=new Uint8Array(n.width*n.height).fill(255))}),n.bandMasks=s,n.mask=m.combineBandMasks(s)),n.updateStatistics()}else n=await r(e,{...a,offset:h?.[0]??a.offset});return"jpg"!==s&&null!=a.noDataValue&&1===n.depthCount&&o(n,a.noDataValue,{customFloatTolerance:a.tolerance}),a.isPoint&&M(n),n}export{R as decode,L as getFormat};
|
|
2
|
+
import t from"../../../core/Error.js";import{assertIsSome as e}from"../../../core/maybe.js";import a from"./ImageCanvasDecoder.js";import i from"./JpgPlus.js";import{load as s,decode as r}from"./Lerc.js";import{decode as n}from"./Lzw.js";import{convertNoDataToMask as o}from"./pixelRangeUtils.js";import{F as h}from"../../../chunks/Zlib.js";import{load as c,decode as l}from"./Qb3.js";import p from"./Raw.js";import{decodeTileOrStrip as d,decode as u}from"./TiffDecoder.js";import{isPlatformLittleEndian as f}from"./utils.js";import m from"../../support/PixelBlock.js";import w from"../../support/SimpleBandStatistics.js";var g=function(t){var e,a,i,s,r,n;function o(t){var e,a,i,s,r,n,o,h,c,l,p,d,u;for(this.data=t,this.pos=8,this.palette=[],this.imgData=[],this.transparency={},this.animation=null,this.text={},r=null;;){switch(e=this.readUInt32(),h=function(){var t,e;for(e=[],t=0;t<4;++t)e.push(String.fromCharCode(this.data[this.pos++]));return e}.call(this).join(""),h){case"IHDR":this.width=this.readUInt32(),this.height=this.readUInt32(),this.bits=this.data[this.pos++],this.colorType=this.data[this.pos++],this.compressionMethod=this.data[this.pos++],this.filterMethod=this.data[this.pos++],this.interlaceMethod=this.data[this.pos++];break;case"acTL":this.animation={numFrames:this.readUInt32(),numPlays:this.readUInt32()||1/0,frames:[]};break;case"PLTE":this.palette=this.read(e);break;case"fcTL":r&&this.animation.frames.push(r),this.pos+=4,r={width:this.readUInt32(),height:this.readUInt32(),xOffset:this.readUInt32(),yOffset:this.readUInt32()},s=this.readUInt16(),i=this.readUInt16()||100,r.delay=1e3*s/i,r.disposeOp=this.data[this.pos++],r.blendOp=this.data[this.pos++],r.data=[];break;case"IDAT":case"fdAT":for("fdAT"===h&&(this.pos+=4,e-=4),t=(null!=r?r.data:void 0)||this.imgData,p=0;0<=e?p<e:p>e;0<=e?++p:--p)t.push(this.data[this.pos++]);break;case"tRNS":switch(this.transparency={},this.colorType){case 3:if(this.transparency.indexed=this.read(e),(c=255-this.transparency.indexed.length)>0)for(d=0;0<=c?d<c:d>c;0<=c?++d:--d)this.transparency.indexed.push(255);break;case 0:this.transparency.grayscale=this.read(e)[0];break;case 2:this.transparency.rgb=this.read(e)}break;case"tEXt":n=(l=this.read(e)).indexOf(0),o=String.fromCharCode.apply(String,l.slice(0,n)),this.text[o]=String.fromCharCode.apply(String,l.slice(n+1));break;case"IEND":return r&&this.animation.frames.push(r),this.colors=function(){switch(this.colorType){case 0:case 3:case 4:return 1;case 2:case 6:return 3}}.call(this),this.hasAlphaChannel=4===(u=this.colorType)||6===u,a=this.colors+(this.hasAlphaChannel?1:0),this.pixelBitlength=this.bits*a,this.colorSpace=function(){switch(this.colors){case 1:return"DeviceGray";case 3:return"DeviceRGB"}}.call(this),void(this.imgData=new Uint8Array(this.imgData));default:this.pos+=e}if(this.pos+=4,this.pos>this.data.length)throw new Error("Incomplete or corrupt PNG file")}}return o.load=function(t,e,a){var i;return"function"==typeof e&&(a=e),(i=new XMLHttpRequest).open("GET",t,!0),i.responseType="arraybuffer",i.onload=function(){var t;return t=new o(new Uint8Array(i.response||i.mozResponseArrayBuffer)),"function"==typeof(null!=e?e.getContext:void 0)&&t.render(e),"function"==typeof a?a(t):void 0},i.send(null)},a=1,i=2,e=0,o.prototype.read=function(t){var e,a;for(a=[],e=0;0<=t?e<t:e>t;0<=t?++e:--e)a.push(this.data[this.pos++]);return a},o.prototype.readUInt32=function(){return this.data[this.pos++]<<24|this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++]},o.prototype.readUInt16=function(){return this.data[this.pos++]<<8|this.data[this.pos++]},o.prototype.decodePixels=function(t){var e,a,i,s,r,n,o,c,l,p,d,u,f,m,w,g,y,x,b,k,T,C,I;if(null==t&&(t=this.imgData),0===t.length)return new Uint8Array(0);for(t=(t=new h(t)).getBytes(),g=(u=this.pixelBitlength/8)*this.width,f=new Uint8Array(g*this.height),n=t.length,w=0,m=0,a=0;m<n;){switch(t[m++]){case 0:for(s=b=0;b<g;s=b+=1)f[a++]=t[m++];break;case 1:for(s=k=0;k<g;s=k+=1)e=t[m++],r=s<u?0:f[a-u],f[a++]=(e+r)%256;break;case 2:for(s=T=0;T<g;s=T+=1)e=t[m++],i=(s-s%u)/u,y=w&&f[(w-1)*g+i*u+s%u],f[a++]=(y+e)%256;break;case 3:for(s=C=0;C<g;s=C+=1)e=t[m++],i=(s-s%u)/u,r=s<u?0:f[a-u],y=w&&f[(w-1)*g+i*u+s%u],f[a++]=(e+Math.floor((r+y)/2))%256;break;case 4:for(s=I=0;I<g;s=I+=1)e=t[m++],i=(s-s%u)/u,r=s<u?0:f[a-u],0===w?y=x=0:(y=f[(w-1)*g+i*u+s%u],x=i&&f[(w-1)*g+(i-1)*u+s%u]),o=r+y-x,c=Math.abs(o-r),p=Math.abs(o-y),d=Math.abs(o-x),l=c<=p&&c<=d?r:p<=d?y:x,f[a++]=(e+l)%256;break;default:throw new Error("Invalid filter algorithm: "+t[m-1])}w++}return f},o.prototype.decodePalette=function(){var t,e,a,i,s,r,n,o,h;for(a=this.palette,r=this.transparency.indexed||[],s=new Uint8Array((r.length||0)+a.length),i=0,a.length,t=0,e=n=0,o=a.length;n<o;e=n+=3)s[i++]=a[e],s[i++]=a[e+1],s[i++]=a[e+2],s[i++]=null!=(h=r[t++])?h:255;return s},o.prototype.copyToImageData=function(t,e){var a,i,s,r,n,o,h,c,l,p,d;if(i=this.colors,l=null,a=this.hasAlphaChannel,this.palette.length&&(l=null!=(d=this._decodedPalette)?d:this._decodedPalette=this.decodePalette(),i=4,a=!0),c=(s=t.data||t).length,n=l||e,r=o=0,1===i)for(;r<c;)h=l?4*e[r/4]:o,p=n[h++],s[r++]=p,s[r++]=p,s[r++]=p,s[r++]=a?n[h++]:this.transparency.grayscale&&this.transparency.grayscale===p?0:255,o=h;else for(;r<c;)h=l?4*e[r/4]:o,s[r++]=n[h++],s[r++]=n[h++],s[r++]=n[h++],s[r++]=a?n[h++]:this.transparency.rgb&&this.transparency.rgb[1]===n[h-3]&&this.transparency.rgb[3]===n[h-2]&&this.transparency.rgb[5]===n[h-1]?0:255,o=h},o.prototype.decode=function(){var t;return t=new Uint8Array(this.width*this.height*4),this.copyToImageData(t,this.decodePixels()),t},r=t.document&&t.document.createElement("canvas"),n=r&&r.getContext("2d"),s=function(t){var e;return n.width=t.width,n.height=t.height,n.clearRect(0,0,t.width,t.height),n.putImageData(t,0,0),(e=new Image).src=r.toDataURL(),e},o.prototype.decodeFrames=function(t){var e,a,i,r,n,o,h,c;if(this.animation){for(c=[],a=n=0,o=(h=this.animation.frames).length;n<o;a=++n)e=h[a],i=t.createImageData(e.width,e.height),r=this.decodePixels(new Uint8Array(e.data)),this.copyToImageData(i,r),e.imageData=i,c.push(e.image=s(i));return c}},o.prototype.renderFrame=function(t,s){var r,n,o;return r=(n=this.animation.frames)[s],o=n[s-1],0===s&&t.clearRect(0,0,this.width,this.height),(null!=o?o.disposeOp:void 0)===a?t.clearRect(o.xOffset,o.yOffset,o.width,o.height):(null!=o?o.disposeOp:void 0)===i&&t.putImageData(o.imageData,o.xOffset,o.yOffset),r.blendOp===e&&t.clearRect(r.xOffset,r.yOffset,r.width,r.height),t.drawImage(r.image,r.xOffset,r.yOffset)},o.prototype.animate=function(t){var e,a,i,s,r,n,o=this;return a=0,n=this.animation,s=n.numFrames,i=n.frames,r=n.numPlays,(e=function(){var n,h;if(n=a++%s,h=i[n],o.renderFrame(t,n),s>1&&a/s<r)return o.animation._timeout=setTimeout(e,h.delay)})()},o.prototype.stopAnimation=function(){var t;return clearTimeout(null!=(t=this.animation)?t._timeout:void 0)},o.prototype.render=function(t){var e,a;return t._png&&t._png.stopAnimation(),t._png=this,t.width=this.width,t.height=this.height,e=t.getContext("2d"),this.animation?(this.decodeFrames(e),this.animate(e)):(a=e.createImageData(this.width,this.height),this.copyToImageData(a,this.decodePixels()),e.putImageData(a,0,0))},o}(self);const y=new Set(["jpg","png","bmp","gif"]);async function x(e,a){if(!f)throw new t("rasterCoded:decode","lerc decoder is not supported on big endian platform");await s();const{offset:i}=a,{width:n,height:o,pixelType:h,statistics:c,depthCount:l,noDataValues:p,bandMasks:d,pixels:u,mask:g}=r(e,{inputOffset:i,returnInterleaved:a.returnInterleaved}),y=new m({width:n,height:o,pixelType:h.toLowerCase(),pixels:u,mask:g,statistics:c.map(({minValue:t,maxValue:e})=>new w(t,e)),bandMasks:d,depthCount:l,noDataValues:p});return c?.length||y.updateStatistics(),y}async function b(e,a){await c();const i=l(e);if(!i)throw new t("rasterCodec:decode","failed to decode the input data.");const{width:s,height:r,pixels:n,pixelType:o}=i,h=new m({width:s,height:r,pixelType:o,pixels:n});return h.updateStatistics(),h}async function k(t,a){const i=await u(t,{...a,noDataValue:a.tiffNoDataValue,matchAllNoData:a.matchAllNoData});e(i);const s=new m({width:i.width,height:i.height,pixels:i.pixels,pixelType:i.pixelType.toLowerCase(),mask:i.mask,bandMasks:i.bandMasks,statistics:null});return s.updateStatistics(),s}async function T(t,e){const a=await d(t,e.customOptions),i=new m({width:a.width,height:a.height,pixels:a.pixels,pixelType:a.pixelType.toLowerCase(),mask:a.mask,statistics:null});return i.updateStatistics(),i}function C(t,e){const a=e.pixelType||"u8",i=m.getPixelArrayConstructor(a),s="u8"===a?t:new i(t.buffer),r=[],n=e.planes||1;if(1===n)r.push(s);else for(let h=0;h<n;h++){const a=(e.width||1)*(e.height||t.length),o=new i(a);for(let t=0;t<a;t++)o[t]=s[t*n+h];r.push(o)}const o=new m({width:e.width||1,height:e.height||t.length,pixels:r,pixelType:a,statistics:null});return o.updateStatistics(),o}function I(t,e){return C(new h(new Uint8Array(t)).getBytes(),e)}function A(t,e){return C(n(t,e.offset,e.eof,!e.isInputBigEndian),e)}function v(t,e,a){const{pixelTypeCtor:i}=P(e.pixelType),s=(0,p.decode)(t,{width:e.width,height:e.height,pixelType:i,format:a}),r=new m({width:e.width,height:e.height,pixels:s.pixels,pixelType:e.pixelType,mask:s.mask,statistics:null});return r.updateStatistics(),r}function D(t,e){const a=i.decode(t,e.hasNoZlibMask??void 0),s=new m({width:a.width,height:a.height,pixels:a.pixels,pixelType:"u8",mask:a.mask,statistics:null});return s.updateStatistics(),s}function U(t,e){const a=new Uint8Array(t),i=new g(a),{width:s,height:r}=e,n=s*r,o=i.decode();let h,c=0,l=0;const p=new Uint8Array(n);for(c=0;c<n;c++)p[c]=o[4*c+3];const d=new m({width:s,height:r,pixels:[],pixelType:"u8",mask:p,statistics:[]});for(c=0;c<3;c++){for(h=new Uint8Array(n),l=0;l<n;l++)h[l]=o[4*l+c];d.addData({pixels:h})}return d.updateStatistics(),d}async function S(t,e,i,s){const r=new a,n={applyJpegMask:!1,format:e,...i},o=await r.decode(t,n,s),h=new m(o);return h.updateStatistics(),h}function j(e){if(null==e)throw new t("rasterCodec:decode","parameter encodeddata is required.");const a=new Uint8Array(e,0,10);let i="";return 255===a[0]&&216===a[1]?i="jpg":137===a[0]&&80===a[1]&&78===a[2]&&71===a[3]?i="png":67===a[0]&&110===a[1]&&116===a[2]&&90===a[3]&&73===a[4]&&109===a[5]&&97===a[6]&&103===a[7]&&101===a[8]&&32===a[9]?i="lerc":76===a[0]&&101===a[1]&&114===a[2]&&99===a[3]&&50===a[4]&&32===a[5]?i="lerc2":73===a[0]&&73===a[1]&&42===a[2]&&0===a[3]||77===a[0]&&77===a[1]&&0===a[2]&&42===a[3]||73===a[0]&&73===a[1]&&43===a[2]&&0===a[3]||77===a[0]&&77===a[1]&&0===a[2]&&43===a[3]?i="tiff":71===a[0]&&73===a[1]&&70===a[2]?i="gif":66===a[0]&&77===a[1]?i="bmp":81===a[0]&&66===a[1]&&51===a[2]?i="qb3":String.fromCharCode.apply(null,a).toLowerCase().includes("error")&&(i="error"),i}function O(e){let a=null;switch(e){case"lerc":case"lerc2":a=x;break;case"jpg":a=D;break;case"png":a=U;break;case"bsq":case"bip":a=(t,a)=>v(t,a,e);break;case"tiff":a=k;break;case"deflate":a=I;break;case"lzw":a=A;break;case"qb3":a=b;break;case"error":a=()=>{throw new t("rasterCodec:decode","input data contains error")};break;default:a=()=>{throw new t("rasterCodec:decode","unsupported raster format")}}return a}function P(t){let e=null,a=null;switch(t?t.toLowerCase():"f32"){case"u1":case"u2":case"u4":case"u8":a=255,e=Uint8Array;break;case"u16":a=a||65535,e=Uint16Array;break;case"u32":a=a||2**32-1,e=Uint32Array;break;case"s8":a=a||-128,e=Int8Array;break;case"s16":a=a||-32768,e=Int16Array;break;case"s32":a=a||0-2**31,e=Int32Array;break;default:e=Float32Array}return{pixelTypeCtor:e,noDataValue:a}}function M(t,e=1){if(!t)return;const{pixels:a,width:i,height:s,mask:r}=t;if(!a||0===a.length)return;const n=i-1,o=s-1,h=[];let c=null;const l=m.getPixelArrayConstructor(t.pixelType);if(0===e){for(const t of a){const e=new l(n*o);for(let a=0;a<o;a++){const s=a*i;for(let i=0;i<n;i++)e[a*n+i]=t[s+i]}h.push(e)}if(null!=r){c=new Uint8Array(n*o);for(let t=0;t<o;t++){const e=t*i;for(let a=0;a<n;a++)c[t*n+a]=r[e+a]}}}else{for(const t of a){const e=new l(n*o);for(let a=0;a<o;a++){const s=a*i;for(let r=0;r<n;r++)e[a*n+r]=(t[s+r]+t[s+r+1]+t[s+i+r]+t[s+i+r+1])/4}h.push(e)}if(r){c=new Uint8Array(n*o);for(let t=0;t<o;t++){const e=t*i;for(let a=0;a<n;a++)c[t*n+a]=Math.min.apply(null,[r[e+a],r[e+a+1],r[e+i+a],r[e+i+a+1]])}}}t.width=n,t.height=o,t.mask=c,t.pixels=h}function L(t){let e=j(t);return"lerc2"===e?e="lerc":"error"===e&&(e=""),e}async function R(e,a={},i){if(null==e)throw new t("rasterCodec:decode","missing encodeddata parameter.");let s=a.format?.toLowerCase();if(!("bsq"!==s&&"bip"!==s||null!=a.width&&null!=a.height))throw new t("rasterCodec:decode","requires width and height in options parameter.");if("tiff"===s&&a.customOptions)return T(e,a);if((!s||"bsq"!==s&&"bip"!==s&&"deflate"!==s&&"lzw"!==s)&&(s=j(e)),a.useCanvas&&y.has(s))return S(e,s,a,i);const r=O(s);let n;a.isPoint&&(null!=(a={...a}).width&&a.width++,null!=a.height&&a.height++);const{offsets:h}=a;if(h&&h.length>1){const t=h.map((t,i)=>r(e.slice(t,h[i+1]),a)),i=await Promise.all(t);n=i[0],n.pixels=i.map(t=>t.pixels[0]);const s=i.map(t=>t.mask);i.some(t=>null!=t)&&(s.forEach((t,e)=>{null==t&&(s[e]=new Uint8Array(n.width*n.height).fill(255))}),n.bandMasks=s,n.mask=m.combineBandMasks(s)),n.updateStatistics()}else n=await r(e,{...a,offset:h?.[0]??a.offset});return"jpg"!==s&&null!=a.noDataValue&&1===n.depthCount&&o(n,a.noDataValue,{customFloatTolerance:a.tolerance}),a.isPoint&&M(n),n}export{R as decode,L as getFormat};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
-
import"../../../core/has.js";import{bytesToUTF8 as e}from"../datasets/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{tiffTags as s,ifdTags as l,getTagName as o,geoKeys as f}from"./tiffTag.js";import{isPlatformLittleEndian as u}from"./utils.js";import{Z as c}from"../../../chunks/Zlib.js";const h=[0,1,1,2,4,8,1,1,2,4,8,4,8,-1,-1,-1,8,8,8],g=4294967296,E=new Set([1,5,6,7,8,34712,34887]);function I(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 T(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 w(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 p(e,t){return e.get(t)?.values}function d(e,t){return e.get(t)?.values}function m(e,t){return e.get(t)?.values?.[0]}function y(e,t){return e.get(t)?.values?.[0]}function A(e,t,n,a=0,i=s,r=4){const l=8===r,f=l?B(new DataView(e,n,8),0,t):new DataView(e,n,2).getUint16(0,t),u=4+2*r,c=l?8:2,h=c+f*u;if(n+h>e.byteLength)return{success:!1,ifd:null,nextIFD:null,requiredBufferSize:h};const g=8===r?8:4,E=n+h+g<=e.byteLength?W(new DataView(e,n+h,g),0,t,8===r):null,I=n+c,T=new Map;let w,p,d,m,y,A=0,S=0;for(let s=0;s<f;s++){p=new DataView(e,I+u*s,u),d=p.getUint16(0,t),y=p.getUint16(2,t),m=o(d,i);const n=[];2===r?(A=p.getUint16(4,t),S=p.getUint16(6,t)):4===r?(A=p.getUint32(4,t),S=p.getUint32(8,t)):8===r&&(A=W(p,4,t,!0),S=W(p,12,t,!0),n.push(p.getUint32(12,t)),n.push(p.getUint32(16,t))),w={id:d,type:y,valueCount:A,valueOffset:S,valueOffsets:n,values:null},N(e,t,w,a,!1,r),T.set(m,w)}return{success:!0,ifd:T,nextIFD:E,requiredBufferSize:h}}const S=(e,t)=>a(e,{inputOffset:t}).pixels[0];function M(e,t){if(t%8==0)return e;const n=t>16?32:t>8?16:8;n>8&&(e=b(e,32===n?4:2));const a=32===n?Uint32Array:16===n?Uint16Array:Uint8Array,i=new a(e),r=Math.floor(8*e.byteLength/t+1e-6),s=new a(r),l=(1<<t)-1;let o=0,f=0,u=0;for(let c=0;c<r;c++)if(0===f&&(u=i[o++],f=n),f>=t)s[c]=u>>>f-t&l,f-=t;else{const e=t-f;let a=(u&l)<<e&l;u=i[o++],f=n-e,a+=u>>>f,s[c]=a}return s.buffer}function P(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 O(e){const t=new c(e).getBytes(),n=new ArrayBuffer(t.length),a=new Uint8Array(n);return a.set(t),a}function b(e,t){const n=new Uint8Array(e),a=new Uint8Array(n.length);if(2===t)for(let i=0;i<n.length;i+=2)a[i]=n[i+1],a[i+1]=n[i];else if(4===t)for(let i=0;i<n.length;i+=4)a[i]=n[i+3],a[i+1]=n[i+2],a[i+2]=n[i+1],a[i+3]=n[i];else for(let i=0;i<n.length;i+=8)a[i]=n[i+7],a[i+1]=n[i+6],a[i+2]=n[i+5],a[i+3]=n[i+4],a[i+4]=n[i+3],a[i+5]=n[i+2],a[i+6]=n[i+1],a[i+7]=n[i];return a.buffer}async function x(e,t,a,r,s){const l=u===t,o=y(a,"BITSPERSAMPLE"),f=y(a,"SAMPLESPERPIXEL")??1,c=y(a,"PHOTOMETRICINTERPRETATION"),h=y(a,"SAMPLEFORMAT")??1,g=I(h,o),E=y(a,"COMPRESSION")??1,w=T(g);let p,d,m;if(34887===E)return await n(),S(e,r);if(1===E)p=e.slice(r,r+s),d=new Uint8Array(p);else if(8===E||32946===E)d=new Uint8Array(e,r,s),d=O(d),p=d.buffer;else if(6===E)d=new Uint8Array(e,r,s),d=P(d,f,c),p=d.buffer;else if(7===E){const t=a.get("JPEGTABLES").values,n=t.length-2;d=new Uint8Array(n+s-2);for(let e=0;e<n;e++)d[e]=t[e];const i=new Uint8Array(e,r+2,s-2);for(let e=0;e<i.length;e++)d[n+e]=i[e];d=P(d,f,c),p=d.buffer}else{if(5!==E)throw new Error("tiff-decode: unsupport compression "+E);d=i(e,r,s,t),p=d.buffer}if(p=M(p,o),l||o<=8)m=new w(p);else{const e=o>32?8:o>16?4:2;m=new w(b(d.buffer,e))}const A=y(a,"PREDICTOR")??1,x=y(a,"TILEWIDTH"),L=y(a,"TILELENGTH");if(A>1&&(5===E||8===E||32946===E)&&x&&L){const e=C(a),t=new w(m.length);t.set(m),m=j(t,L,x,3===h&&3===A,e?1:f)}return m}async function L(e,t,n){const a=d(n,"TILEOFFSETS");if(void 0===a)return null;const i=d(n,"TILEBYTECOUNTS"),{width:r,height:s,pixelType:l,tileWidth:o,tileHeight:f}=k([n]),u=C(n,t),c=y(n,"SAMPLESPERPIXEL")||t.planes,h=r*s,g=y(n,"BITSPERSAMPLE"),E=34887===(y(n,"COMPRESSION")??1),I=T(l),w=[];for(let T=0;T<c;T++)w.push(new I(h));const p=Math.ceil(r/o),m=new Uint8Array(h).fill(255);let A=null,S=!1;if(g%8==0)if(E&&u&&c>1){const l=Math.round(a.length/c);for(let u=0;u<l;u++){const l=Math.floor(u/p)*f,h=u%p*o,g=l*r+h;for(let E=0;E<c;E++){const I=u*c+E;0===i[I]?(A=null,S=!0):A=await x(e,t.littleEndian,n,a[I],i[I]);const T=Math.min(o,r-h),p=Math.min(f,s-l),d=w[E];for(let e=0;e<p;e++){let t=g+e*r,n=e*o;for(let e=0;e<T;e++,t++,n++)A?d[t]=A[n]:m[t]=0}}}}else for(let T=0;T<a.length;T++){const l=Math.floor(T/p)*f,h=T%p*o,g=l*r+h;0===i[T]?(A=null,S=!0):A=await x(e,t.littleEndian,n,a[T],i[T]);const I=Math.min(o,r-h),d=Math.min(f,s-l);for(let e=0;e<c;e++){const t=w[e];if(u||E)for(let n=0;n<d;n++){let a=g+n*r,i=o*f*e+n*o;for(let e=0;e<I;e++,a++,i++)A?t[a]=A[i]:m[a]=0}else for(let n=0;n<d;n++){let a=g+n*r,i=n*o*c+e;for(let e=0;e<I;e++,a++,i+=c)A?t[a]=A[i]:m[a]=0}}}return{width:r,height:s,pixelType:l,pixels:w,mask:S?m:void 0}}const R=(e,t,n)=>{const a=u===t.littleEndian,r=d(n,"STRIPOFFSETS");if(void 0===r)return null;const{width:s,height:l,pixelType:o}=k([n]),f=y(n,"SAMPLESPERPIXEL")||t.planes,c=y(n,"PHOTOMETRICINTERPRETATION"),h=s*l,g=y(n,"BITSPERSAMPLE"),E=T(o),I=new E(h*f),w=d(n,"STRIPBYTECOUNTS"),p=y(n,"ROWSPERSTRIP"),m=y(n,"COMPRESSION")??1;let A,S,b,x;if(g%8==0)for(let u=0;u<r.length;u++){const n=u*(p*s)*f;if("u8"===o||"s8"===o||a)8===m||32946===m?(b=new Uint8Array(e,r[u],w[u]),b=O(b),S=b.buffer):6===m?(b=new Uint8Array(e,r[u],w[u]),b=P(b,f,c),S=b.buffer):5===m?(b=i(e,r[u],w[u],t.littleEndian),S=b.buffer):S=e.slice(r[u],r[u]+w[u]),S=M(S,g),A=new E(S);else{switch(6===m||8===m||32946===m?(b=new Uint8Array(e,r[u],w[u]),x=O(b),S=x.buffer):(S=new ArrayBuffer(w[u]),b=new Uint8Array(e,r[u],w[u]),x=new Uint8Array(S)),o){case"u16":case"s16":for(let e=0;e<b.length;e+=2)x[e]=b[e+1],x[e+1]=b[e];break;case"u32":case"s32":case"f32":for(let e=0;e<b.length;e+=4)x[e]=b[e+3],x[e+1]=b[e+2],x[e+2]=b[e+1],x[e+3]=b[e]}S=M(S,g),A=new E(S)}I.set(A,n)}const L=[];if(1===f)L.push(I);else for(let i=0;i<f;i++){const e=new E(h);for(let t=0;t<h;t++)e[t]=I[t*f+i];L.push(e)}return{width:s,height:l,pixelType:o,pixels:L}},D=(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},U=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"),I=n.get("WavelengthMax");let T=null;if(g){T=[];for(let e=0;e<g.length;e++)T.push({BandName:g[e],WavelengthMin:E&&parseFloat(E[e]),WavelengthMax:I&&parseFloat(I[e])})}return{statistics:h,bandProperties:T,dataType:n.get("DataType"),rawMetadata:n}};function N(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,f=[];const u=h[s],c=8*u,E=l*u,I=l*h[s]*8;let T,w;const p=8===r?64:32,d=n.valueOffsets;if(I>p){if(E>(i?e.byteLength:e?e.byteLength-o+a:0))return n.offlineOffsetSize=[o,E],n.values=null,!1}if(I<=p){if(!t)if(p<=32)o>>>=32-I;else{const e=d?.length?d[0]:o>>>0,t=d?.length?d[1]:Math.round((o-e)/g);I<=32?(o=e>>>32-I,d[0]=o):(o=e*2**(32-I)+(t>>>32-I),d[0]=e,d[1]=t>>>32-I)}if(1===l&&c===p)f=[o];else if(64===p){const e=d?.length?d[0]:o>>>0,t=d?.length?d[1]:Math.round((o-e)/g);let n=e,a=32;for(w=1;w<=l;w++){const e=32-c*w%32;if(a<c){const i=n<<e>>>32-a,r=t<<32-a>>>32-a;n=t,f.push(i+r*2**(c-a)),a-=32-(c-a)}else f.push(n<<e>>>32-c),a-=c;0===a&&(a=32,n=t)}}else for(w=1;w<=l;w++){const e=32-c*w;f.push(o<<e>>>32-c)}}else{o-=a,i&&(o=0);for(let n=o;n<o+E;n+=u){switch(s){case 1:case 2:case 7:T=new DataView(e,n,1).getUint8(0);break;case 3:T=new DataView(e,n,2).getUint16(0,t);break;case 4:case 13:T=new DataView(e,n,4).getUint32(0,t);break;case 5:T=new DataView(e,n,4).getUint32(0,t)/new DataView(e,n+4,4).getUint32(0,t);break;case 6:T=new DataView(e,n,1).getInt8(0);break;case 8:T=new DataView(e,n,2).getInt16(0,t);break;case 9:T=new DataView(e,n,4).getInt32(0,t);break;case 10:T=new DataView(e,n,4).getInt32(0,t)/new DataView(e,n+4,4).getInt32(0,t);break;case 11:T=new DataView(e,n,4).getFloat32(0,t);break;case 12:T=new DataView(e,n,8).getFloat64(0,t);break;case 16:case 18:T=B(new DataView(e,n,8),0,t);break;case 17:T=V(new DataView(e,n,8),0,t);break;default:T=null}f.push(T)}}if(2===s){let e="";const t=f;for(f=[],w=0;w<t.length;w++)0===t[w]&&""!==e?(f.push(e),e=""):e+=String.fromCharCode(t[w]);""===e&&0!==f.length||f.push(e)}return n.values=f,!0}function k(e){const t=e[0],n=y(t,"TILEWIDTH"),a=y(t,"TILELENGTH"),i=y(t,"IMAGEWIDTH"),r=y(t,"IMAGELENGTH"),s=y(t,"BITSPERSAMPLE"),l=y(t,"SAMPLESPERPIXEL"),o=y(t,"SAMPLEFORMAT")??1,f=I(o,s),u=C(t),c=p(t,"GDAL_NODATA");let h=null;c?.length&&(h=c.map(e=>parseFloat(e)),h.some(e=>isNaN(e))&&(h=null));const g=y(t,"COMPRESSION")??1;let T;switch(g){case 1:T="NONE";break;case 2:case 3:case 4:case 32771:T="CCITT";break;case 5:T="LZW";break;case 6:case 7:T="JPEG";break;case 32773:T="PACKBITS";break;case 8:case 32946:T="DEFLATE";break;case 34712:T="JPEG2000";break;case 34887:T="LERC";break;default:T=String(g)}let A=!0,S="";E.has(g)||(A=!1,S+="unsupported tag compression "+g),o>3&&(A=!1,S+="unsupported tag sampleFormat "+o),s>32&&64!==s&&(A=!1,S+="unsupported tag bitsPerSample "+s);const M=m(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=d(t,"GEOTIEPOINTS"),b=d(t,"GEOPIXELSCALE"),x=d(t,"GEOTRANSMATRIX"),L=t.has("GEOKEYDIRECTORY")?t.get("GEOKEYDIRECTORY").data:null;let R,D,N=!1,k=!1;if(L){N=2===y(L,"GTRasterTypeGeoKey");const e=y(L,"GTModelTypeGeoKey");if(2===e){const e=y(L,"GeographicTypeGeoKey");e>=1024&&e<=32766&&(P={wkid:e}),P||32767!==e||(k=!0,P={wkid:4326})}else if(1===e){const e=y(L,"ProjectedCSTypeGeoKey");e>=1024&&e<=32766&&(P={wkid:e})}}if(b&&O&&O.length>=6?(R=[b[0],0,O[3]-O[0]*b[0],0,-Math.abs(b[1]),O[4]-O[1]*b[1]],N&&(R[2]-=.5*R[0]+.5*R[1],R[5]-=.5*R[3]+.5*R[4])):x&&16===x.length&&(R=N?[x[0],x[1],x[3]-.5*x[0],x[4],x[5],x[7]-.5*x[5]]:[x[0],x[1],x[3],x[4],x[5],x[7]]),R){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=w(e[i],R),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;D={xmin:n,xmax:s,ymin:a,ymax:l,spatialReference:P}}else D={xmin:-.5,ymin:.5-r,xmax:i-.5,ymax:.5,spatialReference:P};k&&(D.xmax-D.xmin>400||Math.max(Math.abs(D.xmin),Math.abs(D.xmax))>361)&&(P=null,D.spatialReference=null);const F=G(e);let B,V,W,H,Y;if(F.length>0){W=Math.round(Math.log(i/y(F[0],"IMAGEWIDTH"))/Math.LN2);const e=F[F.length-1];H=F.length,B=y(e,"TILEWIDTH"),V=y(e,"TILELENGTH")}B=null!=H&&H>0?B||n:null,V=null!=H&&H>0?V||a:null,n&&(Y=[{maxCol:Math.ceil(i/n)-1,maxRow:Math.ceil(r/a)-1,minRow:0,minCol:0}],F.forEach(e=>{Y.push({maxCol:Math.ceil(y(e,"IMAGEWIDTH")/y(e,"TILEWIDTH"))-1,maxRow:Math.ceil(y(e,"IMAGELENGTH")/y(e,"TILELENGTH"))-1,minRow:0,minCol:0})}));const j=m(e[0],"GDAL_METADATA"),X=U(j);S+=" "+_({width:i,height:r,tileWidth:n,tileHeight:a,planes:l,ifds:e});const K=v(e).length===F.length+1,J=F?.length?F.map(e=>({x:i/y(e,"IMAGEWIDTH"),y:r/y(e,"IMAGELENGTH")})):void 0;return{width:i,height:r,tileWidth:n,tileHeight:a,planes:l,isBSQ:u,pixelType:f,compression:T,noData:h,hasMaskBand:K,isSupported:A,pyramidResolutions:J,message:S,extent:D,isPseudoGeographic:k,affine:b?null:R,firstPyramidLevel:W,maximumPyramidLevel:H,pyramidBlockWidth:B,pyramidBlockHeight:V,tileBoundary:Y,metadata:X}}function C(e,t){const n=p(e,"PLANARCONFIGURATION");return n?2===n[0]:!!t&&t.isBSQ}function G(e){return e.filter(e=>1===y(e,"NEWSUBFILETYPE"))}function v(e){return e.filter(e=>{const t=!(4&~(y(e,"NEWSUBFILETYPE")??0)),n=4===y(e,"PHOTOMETRICINTERPRETATION");return t&&n})}function F(e){const{littleEndian:t,isBigTiff:n,firstIFDPos:a}=H(e);let i=a;const r=[];do{const a=Y(e,t,i,0,s,n?8:4);if(!a.success)break;r.push(a.ifd),i=a.nextIFD}while(i>0);return{...k(r),littleEndian:t,isBigTiff:n,ifds:r,pyramidIFDs:G(r),maskIFDs:v(r)}}function B(e,t,n){const a=e.getUint32(t,n),i=e.getUint32(t+4,n);return n?i*g+a:a*g+i}function V(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*g+a:a*g+i)}function W(e,t,n,a){return a?B(e,t,n):e.getUint32(t,n)}function H(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:W(t,r,a,s)}}function Y(t,n,a,i=0,r=s,o=4){const u=A(t,n,a,i,r,o);let c;const h=u.ifd;if(h){if(l.forEach((e,a)=>{h.has(a)&&(c=h.get(a),c.data=A(t,n,c.valueOffset-i,i,e).ifd)}),h.has("GEOKEYDIRECTORY")){c=h.get("GEOKEYDIRECTORY");const e=c.values;if(e&&e.length>4){const a=e[0]+"."+e[1]+"."+e[2];c.data=A(t,n,c.valueOffset+6-i,i,f,2).ifd,c.data&&c.data.set("GEOTIFFVersion",{id:0,type:2,valueCount:1,valueOffset:null,values:[a]})}}if(h.has("XMP")){c=h.get("XMP");const t=c.values;"number"==typeof t[0]&&7===c.type&&(c.values=[e(new Uint8Array(t))])}}return u}function _(e){const{width:t,height:n,tileHeight:a,tileWidth:i}=e,r=e.planes,s=i?i*a:t*n,l=y(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 j(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 X(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 x(e,n.littleEndian,a,i[r],s[r]||e.byteLength);l.push(t)}const o=C(a,n),f=y(a,"BITSPERSAMPLE"),u=I(y(a,"SAMPLEFORMAT")??1,f),c=y(a,"SAMPLESPERPIXEL")||n.planes,h=T(u),g=y(a,"TILEWIDTH"),E=y(a,"TILELENGTH"),w=y(a,"COMPRESSION")??1,p=g*E;let d;const m=[];let A=l[0];const S=34887===w;for(let r=0;r<c;r++){if(d=new h(p),l.length===c)A=l[r],A.length===p&&(d=A);else if(A.length)if(o||S)d=A.length===p?A:A.slice(p*r,p*(r+1));else for(let e=0;e<p;e++)d[e]=A[e*c+r];m.push(d)}const M=n.noData?n.noData[0]:t.noDataValue,P=n.metadata?n.metadata.statistics:null,O=P?P.map(e=>e.min):null,b=P?P.map(e=>e.max):null,L={pixelType:u,width:g,height:E,pixels:m,noDataValue:M};return null!=M?r(L,M,{matchAllNoData:t?.matchAllNoData}):O&&b&&t.applyMinMaxConstraint&&(L.mask=D(m,O,b)),L}async function K(e,t={}){const n=t.pyramidLevel||0,a=t.headerInfo||F(e),{ifds:i,noData:s}=a;if(0===i.length)throw new Error("no valid image file directory");const l=_(a);if(l)throw l;let o=null;const f=-1===n?i[i.length-1]:i[n],u=s??t.noDataValue;if(o=a.tileWidth?await L(e,a,f):R(e,a,f),!o)return o;if(null!=u){r(o,u,{matchAllNoData:null==s&&t?.matchAllNoData})}return o}export{K as decode,X as decodeTileOrStrip,k as getImageInfo,v as getMaskIFDs,G as getPyramidIFDs,C as isBSQConfig,N as parseFieldValues,F as parseHeader,Y as parseIFD,H as parseSignature,M as unpackBits};
|
|
2
|
+
import"../../../core/has.js";import{bytesToUTF8 as e}from"../datasets/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{tiffTags as s,ifdTags as l,getTagName as o,geoKeys as f}from"./tiffTag.js";import{isPlatformLittleEndian as u}from"./utils.js";import{F as c}from"../../../chunks/Zlib.js";const h=[0,1,1,2,4,8,1,1,2,4,8,4,8,-1,-1,-1,8,8,8],g=4294967296,E=new Set([1,5,6,7,8,34712,34887]);function I(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 T(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 w(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 p(e,t){return e.get(t)?.values}function d(e,t){return e.get(t)?.values}function m(e,t){return e.get(t)?.values?.[0]}function y(e,t){return e.get(t)?.values?.[0]}function A(e,t,n,a=0,i=s,r=4){const l=8===r,f=l?B(new DataView(e,n,8),0,t):new DataView(e,n,2).getUint16(0,t),u=4+2*r,c=l?8:2,h=c+f*u;if(n+h>e.byteLength)return{success:!1,ifd:null,nextIFD:null,requiredBufferSize:h};const g=8===r?8:4,E=n+h+g<=e.byteLength?W(new DataView(e,n+h,g),0,t,8===r):null,I=n+c,T=new Map;let w,p,d,m,y,A=0,S=0;for(let s=0;s<f;s++){p=new DataView(e,I+u*s,u),d=p.getUint16(0,t),y=p.getUint16(2,t),m=o(d,i);const n=[];2===r?(A=p.getUint16(4,t),S=p.getUint16(6,t)):4===r?(A=p.getUint32(4,t),S=p.getUint32(8,t)):8===r&&(A=W(p,4,t,!0),S=W(p,12,t,!0),n.push(p.getUint32(12,t)),n.push(p.getUint32(16,t))),w={id:d,type:y,valueCount:A,valueOffset:S,valueOffsets:n,values:null},N(e,t,w,a,!1,r),T.set(m,w)}return{success:!0,ifd:T,nextIFD:E,requiredBufferSize:h}}const S=(e,t)=>a(e,{inputOffset:t}).pixels[0];function M(e,t){if(t%8==0)return e;const n=t>16?32:t>8?16:8;n>8&&(e=b(e,32===n?4:2));const a=32===n?Uint32Array:16===n?Uint16Array:Uint8Array,i=new a(e),r=Math.floor(8*e.byteLength/t+1e-6),s=new a(r),l=(1<<t)-1;let o=0,f=0,u=0;for(let c=0;c<r;c++)if(0===f&&(u=i[o++],f=n),f>=t)s[c]=u>>>f-t&l,f-=t;else{const e=t-f;let a=(u&l)<<e&l;u=i[o++],f=n-e,a+=u>>>f,s[c]=a}return s.buffer}function P(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 O(e){const t=new c(e).getBytes(),n=new ArrayBuffer(t.length),a=new Uint8Array(n);return a.set(t),a}function b(e,t){const n=new Uint8Array(e),a=new Uint8Array(n.length);if(2===t)for(let i=0;i<n.length;i+=2)a[i]=n[i+1],a[i+1]=n[i];else if(4===t)for(let i=0;i<n.length;i+=4)a[i]=n[i+3],a[i+1]=n[i+2],a[i+2]=n[i+1],a[i+3]=n[i];else for(let i=0;i<n.length;i+=8)a[i]=n[i+7],a[i+1]=n[i+6],a[i+2]=n[i+5],a[i+3]=n[i+4],a[i+4]=n[i+3],a[i+5]=n[i+2],a[i+6]=n[i+1],a[i+7]=n[i];return a.buffer}async function x(e,t,a,r,s){const l=u===t,o=y(a,"BITSPERSAMPLE"),f=y(a,"SAMPLESPERPIXEL")??1,c=y(a,"PHOTOMETRICINTERPRETATION"),h=y(a,"SAMPLEFORMAT")??1,g=I(h,o),E=y(a,"COMPRESSION")??1,w=T(g);let p,d,m;if(34887===E)return await n(),S(e,r);if(1===E)p=e.slice(r,r+s),d=new Uint8Array(p);else if(8===E||32946===E)d=new Uint8Array(e,r,s),d=O(d),p=d.buffer;else if(6===E)d=new Uint8Array(e,r,s),d=P(d,f,c),p=d.buffer;else if(7===E){const t=a.get("JPEGTABLES").values,n=t.length-2;d=new Uint8Array(n+s-2);for(let e=0;e<n;e++)d[e]=t[e];const i=new Uint8Array(e,r+2,s-2);for(let e=0;e<i.length;e++)d[n+e]=i[e];d=P(d,f,c),p=d.buffer}else{if(5!==E)throw new Error("tiff-decode: unsupport compression "+E);d=i(e,r,s,t),p=d.buffer}if(p=M(p,o),l||o<=8)m=new w(p);else{const e=o>32?8:o>16?4:2;m=new w(b(d.buffer,e))}const A=y(a,"PREDICTOR")??1,x=y(a,"TILEWIDTH"),L=y(a,"TILELENGTH");if(A>1&&(5===E||8===E||32946===E)&&x&&L){const e=C(a),t=new w(m.length);t.set(m),m=j(t,L,x,3===h&&3===A,e?1:f)}return m}async function L(e,t,n){const a=d(n,"TILEOFFSETS");if(void 0===a)return null;const i=d(n,"TILEBYTECOUNTS"),{width:r,height:s,pixelType:l,tileWidth:o,tileHeight:f}=k([n]),u=C(n,t),c=y(n,"SAMPLESPERPIXEL")||t.planes,h=r*s,g=y(n,"BITSPERSAMPLE"),E=34887===(y(n,"COMPRESSION")??1),I=T(l),w=[];for(let T=0;T<c;T++)w.push(new I(h));const p=Math.ceil(r/o),m=new Uint8Array(h).fill(255);let A=null,S=!1;if(g%8==0)if(E&&u&&c>1){const l=Math.round(a.length/c);for(let u=0;u<l;u++){const l=Math.floor(u/p)*f,h=u%p*o,g=l*r+h;for(let E=0;E<c;E++){const I=u*c+E;0===i[I]?(A=null,S=!0):A=await x(e,t.littleEndian,n,a[I],i[I]);const T=Math.min(o,r-h),p=Math.min(f,s-l),d=w[E];for(let e=0;e<p;e++){let t=g+e*r,n=e*o;for(let e=0;e<T;e++,t++,n++)A?d[t]=A[n]:m[t]=0}}}}else for(let T=0;T<a.length;T++){const l=Math.floor(T/p)*f,h=T%p*o,g=l*r+h;0===i[T]?(A=null,S=!0):A=await x(e,t.littleEndian,n,a[T],i[T]);const I=Math.min(o,r-h),d=Math.min(f,s-l);for(let e=0;e<c;e++){const t=w[e];if(u||E)for(let n=0;n<d;n++){let a=g+n*r,i=o*f*e+n*o;for(let e=0;e<I;e++,a++,i++)A?t[a]=A[i]:m[a]=0}else for(let n=0;n<d;n++){let a=g+n*r,i=n*o*c+e;for(let e=0;e<I;e++,a++,i+=c)A?t[a]=A[i]:m[a]=0}}}return{width:r,height:s,pixelType:l,pixels:w,mask:S?m:void 0}}const R=(e,t,n)=>{const a=u===t.littleEndian,r=d(n,"STRIPOFFSETS");if(void 0===r)return null;const{width:s,height:l,pixelType:o}=k([n]),f=y(n,"SAMPLESPERPIXEL")||t.planes,c=y(n,"PHOTOMETRICINTERPRETATION"),h=s*l,g=y(n,"BITSPERSAMPLE"),E=T(o),I=new E(h*f),w=d(n,"STRIPBYTECOUNTS"),p=y(n,"ROWSPERSTRIP"),m=y(n,"COMPRESSION")??1;let A,S,b,x;if(g%8==0)for(let u=0;u<r.length;u++){const n=u*(p*s)*f;if("u8"===o||"s8"===o||a)8===m||32946===m?(b=new Uint8Array(e,r[u],w[u]),b=O(b),S=b.buffer):6===m?(b=new Uint8Array(e,r[u],w[u]),b=P(b,f,c),S=b.buffer):5===m?(b=i(e,r[u],w[u],t.littleEndian),S=b.buffer):S=e.slice(r[u],r[u]+w[u]),S=M(S,g),A=new E(S);else{switch(6===m||8===m||32946===m?(b=new Uint8Array(e,r[u],w[u]),x=O(b),S=x.buffer):(S=new ArrayBuffer(w[u]),b=new Uint8Array(e,r[u],w[u]),x=new Uint8Array(S)),o){case"u16":case"s16":for(let e=0;e<b.length;e+=2)x[e]=b[e+1],x[e+1]=b[e];break;case"u32":case"s32":case"f32":for(let e=0;e<b.length;e+=4)x[e]=b[e+3],x[e+1]=b[e+2],x[e+2]=b[e+1],x[e+3]=b[e]}S=M(S,g),A=new E(S)}I.set(A,n)}const L=[];if(1===f)L.push(I);else for(let i=0;i<f;i++){const e=new E(h);for(let t=0;t<h;t++)e[t]=I[t*f+i];L.push(e)}return{width:s,height:l,pixelType:o,pixels:L}},D=(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},U=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"),I=n.get("WavelengthMax");let T=null;if(g){T=[];for(let e=0;e<g.length;e++)T.push({BandName:g[e],WavelengthMin:E&&parseFloat(E[e]),WavelengthMax:I&&parseFloat(I[e])})}return{statistics:h,bandProperties:T,dataType:n.get("DataType"),rawMetadata:n}};function N(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,f=[];const u=h[s],c=8*u,E=l*u,I=l*h[s]*8;let T,w;const p=8===r?64:32,d=n.valueOffsets;if(I>p){if(E>(i?e.byteLength:e?e.byteLength-o+a:0))return n.offlineOffsetSize=[o,E],n.values=null,!1}if(I<=p){if(!t)if(p<=32)o>>>=32-I;else{const e=d?.length?d[0]:o>>>0,t=d?.length?d[1]:Math.round((o-e)/g);I<=32?(o=e>>>32-I,d[0]=o):(o=e*2**(32-I)+(t>>>32-I),d[0]=e,d[1]=t>>>32-I)}if(1===l&&c===p)f=[o];else if(64===p){const e=d?.length?d[0]:o>>>0,t=d?.length?d[1]:Math.round((o-e)/g);let n=e,a=32;for(w=1;w<=l;w++){const e=32-c*w%32;if(a<c){const i=n<<e>>>32-a,r=t<<32-a>>>32-a;n=t,f.push(i+r*2**(c-a)),a-=32-(c-a)}else f.push(n<<e>>>32-c),a-=c;0===a&&(a=32,n=t)}}else for(w=1;w<=l;w++){const e=32-c*w;f.push(o<<e>>>32-c)}}else{o-=a,i&&(o=0);for(let n=o;n<o+E;n+=u){switch(s){case 1:case 2:case 7:T=new DataView(e,n,1).getUint8(0);break;case 3:T=new DataView(e,n,2).getUint16(0,t);break;case 4:case 13:T=new DataView(e,n,4).getUint32(0,t);break;case 5:T=new DataView(e,n,4).getUint32(0,t)/new DataView(e,n+4,4).getUint32(0,t);break;case 6:T=new DataView(e,n,1).getInt8(0);break;case 8:T=new DataView(e,n,2).getInt16(0,t);break;case 9:T=new DataView(e,n,4).getInt32(0,t);break;case 10:T=new DataView(e,n,4).getInt32(0,t)/new DataView(e,n+4,4).getInt32(0,t);break;case 11:T=new DataView(e,n,4).getFloat32(0,t);break;case 12:T=new DataView(e,n,8).getFloat64(0,t);break;case 16:case 18:T=B(new DataView(e,n,8),0,t);break;case 17:T=V(new DataView(e,n,8),0,t);break;default:T=null}f.push(T)}}if(2===s){let e="";const t=f;for(f=[],w=0;w<t.length;w++)0===t[w]&&""!==e?(f.push(e),e=""):e+=String.fromCharCode(t[w]);""===e&&0!==f.length||f.push(e)}return n.values=f,!0}function k(e){const t=e[0],n=y(t,"TILEWIDTH"),a=y(t,"TILELENGTH"),i=y(t,"IMAGEWIDTH"),r=y(t,"IMAGELENGTH"),s=y(t,"BITSPERSAMPLE"),l=y(t,"SAMPLESPERPIXEL"),o=y(t,"SAMPLEFORMAT")??1,f=I(o,s),u=C(t),c=p(t,"GDAL_NODATA");let h=null;c?.length&&(h=c.map(e=>parseFloat(e)),h.some(e=>isNaN(e))&&(h=null));const g=y(t,"COMPRESSION")??1;let T;switch(g){case 1:T="NONE";break;case 2:case 3:case 4:case 32771:T="CCITT";break;case 5:T="LZW";break;case 6:case 7:T="JPEG";break;case 32773:T="PACKBITS";break;case 8:case 32946:T="DEFLATE";break;case 34712:T="JPEG2000";break;case 34887:T="LERC";break;default:T=String(g)}let A=!0,S="";E.has(g)||(A=!1,S+="unsupported tag compression "+g),o>3&&(A=!1,S+="unsupported tag sampleFormat "+o),s>32&&64!==s&&(A=!1,S+="unsupported tag bitsPerSample "+s);const M=m(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=d(t,"GEOTIEPOINTS"),b=d(t,"GEOPIXELSCALE"),x=d(t,"GEOTRANSMATRIX"),L=t.has("GEOKEYDIRECTORY")?t.get("GEOKEYDIRECTORY").data:null;let R,D,N=!1,k=!1;if(L){N=2===y(L,"GTRasterTypeGeoKey");const e=y(L,"GTModelTypeGeoKey");if(2===e){const e=y(L,"GeographicTypeGeoKey");e>=1024&&e<=32766&&(P={wkid:e}),P||32767!==e||(k=!0,P={wkid:4326})}else if(1===e){const e=y(L,"ProjectedCSTypeGeoKey");e>=1024&&e<=32766&&(P={wkid:e})}}if(b&&O&&O.length>=6?(R=[b[0],0,O[3]-O[0]*b[0],0,-Math.abs(b[1]),O[4]-O[1]*b[1]],N&&(R[2]-=.5*R[0]+.5*R[1],R[5]-=.5*R[3]+.5*R[4])):x&&16===x.length&&(R=N?[x[0],x[1],x[3]-.5*x[0],x[4],x[5],x[7]-.5*x[5]]:[x[0],x[1],x[3],x[4],x[5],x[7]]),R){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=w(e[i],R),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;D={xmin:n,xmax:s,ymin:a,ymax:l,spatialReference:P}}else D={xmin:-.5,ymin:.5-r,xmax:i-.5,ymax:.5,spatialReference:P};k&&(D.xmax-D.xmin>400||Math.max(Math.abs(D.xmin),Math.abs(D.xmax))>361)&&(P=null,D.spatialReference=null);const F=G(e);let B,V,W,H,Y;if(F.length>0){W=Math.round(Math.log(i/y(F[0],"IMAGEWIDTH"))/Math.LN2);const e=F[F.length-1];H=F.length,B=y(e,"TILEWIDTH"),V=y(e,"TILELENGTH")}B=null!=H&&H>0?B||n:null,V=null!=H&&H>0?V||a:null,n&&(Y=[{maxCol:Math.ceil(i/n)-1,maxRow:Math.ceil(r/a)-1,minRow:0,minCol:0}],F.forEach(e=>{Y.push({maxCol:Math.ceil(y(e,"IMAGEWIDTH")/y(e,"TILEWIDTH"))-1,maxRow:Math.ceil(y(e,"IMAGELENGTH")/y(e,"TILELENGTH"))-1,minRow:0,minCol:0})}));const j=m(e[0],"GDAL_METADATA"),X=U(j);S+=" "+_({width:i,height:r,tileWidth:n,tileHeight:a,planes:l,ifds:e});const K=v(e).length===F.length+1,J=F?.length?F.map(e=>({x:i/y(e,"IMAGEWIDTH"),y:r/y(e,"IMAGELENGTH")})):void 0;return{width:i,height:r,tileWidth:n,tileHeight:a,planes:l,isBSQ:u,pixelType:f,compression:T,noData:h,hasMaskBand:K,isSupported:A,pyramidResolutions:J,message:S,extent:D,isPseudoGeographic:k,affine:b?null:R,firstPyramidLevel:W,maximumPyramidLevel:H,pyramidBlockWidth:B,pyramidBlockHeight:V,tileBoundary:Y,metadata:X}}function C(e,t){const n=p(e,"PLANARCONFIGURATION");return n?2===n[0]:!!t&&t.isBSQ}function G(e){return e.filter(e=>1===y(e,"NEWSUBFILETYPE"))}function v(e){return e.filter(e=>{const t=!(4&~(y(e,"NEWSUBFILETYPE")??0)),n=4===y(e,"PHOTOMETRICINTERPRETATION");return t&&n})}function F(e){const{littleEndian:t,isBigTiff:n,firstIFDPos:a}=H(e);let i=a;const r=[];do{const a=Y(e,t,i,0,s,n?8:4);if(!a.success)break;r.push(a.ifd),i=a.nextIFD}while(i>0);return{...k(r),littleEndian:t,isBigTiff:n,ifds:r,pyramidIFDs:G(r),maskIFDs:v(r)}}function B(e,t,n){const a=e.getUint32(t,n),i=e.getUint32(t+4,n);return n?i*g+a:a*g+i}function V(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*g+a:a*g+i)}function W(e,t,n,a){return a?B(e,t,n):e.getUint32(t,n)}function H(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:W(t,r,a,s)}}function Y(t,n,a,i=0,r=s,o=4){const u=A(t,n,a,i,r,o);let c;const h=u.ifd;if(h){if(l.forEach((e,a)=>{h.has(a)&&(c=h.get(a),c.data=A(t,n,c.valueOffset-i,i,e).ifd)}),h.has("GEOKEYDIRECTORY")){c=h.get("GEOKEYDIRECTORY");const e=c.values;if(e&&e.length>4){const a=e[0]+"."+e[1]+"."+e[2];c.data=A(t,n,c.valueOffset+6-i,i,f,2).ifd,c.data&&c.data.set("GEOTIFFVersion",{id:0,type:2,valueCount:1,valueOffset:null,values:[a]})}}if(h.has("XMP")){c=h.get("XMP");const t=c.values;"number"==typeof t[0]&&7===c.type&&(c.values=[e(new Uint8Array(t))])}}return u}function _(e){const{width:t,height:n,tileHeight:a,tileWidth:i}=e,r=e.planes,s=i?i*a:t*n,l=y(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 j(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 X(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 x(e,n.littleEndian,a,i[r],s[r]||e.byteLength);l.push(t)}const o=C(a,n),f=y(a,"BITSPERSAMPLE"),u=I(y(a,"SAMPLEFORMAT")??1,f),c=y(a,"SAMPLESPERPIXEL")||n.planes,h=T(u),g=y(a,"TILEWIDTH"),E=y(a,"TILELENGTH"),w=y(a,"COMPRESSION")??1,p=g*E;let d;const m=[];let A=l[0];const S=34887===w;for(let r=0;r<c;r++){if(d=new h(p),l.length===c)A=l[r],A.length===p&&(d=A);else if(A.length)if(o||S)d=A.length===p?A:A.slice(p*r,p*(r+1));else for(let e=0;e<p;e++)d[e]=A[e*c+r];m.push(d)}const M=n.noData?n.noData[0]:t.noDataValue,P=n.metadata?n.metadata.statistics:null,O=P?P.map(e=>e.min):null,b=P?P.map(e=>e.max):null,L={pixelType:u,width:g,height:E,pixels:m,noDataValue:M};return null!=M?r(L,M,{matchAllNoData:t?.matchAllNoData}):O&&b&&t.applyMinMaxConstraint&&(L.mask=D(m,O,b)),L}async function K(e,t={}){const n=t.pyramidLevel||0,a=t.headerInfo||F(e),{ifds:i,noData:s}=a;if(0===i.length)throw new Error("no valid image file directory");const l=_(a);if(l)throw l;let o=null;const f=-1===n?i[i.length-1]:i[n],u=s??t.noDataValue;if(o=a.tileWidth?await L(e,a,f):R(e,a,f),!o)return o;if(null!=u){r(o,u,{matchAllNoData:null==s&&t?.matchAllNoData})}return o}export{K as decode,X as decodeTileOrStrip,k as getImageInfo,v as getMaskIFDs,G as getPyramidIFDs,C as isBSQConfig,N as parseFieldValues,F as parseHeader,Y as parseIFD,H as parseSignature,M as unpackBits};
|