UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 3.8 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{estimateAttributesMemory as t}from"../../../../core/memoryEstimations.js";import{empty as e,width as i,height as s}from"../../../../geometry/support/aaBoundingRect.js";import{getBoundsXY as r}from"../../../../geometry/support/boundsUtils.js";import{closeRingsAndFixWinding as o}from"../../../../geometry/support/coordsUtils.js";import{isCurvedGeometry as n}from"../../../../geometry/support/curveUtils.js";import{densifyCurvedGeometry as m}from"../../../../geometry/support/densifyUtils.js";import{isExtent as a}from"../../../../geometry/support/jsonUtils.js";import{normalizeCentralMeridianForDisplay as h}from"../../../../geometry/support/normalizeUtilsSync.js";import{estimateGeometryMemory as y}from"../../../../layers/graphics/dehydratedFeatures.js";import{checkProjectionSupport as u,project as p}from"../../../../layers/graphics/data/projectionSupport.js";import{getCoarseDensificationSegments as c,getApproximateMaxDensificationSegments as g,getMinDensificationSegments as l,getPixelsPerSegment as d}from"./densificationConstants.js";import{polygonFromExtent as f}from"./graphicsUtils.js";class j{static fromGraphic(t,e,i,s){return new j(t.geometry,e,t.attributes,t.visible,t.uid,t.version,i,s)}constructor(t,i,s,r,o,n,m,a){this.geometry=t,this.symbol=i,this.attributes=s,this.visible=r,this.objectId=o,this._version=n,this.zOrder=m,this.displayId=a,this.symbolBounds=e(),this.prevSymbolBounds=e(),this.size=[0,0,0,0],this.geometryBounds=e(),this._isDensificationDirty=!1,this._densificationSegmentLength=1/0}get projectedGeometry(){return this._projectedGeometry}get linearCIM(){return this.symbolResource?.symbolInfo.linearCIM}get usedMemory(){return 128+t(this.attributes)+y(this.geometry)}get hasAnimations(){const{linearCIM:t}=this;return!!t&&t.some((t=>"animationParams"in t&&!!t.animationParams))}get hasCurvedGeoemtry(){return null!=this.geometry&&"mesh"!==this.geometry.type&&n(this.geometry)}update(t,i,s){return(this._version!==t.version||this.zOrder!==s||this.symbol!==i)&&(this.prevSymbolBounds=this.symbolBounds,this.symbolBounds=e(),this.zOrder=s,this.geometry=t.geometry,this.attributes=t.attributes,this.symbol=i,this.visible=t.visible,this._version=t.version,this.symbolResource=null,this._projectedGeometry=null,e(this.geometryBounds),this._minDensificationSegmentLength=null,!0)}updateDensificationResolution(t){if(!this.hasCurvedGeoemtry)return!1;const e=Math.max(v(t),this._minDensificationSegmentLength??0);return e!==this._densificationSegmentLength&&(this._densificationSegmentLength=e,this._isDensificationDirty=!0,!0)}async projectAndNormalize(t){let e,o=this.geometry;if(o&&o.spatialReference&&"mesh"!==o.type&&("extent"===o.type&&(o=f(o)),e=n(o)?m(o,{maxSegmentLength:1/0,minSegmentsPerCurve:c()}):o.toJSON(),this._projectedGeometry=await b(e,o.spatialReference,t),r(this.geometryBounds,this._projectedGeometry),this.hasCurvedGeoemtry&&null!=this._projectedGeometry)){const t=i(this.geometryBounds),e=s(this.geometryBounds);(t||e)&&(this._minDensificationSegmentLength=Math.max(t,e)/g())}}async densifyCurvedGeometryForDisplay(t){if(!this.hasCurvedGeoemtry||!this._isDensificationDirty)return;this._isDensificationDirty=!1;const e=this.geometry;if(!e||!e.spatialReference||"mesh"===e.type)return;const i=t.metersPerUnit/e.spatialReference.metersPerUnit,s=this._densificationSegmentLength*i,r=m(e,{maxSegmentLength:s,minSegmentsPerCurve:l()});this._projectedGeometry=await b(r,e.spatialReference,t)}}async function b(t,e,i){await u(t.spatialReference,i);const s=h(t);if(!s)return;const r=p(s,e,i);return r&&o(r),a(r)?f(r):r}function v(t){return 2**Math.round(Math.log2(t))*d()}export{j as GraphicStoreItem};