/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../../../../chunks/_rollupPluginBabelHelpers","../../../../../../core/Error","../../../../../../core/Logger","../../../../../../core/maybe","../../../../../../core/screenUtils","../../../../../../chunks/mat2df32","../../../../../../chunks/vec2f32","../../../../../../symbols/cim/enums","../../color","../../definitions","../../number","../../materialKey/MaterialKey","./util","./WGLBaseMarkerTemplate","./WGLDynamicMeshTemplate","../../util/Result"],(function(t,e,i,s,r,a,o,n,c,h,l,_,p,m,f,y){"use strict";const u=o.create(),M=a.create(),d=i.getLogger("esri.views.2d.engine.webgl.WGLDynamicMarkerTemplate");return function(i){function a(t,e,a){var o;(o=i.call(this,t)||this)._cimMarkerLayer=t,o._minMaxZoom=l.i1616to32(Math.round(e*h.MIN_MAX_ZOOM_PRECISION_FACTOR),Math.round(a*h.MIN_MAX_ZOOM_PRECISION_FACTOR));const _=t.color;if(p.isFunction(_)){const t=(t,e,i)=>c.premultiplyAlphaRGBA(_(t,e,i));o._dynamicPropertyMap.set("_fillColor",t)}else o._fillColor=c.premultiplyAlphaRGBA(_);const m=t.outlineColor;if(p.isFunction(m)){const t=(t,e,i)=>c.premultiplyAlphaRGBA(m(t,e,i));o._dynamicPropertyMap.set("_outlineColor",t)}else o._outlineColor=c.premultiplyAlphaRGBA(m);const f=t.size;if(p.isFunction(f)){const t=(t,e,i)=>r.pt2px(f(t,e,i));o._dynamicPropertyMap.set("_size",t)}else o._size=r.pt2px(f)||0;const y=t.scaleX;p.isFunction(y)?o._dynamicPropertyMap.set("_scaleX",y):o._scaleX=y||1;const u=t.offsetX;if(p.isFunction(u)){const t=(t,e,i)=>r.pt2px(u(t,e,i));o._dynamicPropertyMap.set("xOffset",t)}else o.xOffset=r.pt2px(u)||0;const M=t.offsetY;if(p.isFunction(M)){const t=(t,e,i)=>r.pt2px(M(t,e,i));o._dynamicPropertyMap.set("yOffset",t)}else o.yOffset=r.pt2px(M)||0;const d=t.outlineWidth;if(p.isFunction(d)){const t=(t,e,i)=>r.pt2px(d(t,e,i));o._dynamicPropertyMap.set("_outlineWidth",t)}else o._outlineWidth=r.pt2px(d)||0;const g=t.rotation;if(p.isFunction(g)?o._dynamicPropertyMap.set("_angle",g):o._angle=g||0,s.isSome(t.effects)){const e=t.effects;p.isFunction(e)?o._dynamicPropertyMap.set("_effects",e):o._effects=e}if(s.isSome(t.markerPlacement)){const e=t.markerPlacement;p.isFunction(e)?o._dynamicPropertyMap.set("_markerPlacement",e):o._markerPlacement=e}return o._scaleFactor=s.unwrapOr(t.scaleFactor,1),o._bitSet=(t.alignment===n.Alignment.MAP?1:0)|(t.colorLocked?1:0)<<1|(t.scaleSymbolsProportionally?1:0)<<3,o._materialKey=t.materialKey,o}return t._inheritsLoose(a,i),a.fromCIMMarker=function(t,e){const[i,s]=p.getMinMaxZoom(t.scaleInfo,e);return new a(t,i,s)},a.prototype.bindFeature=function(t,i,s){const a=t.readLegacyFeature(),o=t.getObjectId();this._dynamicPropertyMap.forEach(((t,e)=>{this[e]=t(a,i,s)}));const n=this._cimMarkerLayer.materialHash,c="function"==typeof n?n(a,i,s,o):n,p=this._materialCache.get(c);if(!p||!y.ok(p.spriteMosaicItem)||!p.spriteMosaicItem)return void d.error(new e("mapview-cim","Encountered an error when binding feature"));const m=p.spriteMosaicItem,f=this._cimMarkerLayer.sizeRatio,g=m.width/m.height*this._scaleX,P=this._cimMarkerLayer.rotateClockwise?this._angle:-this._angle;let x=this._size,k=x*g;const O=this.xOffset,F=this.yOffset;this.xOffset*=this._scaleFactor,this.yOffset*=this._scaleFactor;const L=this._cimMarkerLayer.scaleSymbolsProportionally&&this._cimMarkerLayer.frameHeight?this._size/r.pt2px(this._cimMarkerLayer.frameHeight):1,A=this._outlineWidth*L,I=r.pt2px(this._cimMarkerLayer.referenceSize);let R=0,b=0;const w=this._cimMarkerLayer.anchorPoint;w&&(this._cimMarkerLayer.isAbsoluteAnchorPoint?this._size&&(R=-w.x/(this._size*g),b=w.y/this._size):(R=w.x,b=w.y)),this._sizeOutlineWidth=l.i8888to32(Math.round(Math.min(Math.sqrt(128*k),255)),Math.round(Math.min(Math.sqrt(128*x),255)),Math.round(Math.min(Math.sqrt(128*A),255)),Math.round(Math.min(Math.sqrt(128*I),255))),this.angle=P;const C=Math.round(64*f);this._bitestAndDistRatio=l.i1616to32(this._bitSet,C);const z=m.rect.x+h.SPRITE_PADDING,S=m.rect.y+h.SPRITE_PADDING,B=z+m.width,G=S+m.height;this._texUpperLeft=l.i1616to32(z,S),this._texUpperRight=l.i1616to32(B,S),this._texBottomLeft=l.i1616to32(z,G),this._texBottomRight=l.i1616to32(B,G);const W=_.MarkerMaterialKey.load(this._materialKey);W.sdf=m.sdf,W.pattern=!0,W.textureBinding=m.textureBinding,this._materialKey=W.data,this._anchorX=.5-(.5+R)*m.width/m.width,this._anchorY=.5-(.5+b)*m.height/m.height,k*=f,x*=f,k*=this._scaleFactor,x*=this._scaleFactor,k*=m.rect.width/m.width,x*=m.rect.height/m.height,this._computedWidth=k,this._computedHeight=x,this._applyTransformation(M,u),this.xOffset=O,this.yOffset=F},a}(m(f))}));
