UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 5.16 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";import{createTask as s}from"../../../../../core/asyncUtils.js";import{clamp as i}from"../../../../../core/mathUtils.js";import{disposeMaybe as r}from"../../../../../core/maybe.js";import{watch as t,syncAndInitial as a}from"../../../../../core/reactiveUtils.js";import{createScreenPointArray as o,createRenderScreenPointArray as m,screenPointObjectToArray as n}from"../../../../../core/screenUtils.js";import{isSVG as h}from"../../../../../core/urlUtils.js";import{property as l,subclass as u}from"../../../../../core/accessorSupport/decorators.js";import{requestImage as p}from"../../../../../request/image.js";import{InternalRenderCategory as c}from"../../../webgl.js";import _ from"../../../webgl/RenderNode.js";import{M as g}from"../../../../../chunks/Magnifier.glsl.js";import{MagnifierTechnique as d}from"./MagnifierTechnique.js";import{createQuadVAO as f}from"../../lib/glUtil3D.js";import{loadMagnifierResources as v}from"../../../../magnifier/resources.js";import{PrimitiveType as T}from"../../../../webgl/enums.js";import k from"../../../../webgl/Texture.js";import{TextureDescriptor as P}from"../../../../webgl/TextureDescriptor.js";let y=class extends _{constructor(){super(...arguments),this.produces=c.MAGNIFIER,this.consumes={required:[c.MAGNIFIER]},this._imageSources=null,this._imageLoadTask=null,this._passParameters=new g,this._magnifier=null,this._tmpScreenPoint=o(),this._tmpRenderPoint=m()}initialize(){this.addHandles([t(()=>this.view.magnifier,e=>this._update(e),a)])}_update(e){if(e===this._magnifier)return;this.removeAllHandles(),this._magnifier=e;const s=()=>{const e=this._validMagnifier;e?(this._loadResources(e),this.produces=c.MAGNIFIER):this.produces="disabled",this.requestRender()};this._magnifier&&this.addHandles(t(()=>this._magnifier?.version,s)),s()}get _validMagnifier(){return this._magnifier?.visible&&this._magnifier?.position&&this._magnifier?.size>0?this._magnifier:null}get _factor(){return this._magnifier?.factor||1}destroy(){this._magnifier=null,null!=this._imageLoadTask&&(this._imageLoadTask.task.abort(),this._imageLoadTask=null),this._disposeTextures(),this._vao=r(this._vao)}_disposeTextures(){this._passParameters.mask=r(this._passParameters.mask),this._passParameters.overlay=r(this._passParameters.overlay),this._passParameters.input=r(this._passParameters.input)}precompile(){this._imageSources&&this.techniques.precompile(d)}render(e){const s=this._validMagnifier,r=e.find(({name:e})=>e===c.MAGNIFIER);if(null==s)return r;if(null==this._imageSources)return this.requestRender(1),r;const t=this.renderingContext,a=this.camera.pixelRatio,o=Math.ceil(a*s.size);this._vao??=f(t,0,0,1);const m=this.techniques.get(d);if(this._ensureTextureResources(t,o),!m.compiled||!this._passParameters.input)return this.requestRender(1),r;const h=Math.ceil(1/this._factor*o),l=this._passParameters.input;l.resize(h,h),n(s.position,this._tmpScreenPoint);const u=this.camera.screenToRender(this._tmpScreenPoint,this._tmpRenderPoint),p=this.camera.fullWidth,_=this.camera.fullHeight,g=.5*h,v=.5*h;u[0]=i(u[0],g,p-g-1),u[1]=i(u[1],v,_-v-1);const k=Math.floor(u[0]-g),P=Math.floor(u[1]-v);t.bindFramebuffer(r.fbo);return m.program.bindTexture("textureInput",l),t.gl.copyTexImage2D(l.descriptor.target,0,l.descriptor.pixelFormat,k,P,h,h,0),this._passParameters.magnifier=s,t.bindTechnique(m,this.bindParameters,this._passParameters),t.bindVAO(this._vao),t.drawArrays(T.TRIANGLE_STRIP,0,4),r}_loadResources(e){const{maskUrl:i,overlayUrl:r}=e;this._imageLoadTask?.maskUrl===i&&this._imageLoadTask?.overlayUrl===r||(this._imageLoadTask?.task.abort(),this._imageLoadTask=this._imageSources=null),this._imageSources||this._imageLoadTask||(this._imageLoadTask={maskUrl:i,overlayUrl:r,task:s(async e=>{const s=null==i||null==r?v(e):null,t=null!=i?p(i,{signal:e}):s.then(e=>e.mask),a=null!=r?p(r,{signal:e}):s.then(e=>e.overlay);this._imageSources={mask:await t,overlay:await a}})})}_ensureTextureResources(e,s){null==this._imageSources||this._passParameters.size===s&&this._passParameters.input&&this._passParameters.mask&&this._passParameters.overlay||(this._disposeTextures(),this._imageSources.overlay.width=this._imageSources.mask.width=s,this._imageSources.overlay.height=this._imageSources.mask.height=s,this._passParameters.overlay=new k(e,this._createTextureDescriptor(s,6408,this._imageSources.overlay),this._imageSources.overlay),this._passParameters.mask=new k(e,this._createTextureDescriptor(s,6406,this._imageSources.mask),this._imageSources.mask),this._passParameters.input=new k(e,this._createTextureDescriptor(s,6408,null)))}_createTextureDescriptor(e,s,i){const r=this.renderingContext,t=new P(e);return t.pixelFormat=t.internalFormat=s,t.wrapMode=33071,t.flipped=!!i,t.preMultiplyAlpha=!(6408!==s||!i||h(i.src)&&r.driverTest.svgPremultipliesAlpha.result),t}};e([l()],y.prototype,"produces",void 0),e([l()],y.prototype,"consumes",void 0),e([l()],y.prototype,"_imageSources",void 0),e([l()],y.prototype,"_imageLoadTask",void 0),y=e([u("esri.views.3d.webgl-engine.effects.magnifier.Magnifier")],y);export{y as Magnifier};