@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 1.55 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */
import{getCursorBoundsXY as t}from"../../../geometry/support/boundsUtils.js";import{weightedAreaCentroid as e}from"../../../geometry/support/centroid.js";import{getLabelPoint as s}from"../../../geometry/support/labelPoint.js";import{Placement as r}from"../CIMPlacements.js";class n{static{this.instance=null}static local(){return null===n.instance&&(n.instance=new n),n.instance}execute(t,e,s){return new o(t,e,s)}}class o{constructor(t,e,s){this._geometryCursor=t,this._offsetX=void 0!==e.offsetX?e.offsetX*s:0,this._offsetY=void 0!==e.offsetY?e.offsetY*s:0,this._method=void 0!==e.method?e.method:"OnPolygon",this._placementPerPart=void 0!==e.placePerPart&&e.placePerPart,this._internalPlacement=new r}next(){const t=this._geometryCursor;if(!t)return null;if(!this._placementPerPart)return this._geometryCursor=null,this._polygonCenter(t);for(;t.nextPath();)if(!(t.getCurrentRingArea()<0))return this._polygonCenter(t.getCurrentPath());return this._geometryCursor=null,null}_polygonCenter(r){let n=!1;switch(this._method){case"CenterOfMass":{const t=e(r);t&&(this._internalPlacement.setTranslate(t[0]+this._offsetX,t[1]+this._offsetY),n=!0)}break;case"BoundingBoxCenter":{const e=t(r);e&&(this._internalPlacement.setTranslate((e[2]+e[0])/2+this._offsetX,(e[3]+e[1])/2+this._offsetY),n=!0)}break;default:{const t=s(r);null!==t&&(this._internalPlacement.setTranslate(t[0]+this._offsetX,t[1]+this._offsetY),n=!0)}}return n?this._internalPlacement:null}}export{n as PlacementPolygonCenter};