@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 2.24 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as t}from"tslib";import e from"../../../core/Error.js";import{Loadable as i}from"../../../core/Loadable.js";import{throwIfAborted as r}from"../../../core/promiseUtils.js";import{property as s,subclass as h}from"../../../core/accessorSupport/decorators.js";import{RasterJobHandlerMixin as o}from"../../../layers/mixins/RasterJobHandlerMixin.js";let a=class extends(o(i)){constructor(t){super(t)}load(t){return this.addResolvingPromise(this._fetchPixels(t)),Promise.resolve(this)}destroy(){this._source=null}get height(){return this._get("height")}get width(){return this._get("width")}async _fetchPixels(t){const i=(await import("../../../layers/raster/datasets/RasterFactory.js")).default,s=await i.open({url:this.url,ioConfig:{skipExtensions:["jgw","aux.xml"],skipMapInfo:!0},signal:t?.signal});if(r(t),null==s)throw new e("depth-image-service:open-error","Failed to open depth image raster.",{url:this.url});const{width:h,height:o}=s.rasterInfo;await this._initJobHandler(),r(t),s.rasterJobHandler=this._rasterJobHandler;const{pixelBlock:a}=await s.fetchPixels(s.rasterInfo.nativeExtent.clone(),h,o,{noClip:!1,signal:t?.signal});if(r(t),null==a)throw new e("depth-image-service:fetch-error","Failed to fetch depth image pixels.");this._set("width",a.width),this._set("height",a.height),this._source=a.pixels[0]}_getDepthValue(t,e){const i=Math.max(1,Math.min(this.width,t)),r=Math.max(1,Math.min(this.height,e));return this._source[(r-1)*this.width+(i-1)]}_interpolateDepth(t,e){const i=Math.floor(e),r=Math.ceil(e),s=Math.floor(t),h=Math.ceil(t),o=e-i,a=t-s;return(this._getDepthValue(i,s)*(1-o)+this._getDepthValue(r,s)*o)*(1-a)+(this._getDepthValue(i,h)*(1-o)+this._getDepthValue(r,h)*o)*a}depthAt(t,e){if(!this.loaded||!this._source)throw new Error("DepthImageService must be loaded before sampling depth.");const i=t.x/e.width*this.width,r=t.y/e.height*this.height;return this._interpolateDepth(r,i)}};t([s({readOnly:!0,value:0})],a.prototype,"height",null),t([s()],a.prototype,"url",void 0),t([s({readOnly:!0,value:0})],a.prototype,"width",null),a=t([h("esri.widgets.OrientedImageryViewer.services.DepthImageService")],a);const l=a;export{l as default};