@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 2.1 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as t}from"tslib";import{Clonable as e}from"../../core/Clonable.js";import{rad2deg as o,scale as r}from"../../core/mathUtils.js";import{createScreenPoint as n}from"../../core/screenUtils.js";import{property as i,subclass as s}from"../../core/accessorSupport/decorators.js";import{toRadian as l}from"../../core/libs/gl-matrix-2/math/common.js";import a from"../../geometry/Extent.js";import m from"../../geometry/Polygon.js";import{projectOrLoad as c}from"../../geometry/projectionUtils.js";import{GeoreferenceBaseMixin as x}from"./GeoreferenceBaseMixin.js";let p=class extends(x(e)){constructor(t){super(t),this.extent=null,this.rotation=0,this.type="extent-and-rotation"}get coords(){if(null==this.extent)return null;const{xmin:t,ymin:e,xmax:o,ymax:r,spatialReference:n}=this.extent;let i;if(this.rotation){const{x:n,y:s}=this.extent.center,l=u(n,s,this.rotation);i=[l(t,e),l(t,r),l(o,r),l(o,e)],i.push(i[0])}else i=[[t,e],[t,r],[o,r],[o,e],[t,e]];return new m({rings:[i],spatialReference:n})}set coords(t){if(null==t||null==this.extent)return;const e=this.extent.spatialReference;if(t=this.projectOrWarn(t,e),null==t?.extent)return;const{rings:[[r,n,i]],extent:{center:{x:s,y:l}}}=t,m=o(Math.PI/2-Math.atan2(n[1]-r[1],n[0]-r[0])),c=u(s,l,-m),[x,p]=c(r[0],r[1]),[f,y]=c(i[0],i[1]);this.extent=new a({xmin:x,ymin:p,xmax:f,ymax:y,spatialReference:e}),this.rotation=m}toSourceNormalized(t){const{extent:e,rotation:o}=this;if(null==t||null==e)return null;const{xmin:i,ymin:s,xmax:l,ymax:a,center:m,spatialReference:x}=e;t=t.normalize();const p=c(t,x).geometry;if(null==p)return null;let f=p.x,y=p.y;return o&&([f,y]=u(m.x,m.y,-o)(f,y)),n(r(f,i,l,0,1),r(y,a,s,0,1))}};function u(t,e,o){const r=l(o),n=Math.cos(r),i=Math.sin(r);return(o,r)=>[n*(o-t)+i*(r-e)+t,n*(r-e)-i*(o-t)+e]}t([i({clonable:!1})],p.prototype,"coords",null),t([i({type:a})],p.prototype,"extent",void 0),t([i({type:Number})],p.prototype,"rotation",void 0),p=t([s("esri.layers.support.ExtentAndRotationGeoreference")],p);const f=p;export{f as default};