@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 1.72 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{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 n}from"../CIMPlacements.js";import{PlacementPolygonCenterMethod as r}from"../enums.js";class o{static{this.instance=null}static local(){return null===o.instance&&(o.instance=new o),o.instance}execute(t,e,s,n,r){return new i(t,e,s)}}class i{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:r.OnPolygon,this._placementPerPart=void 0!==e.placePerPart&&e.placePerPart,this._internalPlacement=new n}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(n){let o=!1;switch(this._method){case r.CenterOfMass:{const t=e(n);t&&(this._internalPlacement.setTranslate(t[0]+this._offsetX,t[1]+this._offsetY),o=!0)}break;case r.BoundingBoxCenter:{const e=t(n);e&&(this._internalPlacement.setTranslate((e[2]+e[0])/2+this._offsetX,(e[3]+e[1])/2+this._offsetY),o=!0)}break;case r.OnPolygon:default:{const t=s(n);null!==t&&(this._internalPlacement.setTranslate(t[0]+this._offsetX,t[1]+this._offsetY),o=!0)}}return o?this._internalPlacement:null}}export{o as PlacementPolygonCenter};