UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 2.67 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";import{convertUnit as t,isProjectedWKT as r,getMetersPerUnit as s,lengthToDegrees as i}from"../core/units.js";import{property as o,subclass as c}from"../core/accessorSupport/decorators.js";import{ensureType as n}from"../core/accessorSupport/ensureType.js";import{getReferenceEllipsoid as a}from"./ellipsoidUtils.js";import{directGeodeticSolver as p}from"./geodesicUtils.js";import l from"./Point.js";import u from"./Polygon.js";import h from"./SpatialReference.js";import{webMercatorToGeographic as d,geographicToWebMercator as m}from"./support/webMercatorUtils.js";import f from"./support/WKIDUnitConversion.js";var g;let b=g=class extends u{constructor(e){super(e),this.geodesic=!1,this.numberOfPoints=60,this.radius=1e3,this.radiusUnit="meters"}initialize(){const e=this.center,o=this.numberOfPoints;if(this.hasZ=e?.hasZ??!1,0!==this.rings.length||!e)return;const c=t(this.radius,this.radiusUnit,"meters"),n=e.spatialReference;let p,l="geographic";if(n.isWebMercator?l="webMercator":(null!=(n.wkid&&f[n.wkid])||(n.wkt2||n.wkt)&&r(n.wkt2||n.wkt))&&(l="projected"),this.geodesic){let t;switch(l){case"webMercator":t=d(e);break;case"projected":console.error("Creating a geodesic circle requires the center to be specified in web mercator or geographic coordinate system");break;case"geographic":t=e}p=this._createGeodesicCircle(t,c,o),"webMercator"===l&&(p=m(p))}else{let t;"webMercator"===l||"projected"===l?t=c/s(e.spatialReference):"geographic"===l&&(t=i(c,"meters",a(e.spatialReference).radius)),p=this._createPlanarCircle(e,t,o)}this.spatialReference=p.spatialReference,this.addRing(p.rings[0])}get center(){return this._get("center")}set center(e){this._set("center",n(l,e))}clone(){const{center:e,numberOfPoints:t,radius:r,radiusUnit:s,geodesic:i}=this;return new g({center:e?.clone(),numberOfPoints:t,radius:r,radiusUnit:s,geodesic:i})}_createGeodesicCircle(e,t,r){const s=[],i=[e.x,e.y];for(let o=0;o<360;o+=360/r){const r=this.hasZ?[0,0,e.z??0]:[0,0];p(r,i,o,t,h.WGS84),s.push(r)}return s.push(s[0]),new u({rings:[s]})}_createPlanarCircle(e,t,r){const s=[],i=2*Math.PI/r;for(let o=0;o<r;++o){const r=i*o,c=[e.x+Math.cos(-r)*t,e.y+Math.sin(-r)*t];this.hasZ&&c.push(e.z??0),s.push(c)}return s.push(s[0]),new u({spatialReference:e.spatialReference,rings:[s]})}};e([o({type:l,useTypeForAutocast:!1,value:null})],b.prototype,"center",null),e([o()],b.prototype,"geodesic",void 0),e([o()],b.prototype,"numberOfPoints",void 0),e([o()],b.prototype,"radius",void 0),e([o()],b.prototype,"radiusUnit",void 0),b=g=e([c("esri.geometry.Circle")],b);const w=b;export{w as default};