@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 2.65 kB
JavaScript
import{isNone as t}from"../../../../core/maybe.js";import{create as e,containsPointWithMargin as s}from"../../../../geometry/support/aaBoundingRect.js";import{polygonCentroid as r}from"../../../../geometry/support/centroid.js";import{isPolygon as o,getJsonType as i}from"../../../../geometry/support/jsonUtils.js";import{quantizePoint as n,quantizeGeometry as l}from"../../../../geometry/support/quantizationUtils.js";import{getInfo as a}from"../../../../geometry/support/spatialReferenceUtils.js";import{convertFromPolyline as h,generalizeOptimizedGeometry as u,quantizeOptimizedGeometry as m,convertToPolyline as c}from"../../../../layers/graphics/featureConversionUtils.js";import p from"../../../../layers/graphics/OptimizedGeometry.js";const y=new p,g=new p,f="esriGeometryPolyline";function d(t){t.coords.length=0,t.lengths.length=0}class b{constructor(){this.bounds=e(),this.graphic=null}static acquire(t=null,e,s,r,o){let i;return 0===b._pool.length?i=new b:(i=b._pool.pop(),this._set.delete(i)),i.acquire(t,e,s,r,o),i}static release(t){t&&!this._set.has(t)&&(t.release(),this._pool.push(t),this._set.add(t))}static getCentroidQuantized(e,s){if(o(e.geometry)){const o=e.symbol;if(t(o))return null;if(o?.layers.length>0&&o.layers.some((t=>"text"===t.type||"marker"===t.type))){const t=r(e.geometry);return null!==t?n(s,{},{x:t[0],y:t[1]},!1,!1):null}}return null}acquire(t=null,e,s,r,o){t&&this.set(t,e,s,r,o)}release(){this.graphic=null,this.symbolResource=null,this.geometry=null}get symbol(){return this.symbolResource.symbol}set(t,e,s,r,o){this.graphic=t,this.geometry=s,this.symbolResource=e,this.bounds=r,o&&(this.size=o)}getGeometryQuantized(e,r,o,n){const p=this.geometry,b=i(p);if(t(b))return null;switch(b){case"esriGeometryPolygon":{const t=p,{rings:s}=t;if(!s||0===s.length)return null;let r;if(r=1===s.length&&2===s[0].length?l(e,{paths:[[s[0][0],s[0][1]]]}):l(e,this.geometry),!r){const t={x:s[0][0][0],y:s[0][0][1]};if(r=l(e,t),r){const{x:t,y:e}=r;return{rings:[[[t-1,e],[1,-1],[1,1],[-1,1],[-1,-1]]]}}}return r}case"esriGeometryPolyline":{const t=p;d(y),d(g);const s=t.hasZ??!1,r=t.hasM??!1;return h(y,t),u(g,y,s,r,f,e.scale[0]),m(y,g,s,r,f,e),c(y,t.hasZ??!1,t.hasM??!1)}case"esriGeometryMultipoint":{const t=p,i=.5*n*Math.max(Math.abs(this.size[0])+this.size[2]-this.size[0],Math.abs(this.size[1])+this.size[3]-this.size[1]),h=a(o);let u=t.points;if(h){const[t,e]=h.valid,o=e-t;u=u.filter((n=>{if(n[0]+i>e||n[0]-i<t){const t=[...n];return n[0]+i>e?t[0]-=o:t[0]+=o,s(r,n,i)||s(r,t,i)}return s(r,n,i)}))}return 0===u.length?{points:u}:l(e,{points:u})}}return l(e,this.geometry)}}b._pool=[],b._set=new Set;export{b as default};