UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) 2.18 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */ import{GeometryCursor as e}from"../../../geometry/GeometryCursor.js";import{collectPath as t}from"../../../geometry/geometryCursorCollectUtils.js";import r from"../../../geometry/SpatialReference.js";import{isExtent as s}from"../../../geometry/support/jsonTypeUtils.js";import{clipCursorToTileExtent as i,lazyOffsetOperator as o,lazyGraphicBufferOperator as n}from"../CIMEffects.js";import{CurveHelper as f,pixelTolerance as m}from"../CurveHelper.js";const a=10;class l{static{this.instance=null}static local(){return null===l.instance&&(l.instance=new l),l.instance}execute(e,t,r,s,i,o){return new h(e,t,r,s,i,o)}}class h{constructor(e,t,r,s,i,o){this._preventClipping=o,this._inputGeometries=e,this._tileKey=s,this._curveHelper=new f,this._offset=(t.offset??1)*r,this._method=t.method??"Square",this._maxInflateSize=Math.max(Math.abs(i*r),a),this._option=t.option||"Fast",this._offsetFlattenError=m*r}next(){let f;for(;f=this._inputGeometries.next();){if(0===this._offset)return f.clone();if("esriGeometryEnvelope"===f.geometryType){if("Rounded"===this._method&&this._offset>0){const r=t(f),s=this._curveHelper.offset(r,-this._offset,this._method,4,this._offsetFlattenError);if(s){const t=e.createEmptyOptimizedCIM(f.geometryType);return t.pushPath(s),t}return null}const r=f.asJSON();if(s(r)&&Math.min(r.xmax-r.xmin,r.ymax-r.ymin)+2*this._offset>0)return e.fromJSONCIM({xmin:r.xmin-this._offset,xmax:r.xmax+this._offset,ymin:r.ymin-this._offset,ymax:r.ymax+this._offset})}const m=!this._preventClipping&&this._tileKey?i(f,this._maxInflateSize,!0):f.clone();if(!m)continue;const a=o.module,l=n.module,h={...m.asJSON(),spatialReference:{wkid:r.WebMercator.wkid}};let c,p=u(this._method);return"esriGeometryPolygon"===f.geometryType&&this._offset>0?("square"===p&&(p="bevel"),c=l.executeMany([h],[this._offset],p,"round")[0]):c=a.execute(h,-this._offset,{joins:p,flattenError:this._offsetFlattenError,miterLimit:4}),c?e.fromJSONCIM(c):null}return null}}function u(e){switch(e){case"Rounded":return"round";case"Bevelled":return"bevel";case"Mitered":return"miter";case"Square":return"square"}}export{l as EffectOffset};