@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 2.17 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{PathTransformationCursor as e}from"../CIMCursor.js";import{CurveHelper as t}from"../CurveHelper.js";import{PlacementOnLineRelativeTo as n}from"../enums.js";const i=.001;class s{static local(){return null===s.instance&&(s.instance=new s),s.instance}execute(e,t,n,i,s){return new r(e,t,n)}}s.instance=null;class r extends e{constructor(e,n,s){super(e),this._curveHelper=new t,this._angleToLine=void 0===n.angleToLine||n.angleToLine,this._offset=void 0!==n.offset?n.offset*s:0,this._relativeTo=n.relativeTo,this._position=void 0!==n.startPointOffset?n.startPointOffset*s:0,this._epsilon=i*s}processPath(e){const t=this._position;if(this._relativeTo===n.SegmentMidpoint){if(this.iteratePath||(this.iteratePath=!0),e.nextPoint()){let[t,n]=[e.x,e.y],[i,s]=[0,0];for(;e.nextPoint();){i=e.x,s=e.y;const r=this._curveHelper.getLength(t,n,i,s);if(r<this._epsilon){t=i,n=s;continue}const o=.5+this._position/r,[a,l]=this._curveHelper.getAngleCS(t,n,i,s,o),h=this._curveHelper.getCoord2D(t,n,i,s,o);return this.internalPlacement.setTranslate(h[0]-this._offset*l,h[1]+this._offset*a),this._angleToLine&&this.internalPlacement.setRotateCS(a,l),this.internalPlacement}}return this.iteratePath=!1,null}const i=this._relativeTo===n.LineEnd;return this.onLine(e,t,i)}onLine(e,t,i){let s,r=!1;switch(this._relativeTo){case n.LineMiddle:default:e.seekPathStart(),s=e.pathLength()/2+t;break;case n.LineBeginning:s=t;break;case n.LineEnd:s=t,r=!0}i?e.seekPathEnd():e.seekPathStart();let o=0;if(i?e.prevPoint():e.nextPoint()){let[t,n]=[e.x,e.y],[a,l]=[0,0];for(;i?e.prevPoint():e.nextPoint();){a=e.x,l=e.y;const i=this._curveHelper.getLength(t,n,a,l);if(o+i>s){const e=(s-o)/i,[h,c]=this._curveHelper.getAngleCS(t,n,a,l,e),f=this._curveHelper.getCoord2D(t,n,a,l,e),u=r?-this._offset:this._offset;return this.internalPlacement.setTranslate(f[0]-u*c,f[1]+u*h),this._angleToLine&&(r?this.internalPlacement.setRotateCS(-h,-c):this.internalPlacement.setRotateCS(h,c)),this.internalPlacement}t=a,n=l,o+=i}}return null}}export{s as PlacementOnLine};