/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{toRadian as t}from"../../../../core/libs/gl-matrix-2/math/common.js";import{identity as e,multiply as r,translate as i,scale as o,rotate as s}from"../../../../core/libs/gl-matrix-2/math/mat3.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/mat3f32.js";import{fromValues as n}from"../../../../core/libs/gl-matrix-2/factories/vec2f32.js";import{fromValues as l}from"../../../../core/libs/gl-matrix-2/factories/vec3f32.js";import{normalizeMapX as c}from"../../../../geometry/support/normalizeUtils.js";import{getInfo as h}from"../../../../geometry/support/spatialReferenceUtils.js";import{getWorldWidth as d}from"../../viewpointUtils.js";import m from"./WGLContainer.js";import{OverlayTechnique as p}from"./shaderGraph/techniques/overlay/OverlayTechnique.js";class f extends m{constructor(){super(...arguments),this._viewStateId=-1,this._dvsMat3=a(),this._overlayTechnique=new p}get dvsMat3(){return this._dvsMat3}beforeRender(t){this._updateMatrices(t),this._updateOverlays(t,this.children);for(const e of this.children)e.beforeRender(t)}doRender(t){if(1!==t.drawPhase||!this.visible)return;super.doRender(t);const e=this._overlayTechnique;for(const r of this.children)r.draw(t,e)}onDetach(){this._overlayTechnique.shutdown()}_updateMatrices(a){const{state:h}=a,{id:d,size:m,pixelRatio:p,resolution:f,rotation:u,viewpoint:v,displayMat3:_}=h;if(this._viewStateId===d)return;const g=t(u),y=p*m[0],M=p*m[1];this._localOrigin=v.targetGeometry.clone();const{x:w,y:x}=this._localOrigin,b=c(w,h.spatialReference);this._localOrigin.x=b,this._localOrigin.y=x;const j=f*y,O=f*M,R=e(this._dvsMat3);r(R,R,_),i(R,R,n(y/2,M/2)),o(R,R,l(y/j,-M/O,1)),s(R,R,-g),this._viewStateId=d}_updateOverlays(e,r){const{state:i}=e,{rotation:o,spatialReference:s,worldScreenWidth:a,size:n,viewpoint:l}=i,c=this._localOrigin;let m,p=0;const f=h(s);if(f&&s.isWrappable){const e=n[0],r=n[1],c=t(o),h=Math.abs(Math.cos(c)),u=Math.abs(Math.sin(c)),v=Math.round(e*h+r*u),[_,g]=f.valid,y=d(s),{x:M,y:w}=l.targetGeometry,x=[M,w],b=[0,0];i.toScreen(b,x);const j=[0,0];let O;O=v>a?.5*a:.5*v;const R=Math.floor((M+.5*y)/y),q=_+R*y,S=g+R*y,G=[b[0]+O,0];i.toMap(j,G),j[0]>S&&(p=y),G[0]=b[0]-O,i.toMap(j,G),j[0]<q&&(p=-y),m={worldWidth:y,xBounds:[_,g]}}for(const t of r)t.updateDrawCoords(c,p,i,m)}}export{f as default};
