@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 7.09 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{_ as t,a as e}from"../../../../../../../chunks/tslib.es6.js";import{minMaxZoomPrecisionFactor as i,labelPlacementOffsetPadding as o}from"../../../definitions.js";import{location as s,option as l,uniform as a,define as r,input as n,ComputeVertexInput as d}from"../../GraphShaderModule.js";import{abs as p,min as u,Float as y,floor as m,step as c,Vec3 as f,Mat3 as h,Vec2 as v,ifElse as w,equal as x,greaterThan as b,Bool as V,Vec4 as S,texture2D as g,smoothstep as z,Int as R,bitRShift as j,bitAnd as C}from"../../graph/glsl.js";import{AFeatureShader as O,FeatureVertexInput as A,FeatureFragmentInput as M}from"../shaders/AFeatureShader.js";import{sdfFontSize as H,maxSdfDistance as P,bitsetTextIsBackground as L,bitsetTextIsMapAligned as N}from"../shaders/constants.js";import{distPointTriangle as U,failHittest as T}from"../shaders/hittestUtils.js";import{MosaicInfo as _}from"../shaders/MosaicInfo.js";import{getBit as k}from"../shaders/utils.js";import{VisualVariableColor as I}from"../shaders/VisualVariableColor.js";import{VisualVariableOpacity as D}from"../shaders/VisualVariableOpacity.js";import{VisualVariableRotation as B}from"../shaders/VisualVariableRotation.js";import{VisualVariableSizeMinMaxValue as q}from"../shaders/VisualVariableSizeMinMaxValue.js";import{VisualVariableSizeScaleStops as E}from"../shaders/VisualVariableSizeScaleStops.js";import{VisualVariableSizeStops as F}from"../shaders/VisualVariableSizeStops.js";import{VisualVariableSizeUnitValue as W}from"../shaders/VisualVariableSizeUnitValue.js";import{getVisualVariableSize as G,getVisualVariableRotation as Z}from"../shaders/vvUtils.js";const J=360/254;var K;!function(t){t[t.Color=0]="Color",t[t.Outline=1]="Outline",t[t.Halo=2]="Halo"}(K||(K={}));class Q extends A{}t([s(3,S)],Q.prototype,"color",void 0),t([s(4,v)],Q.prototype,"offset",void 0),t([s(5,v)],Q.prototype,"textureUV",void 0),t([s(6,v)],Q.prototype,"fontAndReferenceSize",void 0),t([s(7,S)],Q.prototype,"outlineColor",void 0),t([s(8,S)],Q.prototype,"haloColor",void 0),t([s(9,v)],Q.prototype,"outlineAndHaloSize",void 0),t([s(10,v)],Q.prototype,"zoomRange",void 0),t([s(11,y)],Q.prototype,"clipAngle",void 0),t([s(12,S)],Q.prototype,"referenceSymbol",void 0),t([s(15,y)],Q.prototype,"visibility",void 0);class X extends d{}t([s(13,v)],X.prototype,"offsetNextVertex1",void 0),t([s(14,v)],X.prototype,"offsetNextVertex2",void 0);class Y extends M{}class $ extends O{constructor(){super(...arguments),this.type="TextShader",this.computeAttributes={offset:["offsetNextVertex1","offsetNextVertex2"]},this.textRenderPassType=K.Color,this.isBackgroundPass=!1,this.isLabel=!1}clipLabel(t,e){const{clipAngle:o,zoomRange:s,visibility:l}=t,a=o.multiply(J),r=p(this.view.rotation.subtract(a)),n=u(new y(360).subtract(r),r);let d=new y(0);const f=m(this.view.currentZoom.multiply(i)).divide(i),h=s.x,v=s.y,w=new y(1).subtract(c(h,f)).multiply(2),x=c(new y(90),n).multiply(2),b=new y(2).multiply(new y(1).subtract(c(f,v)));return d=d.add(e.multiply(w)),d=d.add(e.multiply(x)),d=d.add(b),l&&(d=d.add(l)),d}vertex(t,e){const i=k(t.bitset,L),s=new y(1).subtract(i);let l=t.fontAndReferenceSize[0];const a=t.fontAndReferenceSize[1];let r=l.divide(H);const n=this.textRenderPassType===K.Outline?t.outlineColor:this.textRenderPassType===K.Halo?t.haloColor:this._getVertexColor(t),d=this.view.displayViewScreenMat3.multiply(new f(t.pos,1));let p=t.offset,u=new y(1),m=h.identity(),c=new v(0);if(this.isLabel){if(!t.referenceSymbol)throw new Error("InternalError: Optional attribute 'referenceSymbol' expected for labels");const e=t.referenceSymbol,i=e.xy,s=e.z,l=this._unpackDirection(e.w),a=G(this,t.id,s).divide(2),r=l.multiply(a.add(o));c=i.add(r),p=p.add(c)}else{u=G(this,t.id,a).divide(a),l=l.multiply(u),r=r.multiply(u),p=p.multiply(u),m=Z(this,t.id),p=m.multiply(new f(p,0)).xy}const g=k(t.bitset,N),z=this._getViewRotationMatrix(g).multiply(new f(p,0));let R=this.isLabel?this.clipLabel(t,g):this.clip(t.id,t.zoomRange);R=this.isBackgroundPass?R.add(s.multiply(2)):R.add(i.multiply(2));let j=new y(0);if(this.textRenderPassType===K.Outline){R=R.add(w(x(t.outlineAndHaloSize.x,new y(0)),new y(2),new y(0)));j=new y(t.outlineAndHaloSize.x).divide(r).divide(P)}if(this.textRenderPassType===K.Halo){const e=t.outlineAndHaloSize.x,i=new y(t.outlineAndHaloSize.y);R=R.add(w(x(i,new y(0)),new y(2),new y(0)));j=i.add(e).divide(r).divide(P)}const C=this.isLabel?b(R,new y(1)):new V(!1);return{glPosition:new S(d.xy.add(z.xy),R,1),color:n,size:r,textureUV:t.textureUV.divide(this.mosaicInfo.size),antialiasingWidth:new y(.105*H).divide(l).divide(this.view.pixelRatio),outlineDistanceOffset:j,...this.maybeRunHittest(t,e,{vvSizeAdjustment:u,vvRotation:m,labelOffset:c,labelClipped:C})}}_getViewRotationMatrix(t){const e=this.view.displayViewMat3,i=this.view.displayMat3,o=new y(1).subtract(t);return e.multiply(t).add(i.multiply(o))}fragment(t){const e=new y(2/8),i=new y(1).subtract(e),o=g(this.mosaicInfo.texture,t.textureUV).a;let s=i.subtract(t.outlineDistanceOffset);this.highlight&&(s=s.divide(2));const l=t.antialiasingWidth,a=z(s.subtract(l),s.add(l),o);return this.getFragmentOutput(t.color.multiply(a),t)}hittest(t,e,{vvSizeAdjustment:i,vvRotation:o,labelOffset:s,labelClipped:l}){let a,r,n;this.isLabel?(a=new f(t.offset.add(s),0),r=new f(e.offsetNextVertex1.add(s),0),n=new f(e.offsetNextVertex2.add(s),0)):(a=o.multiply(new f(t.offset.multiply(i),0)),r=o.multiply(new f(e.offsetNextVertex1.multiply(i),0)),n=o.multiply(new f(e.offsetNextVertex2.multiply(i),0)));const{viewMat3:d,tileMat3:p}=this.view,u=d.multiply(p).multiply(new f(t.pos,1)),y=u.add(p.multiply(a)).xy,m=u.add(p.multiply(r)).xy,c=u.add(p.multiply(n)).xy,h=U(this.hittestRequest.position,y.xy,m.xy,c.xy);return this.isLabel?w(l,T(this.hittestRequest),h):h}_unpackDirection(t){const e=new R(t),i=j(e,new R(2)),o=C(e,new R(3));return new v(new y(i).subtract(1),new y(o).subtract(1))}_getVertexColor(t){let e=t.color;if(this.visualVariableColor){const i=this.storage.getColorValue(t.id);e=this.visualVariableColor.getColor(i,t.color,new V(!1))}if(this.visualVariableOpacity){const i=this.storage.getOpacityValue(t.id),o=this.visualVariableOpacity.getOpacity(i);e=e.multiply(o)}return e}}t([l(I)],$.prototype,"visualVariableColor",void 0),t([l(D)],$.prototype,"visualVariableOpacity",void 0),t([l(B)],$.prototype,"visualVariableRotation",void 0),t([l(q)],$.prototype,"visualVariableSizeMinMaxValue",void 0),t([l(E)],$.prototype,"visualVariableSizeScaleStops",void 0),t([l(F)],$.prototype,"visualVariableSizeStops",void 0),t([l(W)],$.prototype,"visualVariableSizeUnitValue",void 0),t([a(_)],$.prototype,"mosaicInfo",void 0),t([r],$.prototype,"textRenderPassType",void 0),t([r],$.prototype,"isBackgroundPass",void 0),t([r],$.prototype,"isLabel",void 0),t([e(0,n(Q)),e(1,n(X))],$.prototype,"vertex",null),t([e(0,n(Y))],$.prototype,"fragment",null);export{Y as TextFragmentInput,K as TextRenderPassType,$ as TextShader,Q as TextVertexInput};