@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 5.22 kB
JavaScript
/*
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 e from"../core/Accessor.js";import r from"../core/Logger.js";import{property as s}from"../core/accessorSupport/decorators/property.js";import{cast as i}from"../core/accessorSupport/decorators/cast.js";import"../core/has.js";import"../core/RandomLCG.js";import{reader as o}from"../core/accessorSupport/decorators/reader.js";import{subclass as l}from"../core/accessorSupport/decorators/subclass.js";import{writer as a}from"../core/accessorSupport/decorators/writer.js";import{ensureNumber as n}from"../core/accessorSupport/ensureType.js";import u from"./Geometry.js";import p from"./SpatialReference.js";import{getLatitude as c,getLongitude as h,distance as d}from"./support/pointUtils.js";import{getInfo as m}from"./support/spatialReferenceUtils.js";import{lngLatToXY as y,xyToLngLat as f}from"./support/webMercatorUtils.js";var g;const w=[0,0];function x(t){return t&&("esri.geometry.SpatialReference"===t.declaredClass||null!=t.wkid)}let _=g=class extends u{static copy(t,r){r._set("x",t._get("x")),r._set("y",t._get("y")),r._set("z",t._get("z")),r._set("m",t._get("m"));const s=t._get("spatialReference");r._set("spatialReference",e.isFrozen(s)?s:s.clone())}constructor(...t){super(...t),this.x=0,this.y=0,this.z=void 0,this.m=void 0,this.type="point"}normalizeCtorArgs(t,e,s,i,o){let l;if(Array.isArray(t))l=t,o=e,t=l[0],e=l[1],s=l[2],i=l[3];else if(t&&"object"==typeof t){if(l=t,t=null!=l.x?l.x:l.longitude,e=null!=l.y?l.y:l.latitude,s=l.z,i=l.m,(o=l.spatialReference)&&"esri.geometry.SpatialReference"!==o.declaredClass&&(o=new p(o)),null!=l.longitude||null!=l.latitude)if(null==l.longitude)r.getLogger(this).warn(".longitude=","Latitude was defined without longitude");else if(null==l.latitude)r.getLogger(this).warn(".latitude=","Longitude was defined without latitude");else if(!l.declaredClass&&o?.isWebMercator){const r=y(l.longitude,l.latitude,w);t=r[0],e=r[1]}}else x(s)?(o=s,s=null):x(i)&&(o=i,i=null);const a={x:t,y:e};return null==a.x&&null!=a.y?r.getLogger(this).warn(".y=","Y coordinate was defined without an X coordinate"):null==a.y&&null!=a.x&&r.getLogger(this).warn(".x=","X coordinate was defined without a Y coordinate"),null!=o&&(a.spatialReference=o),null!=s&&(a.z=s),null!=i&&(a.m=i),a}get cache(){return this.commitProperty("x"),this.commitProperty("y"),this.commitProperty("z"),this.commitProperty("m"),this.commitProperty("spatialReference"),{}}get hasM(){return void 0!==this.m}set hasM(t){t!==(void 0!==this._get("m"))&&(this._set("m",t?0:void 0),this._set("hasM",t))}get hasZ(){return void 0!==this.z}set hasZ(t){t!==(void 0!==this._get("z"))&&(this._set("z",t?0:void 0),this._set("hasZ",t))}get latitude(){return c(this)}set latitude(t){const{spatialReference:e,x:r}=this;null!=t&&e&&(e.isWebMercator?this._set("y",y(r,t,w)[1]):e.isGeographic&&this._set("y",t),this._set("latitude",t))}get longitude(){return h(this)}set longitude(t){const{y:e,spatialReference:r}=this;null!=t&&r&&(r.isWebMercator?this._set("x",y(t,e,w)[0]):r.isGeographic&&this._set("x",t),this._set("longitude",t))}writeX(t,e,r){e[r]=isNaN(t)?"NaN":t}readX(t){return"string"==typeof t?NaN:t}clone(){const t=new g;return t.x=this.x,t.y=this.y,t.z=this.z,t.m=this.m,t.spatialReference=this.spatialReference,t}copy(t){return g.copy(t,this),this}equals(t){if(null==t)return!1;const{x:e,y:r,z:s,m:i,spatialReference:o}=this,{z:l,m:a}=t;let{x:n,y:u,spatialReference:p}=t;if(!o.equals(p))if(o.isWebMercator&&p.isWGS84)[n,u]=y(n,u),p=o;else{if(!o.isWGS84||!p.isWebMercator)return!1;[n,u]=f(n,u),p=o}return e===n&&r===u&&s===l&&i===a&&o.wkid===p.wkid}offset(t,e,r){return this.x+=t,this.y+=e,null!=r&&(this.z=(this.z??0)+r),this}normalize(){if(!this.spatialReference)return this;const t=m(this.spatialReference);if(!t)return this;let e=this.x;const[r,s]=t.valid,i=2*s;let o;return e>s?(o=Math.ceil(Math.abs(e-s)/i),e-=o*i):e<r&&(o=Math.ceil(Math.abs(e-r)/i),e+=o*i),this._set("x",e),this}distance(t){return d(this,t)}toArray(){const t=this.hasZ,e=this.hasM;return t&&e?[this.x,this.y,this.z,this.m]:t?[this.x,this.y,this.z]:e?[this.x,this.y,this.m]:[this.x,this.y]}toJSON(t){return this.write({},t)}};t([s({readOnly:!0})],_.prototype,"cache",null),t([s({type:Boolean,json:{read:!1,write:{enabled:!1,overridePolicy:null}}})],_.prototype,"hasM",null),t([s({type:Boolean,json:{read:!1,write:{enabled:!1,overridePolicy:null}}})],_.prototype,"hasZ",null),t([s({type:Number})],_.prototype,"latitude",null),t([s({type:Number})],_.prototype,"longitude",null),t([s({type:Number,json:{type:[Number,String],write:{isRequired:!0,allowNull:!0}}}),i((t=>isNaN(t)?t:n(t)))],_.prototype,"x",void 0),t([a("x")],_.prototype,"writeX",null),t([o("x")],_.prototype,"readX",null),t([s({type:Number,json:{write:!0}})],_.prototype,"y",void 0),t([s({type:Number,json:{write:{overridePolicy(){return{enabled:this.hasZ}}}}})],_.prototype,"z",void 0),t([s({type:Number,json:{write:{overridePolicy(){return{enabled:this.hasM}}}}})],_.prototype,"m",void 0),_=g=t([l("esri.geometry.Point")],_),_.prototype.toJSON.isDefaultToJSON=!0;const j=_;export{j as default};