@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 2.36 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as t}from"tslib";import{clone as e}from"../core/lang.js";import{property as s,subclass as r}from"../core/accessorSupport/decorators.js";import i from"./Extent.js";import o from"./Geometry.js";import n from"./Point.js";import p from"./SpatialReference.js";import{getMultipointExtent as a}from"./support/extentUtils.js";import{updateSupportFromPoint as h}from"./support/zmUtils.js";import{writer as l}from"../core/accessorSupport/decorators/writer.js";var c;function u(t){if(!t)return;let{points:e,hasM:s,hasZ:r,spatialReference:i}=t;switch(e??=[],e?.at(0)?.length){case 4:r??=!0,s??=!0;break;case 3:r??=!0!==s,s??=!r;break;default:r??=!1,s??=!1}return i??=p.WGS84,{...t,hasM:s,hasZ:r,points:e,spatialReference:i}}let m=c=class extends o{constructor(t){super(u(t)),this.points=[],this.type="multipoint"}get cache(){return this.commitProperty("points"),this.commitProperty("hasZ"),this.commitProperty("hasM"),this.commitProperty("spatialReference"),{}}get extent(){const t=a(this);return t?new i({...t,spatialReference:this.spatialReference}):null}writePoints(t,s){s.points=e(this.points)}clone(){const{points:t,spatialReference:s,hasM:r,hasZ:i}=this;return new c({points:e(t),spatialReference:s.clone(),hasM:r,hasZ:i})}addPoint(t){return h(this,t),Array.isArray(t)?this.points.push(t):this.points.push(t.toArray()),this.notifyChange("points"),this}getPoint(t){if(!this._validateInputs(t))return null;const e=this.points[t],s={x:e[0],y:e[1],spatialReference:this.spatialReference};let r=2;return this.hasZ&&(s.z=e[2],r=3),this.hasM&&(s.m=e[r]),new n(s)}removePoint(t){if(!this._validateInputs(t))return null;const e=new n(this.points.splice(t,1)[0],this.spatialReference);return this.notifyChange("points"),e}setPoint(t,e){return this._validateInputs(t)?(h(this,e),Array.isArray(e)||(e=e.toArray()),this.points[t]=e,this.notifyChange("points"),this):this}toJSON(t){return this.write({},t)}_validateInputs(t){return null!=t&&t>=0&&t<this.points.length}};t([s({readOnly:!0})],m.prototype,"cache",null),t([s({readOnly:!0})],m.prototype,"extent",null),t([s({type:[[Number]],json:{write:{isRequired:!0}}})],m.prototype,"points",void 0),t([l("points")],m.prototype,"writePoints",null),m=c=t([r("esri.geometry.Multipoint")],m),m.prototype.toJSON.isDefaultToJSON=!0;export{m as default};