UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 4.8 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{_ as t}from"../../chunks/tslib.es6.js";import i from"../../Viewpoint.js";import e from"../../core/JSONSupport.js";import{property as s}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as o}from"../../core/accessorSupport/decorators/subclass.js";import{toRadian as r}from"../../core/libs/gl-matrix-2/math/common.js";import{fromTranslation as a,rotate as n,translate as p,invert as m}from"../../core/libs/gl-matrix-2/math/mat2d.js";import{create as h}from"../../core/libs/gl-matrix-2/factories/mat2df32.js";import{create as c}from"../../core/libs/gl-matrix-2/factories/mat2df64.js";import{set as l,identity as f,translate as v,rotate as d,multiply as w}from"../../core/libs/gl-matrix-2/math/mat3.js";import{create as u}from"../../core/libs/gl-matrix-2/factories/mat3f32.js";import{copy as x,transformMat2d as j}from"../../core/libs/gl-matrix-2/math/vec2.js";import{fromValues as y}from"../../core/libs/gl-matrix-2/factories/vec2f32.js";import{create as g}from"../../core/libs/gl-matrix-2/factories/vec2f64.js";import{isVec2 as R}from"../../core/libs/gl-matrix-2/types/vec2.js";import _ from"../../geometry/Extent.js";import M from"../../geometry/Point.js";import{getClosestDenormalizedXToReference as b}from"../../geometry/support/normalizeUtils.js";import{copy as z,getWorldWidth as S,getMatrix as N,getResolution as T,getExtent as D,getTransform as V,getTransformNoRotation as A,getWorldScreenWidth as C}from"./viewpointUtils.js";var G;const O=[0,0];let W=G=class extends e{constructor(t){super(t),this._viewpoint2D={center:g(),rotation:0,scale:0,spatialReference:void 0},this.center=[0,0],this.extent=new _,this.id=0,this.inverseTransform=c(),this.resolution=0,this.rotation=0,this.scale=0,this.transform=c(),this.transformNoRotation=c(),this.displayMat3=u(),this.displayViewMat3=u(),this.viewMat3=u(),this.viewMat2d=h(),this.worldScreenWidth=0,this.size=[0,0]}set pixelRatio(t){this._set("pixelRatio",t),this._update()}set size(t){this._set("size",t),this._update()}set viewpoint(t){if(t){const i=this._viewpoint2D,e=t.targetGeometry;i.center[0]=e.x,i.center[1]=e.y,i.rotation=t.rotation,i.scale=t.scale,i.spatialReference=e.spatialReference}this._update()}get visibleArea(){const[t,i]=this.size;return[this.toMap([0,0],0,0),this.toMap([0,0],0,i),this.toMap([0,0],t,i),this.toMap([0,0],t,0)]}copy(t){const i=this.size,e=this.viewpoint;return e&&i?(this.viewpoint=z(e,t.viewpoint),this._set("size",x(i,t.size))):(this.viewpoint=t.viewpoint.clone(),this._set("size",[t.size[0],t.size[1]])),this._set("pixelRatio",t.pixelRatio),this}clone(){return new G({size:this.size,viewpoint:this.viewpoint.clone(),pixelRatio:this.pixelRatio})}toMap(t,i,e){return R(i)?j(t,i,this.inverseTransform):(O[0]=i,O[1]=e,j(t,O,this.inverseTransform))}toScreen(t,i,e){return R(i)?j(t,i,this.transform):(O[0]=i,O[1]=e,j(t,O,this.transform))}toScreenNoRotation(t,i,e){return R(i)?j(t,i,this.transformNoRotation):(O[0]=i,O[1]=e,j(t,O,this.transformNoRotation))}wrapMapCoordinate(t,i){x(t,i);const[e]=i,[s]=this.center,{extent:o,spatialReference:r}=this;let{xmin:a,xmax:n}=o;if(r.isWrappable){const t=S(r)/2;a=Math.max(a,s-t),n=Math.min(n,s+t)}return(e<a||e>n)&&(t[0]=b(e,s,r)),t}getScreenTransform(t,i){const{center:e}=this._viewpoint2D,s=this._get("pixelRatio")||1,o=this._get("size");return N(t,e,o,i,0,s),t}_update(){const{center:t,spatialReference:e,scale:s,rotation:o}=this._viewpoint2D,h=this._get("pixelRatio")||1,c=this._get("size"),u=new i({targetGeometry:new M(t[0],t[1],e),scale:s,rotation:o});if(this._set("viewpoint",u),!c||!e||!s)return;this.resolution=T(u),this.rotation=o,this.scale=s,this.spatialReference=e,x(this.center,t);const j=0!==c[0]?2/c[0]:0,g=0!==c[1]?-2/c[1]:0;l(this.displayMat3,j,0,0,0,g,0,-1,1,1);const R=f(this.viewMat3),_=y(c[0]/2,c[1]/2),b=y(-c[0]/2,-c[1]/2),z=r(o);v(R,R,_),d(R,R,z),v(R,R,b),w(this.displayViewMat3,this.displayMat3,R);const S=a(this.viewMat2d,_);return n(S,S,z),p(S,S,b),D(this.extent,u,c),V(this.transform,u,c,h),m(this.inverseTransform,this.transform),A(this.transformNoRotation,u,c,h),this.worldScreenWidth=C(this.spatialReference,this.resolution),this._set("id",this.id+1),this.notifyChange("visibleArea"),this}};t([s({readOnly:!0})],W.prototype,"id",void 0),t([s({value:1,json:{write:!0}})],W.prototype,"pixelRatio",null),t([s({json:{write:!0}})],W.prototype,"size",null),t([s()],W.prototype,"spatialReference",void 0),t([s({type:i,json:{write:!0}})],W.prototype,"viewpoint",null),t([s({readOnly:!0})],W.prototype,"visibleArea",null),W=G=t([o("esri.views.2d.ViewState")],W);const L=W;export{L as default};