@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.64 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{clone as e}from"../core/lang.js";import{property as s}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import"../core/Logger.js";import{subclass as r}from"../core/accessorSupport/decorators/subclass.js";import{writer as i}from"../core/accessorSupport/decorators/writer.js";import a from"./Extent.js";import o from"./Geometry.js";import n from"./Point.js";import h from"./SpatialReference.js";import{getPolylineExtent as p}from"./support/extentUtils.js";import{updateSupportFromPoint as l}from"./support/zmUtils.js";var c;function u(t){return!Array.isArray(t[0])}function f(t){return"number"==typeof t[0]?.[0]}function m(t){if(!t)return;let{paths:e,hasM:s,hasZ:r,spatialReference:i}=t;switch(e??=[],f(e)&&(e=[e]),e[0]?.[0]?.length){case 4:r??=!0,s??=!0;break;case 3:r??=!0!==s,s??=!r;break;default:r??=!1,s??=!1}return i??=h.WGS84,{...t,hasM:s,hasZ:r,paths:e,spatialReference:i}}let y=c=class extends o{constructor(t){super(m(t)),this.curvePaths=void 0,this.paths=[],this.type="polyline"}get cache(){return this.commitProperty("curvePaths"),this.commitProperty("hasM"),this.commitProperty("hasZ"),this.commitProperty("paths"),this.commitProperty("spatialReference"),{}}writeCurvePaths(t,s){s.curvePaths=e(t)}get extent(){const t=p(this),{spatialReference:e}=this;return t?new a({...t,spatialReference:e}):null}writePaths(t,s){s.paths=e(this.paths)}addPath(t){if(!t)return;const e=this.paths,s=e.length;if(u(t)){const r=[];for(let e=0,s=t.length;e<s;e++)r[e]=t[e].toArray();e[s]=r}else e[s]=t.slice();return this.notifyChange("paths"),this}clone(){const t=new c;return t.spatialReference=this.spatialReference,t.paths=e(this.paths),t.curvePaths=e(this.curvePaths),t.hasZ=this.hasZ,t.hasM=this.hasM,t}getPoint(t,e){if(!this._validateInputs(t,e))return null;const s=this.paths[t][e],r=this.hasZ,i=this.hasM;return r&&!i?new n(s[0],s[1],s[2],void 0,this.spatialReference):i&&!r?new n(s[0],s[1],void 0,s[2],this.spatialReference):r&&i?new n(s[0],s[1],s[2],s[3],this.spatialReference):new n(s[0],s[1],this.spatialReference)}insertPoint(t,e,s){return this._validateInputs(t,e,!0)?(l(this,s),Array.isArray(s)||(s=s.toArray()),this.paths[t].splice(e,0,s),this.notifyChange("paths"),this):this}removePath(t){if(!this._validateInputs(t,null))return null;const e=this.paths.splice(t,1)[0],s=this.spatialReference,r=e.map((t=>new n(t,s)));return this.notifyChange("paths"),r}removePoint(t,e){if(!this._validateInputs(t,e))return null;const s=new n(this.paths[t].splice(e,1)[0],this.spatialReference);return this.notifyChange("paths"),s}setPoint(t,e,s){return this._validateInputs(t,e)?(l(this,s),Array.isArray(s)||(s=s.toArray()),this.paths[t][e]=s,this.notifyChange("paths"),this):this}_validateInputs(t,e,s=!1){if(null==t||t<0||t>=this.paths.length)return!1;if(null!=e){const r=this.paths[t];if(s&&(e<0||e>r.length))return!1;if(!s&&(e<0||e>=r.length))return!1}return!0}toJSON(t){return this.write({},t)}};t([s({readOnly:!0})],y.prototype,"cache",null),t([s({json:{write:!0,origins:{"portal-item":{write:!1},"web-map":{write:!1},"web-scene":{write:!1}}}})],y.prototype,"curvePaths",void 0),t([i("curvePaths")],y.prototype,"writeCurvePaths",null),t([s({readOnly:!0})],y.prototype,"extent",null),t([s({type:[[[Number]]],json:{write:{isRequired:!0}}})],y.prototype,"paths",void 0),t([i("paths")],y.prototype,"writePaths",null),y=c=t([r("esri.geometry.Polyline")],y);const P=y;y.prototype.toJSON.isDefaultToJSON=!0;export{P as default};