text: // All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  // See https://js.arcgis.com/4.3/esri/copyright.txt for details.
  //>>built
  define("../../../../core/declare ../../../../core/watchUtils ../../support/PreallocArray ../../lib/glMatrix ../../webgl-engine/lib/Util ../../webgl-engine/materials/HUDMaterial".split(" "),function(Z,aa,N,k,U,ba){function ca(a,b){return b.posView-a.posView}var E=k.mat4d,d=k.vec3d,r=k.vec2d,g=k.vec4d,G=U.lerp,V=U.VertexAttrConstants,H=[[-1,-1],[1,-1],[1,1],[-1,1]],O=g.create(),F=g.create(),P=g.create(),D=g.create(),K=r.create(),L=r.create(),M=g.create(),W=g.create(),da=g.create(),I=d.create(),R=r.create(),
  S=g.create(),ea=d.create(),fa=d.create(),X=E.create(),ga=d.create(),Q=g.create(),J=new N(100);k=function(a,b){this.constructor=a;this.releaser=b;this.list=[];this.currentIndex=0};k.prototype.alloc=function(){this.currentIndex>=this.list.length&&this.list.push(this.constructor.apply(this,arguments));return this.list[this.currentIndex++]};k.prototype.freeAll=function(a){a=this.currentIndex;for(var b=this.releaser,l=this.list;0<=--a;)b(l[a]);this.currentIndex=0};var Y=new k(function(){return{labelGraphics:null,
  c3dGraphic:null,positions:[r.create(),r.create(),r.create(),r.create()],xMin:0,xMax:0,yMin:0,yMax:0,posView:0,layerView:null,labelId:0}},function(a){a.layerGraphics=null;a.c3dGraphic=null;a.layerView=null});return Z(null,{constructor:function(a){this.layerViews=[];this.view=a;this.stage=a._stage;this._deconflictTimeoutId=0;this._cameraListener=aa.on(a,"navigation","targetViewChanged",this._targetViewChanged.bind(this));this._viewReadyWatcher=a.watch("ready",function(a){!a&&this._deconflictTimeoutId&&
  (clearTimeout(this._deconflictTimeoutId),this._deconflictTimeoutId=0)}.bind(this))},destroy:function(){this._cameraListener.remove();0!==this._deconflictTimeoutId&&(clearTimeout(this._deconflictTimeoutId),this._deconflictTimeoutId=0);this._viewReadyWatcher.remove()},addSceneServiceLayerView:function(a){this.layerViews.push(a)},setDirty:function(){this._deconflictLabelsTimeout(10)},setInitialLabelGraphicState:function(a){a.setVisibilityFlag("VISIBILITY_LABELMANAGER",!1)},removeSceneServiceLayerView:function(a){a=
  this.layerViews.indexOf(a);0<=a&&this.layerViews.splice(a,1)},_drawPoly:function(a,b,l){a.beginPath();a.lineWidth="1";a.strokeStyle=l;a.moveTo(b[0][0],b[0][1]);for(l=1;4>l;l++)a.lineTo(b[l][0],b[l][1]),a.stroke();a.lineTo(b[0][0],b[0][1]);a.stroke();a.closePath()},_tmp_vec:r.create(),_doesIntersectExistingPoly:function(a){var b=this._tmp_vec,l=a.positions,d={},n,t,u,g,x,v,z,k,A,q,p,y,f,e;for(n=Math.floor(a.xMin/this._accBinsSizeX);n<=Math.floor(a.xMax/this._accBinsSizeX);n++)if(!(0>n||n>=this._accBinsNumX))for(t=
  Math.floor(a.yMin/this._accBinsSizeY);t<=Math.floor(a.yMax/this._accBinsSizeY);t++)if(!(0>t||t>=this._accBinsNumY))a:for(u=this._accBins[n][t],g=0;g<u.length;g++)if(x=u.data[g],null==d[x.labelId]){d[x.labelId]=!0;x=x.positions;this._accNumTests++;for(k=0;2>k;k++)b:for(v=0===k?l:x,z=0===k?x:l,f=0;4>f;f++){A=v[f];q=v[(f+1)%4];p=v[(f+2)%4];b[0]=q[0]-A[0];b[1]=q[1]-A[1];q=r.normalize(b);y=q[1];q[1]=q[0];q[0]=-y;y=q[0]*A[0]+q[1]*A[1];e=q[0]*p[0]+q[1]*p[1]<y;for(A=0;4>A;A++)if(p=z[A],p=q[0]*p[0]+q[1]*p[1],
  e&&p<y||!e&&p>y)continue b;continue a}return!0}return!1},_accBinsNumX:15,_accBinsNumY:20,_accBinsSizeX:0,_accBinsSizeY:0,_accBins:null,_accNumTests:0,_initBins:function(a,b){var l,d,n;if(null==this._accBins)for(this._accBins=[],l=0;l<this._accBinsNumX;l++)for(this._accBins.push([]),n=this._accBins[this._accBins.length-1],d=0;d<this._accBinsNumY;d++)n.push(new N(10));for(l=0;l<this._accBinsNumX;l++)for(d=0;d<this._accBinsNumY;d++)this._accBins[l][d].clear();this._accBinsSizeX=a/this._accBinsNumX;this._accBinsSizeY=
  b/this._accBinsNumY;this._accNumTests=0},_addToBins:function(a){var b,d;for(b=Math.floor(a.xMin/this._accBinsSizeX);b<=Math.floor(a.xMax/this._accBinsSizeX);b++)if(!(0>b||b>=this._accBinsNumX))for(d=Math.floor(a.yMin/this._accBinsSizeY);d<=Math.floor(a.yMax/this._accBinsSizeY);d++)0>d||d>=this._accBinsNumY||this._accBins[b][d].push(a)},_accDrawDebug:function(a){var b=[r.create(),r.create(),r.create(),r.create()],d=0,g,n,t,u,k,x,v;for(g=0;g<this._accBinsNumX;g++)for(n=0;n<this._accBinsNumY;n++)t=this._accBins[g][n],
  d+=t.length,u=g*this._accBinsSizeX,k=(g+1)*this._accBinsSizeX,x=n*this._accBinsSizeY,v=(n+1)*this._accBinsSizeY,b[0][0]=u,b[0][1]=x,b[1][0]=k,b[1][1]=x,b[2][0]=k,b[2][1]=v,b[3][0]=u,b[3][1]=v,a.fillText(t.length.toFixed(),u+5,x+15),this._drawPoly(a,b,"blue");a.fillText("total totalShownLabels: "+d,70,40)},_targetViewChanged:function(){this._deconflictLabelsTimeout()},_deconflictLabelsTimeout:function(a){a=a||200;0===this._deconflictTimeoutId&&(this._deconflictTimeoutId=setTimeout(this._deconflictLabels.bind(this),
  a))},_deconflictLabels:function(){var a=this.view;clearTimeout(this._deconflictTimeoutId);this._deconflictTimeoutId=0;Y.freeAll();var b=a.navigation.targetCamera,l=b.viewMatrix,k=1/Math.tan(b.fovX/2),n=b.projectionMatrix,t=b.fullWidth,u=b.fullHeight;J.clear();for(var T={},x=!1,v=0;v<this.layerViews.length;v++){var z=this.layerViews[v];if(null!=z.layerLabelsEnabled&&z.layerLabelsEnabled()&&null!=z.getGraphics3DGraphics&&null!=z.getGraphics3DGraphicsKeys){x||(this._initBins(t,u),x=!0);for(var N=z.getGraphics3DGraphics(),
  A=z.getGraphics3DGraphicsKeys(),q=0;q<A.length;q++){var p=N[A[q]];if(!(null==p._labelGraphics||1>p._labelGraphics.length)&&p.areVisibilityFlagsSet(void 0,"VISIBILITY_LABELMANAGER")){var y=p._labelGraphics[0],f=y.stageObject,e=f.getGeometryRecord(0);if(null!=e){var h=e.materials[0];if(null!=h&&h instanceof ba&&null!=e.origin){var a=l,f=f.getCenter(),c=e.origin.vec3;g.set4(f[0]-c[0],f[1]-c[1],f[2]-c[2],1,O);E.translate(a,c,X);a=X;E.multiplyVec4(a,O,F);for(var B=e.geometry.getData().getVertexAttr()[V.AUXPOS1],
  c=0;3>c;c++)F[c]+=B.data[c];E.multiplyVec4(n,F,P);g.scale(P,1/Math.abs(P[3]),D);r.set2(G(0,t,.5+.5*D[0]),G(0,u,.5+.5*D[1]),R);if(-1>D[0]||-1>D[1]||-1>D[2]||1<=D[0]||1<=D[1]){a=!1;for(e=0;e<p._labelGraphics.length;e++)a=a||p._labelGraphics[e].setVisibilityFlag("VISIBILITY_LABELMANAGER",!1);a&&(T[z]=!0)}else{c=h.getParams();h=e.geometry.getData().getVertexAttr()[V.SIZE].data;r.subtract(c.anchorPos,[.5,.5],K);r.scale(c.screenOffset,.5,L);e=Y.alloc();if(c.direction){var m=d.set3(y.geometry.normal[0],
  y.geometry.normal[1],y.geometry.normal[2],ea),B=d.normalize(d.subtract(b.eye,b.center,M),M),w=d.normalize(d.set(c.direction,fa)),C,y=0;d.scale(w,d.dot(w,B),I);d.subtract(B,I,I);d.normalize(I);C=Math.abs(d.dot(I,m));.985>Math.abs(d.dot(B,w))&&.5>C?.422>C?(B=w,C=m,y=.5):(B=w,C=ga,d.cross(w,I,C),y=d.dot(C,m)/2):(B=w,C=d.normalize(d.cross(m,w)));m=d.dist(b.eye,f)/k/b.width*2;f=m*c.screenMinMaxSize[0];w=m*c.screenMinMaxSize[1];c.worldScale?(m=1,0<f&&f>h[1]&&(m=f/h[1]),0<w&&h[1]>w&&(m=w/h[1])):m=.5*P[3]/
  t;for(c=0;4>c;c++)g.set(O,Q),d.add(Q,d.scale(B,H[c][0]*h[0]*m,W)),d.add(Q,d.scale(C,(H[c][1]+y)*h[1]*m,da)),E.multiplyVec4(a,Q,M),f=E.multiplyVec4(n,M,W),g.scale(f,1/Math.abs(f[3]),f),e.positions[c][0]=G(0,t,.5+.5*f[0]),e.positions[c][1]=u-G(0,u,.5+.5*f[1])}else if(c.worldScale)for(m=d.dist(b.eye,f)/k/b.width*2,f=m*c.screenMinMaxSize[0],w=m*c.screenMinMaxSize[1],m=1,0<f&&f>h[1]&&(m=f/h[1]),0<w&&h[1]>w&&(m=w/h[1]),c=0;4>c;c++)S[0]=F[0]+(.5*H[c][0]-K[0])*h[0]*m,S[1]=F[1]+(.5*H[c][1]-K[1])*h[1]*m,f=
  E.multiplyVec4(n,S,M),g.scale(f,1/Math.abs(f[3]),f),e.positions[c][0]=G(0,t,.5+.5*f[0])+L[0],e.positions[c][1]=u-G(0,u,.5+.5*f[1])-L[1];else for(a=d.dist(b.eye,O),c=0;4>c;c++)e.positions[c][0]=R[0]+(.5*H[c][0]-K[0])*h[0]+L[0],e.positions[c][1]=u-R[1]+(.5*H[c][1]+K[1])*h[1]-L[1];a=F[2];p.areVisibilityFlagsSet("VISIBILITY_LABELMANAGER",void 0)&&(a*=.7);e.labelId=J.length;e.xMin=Number.MAX_VALUE;e.yMin=Number.MAX_VALUE;e.xMax=-Number.MAX_VALUE;e.yMax=-Number.MAX_VALUE;for(h=0;4>h;h++)e.xMin=Math.min(e.positions[h][0],
  e.xMin),e.yMin=Math.min(e.positions[h][1],e.yMin),e.xMax=Math.max(e.positions[h][0],e.xMax),e.yMax=Math.max(e.positions[h][1],e.yMax);e.labelGraphics=p._labelGraphics;e.c3dGraphic=p;e.posView=a;e.layerView=z;J.push(e)}}}}}}}J.sort(ca);for(v=0;v<J.length;v++){b=J.data[v];a=!1;z=b.layerView;if(this._doesIntersectExistingPoly(b))for(c=0;c<b.labelGraphics.length;c++)a=a||b.labelGraphics[c].setVisibilityFlag("VISIBILITY_LABELMANAGER",!1);else for(this._addToBins(b),c=0;c<b.labelGraphics.length;c++)a=a||
  b.labelGraphics[c].setVisibilityFlag("VISIBILITY_LABELMANAGER",!0);a&&b.c3dGraphic.isDraped()&&(T[z]=!0);Object.keys(T).forEach(function(a){a.emit&&a.emit("draped-data-change")})}}})});