import{_ as u,$ as p,a0 as K,a1 as ne,t as _,dW as H,k as oe,dX as le,ar as he,a as x,aW as j,dY as ee,cf as k,G as de,dZ as ce,d_ as ue,E as me,af as pe,R as F,S as O,a8 as ye,Q as fe,s as te,g as _e,j as S,z as ve,a3 as ge,F as we,aD as Re,aV as Me,M as $e,aX as xe,I as Ce,J as Ee,ap as Te,du as Ve,ct as Se,cH as be,cC as qe,cD as Ae,d$ as De,m as Ie,cA as Pe,dU as Oe,aq as ze}from"./index.6c049565.js";import{a as Ue}from"./normalizeUtilsSync.f896b328.js";import{e as b}from"./mat3f64.6d32a1d7.js";import{r as je}from"./utils.eb2c3fd5.js";import{E as N,a as We}from"./VertexArrayObject.729879be.js";import{P as Le,G as Ge,L as Qe,D as Be,F as Y}from"./enums.2d9e6f64.js";import{n as J,E as He}from"./Texture.8e8dfb11.js";import{r as ke}from"./vec3f32.1121a836.js";import{o as Fe,c as Ne}from"./WGLContainer.bbd0fcb8.js";import{I as Ye}from"./Utils.e8554a0e.js";import{y as Je,u as Xe}from"./LayerView.7c2db9bf.js";import"./MaterialKey.bbaab8f1.js";import"./enums.0295eb81.js";import"./pixelUtils.f4eba4af.js";import"./VertexElementDescriptor.1fdca6da.js";import"./ProgramTemplate.83fdf5b6.js";import"./StyleDefinition.d56936e4.js";import"./config.82550349.js";import"./GeometryUtils.51c4032a.js";import"./earcut.afc1d357.js";let m=class extends ne{constructor(r){super(r)}get bounds(){const r=this.coords;return _(r)||_(r.extent)?null:H(r.extent)}get coords(){var e;const r=(e=oe(this.element.georeference))==null?void 0:e.coords;return le(r,this.spatialReference).geometry}get normalizedCoords(){return he.fromJSON(Ue(this.coords))}get normalizedBounds(){const r=x(this.normalizedCoords)?this.normalizedCoords.extent:null;return x(r)?H(r):null}};u([p()],m.prototype,"spatialReference",void 0),u([p()],m.prototype,"element",void 0),u([p()],m.prototype,"bounds",null),u([p()],m.prototype,"coords",null),u([p()],m.prototype,"normalizedCoords",null),u([p()],m.prototype,"normalizedBounds",null),m=u([K("esri.layers.support.media.MediaElementView")],m);const z=me(),R=b(),U=b(),X=b();function Ze(r,e,t){return Z(U,e[0],e[1],e[2],e[3],e[4],e[5],e[6],e[7]),Z(X,t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7]),j(r,ee(U,U),X)}function Z(r,e,t,s,a,i,n,h,y){k(r,e,s,i,t,a,n,1,1,1),de(z,h,y,1),ee(R,r);const[o,l,d]=ce(z,z,ue(R,R));return k(R,o,0,0,0,l,0,0,0,d),j(r,R,r)}const M=b();class Ke extends je{constructor(e){super(),this.elementView=e,this.isWrapAround=!1,this.perspectiveTransform=pe(),this._vertices=new Float32Array(20),this._handles=[],this._handles.push(F(()=>this.elementView.element.opacity,t=>this.opacity=t,O),F(()=>[this.elementView.coords],()=>{this.requestRender()},O),ye(()=>this.elementView.element.loaded,()=>{const t=this.elementView.element;this.ready(),t.type==="video"&&x(t.content)&&this._handles.push(fe(t.content,"play",()=>this.requestRender()))},O)),e.element.load().catch(t=>{te.getLogger("esri.views.2d.layers.MediaLayerView2D").error(new _e("element-load-error","Element cannot be displayed",{element:e,error:t}))})}destroy(){var e;this._handles.forEach(t=>t.remove()),(e=this.texture)==null||e.dispose(),this.texture=null}get dvsMat3(){return this.parent.dvsMat3}beforeRender(e){const{context:t}=e,s=this.elementView.element.content;if(x(s)){const a=s instanceof HTMLImageElement,i=s instanceof HTMLVideoElement,n=a?s.naturalWidth:i?s.videoWidth:s.width,h=a?s.naturalHeight:i?s.videoHeight:s.height;this._updatePerspectiveTransform(n,h),this.texture?i&&!s.paused&&(this.texture.setData(s),this.requestRender(),(J(t.gl)||S(n)&&S(h))&&this.texture.generateMipmap()):(this.texture=new He(t,{pixelFormat:Le.RGBA,dataType:Ge.UNSIGNED_BYTE,samplingMode:Qe.LINEAR,wrapMode:Be.CLAMP_TO_EDGE,width:n,height:h,preMultiplyAlpha:!0},s),(J(t.gl)||S(n)&&S(h))&&this.texture.generateMipmap(),i&&!s.paused&&this.requestRender())}super.beforeRender(e)}_createTransforms(){return null}updateDrawCoords(e,t){const s=this.elementView.coords;if(_(s))return;const[a,i,n,h]=s.rings[0],y=this._vertices,{x:o,y:l}=e,d=t!==0;d?y.set([i[0]-o,i[1]-l,a[0]-o,a[1]-l,n[0]-o,n[1]-l,h[0]-o,h[1]-l,h[0]-o,h[1]-l,i[0]+t-o,i[1]-l,i[0]+t-o,i[1]-l,a[0]+t-o,a[1]-l,n[0]+t-o,n[1]-l,h[0]+t-o,h[1]-l]):y.set([i[0]-o,i[1]-l,a[0]-o,a[1]-l,n[0]-o,n[1]-l,h[0]-o,h[1]-l]),this.isWrapAround=d}getVAO(e,t,s){if(_(this.elementView.coords))return null;const a=this._vertices;if(this._vao)this._geometryVbo.setData(a);else{this._geometryVbo=N.createVertex(e,Y.DYNAMIC_DRAW,a);const i=N.createVertex(e,Y.STATIC_DRAW,new Uint16Array([0,0,0,1,1,0,1,1,1,1,0,0,0,0,0,1,1,0,1,1]));this._vao=new We(e,s,t,{geometry:this._geometryVbo,tex:i})}return this._vao}_updatePerspectiveTransform(e,t){const s=this._vertices;Ze(M,[0,0,e,0,0,t,e,t],[s[0],s[1],s[4],s[5],s[2],s[3],s[6],s[7]]),ve(this.perspectiveTransform,M[6]/M[8]*e,M[7]/M[8]*t)}}class et extends Fe{constructor(){super(...arguments),this._localOrigin=ge(0,0),this._viewStateId=-1,this._dvsMat3=we(),this.requiresDedicatedFBO=!1}get dvsMat3(){return this._dvsMat3}beforeRender(e){this._updateMatrices(e),this._updateOverlays(e,this.children);for(const t of this.children)t.beforeRender(e)}prepareRenderPasses(e){const t=e.registerRenderPass({name:"overlay",brushes:[Ne.overlay],target:()=>this.children,drawPhase:Ye.MAP});return[...super.prepareRenderPasses(e),t]}_updateMatrices(e){const{state:t}=e,{id:s,size:a,pixelRatio:i,resolution:n,rotation:h,viewpoint:y,displayMat3:o}=t;if(this._viewStateId===s)return;const l=Math.PI/180*h,d=i*a[0],g=i*a[1],{x:C,y:q}=y.targetGeometry,A=Re(C,t.spatialReference);this._localOrigin.x=A,this._localOrigin.y=q;const E=n*d,w=n*g,c=Me(this._dvsMat3);j(c,c,o),$e(c,c,xe(d/2,g/2)),Ce(c,c,ke(d/E,-g/w,1)),Ee(c,c,-l),this._viewStateId=s}_updateOverlays(e,t){const{state:s}=e,{rotation:a,spatialReference:i,worldScreenWidth:n,size:h,viewpoint:y}=s,o=this._localOrigin;let l=0;if(i.isWrappable){const d=h[0],g=h[1],C=180/Math.PI*a,q=Math.abs(Math.cos(C)),A=Math.abs(Math.sin(C)),E=Math.round(d*q+g*A),[w,c]=Te(i).valid,f=Ve(i),{x:W,y:se}=y.targetGeometry,re=[W,se],D=[0,0];s.toScreen(D,re);const T=[0,0];let I;I=E>n?.5*n:.5*E;const L=Math.floor((W+.5*f)/f),ie=w+L*f,ae=c+L*f,P=[D[0]+I,0];s.toMap(T,P),T[0]>ae&&(l=f),P[0]=D[0]-I,s.toMap(T,P),T[0]w?V.updateDrawCoords(o,f):B>c&&Qthis.layer.source,"refresh",()=>{for(const r of this._tileStrategy.tiles)this._updateTile(r);this.requestUpdate()})),this._overlayContainer=new et,this.container.addChild(this._overlayContainer),this._fetchQueue=new qe({tileInfoView:this.view.featuresTilingScheme,concurrency:10,process:(r,e)=>this._queryElements(r,e)}),this._tileStrategy=new Ae({cachePolicy:"purge",resampling:!0,acquireTile:r=>this._acquireTile(r),releaseTile:r=>this._releaseTile(r),tileInfoView:this.view.featuresTilingScheme}),this.requestUpdate()}detach(){this.handles.removeAll(),this.elements.removeAll(),this._tileStrategy.destroy(),this._fetchQueue.destroy(),this._overlayContainer.removeAllChildren(),this.container.removeAllChildren(),this._elementReferences.clear()}supportsSpatialReference(r){return!0}moveStart(){this.requestUpdate()}viewChange(){this.requestUpdate()}moveEnd(){this.requestUpdate()}update(r){this._tileStrategy.update(r)}async hitTest(r,e){const t=[],s=r.normalize(),a=[s.x,s.y];for(const{projectedElement:{normalizedCoords:i,element:n}}of this._elementReferences.values())x(i)&&De(i.rings,a)&&t.push({type:"media",element:n,layer:this.layer,mapPoint:r});return t.reverse()}canResume(){return this.layer.source!=null&&super.canResume()}async doRefresh(){}_acquireTile(r){const e=new tt(r.clone());return this._updateTile(e),e}_updateTile(r){this.updatingHandles.addPromise(this._fetchQueue.push(r.key).then(e=>{const[t,s]=r.setElements(e);this._acquireElements(r,t),this._releaseElements(r,s),this.requestUpdate()},e=>{Ie(e)||te.getLogger(this.declaredClass).error(e)}))}_releaseTile(r){this._fetchQueue.abort(r.key.id),r.elements&&this._releaseElements(r,r.elements),this.requestUpdate()}async _queryElements(r,e){const t=this.layer.source;if(_(t))return[];this.view.featuresTilingScheme.getTileBounds($,r,!0);const s=new Pe({xmin:$[0],ymin:$[1],xmax:$[2],ymax:$[3],spatialReference:this.view.spatialReference});return t.queryElements(s,e)}_acquireElements(r,e){const t=this.layer.source,s=this.view.spatialReference;if(!_(t))for(const a of e)Oe(this._elementReferences,a.uid,()=>{const i=new m({element:a,spatialReference:s}),n=new Ke(i);return this._overlayContainer.addChild(n),this.elements.add(a),{tiles:new Set,projectedElement:i,overlay:n}}).tiles.add(r)}_releaseElements(r,e){for(const t of e){const s=this._elementReferences.get(t.uid);s.tiles.delete(r),s.tiles.size||(this._overlayContainer.removeChild(s.overlay),s.overlay.destroy(),s.projectedElement.destroy(),this._elementReferences.delete(t.uid),this.elements.remove(t))}}};u([p()],v.prototype,"_fetchQueue",void 0),u([p()],v.prototype,"layer",void 0),u([p({readOnly:!0})],v.prototype,"elements",void 0),v=u([K("esri.views.2d.layers.MediaLayerView2D")],v);const $=ze();class tt{constructor(e){this.key=e,this.elements=null,this.isReady=!1,this.visible=!0}setElements(e){const t=[],s=new Set(this.elements);this.elements=e;for(const a of e)s.has(a)?s.delete(a):t.push(a);return this.isReady=!0,[t,Array.from(s)]}}const Mt=v;export{Mt as default};