UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 4.05 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import e from"../../../core/Handles.js";import{deg2rad as t}from"../../../core/mathUtils.js";import{destroyMaybe as r}from"../../../core/maybe.js";import{watch as i,initial as s}from"../../../core/reactiveUtils.js";import{convertUnit as n}from"../../../core/unitUtils.js";import{fromRotation as o,translate as a,rotate as l,scaleByVec2 as m}from"../../../core/libs/gl-matrix-2/math/mat3.js";import{create as c}from"../../../core/libs/gl-matrix-2/factories/mat3f32.js";import{set as h,sub as p,scale as d,rotate as u}from"../../../core/libs/gl-matrix-2/math/vec2.js";import{ZEROS as f}from"../../../core/libs/gl-matrix-2/factories/vec2f32.js";import{create as j}from"../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{isLoadedOrLoadFor as _,project as g}from"../../../geometry/projectionUtils.js";import{getClosestDenormalizedXToReference as C}from"../../../geometry/support/normalizeUtils.js";import{getResolutionForScale as R}from"../../../geometry/support/scaleUtils.js";import{equals as U}from"../../../geometry/support/spatialReferenceUtils.js";import{DisplayObject as v}from"../engine/DisplayObject.js";import{WGLDrawPhase as y}from"../engine/webgl/enums.js";import{GridTechnique as S}from"../engine/webgl/shaderGraph/techniques/grid/GridTechnique.js";import{minimumPixelsPerStrideForDisplayWhenScalingOff as b}from"./constants.js";import{measureMetersPerUnitAtReferencePoint as L,getScaleFactor as P}from"./gridUtils.js";const x=j();class w extends v{constructor(){super(),this._handles=new e,this._projectedCenter=null,this._metersPerSRUnit=null,this._technique=new S,this._grid=null,this.visible=!0}destroy(){this._handles=r(this._handles),this._technique.shutdown()}get grid(){return this._grid}set grid(e){this._grid=e,this._handles.removeAll(),this._handles.add([i((()=>e?.center),(()=>{this._projectedCenter=null}),s),i((()=>[e?.center,e?.dynamicScaling,e?.majorLineColor,e?.majorLineInterval,e?.minorLineColor,e?.rotateWithMap,e?.rotation,e?.spacing,e?.units]),(()=>this.requestRender()),s)])}_createTransforms(){return{displayViewScreenMat3:c()}}doRender(e){if(e.drawPhase!==y.MAP||null==this.grid||!this.visible)return;const{spacing:t,units:r,majorLineInterval:i,dynamicScaling:s,majorLineColor:o,minorLineColor:a}=this.grid;if(0===t)return;if(this._updateDerivedValues(e),null==this._projectedCenter||null==this._metersPerSRUnit)return;const{scale:l,spatialReference:m}=e.state,c=n(t,r,"meters"),h=this._metersPerSRUnit*R(l,m),p=c/h;if(!s&&p<b)return;const d=c*P(i,p,s);this._updateTransform(e,h,d),this._technique.render(e,{transform:{dvs:this.transforms.displayViewScreenMat3},config:{pxPerCell:d/h,minorLineColor:q(a),majorLineColor:q(o),majorLineInterval:i,halfWidth:.25,aaWidth:.5}})}_updateDerivedValues(e){if(!this.grid)return;const{center:t}=this.grid,{spatialReference:r}=e.state;this._projectedCenter&&U(this._projectedCenter.spatialReference,r)||(this._metersPerSRUnit=null,U(t.spatialReference,r)?this._projectedCenter=t:_(t.spatialReference,r)?this._projectedCenter=g(t,r):this.requestRender()),null==this._metersPerSRUnit&&null!=this._projectedCenter&&(this._metersPerSRUnit=L(this._projectedCenter))}_updateTransform(e,r,i){const{grid:s}=this,{center:n,rotation:c,size:j,spatialReference:_}=e.state;if(null==s||null==this._projectedCenter||null==this._metersPerSRUnit)return;const g=r*(j[0]/2),R=r*(j[1]/2),U=this._metersPerSRUnit/i,v=this._projectedCenter,y=t(s.rotation),S=t(c),b=this.transforms.displayViewScreenMat3;o(b,-y);const L=_.isWrappable?C(v.x,n[0],_):v.x,P=h(x,L,v.y),w=p(x,n,P);d(w,w,U),s.rotateWithMap||u(w,w,f,-S),u(w,w,f,-y),d(w,w,1/s.majorLineInterval),M(w,w),d(w,w,s.majorLineInterval),u(w,w,f,y),a(b,b,w),s.rotateWithMap&&l(b,b,S);const q=h(x,g/i,R/i);m(b,b,q)}}function M(e,t){return e[0]=t[0]-Math.trunc(t[0]),e[1]=t[1]-Math.trunc(t[1]),e}function q(e){const[t,r,i,s]=e.toArray().map((e=>e/255));return[t*s,r*s,i*s,s]}export{w as default};