UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) • 27.5 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{isRGB as e}from"../../core/colorUtils.js";import{getFontFamily as r}from"../../core/fontUtils.js";import{clone as t}from"../../core/lang.js";import i from"../../core/Logger.js";import{pt2px as o,px2pt as a}from"../../core/screenUtils.js";import{numericHash as s}from"../../core/string.js";import{checkForAnimations as l,getAnimationParams as n,handleAbsoluteAnchor as p,handleMarker as c,handleRelativeAnchor as m,getFrameTranslation as y,translate as d,getStaticParam as h,shouldUseAnimatedPath as f}from"./animationUtils.js";import{CIMSymbolHelper as u}from"./CIMSymbolHelper.js";import{defaultCIMValues as v}from"./defaultCIMValues.js";import{Alignment as O,SymbolUnits as g}from"./enums.js";import{fitVectorMarker as _}from"./fitVectorMarker.js";import{OverrideHelper as M}from"./OverrideHelper.js";import{getExtent as S,getSDFMetrics as k,getSDFDimensions as b}from"./SDFHelper.js";import{colorToArray as C,normalizeAlpha as P,getSize as z,isCIMMarkerStrokePlacement as x,getTintColor as E,getNumericValue as I,normalizePrimitiveOverrideProps as L,getDefaultCIMValue as V,getEnum as N,getStrokeWidth as R,getFillColor as A,getStrokeColor as w,fromCIMFontDecoration as G,fromCIMFontStyle as F,fromCIMHorizontalAlignment as T,fromCIMVerticalAlignment as X,isValidCIMValue as Y,uncapitalize as j}from"./utils.js";import{CIMEffectHelper as W}from"./effects/CIMEffectHelper.js";import{rasterizedVectorMarkerMinSize as U,randomInsidePolygonTextureSize as D}from"../../views/2d/engine/webgl/definitions.js";const H=()=>i.getLogger("esri.symbols.cim.cimAnalyzer");function J(e){const r=e.markerPlacement;return r&&r.angleToLine?O.MAP:O.SCREEN}class B{constructor(e){this._cimLayers=[],this._poMap={},this._primitiveOverrides=[],e&&(this._resourceManager=e)}analyzeSymbolReference(r,t,i){if(this._cimLayers=i??[],!r)return this._cimLayers;if(this._reset(),r.primitiveOverrides){this._primitiveOverrides=r.primitiveOverrides;for(const r of this._primitiveOverrides){const t=r.valueExpressionInfo;if(t)this._setPoMap(r.primitiveName,r.propertyName,t);else if(null!=r.value){let t=r.value;r.propertyName.includes("Color")&&(e(t)&&(t=C(t)),t=P(t)),this._setPoMap(r.primitiveName,r.propertyName,t)}}}return this._analyzeSymbol(r.symbol,t),this._cimLayers}_reset(){this._cimLayers=[],this._poMap={},this._primitiveOverrides=[]}_analyzeSymbol(e,r){switch(e?.type){case"CIMPointSymbol":case"CIMLineSymbol":case"CIMPolygonSymbol":this._analyzeMultiLayerSymbol(e,r)}}_analyzeMultiLayerSymbol(e,r){const t=e?.symbolLayers;if(!t)return;for(let l=0;l<t.length;l++){const e=t[l];"CIMVectorMarker"===e.type&&(t[l]=_(e,this._resourceManager.geometryEngine))}const i=e.effects;let o=O.SCREEN;const a=z(e)??0;"CIMPointSymbol"===e.type&&"Map"===e.angleAlignment&&(o=O.MAP);let s={transform:[0,0,0,1],fromColor:[1,1,1,1],toColor:[1,1,1,1],colorMix:[0,0,0,0],toOpacity:[1,1,1,1],opacityMix:[0,0,0,0],hasAnimations:l(e)};s=n(this._poMap,e,s);const p="CIMPolygonSymbol"===e.type;let c=t.length;for(;c--;){const l=t[c];if(!l||!1===l.enable)continue;let n;i?.length&&(n=[...i]);const m=l.effects;m?.length&&(i?n.push(...m):n=[...m]);let y=null;if(n){y=[];for(const e of n){const r=M.findEffectOverrides(e,this._primitiveOverrides);r&&y.push(r)}}const d=[];switch(M.findApplicableOverrides(l,this._primitiveOverrides,d),l.type){case"CIMSolidFill":this._analyzeSolidFill(l,y);break;case"CIMPictureFill":this._analyzePictureFill(l,y);break;case"CIMHatchFill":this._analyzeHatchFill(l,y);break;case"CIMGradientFill":this._analyzeGradientFill(l,y);break;case"CIMSolidStroke":this._analyzeSolidStroke(l,y,p,a);break;case"CIMPictureStroke":this._analyzePictureStroke(l,y,p,a);break;case"CIMGradientStroke":this._analyzeGradientStroke(l,y,p,a);break;case"CIMCharacterMarker":case"CIMPictureMarker":case"CIMVectorMarker":{"CIMLineSymbol"!==e.type&&"CIMPolygonSymbol"!==e.type||(o=J(l));const t=[],i=l.primitiveName;i&&t.push(i);const n=p&&x(l.markerPlacement);this._analyzeMarker(l,y,null,t,o,a,r,[],s,!1,n);break}default:H().error("Cannot analyze CIM layer",l.type)}}}_analyzeSolidFill(e,r){const{primitiveName:t,type:i}=e,o=P(e.color);this._cimLayers.push({type:"fill",spriteRasterizationParam:null,colorLocked:!!e.colorLocked,color:this._getValueOrOverrideExpression(i,t,"Color",o),height:0,angle:0,offsetX:0,offsetY:0,scaleX:1,effects:r,applyRandomOffset:!1,sampleAlphaOnly:!0,hasUnresolvedReplacementColor:!1})}_analyzePictureFill(e,r){const{primitiveName:t,type:i}=e,o=E(e),a=I(e.height,v.CIMPictureFill.height);let s=I(e.scaleX,1);if("width"in e&&"number"==typeof e.width){const r=e.width;let t=1;const i=this._resourceManager.getResource(e.url);null!=i&&(t=i.width/i.height),s/=t*(a/r)}const l={type:"sprite-rasterization-param",resource:e,overrides:this._getPrimitiveMaterialOverrides(t,i)};this._cimLayers.push({type:"fill",spriteRasterizationParam:l,colorLocked:!!e.colorLocked,effects:r,color:this._getValueOrOverrideExpression(i,t,"TintColor",o),height:this._getValueOrOverrideExpression(i,t,"Height",a),scaleX:this._getValueOrOverrideExpression(i,t,"ScaleX",s),angle:this._getValueOrOverrideExpression(i,t,"Rotation",I(e.rotation)),offsetX:this._getValueOrOverrideExpression(i,t,"OffsetX",I(e.offsetX)),offsetY:this._getValueOrOverrideExpression(i,t,"OffsetY",I(e.offsetY)),applyRandomOffset:!1,sampleAlphaOnly:!1,hasUnresolvedReplacementColor:!1})}_analyzeHatchFill(e,r){const{primitiveName:t,type:i}=e,o=this._analyzeMaterialOverrides(t,["Rotation","OffsetX","OffsetY"]),a=L(o);let s=[255,255,255,1],l=!1;if(e.lineSymbol?.symbolLayers)for(const p of e.lineSymbol.symbolLayers){if("CIMSolidStroke"!==p.type)continue;const e=p.primitiveName??t;l||!e||p.colorLocked||null==this._poMap[e]?.Color&&null==this._poMap[e]?.StrokeColor||(s=P(p.color),s=this._maybeGetValueOrOverrideExpression(e,"StrokeColor")??this._getValueOrOverrideExpression(i,e,"Color",s),l=!0);const r=this._maybeGetValueOrOverrideExpression(e,"StrokeWidth");if(r){let t=null,o=null;"number"==typeof r?t=r:o=r.valueExpressionInfo;let s=a.find((e=>"strokeWidth"===e.propertyName));s?s.propertyName="width":(s={type:"CIMPrimitiveOverride",primitiveName:e,propertyName:"width",valueExpressionInfo:o,value:t,defaultValue:V(i,"width")},a.push(s))}}const n={type:"sprite-rasterization-param",resource:e,overrides:a};this._cimLayers.push({type:"fill",spriteRasterizationParam:n,colorLocked:!!e.colorLocked,effects:r,color:s,height:this._getValueOrOverrideExpression(i,t,"Separation",I(e.separation,v.CIMHatchFill.separation)),scaleX:1,angle:this._getValueOrOverrideExpression(i,t,"Rotation",I(e.rotation)),offsetX:this._getValueOrOverrideExpression(i,t,"OffsetX",I(e.offsetX)),offsetY:this._getValueOrOverrideExpression(i,t,"OffsetY",I(e.offsetY)),applyRandomOffset:!1,sampleAlphaOnly:!0,hasUnresolvedReplacementColor:!l})}_analyzeGradientFill(e,r){const{angle:t,gradientMethod:i,gradientSize:o,gradientSizeUnits:a,gradientType:s,interval:l,primitiveName:n,type:p}=e,c=v.CIMGradientFill,m=e.colorRamp;this._cimLayers.push({type:"gradientFill",spriteRasterizationParam:{type:"sprite-rasterization-param",resource:e,overrides:this._getPrimitiveMaterialOverrides(n,p)},colorLocked:!1,effects:r,color:[255,255,255,1],gradientMethod:this._getValueOrOverrideExpression(p,n,"GradientMethod",i??"Linear"),angle:this._getValueOrOverrideExpression(p,n,"Angle",I(t,c.angle)),gradientType:this._getValueOrOverrideExpression(p,n,"GradientType",s??c.gradientType),interval:this._getValueOrOverrideExpression(p,n,"Interval",I(l,"CIMFixedColorRamp"===m.type?m.colors.length:c.interval)),gradientSize:this._getValueOrOverrideExpression(p,n,"GradientSize",I(o,c.gradientSize)),gradientSizeUnits:"Absolute"===a?g.Absolute:"Relative"===a?g.Relative:c.gradientSizeUnits})}_analyzeSolidStroke(e,r,t,i){const{primitiveName:o,type:a}=e,s=P(e.color),l=I(e.width,v.CIMSolidStroke.width),n=N(e.capStyle,v.CIMSolidStroke.capstyle),p=N(e.joinStyle,v.CIMSolidStroke.joinstyle),c=e.miterLimit;let m,y,d,h,f=[];if(this._analyzePrimitiveOverrides(o,r,null,null)&&(f=this._getPrimitiveMaterialOverrides(o,a)),r&&Array.isArray(r)&&r.length>0){const e=r[r.length-1].effect;e&&"CIMGeometricEffectDashes"===e.type&&"NoConstraint"===e.lineDashEnding&&(m=e.dashTemplate,y=e.scaleDash,d=e.offsetAlongLine,h=e.primitiveName,(r=[...r]).pop())}null!=h&&f.push(...this._getPrimitiveMaterialOverrides(h,a).filter((e=>"dashTemplate"===e.propertyName)));const u=void 0!==m?{type:"sprite-rasterization-param",resource:{type:"dash",dashTemplate:m,primitiveName:h},overrides:f}:null;this._cimLayers.push({type:"line",spriteRasterizationParam:u,isOutline:t,colorLocked:!!e.colorLocked,effects:r,color:this._getValueOrOverrideExpression(a,o,"Color",s),width:this._getValueOrOverrideExpression(a,o,"Width",l),cap:this._getValueOrOverrideExpression(a,o,"CapStyle",n),join:this._getValueOrOverrideExpression(a,o,"JoinStyle",p),miterLimit:c&&this._getValueOrOverrideExpression(a,o,"MiterLimit",c),referenceWidth:i,zOrder:K(e.name),dashTemplate:this._maybeGetValueOrOverrideExpression(h,"DashTemplate")??m,offsetAlongLine:this._getValueOrOverrideExpression(a,h,"OffsetAlongLine",d??0),scaleDash:y,sampleAlphaOnly:!0})}_analyzePictureStroke(e,r,t,i){const{primitiveName:o,type:a}=e,s=E(e),l=I(e.width,v.CIMPictureStroke.width),n=N(e.capStyle,v.CIMPictureStroke.capstyle),p=N(e.joinStyle,v.CIMPictureStroke.joinstyle),c=e.miterLimit,m={type:"sprite-rasterization-param",resource:e,overrides:this._getPrimitiveMaterialOverrides(o,a)};this._cimLayers.push({type:"line",spriteRasterizationParam:m,isOutline:t,colorLocked:!!e.colorLocked,effects:r,color:this._getValueOrOverrideExpression(a,o,"TintColor",s),width:this._getValueOrOverrideExpression(a,o,"Width",l),cap:this._getValueOrOverrideExpression(a,o,"CapStyle",n),join:this._getValueOrOverrideExpression(a,o,"JoinStyle",p),miterLimit:c&&this._getValueOrOverrideExpression(a,o,"MiterLimit",c),referenceWidth:i,zOrder:K(e.name),dashTemplate:null,scaleDash:!1,sampleAlphaOnly:!1})}_analyzeGradientStroke(e,r,t,i){const{gradientMethod:o,gradientSize:a,gradientSizeUnits:s,gradientType:l,interval:n,primitiveName:p,type:c}=e,m=v.CIMGradientStroke,y=I(e.width,m.width),d=N(e.capStyle,m.capstyle),h=N(e.joinStyle,m.joinstyle),f=e.miterLimit,u=e.colorRamp;this._cimLayers.push({type:"gradientStroke",spriteRasterizationParam:{type:"sprite-rasterization-param",resource:e,overrides:this._getPrimitiveMaterialOverrides(p,c)},colorLocked:!!e.colorLocked,effects:r,color:[255,255,255,1],width:this._getValueOrOverrideExpression(c,p,"Width",y),cap:this._getValueOrOverrideExpression(c,p,"CapStyle",d),join:this._getValueOrOverrideExpression(c,p,"JoinStyle",h),miterLimit:f&&this._getValueOrOverrideExpression(c,p,"MiterLimit",f),referenceWidth:i,isOutline:t,gradientMethod:this._getValueOrOverrideExpression(c,p,"GradientMethod",o??m.gradientMethod),gradientType:this._getValueOrOverrideExpression(c,p,"GradientType",l??m.gradientType),interval:this._getValueOrOverrideExpression(c,p,"Interval",I(n,"CIMFixedColorRamp"===u.type?u.colors.length:m.interval)),gradientSize:this._getValueOrOverrideExpression(c,p,"GradientSize",I(a,m.gradientSize)),gradientSizeUnits:"Absolute"===s?g.Absolute:"Relative"===s?g.Relative:m.gradientSizeUnits})}_analyzeMarker(e,r,t,i,o,a,s,l,y,d=!1,h=!1){if(d||=!!e.colorLocked,this._analyzeMarkerInsidePolygon(e,r,d))return;const f=I(e.size,v.CIMVectorMarker.size),u=I(e.rotation),O=I(e.offsetX),g=I(e.offsetY),{primitiveName:_,type:M}=e,S=this._getValueOrOverrideExpression(M,_,"Size",f),k=this._getValueOrOverrideExpression(M,_,"Rotation",u),b=this._getValueOrOverrideExpression(M,_,"OffsetX",O),C=this._getValueOrOverrideExpression(M,_,"OffsetY",g);let P=y;switch(P=n(this._poMap,e,P),P=p(e,P),P=c(this._poMap,e,P),P=m(e,P),e.type){case"CIMPictureMarker":this._analyzePictureMarker(e,r,t,i,o,a,S,k,b,C,l,P,d,h);break;case"CIMVectorMarker":this._analyzeVectorMarker(e,r,t,i,o,a,S,k,b,C,l,P,s,d,h)}}_analyzeMarkerInsidePolygon(e,r,t){const{markerPlacement:i,type:o}=e;if(!i||"CIMMarkerPlacementInsidePolygon"!==i.type)return!1;if("CIMVectorMarker"===o||"CIMPictureMarker"===o){const t=e.primitiveName;if(t&&this._analyzePrimitiveOverrides([t],r,null,null))return!1;const a=i.primitiveName;if(a&&this._analyzePrimitiveOverrides([a],r,null,null))return!1;if("CIMVectorMarker"===o){const{markerGraphics:r}=e;if(r)for(const e of r){const{symbol:r}=e;if("CIMPolygonSymbol"===r?.type&&r.symbolLayers){const{symbolLayers:e}=r;for(const r of e)if("CIMSolidStroke"===r.type)return!1}}}else{const{animatedSymbolProperties:r}=e;if(r)return!1}}const s=Math.abs(i.stepX),l=Math.abs(i.stepY);if(0===s||0===l)return!0;let n,p;if("Random"===i.gridType){const e=a(D),r=Math.max(Math.floor(e/s),1);n=l*Math.max(Math.floor(e/l),1);p=r*s/n}else i.shiftOddRows?(n=2*l,p=s/l*.5):(n=l,p=s/l);const c=E(e),m="CIMCharacterMarker"===e.type?null:{type:"sprite-rasterization-param",resource:e,overrides:[]};return this._cimLayers.push({type:"fill",spriteRasterizationParam:m,colorLocked:t,effects:r,color:c,height:n,scaleX:p,angle:i.gridAngle,offsetX:I(i.offsetX),offsetY:I(i.offsetY),applyRandomOffset:"Random"===i.gridType,sampleAlphaOnly:"CIMPictureMarker"!==e.type,hasUnresolvedReplacementColor:!0}),!0}_analyzePictureMarker(e,r,i,o,a,l,n,p,c,m,y,d,h,f){const{animatedSymbolProperties:u,primitiveName:v,type:O}=e;let g=I(e.scaleX,1);const _=E(e);i||(i=this._createMarkerPlacementOverrideExpression(e.markerPlacement));const M=this._createGIFAnimatedSymbolPropertiesOverrideExpression(u),S=e.anchorPoint??{x:0,y:0};if("width"in e&&"number"==typeof e.width){const r=e.width;let t=1;const i=this._resourceManager.getResource(e.url);null!=i&&(t=i.width/i.height);g/=t*(I(e.size)/r)}const k=[...o];let b;e.primitiveName&&k.push(e.primitiveName),u||M?b={type:"animated",url:e.url,urlHash:"H"+s(e.url),playAnimation:e.animatedSymbolProperties?.playAnimation,reverseAnimation:e.animatedSymbolProperties?.reverseAnimation,randomizeStartTime:e.animatedSymbolProperties?.randomizeStartTime,randomizeStartSeed:e.animatedSymbolProperties?.randomizeStartSeed,startTimeOffset:e.animatedSymbolProperties?.startTimeOffset,duration:e.animatedSymbolProperties?.duration,repeatType:e.animatedSymbolProperties?.repeatType,repeatDelay:e.animatedSymbolProperties?.repeatDelay}:(b=t(e),b.markerPlacement=null);const C={type:"sprite-rasterization-param",resource:b,overrides:this._getMaterialOverrides(k,O)};M&&C.overrides.push(...M.overrides);const P=n;this._cimLayers.push({type:"marker",spriteRasterizationParam:C,colorLocked:h,effects:r,scaleSymbolsProportionally:!1,alignment:a,size:n,scaleX:this._getValueOrOverrideExpression(O,v,"ScaleX",g),rotation:p,offsetX:c,offsetY:m,transform:{type:"cim-marker-transform-param",params:y},color:this._getValueOrOverrideExpression(O,v,"TintColor",_),anchorPoint:{x:S.x,y:S.y},isAbsoluteAnchorPoint:"Relative"!==e.anchorPointUnits,outlineColor:[0,0,0,0],outlineWidth:0,frameHeight:0,widthRatio:1,rotateClockwise:!!e.rotateClockwise,referenceSize:l,sizeRatio:1,isOutline:f,markerPlacement:i,animationParams:te(d),baseSize:P})}_analyzeVectorMarker(e,r,t,i,o,a,s,l,p,c,m,f,u,v,O){const g=e.markerGraphics;if(!g)return;const _=e.frame;let M=0;M=_?_.ymax-_.ymin:a;const S=!!e.scaleSymbolsProportionally;if(M){const r={offsetX:p,offsetY:c,rotation:l,size:s,frameHeight:M,rotateClockWise:!!e.rotateClockwise,absoluteAnchorPoint:!1,scaleSymbolsProportionally:S};m=[...m,r]}t||(t=this._createMarkerPlacementOverrideExpression(e.markerPlacement));for(const k of g)if(k){const s=k.symbol;if(!s)continue;const l=k.primitiveName;l&&i.push(l);let p,c=f;if(("CIMPointSymbol"===s.type||"CIMTextSymbol"===s.type)&&_){let r=0,t=0;const i=k.geometry;"x"in i&&"y"in i&&(r+=i.x-.5*(_.xmin+_.xmax),t+=i.y-.5*(_.ymin+_.ymax));const o=e.anchorPoint;let a=!1;o&&("Absolute"===e.anchorPointUnits?(r-=o.x,t-=o.y,a=!0):_&&(r-=(_.xmax-_.xmin)*o.x,t-=(_.ymax-_.ymin)*o.y));const s={offsetX:r,offsetY:t,rotation:0,size:0,frameHeight:0,rotateClockWise:!1,absoluteAnchorPoint:a,scaleSymbolsProportionally:S};p=[...m,s]}const g=k.geometry,[b,C]=y(g,_);switch(0===b&&0===C||(c=d(c,b,C)),"CIMPointSymbol"===s.type&&(c=n(this._poMap,s,c)),s.type){case"CIMPointSymbol":case"CIMLineSymbol":case"CIMPolygonSymbol":u||$(s)?(c={...c,transform:{type:"AnimatedTransform",relativeTranslation:!1,absoluteScale:!0,translation:h([0,0]),rotation:h(0),scale:h(M),parent:f.transform}},this._analyzeMultiLayerGraphicNonSDF(e,r,t,k,i,o,a,p??m,c,M,v,O)):this._analyzeMultiLayerGraphic(e,r,t,k,i,o,a,p??m,c,M,v,O);break;case"CIMTextSymbol":this._analyzeTextGraphic(r,t,k,i,o,a,p??m,v)}l&&i.pop()}}_analyzeMultiLayerGraphic(e,r,t,i,o,a,s,l,n,p,c,m){const y=i.symbol.symbolLayers;y&&(!Z(y)||f(n)?ee(y)?this._analyzeMultiLayerGraphicNonSDF(e,r,t,i,o,a,s,l,n,p,!!c,m):this._analyzeMarkerGraphicSymbolLayers(e,r,t,i,o,a,s,l,n,p,c,m):this._analyzeCompositeMarkerGraphic(e,r,t,i,y,a,s,l,p,c,m))}_analyzeMarkerGraphicSymbolLayers(e,r,t,i,o,a,s,l,p,c,m,y){const d=i.symbol,h=d.symbolLayers;if(!h)return;const f=this._resourceManager.geometryEngine,u=W.applyEffects(d.effects,i.geometry,f);if(!u)return;let O=h.length;for(;O--;){const d=h[O];if(!d||!1===d.enable)continue;const g=d.primitiveName;switch(g&&o.push(g),d.type){case"CIMSolidFill":case"CIMSolidStroke":{const o=W.applyEffects(d.effects,u,f),h=S(o);if(!h)continue;const O="Relative"!==e.anchorPointUnits,_=R(d)??0,{frameSizeRatio:M,anchorX:C,anchorY:z,widthRatio:x,sdfPaddingRatio:E}=k(h,e.frame,e.size,e.anchorPoint,O,_,e.scaleSymbolsProportionally),L="CIMSolidFill"===d.type,V={type:"sdf",geom:o,sdfPaddingRatio:E,asFill:L},{path:N}=d,G=L?P(A(d)):null==N?P(w(d)):[0,0,0,0],F=L?[0,0,0,0]:P(w(d));if(!L&&!_)break;const T=i.primitiveName;let X=null;L&&!d.colorLocked&&(X=this._maybeGetValueOrOverrideExpression(T,"FillColor"));let Y=null;L||d.colorLocked||(Y=this._maybeGetValueOrOverrideExpression(T,"StrokeColor"));const j=X??this._getValueOrOverrideExpression(d.type,g,"Color",G),U=Y??this._getValueOrOverrideExpression(d.type,g,"Color",F),D=this._maybeGetValueOrOverrideExpression(T,"StrokeWidth")??this._getValueOrOverrideExpression(d.type,g,"Width",_),H=N?{type:"sprite-rasterization-param",resource:{type:"path",path:N,asFill:L},overrides:[]}:{type:"sprite-rasterization-param",resource:V,overrides:[]},J=n(this._poMap,d,p),B=I(e.size,v.CIMVectorMarker.size),q=this._getValueOrOverrideExpression(e.type,e.primitiveName,"Size",B);this._cimLayers.push({type:"marker",spriteRasterizationParam:H,colorLocked:!!d.colorLocked||!!m,effects:r,scaleSymbolsProportionally:!!e.scaleSymbolsProportionally,alignment:a,anchorPoint:{x:C,y:z},isAbsoluteAnchorPoint:O,size:c,rotation:0,offsetX:0,offsetY:0,scaleX:1,transform:{type:"cim-marker-transform-param",params:l},frameHeight:c,widthRatio:x,rotateClockwise:!1,referenceSize:s,sizeRatio:M,color:j,outlineColor:U,outlineWidth:D,isOutline:y,markerPlacement:t,animationParams:te(J),isStroke:"CIMSolidFill"!==d.type,baseSize:q,...b(o,E)});break}case"CIMPictureMarker":case"CIMVectorMarker":if(d.markerPlacement){H().error("Error analyzing CIM, got unexpected marker placement");break}this._analyzeMarker(d,r,t,o,a,s,!1,l,p,m,y)}g&&o.pop()}}_analyzeTextGraphic(e,t,i,o,a,s,l,n){const p=[];M.findApplicableOverrides(i,this._primitiveOverrides,p);const c=i.geometry;if(!("x"in c)||!("y"in c))return;const m=i.symbol,y=G(m),d=F(m.fontStyleName),h=r(m.fontFamilyName);m.font={family:h,decoration:y,...d};const f=I(m.height,v.CIMTextSymbol.height),u=I(m.angle),O=I(m.offsetX),g=I(m.offsetY),{haloSymbol:_}=m,S=I(m.haloSize,0);let k=[0,0,0,0];if(_?.symbolLayers?.length){const e=_.symbolLayers;for(const r of e)if(r.color){k=this._getValueOrOverrideExpression(m?.haloSymbol?.type??"CIMPolygonSymbol",r.primitiveName,"Color",P(r.color));break}}const b=i.primitiveName;let C=[0,0,0,1],z=[0,0,0,0],x=0,E=!1;if(m.symbol?.symbolLayers)for(const r of m.symbol.symbolLayers){const e=r.primitiveName;if("CIMSolidStroke"===r.type)z=this._getValueOrOverrideExpression("CIMSolidStroke",e,"Color",P(r.color)),x=this._getValueOrOverrideExpression("CIMSolidStroke",e,"Width",R(r)??0);else if("CIMSolidFill"===r.type){const t=P(r.color);E=E??!!r.colorLocked,C=this._getValueOrOverrideExpression("CIMSolidFill",e??b,"Color",t)}}let L=null,V=null,N=null,A=null,w=null;b&&(L=this._maybeGetValueOrOverrideExpression(b,"TextSize"),V=this._maybeGetValueOrOverrideExpression(b,"TextAngle"),N=this._maybeGetValueOrOverrideExpression(b,"TextOffsetX"),A=this._maybeGetValueOrOverrideExpression(b,"TextOffsetY"),E||(w=this._maybeGetValueOrOverrideExpression(b,"FillColor")));const Y=w??C;let j=null,W=null,U=0;if(m.callout&&"CIMBackgroundCallout"===m.callout.type){const e=m.callout;if(e.backgroundSymbol){const r=e.backgroundSymbol.symbolLayers;if(r)for(const e of r)"CIMSolidFill"===e.type?j=P(e.color):"CIMSolidStroke"===e.type&&(W=P(e.color),U=I(e.width,v.CIMSolidStroke.width))}}const D=this._getValueOrOverrideExpression(m.type,i.primitiveName,"TextString",i.textString??"");if(null==D)return;const{fontStyleName:H}=m,J=h+(H?"-"+H.toLowerCase():"-regular"),B=this._getMaterialOverrides(o,m.type);B.push(...this._getPrimitiveMaterialOverrides(i.primitiveName,m.type));const q={type:"text-rasterization-param",resource:{type:"text",textString:i.textString??"",font:m.font,symbol:m,primitiveName:i.primitiveName},overrides:B};this._cimLayers.push({type:"text",lineWidth:m.lineWidth,textRasterizationParam:q,colorLocked:!!n||!!E,effects:e,alignment:a,anchorPoint:{x:0,y:0},isAbsoluteAnchorPoint:!1,fontName:J,decoration:y,haloSize:S,haloColor:k,weight:d.weight,style:d.style,size:L??f,angle:V??u,offsetX:N??O,offsetY:A??g,transform:{type:"cim-marker-transform-param",params:l},horizontalAlignment:T(m.horizontalAlignment),verticalAlignment:X(m.verticalAlignment),text:D,color:Y,outlineColor:z,outlineSize:x,backgroundColor:j,borderLineColor:W,borderLineWidth:U,referenceSize:s,sizeRatio:1,markerPlacement:t})}_analyzeMultiLayerGraphicNonSDF(e,r,t,i,a,s,l,n,p,c,m,y){const d=q(e,i),h=e.primitiveName,f=this._analyzeMaterialOverrides(h,["Rotation","OffsetX","OffsetY"]),O=L(f),[g,_,M]=u.getTextureAnchor(d,this._resourceManager,U),S=this._getMaterialOverrides(a,e.type);S.push(...O);const k={type:"sprite-rasterization-param",resource:{...d,avoidSDFRasterization:!0},overrides:S},b=I(e.size,v.CIMVectorMarker.size),C=this._getValueOrOverrideExpression(e.type,h,"Size",b);this._cimLayers.push({type:"marker",spriteRasterizationParam:k,colorLocked:m,effects:r,scaleSymbolsProportionally:!!e.scaleSymbolsProportionally,alignment:s,anchorPoint:{x:g,y:_},isAbsoluteAnchorPoint:!1,size:c,rotation:0,offsetX:0,offsetY:0,transform:{type:"cim-marker-transform-param",params:n},color:[255,255,255,1],outlineColor:[0,0,0,0],outlineWidth:0,scaleX:1,frameHeight:c,widthRatio:1,rotateClockwise:!!e.rotateClockwise,referenceSize:l,sizeRatio:M/o(e.size),isOutline:y,markerPlacement:t,animationParams:te(p),baseSize:C})}_createMarkerPlacementOverrideExpression(e){if(!e)return null;const r=[];return M.findApplicableOverrides(e,this._primitiveOverrides,r),{type:"cim-marker-placement-param",placement:e,overrides:re(r)}}_createGIFAnimatedSymbolPropertiesOverrideExpression(e){if(!e)return null;const r=[];return M.findApplicableOverrides(e,this._primitiveOverrides,r),{type:"cim-gif-animation-params",animation:e,overrides:re(r)}}_analyzeCompositeMarkerGraphic(e,r,t,i,o,a,s,l,n,p,c){const m=i.geometry,y=o[0],d=o[1],h=S(m);if(!h)return;const f="Relative"!==e.anchorPointUnits,u=I(y.width,v.CIMSolidStroke.width),{frameSizeRatio:O,anchorX:g,anchorY:_,widthRatio:M,sdfPaddingRatio:b}=k(h,e.frame,e.size,e.anchorPoint,f,u,e.scaleSymbolsProportionally),{path:C}=d,z=d.primitiveName,x=y.primitiveName,E=i.primitiveName;let L=null;d.colorLocked||p||(L=this._maybeGetValueOrOverrideExpression(E,"FillColor"));const V=L??this._getValueOrOverrideExpression(d.type,z,"Color",P(d.color));let N=null;y.colorLocked||p||(N=this._maybeGetValueOrOverrideExpression(E,"StrokeColor"));const R=N??this._getValueOrOverrideExpression(y.type,x,"Color",P(y.color)),A=this._maybeGetValueOrOverrideExpression(E,"StrokeWidth")??this._getValueOrOverrideExpression(y.type,x,"Width",u),w={type:"sprite-rasterization-param",resource:C?{type:"path",path:C,asFill:!0}:{type:"sdf",geom:m,sdfPaddingRatio:b,asFill:!0},overrides:[]};this._cimLayers.push({type:"marker",spriteRasterizationParam:w,colorLocked:p,effects:r,scaleSymbolsProportionally:!!e.scaleSymbolsProportionally,alignment:a,anchorPoint:{x:g,y:_},isAbsoluteAnchorPoint:f,size:n,rotation:0,offsetX:0,offsetY:0,scaleX:1,transform:{type:"cim-marker-transform-param",params:l},frameHeight:n,widthRatio:M,rotateClockwise:!1,referenceSize:s,sizeRatio:O,color:V,outlineColor:R,outlineWidth:A,isOutline:c,markerPlacement:t})}_setPoMap(e,r,t){let i;this._poMap[e]?i=this._poMap[e]:(i={},this._poMap[e]=i),i[r]=t}_maybeGetValueOrOverrideExpression(e,r,t){return this._getValueOrOverrideExpression("",e,r,t,!1)}_getValueOrOverrideExpression(e,r,t,i,o=!0){if(o&&!Y(i)&&(i=V(e,t.toLowerCase())),null==r)return i;const a=this._poMap[r];if(null==a)return i;const s=a[t];return"string"==typeof s||"number"==typeof s||Array.isArray(s)?s:s?{valueExpressionInfo:s,defaultValue:i}:i}_analyzePrimitiveOverrides(e,r,t,i){if(null==e)return!1;"string"==typeof e&&(e=[e]);for(const o of this._primitiveOverrides)if(e.includes(o.primitiveName)&&o.valueExpressionInfo)return!0;if(null!=r)for(const o of r)if(o?.overrides.length>0)return!0;if(null!=t)for(const o of t)if(o?.overrides.length>0)return!0;if(null!=i)for(const o of i)if(o?.overrides.length>0)return!0;return!1}_getMaterialOverrides(e,r){if(!e)return[];const t=[];for(const i of e)t.push(...this._getPrimitiveMaterialOverrides(i,r));return t}_getPrimitiveMaterialOverrides(e,r){if(!e)return[];const t=L(this._primitiveOverrides.filter((r=>r.primitiveName===e)));return t.forEach((e=>e.defaultValue=V(r,e.propertyName.toLowerCase()))),t}_analyzeMaterialOverrides(e,r){return this._primitiveOverrides.filter((t=>t.primitiveName!==e||!r.includes(t.propertyName)))}}function q(e,r){return{type:e.type,enable:!0,name:e.name,colorLocked:e.colorLocked,primitiveName:e.primitiveName,anchorPoint:e.anchorPoint,anchorPointUnits:e.anchorPointUnits,offsetX:0,offsetY:0,rotateClockwise:e.rotateClockwise,rotation:0,size:e.size,billboardMode3D:e.billboardMode3D,depth3D:e.depth3D,frame:e.frame,markerGraphics:[r],scaleSymbolsProportionally:e.scaleSymbolsProportionally,respectFrame:e.respectFrame,clippingPath:e.clippingPath}}function K(e){if(e&&0===e.indexOf("Level_")){const r=parseInt(e.slice(6),10);if(!isNaN(r))return r}return 0}function Q(e,r){if(!r||0===r.length)return e;const i=t(e);return M.applyOverrides(i,r),i}const Z=e=>e&&2===e.length&&e[0].enable&&e[1].enable&&"CIMSolidStroke"===e[0].type&&"CIMSolidFill"===e[1].type&&null==e[0].path&&null==e[1].path&&!e[0].effects&&!e[1].effects&&!e[0].animations&&!e[1].animations;function $(e){const r=e.symbolLayers;if(!r)return!1;const t=r.find((e=>e.effects?.find((e=>"CIMGeometricEffectDashes"===e.type&&null!=e.dashTemplate)))),i=r.find((e=>e.effects?.find((e=>"CIMGeometricEffectAddControlPoints"===e.type))));return!!t||!!i}function ee(e){return e.some((e=>"CIMSolidFill"!==e.type&&"CIMSolidStroke"!==e.type&&("CIMVectorMarker"!==e.type&&"CIMPictureMarker"!==e.type||null!=e.markerPlacement)))}function re(e){return t(e).map((e=>({...e,propertyName:j(e.propertyName)})))}function te(e){return f(e)?{type:"animation-params",params:e}:null}export{B as CIMAnalyzer,Q as analyzeCIMResource};