Point.js 5.3 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. import{_ as e}from"../chunks/tslib.es6.js";import t from"../core/Logger.js";import{isNone as r}from"../core/maybe.js";import{property as s}from"../core/accessorSupport/decorators/property.js";import"../core/arrayUtils.js";import{cast as i}from"../core/accessorSupport/decorators/cast.js";import{reader as o}from"../core/accessorSupport/decorators/reader.js";import{subclass as a}from"../core/accessorSupport/decorators/subclass.js";import{writer as l}from"../core/accessorSupport/decorators/writer.js";import{ensureNumber as n}from"../core/accessorSupport/ensureType.js";import c from"./Geometry.js";import u from"./SpatialReference.js";import{distance as p}from"./support/pointUtils.js";import{getInfo as h}from"./support/spatialReferenceUtils.js";import{lngLatToXY as d,xyToLngLat as y}from"./support/webMercatorUtils.js";var m;const f=[0,0];function g(e){return e&&("esri.geometry.SpatialReference"===e.declaredClass||null!=e.wkid)}let x=m=class extends c{constructor(...e){super(...e),this.x=0,this.y=0,this.z=void 0,this.m=void 0,this.type="point"}static copy(e,t){t._set("x",e._get("x")),t._set("y",e._get("y")),t._set("z",e._get("z")),t._set("m",e._get("m"));const r=e._get("spatialReference");t._set("spatialReference",Object.isFrozen(r)?r:r.clone())}normalizeCtorArgs(e,r,s,i,o){let a;if(Array.isArray(e))a=e,o=r,e=a[0],r=a[1],s=a[2],i=a[3];else if(e&&"object"==typeof e){if(a=e,e=null!=a.x?a.x:a.longitude,r=null!=a.y?a.y:a.latitude,s=a.z,i=a.m,(o=a.spatialReference)&&"esri.geometry.SpatialReference"!==o.declaredClass&&(o=new u(o)),null!=a.longitude||null!=a.latitude)if(null==a.longitude)t.getLogger(this.declaredClass).warn(".longitude=","Latitude was defined without longitude");else if(null==a.latitude)t.getLogger(this.declaredClass).warn(".latitude=","Longitude was defined without latitude");else if(!a.declaredClass&&o&&o.isWebMercator){const t=d(a.longitude,a.latitude,f);e=t[0],r=t[1]}}else g(s)?(o=s,s=null):g(i)&&(o=i,i=null);const l={x:e,y:r};return null==l.x&&null!=l.y?t.getLogger(this.declaredClass).warn(".y=","Y coordinate was defined without an X coordinate"):null==l.y&&null!=l.x&&t.getLogger(this.declaredClass).warn(".x=","X coordinate was defined without a Y coordinate"),null!=o&&(l.spatialReference=o),null!=s&&(l.z=s),null!=i&&(l.m=i),l}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(e){e!==(void 0!==this._get("m"))&&(this._set("m",e?0:void 0),this._set("hasM",e))}get hasZ(){return void 0!==this.z}set hasZ(e){e!==(void 0!==this._get("z"))&&(this._set("z",e?0:void 0),this._set("hasZ",e))}get latitude(){const{spatialReference:e,x:t,y:r}=this;if(e){if(e.isWebMercator)return y(t,r,f)[1];if(e.isGeographic)return r}return null}set latitude(e){const{spatialReference:t,x:r}=this;null!=e&&t&&(t.isWebMercator?this._set("y",d(r,e,f)[1]):t.isGeographic&&this._set("y",e),this._set("latitude",e))}get longitude(){const{x:e,y:t,spatialReference:r}=this;if(r){if(r.isWebMercator)return y(e,t,f)[0];if(r.isGeographic)return e}return null}set longitude(e){const{y:t,spatialReference:r}=this;null!=e&&r&&(r.isWebMercator?this._set("x",d(e,t,f)[0]):r.isGeographic&&this._set("x",e),this._set("longitude",e))}writeX(e,t,r){t[r]=isNaN(e)?"NaN":e}readX(e){return"string"==typeof e?NaN:e}clone(){const e=new m;return e.x=this.x,e.y=this.y,e.z=this.z,e.m=this.m,e.spatialReference=this.spatialReference,e}copy(e){return m.copy(e,this),this}equals(e){if(r(e))return!1;const{x:t,y:s,z:i,m:o,spatialReference:a}=this,{z:l,m:n}=e;let{x:c,y:u,spatialReference:p}=e;if(!a.equals(p))if(a.isWebMercator&&p.isWGS84)[c,u]=d(c,u),p=a;else{if(!a.isWGS84||!p.isWebMercator)return!1;[c,u]=y(c,u),p=a}return t===c&&s===u&&i===l&&o===n&&a.wkid===p.wkid}offset(e,t,r){return this.x+=e,this.y+=t,null!=r&&(this.z=(this.z??0)+r),this}normalize(){if(!this.spatialReference)return this;const e=h(this.spatialReference);if(!e)return this;let t=this.x;const[r,s]=e.valid,i=2*s;let o;return t>s?(o=Math.ceil(Math.abs(t-s)/i),t-=o*i):t<r&&(o=Math.ceil(Math.abs(t-r)/i),t+=o*i),this._set("x",t),this}distance(e){return p(this,e)}toArray(){const e=this.hasZ,t=this.hasM;return e&&t?[this.x,this.y,this.z,this.m]:e?[this.x,this.y,this.z]:t?[this.x,this.y,this.m]:[this.x,this.y]}toJSON(e){return this.write({},e)}};e([s({readOnly:!0})],x.prototype,"cache",null),e([s({type:Boolean,json:{read:!1,write:{enabled:!1,overridePolicy:null}}})],x.prototype,"hasM",null),e([s({type:Boolean,json:{read:!1,write:{enabled:!1,overridePolicy:null}}})],x.prototype,"hasZ",null),e([s({type:Number})],x.prototype,"latitude",null),e([s({type:Number})],x.prototype,"longitude",null),e([s({type:Number,json:{type:[Number,String],write:{isRequired:!0,allowNull:!0}}}),i((e=>isNaN(e)?e:n(e)))],x.prototype,"x",void 0),e([l("x")],x.prototype,"writeX",null),e([o("x")],x.prototype,"readX",null),e([s({type:Number,json:{write:!0}})],x.prototype,"y",void 0),e([s({type:Number,json:{write:{overridePolicy(){return{enabled:this.hasZ}}}}})],x.prototype,"z",void 0),e([s({type:Number,json:{write:{overridePolicy(){return{enabled:this.hasM}}}}})],x.prototype,"m",void 0),x=m=e([a("esri.geometry.Point")],x),x.prototype.toJSON.isDefaultToJSON=!0;const w=x;export{w as default};