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