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