Point.js 4.86 KB
// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See https://js.arcgis.com/4.6/esri/copyright.txt for details.
//>>built
define("require exports ../core/tsSupport/declareExtendsHelper ../core/tsSupport/decorateHelper ../core/accessorSupport/decorators ./Geometry ./SpatialReference ./support/spatialReferenceUtils ./support/webMercatorUtils".split(" "),function(l,v,q,f,d,r,t,u,m){function p(d){return d&&("esri.SpatialReference"===d.declaredClass||null!=d.wkid)}var n=[0,0];l=function(l){function b(a,c,b,g,d){a=l.call(this)||this;a.x=0;a.y=0;a.z=void 0;a.m=void 0;a.type="point";return a}q(b,l);h=b;b.copy=function(a,c){c.x=
a.x;c.y=a.y;c.z=a.z;c.m=a.m;c.spatialReference=Object.isFrozen(a.spatialReference)?a.spatialReference:a.spatialReference.clone()};b.distance=function(a,c){var b=a.x-c.x,g=a.y-c.y;a=a.hasZ&&c.hasZ?a.z-c.z:0;return Math.sqrt(b*b+g*g+a*a)};b.prototype.normalizeCtorArgs=function(a,c,b,g,d){var e;Array.isArray(a)?(e=a,d=c,a=e[0],c=e[1],b=e[2],g=e[3]):a&&"object"===typeof a?(e=a,a=null!=e.x?e.x:e.longitude,c=null!=e.y?e.y:e.latitude,b=null!=e.z?e.z:e.altitude,g=e.m,(d=e.spatialReference)&&"esri.SpatialReference"!==
d.declaredClass&&(d=new t(d)),!e.declaredClass&&d&&d.isWebMercator&&null!=e.longitude&&null!=e.latitude&&(c=m.lngLatToXY(e.longitude,e.latitude,n),a=c[0],c=c[1])):p(b)?(d=b,b=null):p(g)&&(d=g,g=null);a={x:a,y:c};null!=d&&(a.spatialReference=d);null!=b&&(a.z=b);null!=g&&(a.m=g);return a};Object.defineProperty(b.prototype,"hasM",{get:function(){return void 0!==this.m},set:function(a){var c=this._get("hasM");a!==c&&(this._set("m",a?0:void 0),this._set("hasM",a))},enumerable:!0,configurable:!0});Object.defineProperty(b.prototype,
"hasZ",{get:function(){return void 0!==this.z},set:function(a){var c=this._get("hasZ");a!==c&&(this._set("z",a?0:void 0),this._set("hasZ",a))},enumerable:!0,configurable:!0});Object.defineProperty(b.prototype,"latitude",{get:function(){var a=this._get("spatialReference");if(a){if(a.isWebMercator)return m.xyToLngLat(this.x,this.y,n)[1];if(a.isWGS84)return this._get("y")}return null},set:function(a){var c=this._get("spatialReference");c&&(c.isWebMercator?this._set("y",m.lngLatToXY(this.x,a,n)[1]):c.isWGS84&&
this._set("y",a),this._set("latitude",a))},enumerable:!0,configurable:!0});Object.defineProperty(b.prototype,"longitude",{get:function(){var a=this._get("spatialReference");if(a){if(a.isWebMercator)return m.xyToLngLat(this._get("x"),this._get("y"),n)[0];if(a.isWGS84)return this._get("x")}return null},set:function(a){var c=this._get("spatialReference");c&&(c.isWebMercator?this._set("x",m.lngLatToXY(a,this._get("y"),n)[0]):c.isWGS84&&this._set("x",a),this._set("longitude",a))},enumerable:!0,configurable:!0});
b.prototype.clone=function(){var a=new h;a.x=this.x;a.y=this.y;a.z=this.z;a.m=this.m;a.spatialReference=this.spatialReference;return a};b.prototype.copy=function(a){h.copy(a,this);return this};b.prototype.equals=function(a){if(!a)return!1;var c=this.x,b=this.y,d=this.z,f=this.m,e=this.spatialReference,l=a.z,n=a.m,h=a.x,k=a.y;a=a.spatialReference;if(!e.equals(a))if(e.isWebMercator&&a.isWGS84)k=m.lngLatToXY(h,k),h=k[0],k=k[1],a=e;else if(e.isWGS84&&a.isWebMercator)k=m.xyToLngLat(h,k),h=k[0],k=k[1],
a=e;else return!1;return c===h&&b===k&&d===l&&f===n&&e.wkid===a.wkid};b.prototype.offset=function(a,c,b){this.x+=a;this.y+=c;null!=b&&this.hasZ&&(this.z+=b);return this};b.prototype.normalize=function(){if(!this.spatialReference)return this;var a=u.getInfo(this.spatialReference);if(!a)return this;var c=this.x,b=a.valid,a=b[0],d=b[1],b=2*d;c>d?(a=Math.ceil(Math.abs(c-d)/b),c-=a*b):c<a&&(a=Math.ceil(Math.abs(c-a)/b),c+=a*b);this._set("x",c);return this};b.prototype.distance=function(a){return h.distance(this,
a)};b.prototype.toArray=function(){var a=this.hasZ,b=this.hasM;return a&&b?[this.x,this.y,this.z,this.m]:a?[this.x,this.y,this.z]:b?[this.x,this.y,this.m]:[this.x,this.y]};b.prototype.toJSON=function(a){return this.write(null,a)};f([d.property({dependsOn:["x","y","z","m","spatialReference"]})],b.prototype,"cache",void 0);f([d.property({type:Boolean,dependsOn:["m"],json:{write:{enabled:!1,overridePolicy:null}}})],b.prototype,"hasM",null);f([d.property({type:Boolean,dependsOn:["z"],json:{write:{enabled:!1,
overridePolicy:null}}})],b.prototype,"hasZ",null);f([d.property({type:Number,dependsOn:["y"]})],b.prototype,"latitude",null);f([d.property({type:Number,dependsOn:["x"]})],b.prototype,"longitude",null);f([d.property({type:Number,json:{write:{isRequired:!0}}})],b.prototype,"x",void 0);f([d.property({type:Number,json:{write:!0}})],b.prototype,"y",void 0);f([d.property({type:Number,json:{write:{overridePolicy:function(){return{enabled:this.hasZ}}}}})],b.prototype,"z",void 0);f([d.property({type:Number,
json:{write:{overridePolicy:function(){return{enabled:this.hasM}}}}})],b.prototype,"m",void 0);return b=h=f([d.subclass("esri.geometry.Point")],b);var h}(d.declared(r));l.prototype.toJSON.isDefaultToJSON=!0;return l});