@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.5 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{GeometryCursor as t}from"../../../geometry/GeometryCursor.js";import{collectPath as e}from"../../../geometry/geometryCursorCollectUtils.js";import{PathEffectCursor as r}from"../CIMCursor.js";import{CurveHelper as n,pixelTolerance as o}from"../CurveHelper.js";import{GeometricEffectArrowType as s,GeometricEffectOffsetMethod as i}from"../enums.js";const c=1.7320508075688772,u=5,h=s.OpenEnded;class p{static{this.instance=null}static local(){return null===p.instance&&(p.instance=new p),p.instance}execute(t,e,r,n,o){return new P(t,e,r)}}class P extends r{constructor(t,e,r){super(t,!1,!0),this._curveHelper=new n,this._width=(void 0!==e.width?e.width:u)*r,this._arrowType=void 0!==e.geometricEffectArrowType?e.geometricEffectArrowType:void 0!==e.arrowType?e.arrowType:h,this._offsetFlattenError=o*r}processPath(e){const r=t.createEmptyOptimizedCIM(e.geometryType);switch(this._arrowType){case s.OpenEnded:default:this._constructSimpleArrow(r,e,!0);break;case s.Block:this._constructSimpleArrow(r,e,!1);break;case s.Crossed:this._constructCrossedArrow(r,e)}return r}_constructSimpleArrow(t,r,n){const o=r.pathLength();let s=this._width;o<2*s&&(s=o/2);const i=this._curveHelper.getSubCurve(r,0,o-s);if(!i||!i.nextPath())return;i.seekPathStart();const c=s/2;if(this._curveHelper.isEmpty(i))return;const u=e(i),h=this._constructOffset(u,-c);if(!h)return;const p=this._constructOffset(u,c);if(!p)return;const P=this._constructArrowBasePoint(h,-c/2);if(!P)return;const l=this._constructArrowBasePoint(p,c/2);if(!l)return;r.seekInPath(r.pathSize-1);const a=[r.x,r.y];t.pushPath(p),t.nextPath(),t.nextPoint(),t.setControlPoint(),t.pushPoint(l),t.nextPoint(),t.setControlPoint(),t.pushPoint(a),t.nextPoint(),t.setControlPoint(),t.pushPoint(P),t.nextPoint(),t.setControlPoint(),t.pushPoints(h.reverse()),t.setControlPoint(),n||(t.setControlPointAt(0),t.setControlPointAt(t.pathSize-1),t.pushPoint(p[0])),t.reset()}_constructCrossedArrow(t,r){const n=r.pathLength();let o=this._width;n<o*(1+c+1)&&(o=n/(1+c+1)),r.seekPathStart();const s=this._curveHelper.getSubCurve(r,0,n-o*(1+c));if(!s)return;s.nextPath();const i=o/2;if(this._curveHelper.isEmpty(s))return;const u=e(s),h=this._constructOffset(u,i);if(!h)return;const p=this._constructOffset(u,-i);if(!p)return;const P=this._curveHelper.getSubCurve(r,0,n-o);if(!P)return;if(P.nextPath(),this._curveHelper.isEmpty(P))return;const l=e(P),a=this._constructOffset(l,i);if(!a)return;const f=this._constructOffset(l,-i);if(!f)return;const _=a[a.length-1],m=this._constructArrowBasePoint(a,i/2);if(!m)return;const C=f[f.length-1],w=this._constructArrowBasePoint(f,-i/2);if(!w)return;r.seekInPath(r.pathSize-1);const x=[r.x,r.y];t.pushPath(h),t.nextPath(),t.nextPoint(),t.setControlPoint(),t.pushPoint(C),t.nextPoint(),t.setControlPoint(),t.pushPoint(w),t.nextPoint(),t.setControlPoint(),t.pushPoint(x),t.nextPoint(),t.setControlPoint(),t.pushPoint(m),t.nextPoint(),t.setControlPoint(),t.pushPoint(_),t.nextPoint(),t.setControlPoint(),t.pushPoints(p.reverse()),t.nextPoint(),t.setControlPoint(),t.reset()}_constructOffset(t,e){return this._curveHelper.offset(t,e,i.Rounded,4,this._offsetFlattenError)}_constructArrowBasePoint(t,e){if(!t||t.length<2)return null;const r=t[t.length-2],n=t[t.length-1],o=[n[0]-r[0],n[1]-r[1]];return this._curveHelper.normalize(o),[n[0]+o[1]*e,n[1]-o[0]*e]}}export{p as EffectArrow};