@arcgis/core 4.34.3 → 4.34.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/{0638a36eaacb56cf89fa.js → 262851e9feb1e55ad09d.js} +1 -1
- package/assets/esri/core/workers/chunks/ce961c602c51637b3e1c.js +1 -0
- package/interfaces.d.ts +2 -2
- package/kernel.js +1 -1
- package/layers/IntegratedMesh3DTilesLayer.js +1 -1
- package/layers/graphics/sources/ParquetSource.js +1 -1
- package/layers/orientedImagery/transformations/imageToWorld.js +1 -1
- package/layers/support/parquetUtils.js +1 -1
- package/package.json +1 -1
- package/support/revision.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/raster/RasterColorizerTechnique.js +1 -1
- package/views/3d/layers/FlowSubView3D.js +1 -1
- package/views/3d/support/flow/constants.js +1 -1
- package/views/3d/webgl-engine/effects/smaa/SMAA.js +1 -1
- package/widgets/Editor/CreateFeaturesWorkflow.js +1 -1
- package/widgets/Editor/UpdateFeaturesWorkflowData.js +1 -1
- package/widgets/Legend/support/ActiveLayerInfo.js +1 -1
- package/widgets/OrientedImageryViewer/OrientedImageryViewerViewModel.js +1 -1
- package/widgets/OrientedImageryViewer/adapters/view/MapViewAdapter.js +1 -1
- package/widgets/OrientedImageryViewer/adapters/view/SceneViewAdapter.js +1 -1
- package/widgets/UtilityNetworkTrace/UtilityNetworkTraceViewModel.js +1 -1
- package/widgets/UtilityNetworkTrace.js +1 -1
- package/widgets/support/forms/expressions/FormExpressionArcadeExecutor.js +1 -1
- package/assets/esri/core/workers/chunks/c91ce5fcdd4d0a6514d3.js +0 -1
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.34/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{__decorate as e}from"tslib";import t from"../../../Color.js";import{addTokenParameter as i}from"../../../kernel.js";import s from"../../../request.js";import l from"../../../core/Accessor.js";import{isSome as r}from"../../../core/arrayUtils.js";import n from"../../../core/Collection.js";import has from"../../../core/has.js";import{JSONMap as a}from"../../../core/jsonMap.js";import o from"../../../core/Logger.js";import{clamp as u}from"../../../core/mathUtils.js";import{debounce as c}from"../../../core/promiseUtils.js";import{on as d,watch as y,initial as h,whenOnce as f}from"../../../core/reactiveUtils.js";import{px2pt as m}from"../../../core/screenUtils.js";import{parseWhereClause as p}from"../../../core/sql.js";import{addQueryParameters as g}from"../../../core/urlUtils.js";import{property as b}from"../../../core/accessorSupport/decorators/property.js";import{subclass as _}from"../../../core/accessorSupport/decorators/subclass.js";import{EffectView as S}from"../../../layers/effects/EffectView.js";import{getEffectiveDisplayFilter as w}from"../../../layers/support/displayFilterUtils.js";import{ExportImageParameters as v}from"../../../layers/support/ExportImageParameters.js";import{collectFields as L,collectArcadeFieldNames as E}from"../../../layers/support/fieldUtils.js";import{isFeatureLayer as F,supportsFieldConfiguration as C}from"../../../layers/support/layerUtils.js";import{getPixelValueRange as I}from"../../../layers/support/rasterFormats/pixelRangeUtils.js";import{fromJSON as R}from"../../../renderers/support/jsonUtils.js";import{isSupportedRenderer3D as V}from"../../../renderers/support/rendererConversion.js";import D from"../../../renderers/visualVariables/SizeVariable.js";import x from"../../../renderers/visualVariables/support/SizeVariableLegendOptions.js";import{updateReferenceSizeSymbol as z}from"../../../smartMapping/renderers/support/referenceSizeUtils.js";import T from"../../../symbols/SimpleFillSymbol.js";import j from"../../../symbols/SimpleMarkerSymbol.js";import{applyCIMSymbolColor as O}from"../../../symbols/support/cimSymbolUtils.js";import{renderSymbol as k}from"../../../symbols/support/renderUtils.js";import{renderColorRampPreviewHTML as M,renderDotDensityPreviewHTML as P,renderPieChartPreviewHTML as U,renderPreviewHTML as A}from"../../../symbols/support/symbolUtils.js";import{getCSSFilterFromEffectList as B,isVolumetricSymbol as N}from"../../../symbols/support/utils.js";import{getEffectiveClusterSizeVariable as $}from"./clusterUtils.js";import{getColorFromPointCloudStops as H,getRampStopsForPointCloud as q,getStretchRampStops as W,getRampStops as G}from"./colorRampUtils.js";import{getHeatmapRampStops as J}from"./heatmapRampUtils.js";import{getRotationAngleForFocus as Z,getRelationshipRampElement as Q}from"./relationshipRampUtils.js";import{getRampStops as K,realWorldMaxSize as X,realWorldMinSize as Y}from"./sizeRampUtils.js";import{specialCharsLessThan as ee,specialCharsGreaterThan as te,getAuthoringInfoVisualVariableByTheme as ie,getSymbolForFlowRenderer as se,formatValue as le,getFormatOptions as re,mergeWhereClauses as ne,getMedianColor as ae,rgbImgSource as oe,getFormatOptionsForVisualVariable as ue}from"./utils.js";import{formatNumberLabel as ce}from"../../smartMapping/support/utils.js";const de=16,ye="https://utility.arcgis.com/sharing/tools/legend",he="esri.layers.ImageryLayer",fe="esri.layers.ImageryTileLayer",me="esri.layers.WCSLayer",pe=/^\s*(return\s+)?\$view\.scale\s*(;)?\s*$/i,ge=new a({esriGeometryPoint:"point",esriGeometryMultipoint:"multipoint",esriGeometryPolyline:"polyline",esriGeometryPolygon:"polygon",esriGeometryMultiPatch:"multipatch"}),be=new j({size:6,outline:{color:[128,128,128,.5],width:.5}}),_e=new T({style:"solid"});function Se(e){return"flow"===e.type}function we(e){return"vector-field"===e.type}function ve(e){return"raster-colormap"===e.type}function Le(e){return"raster-stretch"===e.type}function Ee(e){return"raster-shaded-relief"===e.type}function Fe(e){return"esri.renderers.SimpleRenderer"===e.declaredClass}function Ce(e){return"esri.renderers.ClassBreaksRenderer"===e.declaredClass}function Ie(e){return"esri.renderers.UniqueValueRenderer"===e.declaredClass}function Re(e){return"esri.renderers.HeatmapRenderer"===e.declaredClass}function Ve(e){return xe(e)||ze(e)||Te(e)||De(e)}function De(e){return"esri.renderers.PointCloudRGBRenderer"===e.declaredClass}function xe(e){return"esri.renderers.PointCloudClassBreaksRenderer"===e.declaredClass}function ze(e){return"esri.renderers.PointCloudStretchRenderer"===e.declaredClass}function Te(e){return"esri.renderers.PointCloudUniqueValueRenderer"===e.declaredClass}function je(e){return"esri.renderers.DotDensityRenderer"===e.declaredClass}function Oe(e){return"esri.renderers.PieChartRenderer"===e.declaredClass}function ke(e,t){return Fe(e)||Ce(e)||Ie(e)||Re(e)||je(e)||Oe(e)?"2d"===t.type||V(e):Le(e)||ve(e)||Ee(e)||xe(e)||ze(e)||Te(e)||we(e)||Se(e)}function Me(e){return"esri.layers.BuildingSceneLayer"===e.declaredClass}function Pe(e){return"esri.layers.SubtypeGroupLayer"===e.declaredClass}function Ue(e){return"esri.layers.VoxelLayer"===e.declaredClass}function Ae(e){return"esri.layers.WMSLayer"===e.declaredClass}function Be(e){return"esri.layers.WMTSLayer"===e.declaredClass}function Ne(e){return"esri.layers.MapImageLayer"===e.declaredClass}function $e(e){return"esri.layers.TileLayer"===e.declaredClass}function He(e){return e.declaredClass===he}function qe(e){return e.declaredClass===fe}function We(e){return e.declaredClass===me}function Ge(e){return"stretch-ramp"===e.type}function Je(e){const t="authoringInfo"in e?e?.authoringInfo:null;return"univariate-color-size"===t?.type}function Ze(e){const t="authoringInfo"in e?e?.authoringInfo:null;return"univariate-color-size"===t?.type&&"above-and-below"===t?.univariateTheme}function Qe(e){return"sublayers"in e}function Ke(e){return e&&"symbol"in e}function Xe(e,t){const{field:i,field2:s,field3:l,fieldDelimiter:r,valueExpression:n}=e;if(!i)return null;const a=!(!i&&!n||!s&&!l)?t?.toString().split(r||""):[t],o=i?{[i]:a?.[0]}:null;return o&&(s&&(o[s]=a?.[1]),l&&(o[l]=a?.[2])),o}const Ye=new j({style:"path",path:"M10,5 L5,0 0,5 M5,0 L5,15",size:15,outline:{width:1,color:[85,85,85,1]}});let et={};const tt=new WeakMap;let it=class extends l{constructor(e){super(e),this._hasColorRamp=!1,this._hasOpacityRamp=!1,this._hasSizeRamp=!1,this._loading=!1,this._webStyleSymbolCache=new Map,this._dotDensityUrlCache=new Map,this._scaleDrivenSizeVariable=null,this._clusterSizeVariable=null,this._layerDefinitionExpression=null,this._layerDefinitionExpressionClause=null,this._layerDisplayFilter=null,this._layerDisplayFilterClause=null,this.children=new n,this.layerView=null,this.layer=null,this.legendElements=[],this.parent=null,this.hideLayersNotInCurrentView=!1,this.keepCacheOnDestroy=!1,this.respectLayerDefinitionExpression=!1,this.respectLayerVisibility=!0,this.sublayerIds=[],this.title=null,this.view=null}initialize(){const e=()=>this.notifyChange("ready");this.addHandles([d(()=>this.children,"change",t=>{const{added:i,removed:s}=t;i.forEach(t=>{const i=`activeLayerInfo-ready-watcher-${t.layer.uid}`;this.addHandles(y(()=>t.ready,e,h),i)}),s.forEach(e=>this.removeHandles(e.layer.uid)),e()})]),this.keepCacheOnDestroy||(et={})}destroy(){this._webStyleSymbolCache=null,this._dotDensityUrlCache=null,this._scaleDrivenSizeVariable=null,this.keepCacheOnDestroy||(et=null),this._layerDefinitionExpressionClause=null}get cssEffectFilter(){const{layer:e,scale:t}=this,i="effect"in e?e.effect:null;if(!i)return null;const s=new S({effect:i});return s.endTransition(),s.scale=t,B(s,!0)}get loading(){return this.children.length>0?this.children.some(e=>e.loading):this._loading}get opacity(){const e=this.layer.opacity,t=this.parent?.opacity,i=this.layer.parent,s=i&&"uid"in i?this._getParentLayerOpacity(i):null;return null!=t?t*e:null!=s?s*e:e}get ready(){return null===this.layer||(this.children.length>0?this._isGroupActive():this.legendElements.length>0)}get scale(){return this.view?.scale??0}get isScaleDriven(){const e=this.layer;if(null===e)return!1;if("effect"in e&&e.effect&&Array.isArray(e.effect))return!0;if("featureReduction"in e&&e.featureReduction){if("cluster"===e.featureReduction.type)return!0;if("binning"===e.featureReduction.type&&"renderer"in e.featureReduction&&e.featureReduction.renderer)return this._isRendererScaleDriven(e.featureReduction.renderer)}return"renderer"in e&&e.renderer?!!("displayFilterInfo"in e&&e.displayFilterInfo&&Ie(e.renderer))||this._isRendererScaleDriven(e.renderer):this._isLayerScaleDriven(this.layer)}get version(){return this._get("version")+1}async buildLegendElementsForFeatureCollections(e){this._loading=!0;if(!(!this.hideLayersNotInCurrentView||await this._isLayerInCurrentView()))return this.legendElements=[],this._loading=!1,void this.notifyChange("ready");const t=Array.from(e,e=>{if(F(e))return this._getRendererLegendElements(e.renderer,{title:e.title});if(e.featureSet?.features.length){const t=e.layerDefinition,i=t?.drawingInfo,s=i&&R(i.renderer),l=ge.read(t.geometryType);return s?this._getRendererLegendElements(s,{title:e.name,geometryType:l}):(o.getLogger(this).warn("drawingInfo not available!"),null)}return null});try{const e=[],i=await Promise.allSettled(t);for(const t of i)if("fulfilled"===t.status)for(const i of t.value??[])e.push(i);this.legendElements=e}catch(i){o.getLogger(this).warn("error while building legend for layer!",i)}finally{this._loading=!1,this.notifyChange("ready")}}async buildLegendElementsForRenderer(e){try{this._loading=!0;const t=!this.hideLayersNotInCurrentView||await this._isLayerInCurrentView();this.legendElements=t?await this._getRendererLegendElements(e):[]}catch(t){o.getLogger(this).warn("error while building legend for layer!",t)}finally{this._loading=!1,this.notifyChange("ready")}}async buildLegendElementsForFeatureReduction(e){try{this._loading=!0,await this._waitForLayerViewUpdate(this.layerView);const t=!this.hideLayersNotInCurrentView||await this._isLayerInCurrentView();this.legendElements=t?await this._getLegendElementsForFeatureReduction(e):[]}catch(t){o.getLogger(this).warn("error while building legend for layer!",t)}finally{this._loading=!1,this.notifyChange("ready")}}async buildLegendElementsForTools(){this._loading=!0;const e=this.layer;if(Ue(e))await this._constructLegendElementsForVoxelLayer();else if(Be(e))this._constructLegendElementsForWMTSlayer();else if(Ae(e))await this._constructLegendElementsForWMSSublayers();else if(Me(e))await this._constructLegendElementsForBuildingSceneLayer();else if(Ne(e)||$e(e)||Pe(e))await this._constructLegendElementsForSublayers();else{this.removeHandles("imageryLayers-watcher");let t="default";if(He(e)){const i=e;t=(i?.rasterFunction?.functionName||"default")+"_"+(e.bandIds?.length?e.bandIds.join(""):"###")}if(qe(e)||"link-chart"===e.type)return;await this._getLegendLayers(`${e.uid}-${t}`).then(async t=>{this.legendElements=[];const i=t.map(async t=>{if(He(e)){const t=y(()=>[e.rasterFunction,e.bandIds],()=>c(async()=>{et.default=null,e.renderer?await this.buildLegendElementsForRenderer(e.renderer):await this.buildLegendElementsForTools()})());this.addHandles(t,"imageryLayers-watcher")}const i=this._generateSymbolTableElementForLegendLayer(t);i?.infos.length&&(He(e)&&(i.title=e.title),this.legendElements.push(i))});await Promise.allSettled(i)}).catch(e=>{o.getLogger(this).warn("Request to server for legend has failed!",e)})}this._loading=!1,this.notifyChange("ready")}async _isLayerInCurrentView(e){return this._checkFeatureCountForExpression(e,this.view.extent)}_getParentLayerOpacity(e){let t=1;const i=e.parent;return i&&"uid"in i&&(t=this._getParentLayerOpacity(i)),e.opacity*t}_isGroupActive(){return this.children.some(e=>e.ready)}_isRendererScaleDriven(e){if("dot-density"===e.type)return!0;const t="valueExpression"in e?e.valueExpression:null;if(pe.test(t))return!0;const i="visualVariables"in e?e.visualVariables:null;return!!i?.some(e=>this._isScaleDrivenSizeVariable(e))||this._hasScaleDrivenSymbols(e)}_hasScaleDrivenSymbols(e){switch(e.type){case"simple":return this._isScaleDrivenSymbol(e.symbol);case"class-breaks":return this._isScaleDrivenSymbol(e.defaultSymbol)||e.classBreakInfos.some(e=>this._isScaleDrivenSymbol(e.symbol));case"unique-value":return this._isScaleDrivenSymbol(e.defaultSymbol)||!!e.uniqueValueInfos?.some(e=>this._isScaleDrivenSymbol(e.symbol))}return!1}_isScaleDrivenSymbol(e){if("cim"===e?.type){const{primitiveOverrides:t,minScale:i,maxScale:s}=e.data,l=t?.some(e=>(e.valueExpressionInfo?.expression||"").includes("$view.scale"))??!1;return null!=i||null!=s||l}return!1}_isScaleDrivenSizeVariable(e){if(e&&"size"!==e.type)return!1;const t=e,i=t.minSize,s=t.maxSize;return!("object"!=typeof i||!i||!this._isScaleDrivenSizeVariable(i))||(!("object"!=typeof s||!s||!this._isScaleDrivenSizeVariable(s))||pe.test(t.valueExpression))}_isLayerScaleDriven(e){if("minScale"in e&&e.minScale>0||"maxScale"in e&&e.maxScale>0)return!0;if("sublayers"in e&&e.sublayers)return e.sublayers.some(e=>this._isLayerScaleDriven(e));const t=e.parent;if(!1===e.loaded&&t&&Ne(t)&&"source"in e&&e.source&&"map-layer"===e.source.type)for(const i of t.sourceJSON.layers??[])if(i.id===e.source.mapLayerId&&(i.minScale>0||i.maxScale>0))return!0;return!1}async _constructLegendElementsForVoxelLayer(){this._loading=!0,this.legendElements=[],this.removeHandles("voxel-style-watcher"),this.removeHandles("voxel-current-variable");const e=this.layer;this.addHandles(y(()=>e.currentVariableId,()=>this._constructLegendElementsForVoxelLayer()),"voxel-current-variable"),this.addHandles(y(()=>e.getVariableStyles(),()=>this._constructLegendElementsForVoxelLayer()),"voxel-style-watcher");const t=e.getVariableStyle(null),i=[];if(t)if(t.uniqueValues?.length){const e=[];t.uniqueValues.forEach(t=>{t.enabled&&e.push({label:t.label||`${t.value}`,value:t.value,symbol:new T({color:t.color,outline:null})})}),e.length&&i.push({type:"symbol-table",title:t.label,infos:e})}else if(t.transferFunction){const{colorStops:e,stretchRange:s}=t.transferFunction,l=e.toArray().reverse(),r=s.map((e,t)=>`${0===t?ee:te} ${ce(e)}`).reverse(),n=l.map(e=>({color:e.color,value:null,label:null}));n[0].label=r[0],n[n.length-1].label=r[1],i.push({type:"color-ramp",title:t.label,infos:n,preview:M(l.map(e=>e.color))})}await this._generatePreviewsForLegendElements(i,{opacity:e.opacity}),this.legendElements=i,this._loading=!1,this.notifyChange("ready")}_constructLegendElementsForWMTSlayer(){this._loading=!0,this.legendElements=[],this.removeHandles("wmts-activeLayer-watcher");const e=this.layer.activeLayer;this.addHandles(y(()=>{const{layer:e}=this;return e&&"activeLayer"in e&&e.activeLayer},()=>this._constructLegendElementsForWMTSlayer()),"wmts-activeLayer-watcher");const t=e.styleId?e.styles?.find(({id:t})=>t===e.styleId)?.legendUrl:void 0;t&&(this.legendElements=[{type:"symbol-table",title:e.title,infos:[{src:t,opacity:this.opacity}]}]),this._loading=!1,this.notifyChange("ready")}async _constructLegendElementsForWMSSublayers(){this._loading=!0,this.legendElements=[],this.removeHandles("wms-sublayers-watcher");const e=this.layer;let t=null;(e.customParameters||e.customLayerParameters)&&(t={...e.customParameters,...e.customLayerParameters}),this.addHandles(y(()=>{const{layer:e}=this;return e&&"sublayers"in e&&e.sublayers},()=>this._constructLegendElementsForWMSSublayers()),"wms-sublayers-watcher"),this.legendElements=await this._generateLegendElementsForWMSSublayers(e.sublayers,t),this._loading=!1,this.notifyChange("ready")}async _generateLegendElementsForWMSSublayers(e,t){const i=this.layer,s=[];this.addHandles(e.on("change",()=>this._constructLegendElementsForWMSSublayers()),"wms-sublayers-watcher");const l=this.sublayerIds?.map(e=>i.findSublayerById(e))?.filter(r)??[],n=l.length?l:e.toArray();for(const r of n){const e=y(()=>[r.title,r.visible,r.legendEnabled],()=>this._constructLegendElementsForWMSSublayers());if(this.addHandles(e,"wms-sublayers-watcher"),!this.respectLayerVisibility||r.visible&&r.legendEnabled){const e=await this._generateSymbolTableElementForWMSSublayer(r,t);e?.infos.length&&s.unshift(e)}}return s}async _generateSymbolTableElementForWMSSublayer(e,t){if(!e.legendUrl&&e.sublayers){const i=(await this._generateLegendElementsForWMSSublayers(e.sublayers,t)).filter(e=>e);return{type:"symbol-table",title:e.title,infos:i}}return this._generateSymbolTableElementForLegendUrl(e,t)}async _generateSymbolTableElementForLegendUrl(e,t){let i=e.legendUrl;if(!i)return;const l={type:"symbol-table",title:e.title||e.name||String(e.id??""),infos:[]};t&&(i=g(i,t));let r=null;const n=e.layer?.opacity;try{r=(await s(i,{responseType:"image"})).data,r&&(r.style.opacity=n)}catch{}return l.infos.push({src:i,preview:r,opacity:n}),l}_getLegendLayers(e,t){const i=et&&et[e];return i?Promise.resolve(i):this._legendRequest(t).then(t=>{const i=t.layers;return et[e]=i,i})}_legendRequest(e){const t=this.layer;let i={f:"json",dynamicLayers:e};if(He(t)){const e=t.exportImageServiceParameters.rasterFunction;if(e&&(i.renderingRule=JSON.stringify(e.functionDefinition?.toJSON()||e.toJSON())),t.bandIds&&(i.bandIds=t.bandIds.join()),t.raster||t.viewId||t.customParameters){const{raster:e,viewId:s,customParameters:l}=t;i={raster:e,viewId:s,...i,...l}}}let l=t.url.replace(/(\/)+$/,"");if("version"in t&&+t.version>=10.01){const e=l.indexOf("?");e>-1?l=l.slice(0,e)+"/legend"+l.slice(e):l+="/legend"}else{const e=l.toLowerCase().indexOf("/rest/"),t=-1===e?l:l.slice(0,e)+l.slice(e+5);l=ye+"?soapUrl="+encodeURI(t)+"&returnbytes=true"}return s(l,{query:i}).then(e=>e.data)}async _constructLegendElementsForBuildingSceneLayer(){this._loading=!0,this.legendElements=[],this.removeHandles("sublayers-watcher");const e=this.layer;this.addHandles(y(()=>e.sublayers,()=>this._constructLegendElementsForBuildingSceneLayer()),"sublayers-watcher");try{this.legendElements=await this._generateLegendElementsForBuildingSublayers(e.sublayers,this.opacity)}catch(t){o.getLogger(this).warn("Request to server for legend has failed!",t)}finally{this._loading=!1,this.notifyChange("ready")}}async _generateLegendElementsForBuildingSublayers(e,t){let i=[];this.addHandles(e.on("change",()=>this._constructLegendElementsForBuildingSceneLayer()),"sublayers-watcher");const s=e.toArray();for(const l of s){const e=y(()=>["renderer"in l&&l.renderer,l.opacity,l.title,l.visible],()=>this._constructLegendElementsForBuildingSceneLayer());if(this.addHandles(e,"sublayers-watcher"),!this.respectLayerVisibility||l.visible){const e=null!=l?.opacity?l.opacity:null,s=null!=e?e*t:t;if("building-group"===l.type){const e={type:"symbol-table",title:l.title,infos:[]},t=await this._generateLegendElementsForBuildingSublayers(l.sublayers,s);e.infos.push(...t),i=[e,...i]}else if(l.renderer){i=[...await this._getRendererLegendElements(l.renderer,{title:l.title,opacity:s,sublayer:l}),...i]}}}return i.filter(e=>!!e&&(!("infos"in e)||!e.infos||e.infos.length>0))}async _constructLegendElementsForSublayers(){this._loading=!0,this.removeHandles("sublayers-watcher");const e=this.layer;if(!(Ne(e)||$e(e)||Pe(e))||this.hideLayersNotInCurrentView&&!await this._isLayerInCurrentView())return this.legendElements=[],this._loading=!1,void this.notifyChange("ready");this.addHandles(y(()=>e.sublayers,()=>this._constructLegendElementsForSublayers),"sublayers-watcher");try{this.legendElements=await this._generateLegendElementsForSublayers(e.sublayers,this.opacity)}catch(t){o.getLogger(this).warn("Request to server for legend has failed!",t)}finally{this._loading=!1,this.notifyChange("ready")}}async _generateLegendElementsForSublayers(e,t,i){const s=this.layer;let l=[];this.addHandles(e.on("change",()=>this._constructLegendElementsForSublayers()),"sublayers-watcher");let n=e.toArray();!i&&this.sublayerIds&&this.sublayerIds.length&&(n=Pe(s)?this.sublayerIds.map(e=>s.findSublayerForSubtypeCode(e)).filter(r):this.sublayerIds.map(e=>s.findSublayerById(e)).filter(r));for(const r of n){const e=y(()=>[r.renderer,r.opacity,r.title,r.visible,r.legendEnabled],()=>this._constructLegendElementsForSublayers());this.addHandles(e,"sublayers-watcher");const s=r.createQuery().where,n=!this.hideLayersNotInCurrentView||await this._isLayerInCurrentView(s),a=!this.respectLayerVisibility||r.visible&&r.legendEnabled&&this._isSublayerInScale(r);if(n&&a){const e=null!=r?.opacity?r.opacity:null,s=null!=e?e*t:t,n=!Qe(r)||r.originIdOf("renderer")>2&&!r.sublayers;if(r.renderer&&n){await r.load();l=[...await this._getRendererLegendElements(r.renderer,{title:r.title,opacity:s,sublayer:r}),...l]}else if(Qe(r)){const e=await this._generateSymbolTableElementForSublayer(r,s,i);e&&l.unshift(e)}}}return l.filter(e=>!!e&&(!("infos"in e)||!e.infos||e.infos.length>0))}async _generateSymbolTableElementForSublayer(e,t,i){if(!i){i=new Map;const t=this.layer,s=e.source;let l=null;if(!(!s||"map-layer"===s.type&&s.mapLayerId===e.id&&(!s.gdbVersion||s.gdbVersion===("gdbVersion"in t&&t.gdbVersion)))||e.originIdOf("renderer")>2||e.originIdOf("labelingInfo")>2||e.originIdOf("labelsVisible")>2){const e=new v({layer:this.layer});l=e.hasDynamicLayers?e.dynamicLayers:null,e.destroy()}const r=l||`${t.uid}-default`;(await this._getLegendLayers(r,l)).forEach(e=>i.set(e.layerId,e))}const s=i.get(e.id);if((!s||s?.subLayerIds&&s.defaultVisibility)&&e.sublayers){const s=await this._generateLegendElementsForSublayers(e.sublayers,t,i);return{type:"symbol-table",title:e.title,infos:s}}return this._generateSymbolTableElementForLegendLayer(s,e,t)}_generateSymbolTableElementForLegendLayer(e,t,i){if(!e?.legend||this.respectLayerVisibility&&!this._isLegendLayerInScale(e,t))return null;const s=t?.renderer;let l=t?.title||e.layerName;if(s&&(!t||t?.originIdOf("renderer")>2)){const e=t?.title||this._getRendererTitle(s,t);e&&(l&&"string"!=typeof e&&"title"in e&&(e.title=l),l=e)}const r={type:"symbol-table",title:l,legendType:e.legendType||null,infos:[]},n=t?this._sanitizeLegendForSublayer(e.legend.slice(),t):e.legend;return e.legendGroups&&e.legendGroups.length>0?e.legendGroups.forEach(s=>{const l={type:"symbol-table",title:s.heading,legendType:e.legendType||null,infos:this._generateSymbolTableElementInfosForLegendLayer(n.filter(e=>e.groupId===s.id),e.layerId,s.heading||r.title||t?.title,i)};l.infos?.length>0&&r.infos.push(l)}):r.infos=this._generateSymbolTableElementInfosForLegendLayer(n,e.layerId,r.title||t?.title,i),r.infos.length>0?r:null}_generateSymbolTableElementInfosForLegendLayer(e,t,s,l){return e.map(e=>{let r=e.url;if(e.imageData&&e.imageData.length>0)r=`data:image/png;base64,${e.imageData}`;else{if(r.startsWith("http"))return null;r=i(`${this.layer.url}/${t}/images/${r}`)}let n=e.label;return"<all other values>"===n&&(n="others"),{previewAriaLabel:n||s,label:n,src:r,opacity:l??this.opacity,width:e.width,height:e.height}}).filter(r)}_isSublayerInScale(e){const t=e.minScale||0,i=e.maxScale||0;return!(t>0&&t<this.scale||i>this.scale)}_isLegendLayerInScale(e,t){const i=t||this.layer;let s=null,l=null,r=!0;return!i.minScale&&0!==i.minScale||!i.maxScale&&0!==i.maxScale?(0===e.minScale&&i.tileInfo&&(s=i.tileInfo.lods[0].scale),0===e.maxScale&&i.tileInfo&&(l=i.tileInfo.lods[i.tileInfo.lods.length-1].scale)):(s=Math.min(i.minScale,e.minScale)||i.minScale||e.minScale,l=Math.max(i.maxScale,e.maxScale)),(s>0&&s<this.scale||l>this.scale)&&(r=!1),r}_sanitizeLegendForSublayer(e,t){if("version"in this.layer&&+this.layer.version<10.1||0===e.length)return e;const i=t.renderer,s=e.some(e=>e.values);let l=0,r=null;return s&&e.some((e,t)=>(e.values||(l=t,r=e,r.label||(r.label="others")),null!=r)),i?"unique-value"===i.type?r&&(e.splice(l,1),e.push(r)):"class-breaks"===i.type&&(r&&e.splice(l,1),i.legendOptions?.order||e.reverse(),r&&e.push(r)):r&&(e.splice(l,1),e.push(r)),e}async _getRendererLegendElements(e,t={}){if(!ke(e,this.view))return o.getLogger(this).warn(`Renderer of type '${e.type}' not supported!`),[];if(Ve(e))return this._constructPointCloudRendererLegendElements(e,t);if(je(e))return this._constructDotDensityRendererLegendElements(e);const i=await this._loadRenderer(e);return Oe(i)?this._constructPieChartRendererLegendElements(i):this._constructRendererLegendElements(i,t)}async _getLegendElementsForFeatureReduction(e){let t=null;return"binning"===e.type?t=e.renderer:"cluster"===e.type&&(t=this._getClusterRenderer(e)),t?this._getRendererLegendElements(t,{isFeatureReductionRenderer:!0}):[]}_getPointCloudRendererTitle(e){return(e.legendOptions?.title||e.field)??""}async _constructPointCloudRendererLegendElements(e,t={}){const i=t.title,s=[];let l=null,r=null;if(xe(e))l={type:"symbol-table",title:i||this._getPointCloudRendererTitle(e),infos:[]},e.colorClassBreakInfos.forEach(e=>{l.infos.unshift({label:e.label||e.minValue+" - "+e.maxValue,value:[e.minValue,e.maxValue],symbol:this._getAppliedCloneSymbol(be,e.color)})});else if(ze(e)){const t=e.stops;let s=null;if(t?.length&&(1===t.length&&(s=t[0].color),!s)){const e=t[0].value,i=t[t.length-1].value;if(null!=e&&null!=i){s=H(e+(i-e)/2,t)}}l={type:"symbol-table",title:null,infos:[{label:null,value:null,symbol:this._getAppliedCloneSymbol(be,s||be.color)}]};const n=q(e.stops??[])??[];r={type:"color-ramp",title:i||this._getPointCloudRendererTitle(e),infos:n,preview:M(n.map(e=>e.color))}}else Te(e)&&(l={type:"symbol-table",title:i||this._getPointCloudRendererTitle(e),infos:[]},e.colorUniqueValueInfos?.forEach(e=>{l.infos.push({label:e.label||e.values.join(", "),value:e.values.join(", "),symbol:this._getAppliedCloneSymbol(be,e.color)})}));return l?.infos.length&&s.push(l),r?.infos.length&&s.push(r),await this._generatePreviewsForLegendElements(s,{opacity:this.opacity,symbolConfig:{applyColorModulation:!!e.colorModulation}}),s}async _getElementInfoForDotDensity(e,t){const{color:i,label:s,valueExpressionTitle:l}=t,{backgroundColor:r,outline:n,dotSize:a}=e,o=this.cssEffectFilter,u=a+"-"+i+"-"+r+"-"+(n&&JSON.stringify(n.toJSON()))+"-"+o,c=this._dotDensityUrlCache,d=c.has(u)?c.get(u):P(e,i);c.set(u,d);const y={shape:{type:"image",x:0,y:0,width:d.width,height:d.height,src:d.src},fill:null,stroke:null,offset:[0,0]},h=k([[y]],[d.width,d.height],{cssEffectFilter:this.cssEffectFilter});return{opacity:1,src:d.src,preview:h,width:d.width,height:d.height,previewAriaLabel:s||l}}async _constructDotDensityRendererLegendElements(e){const t=e.calculateDotValue(this.view.scale),i=e.legendOptions?.unit,s={type:"symbol-table",title:{value:t&&Math.round(t),unit:i||""},infos:[]};for(const l of e.attributes){const t=await this._getElementInfoForDotDensity(e,l);t.label=l.label||l.valueExpressionTitle||l.field,s.infos.push(t)}return[s]}async _constructPieChartRendererLegendElements(e){const t=[];let i=null;const s=e.outline;e.attributes.forEach(e=>{const i=new j({color:e.color,outline:s}),l=e.label||e.valueExpressionTitle||e.field;t.push({label:l,symbol:i})});const l=t.length?[...t]:[];if(e.othersCategory?.color&&0!==e.othersCategory?.threshold){const l=new j({color:e.othersCategory.color,outline:s});i=e.othersCategory.label||"Other",t.push({label:i,symbol:l})}if(e.defaultColor?.a){const i=new j({color:e.defaultColor,outline:s});t.push({label:e.defaultLabel,symbol:i})}const r=await this._getVisualVariableLegendElements(e,this.layer)||[];if(t.length){r.unshift({type:"symbol-table",title:null,infos:t});const n=l.filter(e=>e.label!==i).map(e=>e.symbol.color).filter(Boolean),a=U(n,{holePercentage:e.holePercentage,backgroundColor:e.backgroundFillSymbol?.color,cssEffectFilter:this.cssEffectFilter,outline:s});r.unshift({type:"pie-chart-ramp",title:this._getRendererTitle(e,this.layer),infos:t,preview:a})}return await this._generatePreviewsForLegendElements(r,{opacity:this.layer.opacity,cssEffectFilter:this.cssEffectFilter}),r}async _getWhereClause(e,t,i){const s=await p(e,i),l=new Set,{field:r,field2:n,field3:a}=t;L(l,i,[r,n,a]),await E(l,i,null,t.valueExpression);const o=new Set(Array.from(l,e=>e.toLowerCase())),u=s?.fieldNames.map(e=>e.toLowerCase());return u?.some(e=>!o.has(e))?null:s}async _processDefinitionExpression(e,t){if(!("definitionExpression"in e))return;const i=e.definitionExpression;i&&this.respectLayerDefinitionExpression?this._layerDefinitionExpression!==i&&(this._layerDefinitionExpressionClause=await this._getWhereClause(i,t,e.fieldsIndex)):this._layerDefinitionExpressionClause=null,this._layerDefinitionExpression=i}async _processDisplayFilter(e,t){if(!("displayFilterInfo"in e))return;const i=e.displayFilterInfo?w(e.displayFilterInfo,this.view):null;return i?.where?this._layerDisplayFilter?.id!==i?.id&&(this._layerDisplayFilterClause=await this._getWhereClause(i.where,t,e.fieldsIndex)):this._layerDisplayFilterClause=null,this._layerDisplayFilter=i,i}async _constructRendererLegendElements(e,t={}){const{title:i,sublayer:s,isFeatureReductionRenderer:l}=t,r=s||this.layer,n=ie(e,"reference-size"),a=ie(e,"spike"),o=l&&"renderer"in r&&r.renderer?r.renderer:e;let u=null;Ie(o)&&(await this._processDefinitionExpression(r,o),u=await this._processDisplayFilter(r,o)),this._hasColorRamp=!1,this._hasOpacityRamp=!1,this._hasSizeRamp=!1,this._scaleDrivenSizeVariable=null;const c=await this._getVisualVariableLegendElements(e,r)||[],d={type:"symbol-table",title:i||this._getRendererTitle(e,r),infos:[]};let y=null,h=!1;const f=new Set;if(Se(e)&&!this._hasSizeRamp){const t=await se(e);d.infos.push({label:null,symbol:t})}else if(Je(e)){let t=i;const s=Ze(e)?"univariate-above-and-below-ramp":"univariate-color-size-ramp",l=c.findIndex(e=>"color-ramp"===e.type),r=-1!==l?c.splice(l,1)[0]:null,n=c.findIndex(e=>"size-ramp"===e.type),a=-1!==n?c.splice(n,1)[0]:null,o=[];r&&(t=r.title,o.push(r)),a&&(t=a.title,o.push(a)),o.length>0&&c.push({type:s,title:t,infos:o})}else if(Re(e)){const t=J(e);c.push({type:"heatmap-ramp",title:i||this._getRendererTitle(e,r),infos:t,preview:M(t.map(e=>e.color),{cssEffectFilter:this.cssEffectFilter})})}else if(Ie(e)){const t=e.authoringInfo;if(t&&"relationship"===t.type){const{numClasses:i,field1:s,field2:l}=t,n=t.focus;if(i&&s&&l){const t=[s,l];let a=Z(n)||0;for(const e of t){const{field:t,normalizationField:i,label:s}=e,l=s||{field:this._getFieldAlias(t,r),normField:i&&this._getFieldAlias(i,r)},n=Ye.clone();n.angle=a,d.infos.push({label:l,symbol:n}),f.add(n),a+=90}const o=Q({focus:n,numClasses:i,infos:e.uniqueValueInfos??[]});c.unshift(o)}}else if(He(this.layer)||qe(this.layer)){const{uniqueValueInfos:t}=e;if(t)for(const e of t)e.symbol&&await this._checkClausesForUVR(o,e.value)&&d.infos.push({label:e.label||e.value,value:e.value,symbol:e.symbol})}else{const{field:t,field2:s,field3:l,fieldDelimiter:a,valueExpression:c,defaultSymbol:y}=e,f=!(!t&&!c||!s&&!l),m=u?u.title:null,p=[],{uniqueValueGroups:g}=e;if(g)for(const e of g){const i={type:"symbol-table",title:m||e.heading,infos:[]},{classes:u}=e;if(u)for(const e of u){const{symbol:u,values:d}=e;if(u){const y=[],h=[];for(const e of d??[]){const{value:i,value2:n,value3:o}=e,u=[],d=[];(t||c)&&(u.push(i),d.push(this._getDomainName(t,i,r)??le(i,re(r,t,this.view.timeZone)))),s&&(u.push(n),d.push(this._getDomainName(s,n,r)??le(n,re(r,s,this.view.timeZone)))),l&&(u.push(o),d.push(this._getDomainName(l,o,r)??le(o,re(r,l,this.view.timeZone)))),y.push(f?u.join(a||""):u[0]),h.push(d.join(" - "))}const m=y.join(", ");let p=e.label;if(!p){const e=h.filter(Boolean);p=e.length?e.join(", "):m}let g=u;"cim"===g.type&&n&&(g=g.clone(),z(g,{innerDotSize:.5*de,outerRingSize:de}));let b=!1;for(const e of y)if(b=await this._checkClausesForUVR(o,e),b)break;b&&i.infos.push({label:p,value:m,symbol:g})}}i.infos.length&&p.push(i)}if(p.length){const t=p[0];if(1===p.length&&"title"in t&&!t.title){const e=t.infos?.filter(Ke)??[];d.infos.push(...e)}else y&&(p.push({type:"symbol-table",infos:[{label:e.defaultLabel||"others",symbol:y}]}),h=!0),d.infos.push(...p);i||e.legendOptions?.title||e.valueExpressionTitle||(d.title=null)}}e.defaultSymbol&&!h&&(d.infos.push({label:e.defaultLabel||"others",symbol:e.defaultSymbol}),h=!0)}else if(Ce(e)){if(!n&&!a){y=this._isUnclassedRenderer(e);if(!y||!this._hasSizeRamp){const t=e.classBreakInfos.filter(({symbol:e})=>e),i="ascending-values"===e.legendOptions?.order;for(const{label:e,minValue:s,maxValue:l,symbol:n}of t){const t=e||(y?null:`${s} - ${l}`),a={previewAriaLabel:t||d.title||r.title,label:t,value:[s,l],symbol:n};i?d.infos.push(a):d.infos.unshift(a)}y&&(d.title=null),this._updateInfosForClassedSizeRenderer(e,d.infos)}e.defaultSymbol&&!y&&(d.infos.push({label:e.defaultLabel||"others",symbol:e.defaultSymbol}),h=!0)}}else if(Le(e))if(qe(this.layer)||We(this.layer)){const t=await this._constructTileImageryStretchRendererElements(e);Ge(t)?c.push(t):d.infos=t}else{const t=this.layer;let i,s;e.customStatistics?.length&&({min:i,max:s}=e.customStatistics[0]);let l=[],r=t.serviceRasterInfo;if(t.rasterFunction)try{r=await t.generateRasterInfo(t.rasterFunction)}catch{}const n=I(r.pixelType);if(1===r.bandCount){const l=t.bandIds?.[0]||0;i=null!=i?i:r.statistics?r.statistics[l].min:n[0],s=null!=s?s:r.statistics?r.statistics[l].max:n[1],i||s?c.push(await this._getStretchLegendElements(e,{min:i,max:s})):this._getServerSideLegend()}else if(t.bandIds&&1===t.bandIds.length)i=null!=i?i:r.statistics?r.statistics[t.bandIds[0]].min:n[0],s=null!=s?s:r.statistics?r.statistics[t.bandIds[0]].max:n[1],i||s?c.push(await this._getStretchLegendElements(e,{min:i,max:s})):this._getServerSideLegend();else if(r.bandCount>=3){const{bandInfos:e}=r,{bandIds:i}=t;e.length>=r.bandCount?3===i?.length?(l=i.map(t=>e[t].name),d.infos=this._createSymbolTableElementMultiBand(l)):"lerc"===t.format?(l=[0,1,2].map(t=>e[t].name),d.infos=this._createSymbolTableElementMultiBand(l)):this._getServerSideLegend():"lerc"===t.format?(l=["band1","band2","band3"],d.infos=this._createSymbolTableElementMultiBand(l)):this._getServerSideLegend()}else this._getServerSideLegend()}else if(ve(e))e.colormapInfos.forEach(e=>{d.infos.push({label:e.label,value:e.value,symbol:this._getAppliedCloneSymbol(_e,e.color)})});else if(Fe(e)){let i=e.symbol;switch(t.geometryType){case"point":i="pointSymbol"in r?r.pointSymbol:null;break;case"polyline":i="lineSymbol"in r?r.lineSymbol:null;break;case"polygon":i="polygonSymbol"in r?r.polygonSymbol:null}const s=this._clusterSizeVariable&&this._getClusterSymbol()||!this._hasSizeRamp;e.symbol&&s&&d.infos.push({previewAriaLabel:e.label||d.title||r.title,label:e.label,symbol:i})}else if(we(e)){e.outputUnit&&(this.title="("+e.toJSON().outputUnit+")"),d.title=e.attributeField;const t=e.getClassBreakInfos();t?.length?t.forEach(e=>{d.infos.push({label:e.minValue+" - "+e.maxValue,symbol:e.symbol})}):d.infos.push({label:e.attributeField,symbol:e.getDefaultSymbol()})}else Ee(e)&&c.push(await this._getStretchLegendElements(e,{min:0,max:255}));const m=e.defaultSymbol;!m||h||Fe(e)||y&&!this._hasColorRamp&&!this._hasSizeRamp&&!this._hasOpacityRamp||c.push({type:"symbol-table",infos:[{label:e.defaultLabel||"others",symbol:m}]}),d.infos.length&&c.unshift(d);const p=null==t.opacity?this.opacity:t.opacity,g=this._isTallSymbol("visualVariables"in e?e.visualVariables:null),b=He(this.layer)||qe(this.layer);return await this._generatePreviewsForLegendElements(c,{opacity:p,symbolConfig:{isTall:g,isSquareFill:b},cssEffectFilter:this.cssEffectFilter},{arrowMarkerSymbols:f}),e=null,c}async _waitForLayerViewUpdate(e){await f(()=>!e.updating)}async _checkFeatureCountForExpression(e,t){const i=this.layerView;if(!(i&&"createQuery"in i&&"queryFeatureCount"in i))return!0;try{await this._waitForLayerViewUpdate(i);const s=i.createQuery();e&&(s.where=ne(s.where,e)),t&&(s.geometry=t);return await i.queryFeatureCount(s)>0}catch{return!0}}async _checkClausesForUVR(e,t){const i=Xe(e,t);if(!i)return!0;return(!!!(!this._layerDefinitionExpressionClause&&this._layerDefinitionExpression&&this.respectLayerDefinitionExpression||!this._layerDisplayFilterClause&&this._layerDisplayFilter?.where)||await this._checkFeatureCountForExpression(`${e.field} = ${t}`))&&(!this._layerDefinitionExpressionClause||this._layerDefinitionExpressionClause.testFeature(i))&&(!this._layerDisplayFilterClause||this._layerDisplayFilterClause.testFeature(i))}_getServerSideLegend(){setTimeout(()=>this.buildLegendElementsForTools(),0)}_getAllInfos(e){const t=e?.infos;return t?t.reduce((e,t)=>e.concat(this._getAllInfos(t)),[]):[e]}async _constructTileImageryStretchRendererElements(e){const t=this.layer,i=t.symbolizer.rasterInfo??t.raster.rasterInfo;let s,l;const r=e?.customStatistics?.length?e.customStatistics:i?.statistics;if(r)({min:s,max:l}=r[0]);else{const e=I(i.pixelType);s=e[0],l=e[1]}if(t.hasStandardTime()&&(s=t.getStandardTimeValue(s),l=t.getStandardTimeValue(l)),1===i.bandCount||1===t.bandIds?.length)return this._getStretchLegendElements(e,{min:s,max:l});const n=(t?.bandIds?.length?t.bandIds:Array.from(Array(Math.min(i.bandCount,3)).keys())).map(e=>i.bandInfos[e].name);return n.length<3?n.push(n[1]):n.length>3&&n.splice(3),this._createSymbolTableElementMultiBand(n)}async _getStretchLegendElements(e,t){const i=e.colorRamp,s=W(i,t);return{type:"stretch-ramp",title:"",infos:s,preview:M(s.map(e=>e.color))}}_getClusterSymbol(){const e=this.layer,t="featureReduction"in e&&e.featureReduction,i=t&&"symbol"in t&&t.renderer;return i&&!0!==i?.authoringInfo?.isAutoGenerated?null:t&&"symbol"in t?t.symbol:null}async _getSizeLegendElement(e,t,i,s){return{type:"size-ramp",title:this._clusterSizeVariable?this._getClusterTitle(t):e,infos:await K(i,t,await ae(i),this.scale,this.view,s,this._clusterSizeVariable?this._getClusterSymbol():null)}}_createSymbolTableElementMultiBand(e){const t=[],i=["red","green","blue"];return e.forEach((e,s)=>{t.push({label:{colorName:i[s],bandName:e},src:oe[s],opacity:this.opacity??1})}),t}_updateInfosForClassedSizeRenderer(e,t){const i=e.authoringInfo&&"class-breaks-size"===e.authoringInfo.type,s=e.classBreakInfos.some(e=>N(e.symbol));if(i&&s){const i=X,s=Y,l=e.classBreakInfos.length,r=(i-s)/(l>1?l-1:l);t.forEach((e,t)=>{e.size=i-r*t})}}_isTallSymbol(e){let t=!1,i=!1;if(e)for(let s=0;s<e.length&&(!t||!i);s++){const l=e[s];"size"===l.type&&("height"===l.axis&&(t=!0),"width-and-depth"===l.axis&&(i=!0))}return t&&i}async _generatePreviewsForLegendElements(e,t,i){const s=[];for(const l of e)for(const e of l.infos??[])if("infos"in e&&e.infos&&s.push(this._generatePreviewsForLegendElements([e],t,i)),Ke(e)&&e.symbol&&!e.preview){let r=!0;if("cim"===e.symbol.type){const{minScale:t,maxScale:i}=e.symbol.data;(t&&t<this.scale||i&&i>this.scale)&&(r=!1)}r&&s.push(this._generateSymbolPreviewForInfo(e,{...t,clipBloomEffect:"theme"in l&&"spike"===l.theme,cssEffectFilter:i?.arrowMarkerSymbols?.has(e.symbol)?null:t.cssEffectFilter},i?{applyScaleDrivenSize:!i.arrowMarkerSymbols?.has(e.symbol)}:void 0))}await Promise.all(s)}async _getSize(e,t){let i=null==e.size&&this._hasSizeRamp?m(22):e.size;if(this._scaleDrivenSizeVariable&&t?.applyScaleDrivenSize){const{getSize:t}=await import("../../../renderers/visualVariables/support/visualVariableUtils.js");i=t(this._scaleDrivenSizeVariable,null,{view:this.view.type,scale:this.scale,shape:"simple-marker"===e.symbol.type?e.symbol.style:null})}return i}_getPreviewCIMOptions(e){return{style:"legend",cimOptions:{allowScalingUp:this._hasSizeRamp||!(!this._scaleDrivenSizeVariable||!e?.applyScaleDrivenSize),viewParams:this.isScaleDriven?{viewingMode:"2d"===this.view?.type?"map":this.view?.viewingMode,scale:this.view?.scale}:null}}}async _generateSymbolPreviewForInfo(e,t={},i){const{symbol:s}=e;try{if(t.size=await this._getSize(e,i),t.scale=!1,"cim"===s.type){const e=this._getPreviewCIMOptions(i);t={...t,...e}}e.preview=await A(s,t)}catch{e.preview=null,o.getLogger(this).warn(`Generating symbol preview failed for symbol type: ${s?.type}`)}}_getClusterRenderer(e){this._clusterSizeVariable=null;const t="renderer"in this.layer?this.layer.renderer:null,i=e.renderer?.clone()||t?.clone(),s=$(e,this.layerView,this.view);if(s&&null!=i&&"visualVariables"in i){const t=i.visualVariables?.some(e=>"size"===e.type&&"outline"!==e.target&&!pe.test(e.valueExpression));if(!t){if("clusterMinSize"in e&&"clusterMaxSize"in e){const{clusterMinSize:t,clusterMaxSize:i}=e;s.legendOptions=new x({showLegend:t!==i})}const t=i.visualVariables||[];i.visualVariables=t.concat([s]),this._clusterSizeVariable=s}}return i}async _loadRenderer(e){if(tt.has(e))return tt.get(e);const t=[],i=e.clone(),s=await ae(i);if(Ce(i)||Ie(i)){const e=(i.classBreakInfos||i.uniqueValueInfos).map(e=>this._fetchSymbol(e.symbol,s).then(t=>{e.symbol=t}).catch(()=>{e.symbol=null}));Array.prototype.push.apply(t,e)}return t.push(this._fetchSymbol(i.symbol||i.defaultSymbol,i.defaultSymbol?null:s).then(e=>{this._applySymbolToRenderer(i,e,Fe(i))}).catch(()=>{this._applySymbolToRenderer(i,null,Fe(i))})),await Promise.allSettled(t),tt.set(e,i),i}_applySymbolToRenderer(e,t,i){i?e.symbol=t:e.defaultSymbol=t}async _fetchSymbol(e,t){if(!e)throw new Error;if("web-style"===e.type){const i=this._webStyleSymbolCache;try{const s=await e.fetchSymbol({cache:i});return this._getAppliedCloneSymbol(s,t)}catch{throw o.getLogger(this).warn("Fetching web-style failed!"),new Error}}return this._getAppliedCloneSymbol(e,t)}_getAppliedCloneSymbol(e,i){if(!e||!i)return e;const s=e.clone(),l=i&&i.toRgba();return s.type.includes("3d")?this._applyColorTo3dSymbol(s,l):"cim"===s.type?O(s,i):s.color&&(s.color=new t(l||s.color)),s}_applyColorTo3dSymbol(e,i){i&&e.symbolLayers.forEach(e=>{e&&(e.material||(e.material={}),e.material.color=new t(i))})}async _getVisualVariableLegendElements(e,t){if(!("visualVariables"in e)||"vector-field"===e.type)return null;const i=e.visualVariables??[],s=[],l=[],n=[],a=ie(e,"reference-size")??ie(e,"spike");let o;const c=this._clusterSizeVariable;if(2===a?.sizeStops?.length&&(Ce(e)||Ie(e))){const[e,t]=a.sizeStops,i=c?c.minDataValue:e.value,s=c?c.maxDataValue:t.value;o=new D({field:a.field??void 0,normalizationField:a.normalizationField,minSize:u(e.size,10,100),maxSize:u(t.size,50,150),minDataValue:i,maxDataValue:s}),l.push(o)}for(const r of i)if("color"===r.type)s.push(r);else if("size"===r.type){if("cluster_count"===r.field&&o)continue;l.push(r)}else"opacity"===r.type&&n.push(r);const d=[...s,...l,...n];let y,h;if(0===s.length&&Ce(e)&&e.classBreakInfos&&1===e.classBreakInfos.length){const t=e.classBreakInfos[0];y=t&&t.symbol}if(0===s.length&&Fe(e)&&(y=e.symbol),y)if(y.type.includes("3d")){const e=y.symbolLayers.at(0);"water"===e.type?null!=e.color&&(h=e.color):null!=e.material?.color&&(h=e.material.color)}else y.url||(h=y.color);const f=this.cssEffectFilter;return(await Promise.all(d.map(async i=>{if(!i.legendOptions||!1!==i.legendOptions.showLegend){const s=Se(e)?i.field:this._getRampTitle(i,t);let l=null;const r=ue(t,i,this.view.timeZone);if("color"===i.type){const e=await G(i,null,r)??[];l={type:"color-ramp",title:s,infos:e,preview:M(e.map(e=>e.color),{cssEffectFilter:f})},this._hasColorRamp||(this._hasColorRamp=e.length>0)}else if("size"===i.type&&"outline"!==i.target)pe.test(i.valueExpression)?this._clusterSizeVariable||(this._scaleDrivenSizeVariable=i):(l=await this._getSizeLegendElement(s,i,e,r),o===i&&"spike"===a?.theme&&(l.theme=a.theme),this._hasSizeRamp||(this._hasSizeRamp=!(null==l.infos||!l.infos.length)));else if("opacity"===i.type){const e=await G(i,h,r)??[];l={type:"opacity-ramp",title:s,infos:e,preview:M(e.map(e=>e.color),{cssEffectFilter:f})},this._hasOpacityRamp||(this._hasOpacityRamp=e.length>0)}return l?.infos?l:null}}))).filter(r)}_getDomainName(e,t,i){if(e&&"function"!=typeof e){const s="getField"in i&&i.getField?.(e),l=s&&"getFieldDomain"in i&&i.getFieldDomain?i.getFieldDomain(s.name,{excludeImpliedDomains:has("esri-widget-legacy-field-domain-calculation")}):null;return"coded-value"===l?.type?l.getName(t):null}return null}_getClusterTitle(e){const t=this.layer,i=e.field;if("featureReduction"in t&&t.featureReduction&&"cluster"===t.featureReduction.type){const e=t.featureReduction,s="popupTemplate"in e&&e.popupTemplate,l=s&&s.fieldInfos;if(l)for(const t of l)if(t.fieldName===i)return"cluster_count"===i?t.label||{showCount:!0}:t.label}return{showCount:!0}}_getRampTitle(e,t){let i=e.field,s=e.normalizationField,l=!1,r=!1,n=!1,a=null;i="function"==typeof i?null:i,s="function"==typeof s?null:s;const o=e.legendOptions?.title;if(null!=o)a=o;else if(e.valueExpressionTitle)a=e.valueExpressionTitle;else{if("renderer"in t&&t.renderer&&"authoringInfo"in t.renderer&&t.renderer.authoringInfo?.visualVariables){const e=t.renderer.authoringInfo.visualVariables;for(let t=0;t<e.length;t++){const i=e[t];if("color"===i.type){if("ratio"===i.style){l=!0;break}if("percent"===i.style){r=!0;break}if("percent-of-total"===i.style){n=!0;break}}}}a={field:i&&this._getFieldAlias(i,t),normField:s&&this._getFieldAlias(s,t),ratio:l,ratioPercent:r,ratioPercentTotal:n}}return a}_getRendererTitle(e,t){const i=e;if(i.legendOptions?.title)return i.legendOptions.title;if(i.valueExpressionTitle)return i.valueExpressionTitle;let s=i.field,l=null,r=null;if(Ce(i)&&(l=i.normalizationField,r="percent-of-total"===i.normalizationType),s="function"==typeof s?null:s,l="function"==typeof l?null:l,Ie(i)){const{field2:e,field3:l,fieldDelimiter:r}=i;let n=s&&this._getFieldAlias(s,t);return e&&(n=`<${n}>${r}<${this._getFieldAlias(e,t)}>`,l&&(n=`${n}${r}<${this._getFieldAlias(l,t)}>`)),n}let n=null;return(s||l)&&(n={field:s&&this._getFieldAlias(s,t),normField:l&&this._getFieldAlias(l,t),normByPct:r}),n}_getFieldAlias(e,t){const i="featureReduction"in t&&t.featureReduction;if(C(t)&&!i)return t.getFieldAlias(e)||e;const s="popupTemplate"in t?t.popupTemplate:null,l=s?.fieldInfos;let r=l?.find(t=>e===t.fieldName),n=null;"getField"in t&&t.getField?n=t.getField(e):"fieldsIndex"in t&&t.fieldsIndex&&(n=t.fieldsIndex.get(e));let a=null;i&&(r??="popupTemplate"in i?i.popupTemplate?.fieldInfos?.find(t=>e?.toLowerCase()===t.fieldName?.toLowerCase()):void 0,"fields"in i&&i.fields&&(a=i.fields.find(t=>t.name?.toLowerCase()===e?.toLowerCase())));const o=r||n||a;let u=null;return o&&(u=r?.label||n?.alias||a?.alias||"name"in o&&o.name||"fieldName"in o&&o.fieldName||null),u}_isUnclassedRenderer(e){const t=e.visualVariables;let i=!1;return Ce(e)&&e.classBreakInfos&&1===e.classBreakInfos.length&&t&&(i=e.field?t.some(t=>!(!t||e.field!==t.field||(e.normalizationField||t.normalizationField)&&e.normalizationField!==t.normalizationField)):!!t.length),i}};e([b()],it.prototype,"_loading",void 0),e([b()],it.prototype,"children",void 0),e([b({readOnly:!0})],it.prototype,"cssEffectFilter",null),e([b()],it.prototype,"layerView",void 0),e([b()],it.prototype,"layer",void 0),e([b()],it.prototype,"legendElements",void 0),e([b({readOnly:!0})],it.prototype,"loading",null),e([b({readOnly:!0})],it.prototype,"opacity",null),e([b()],it.prototype,"parent",void 0),e([b({readOnly:!0,dependsOn:[]})],it.prototype,"ready",null),e([b()],it.prototype,"hideLayersNotInCurrentView",void 0),e([b()],it.prototype,"keepCacheOnDestroy",void 0),e([b()],it.prototype,"respectLayerDefinitionExpression",void 0),e([b()],it.prototype,"respectLayerVisibility",void 0),e([b({readOnly:!0})],it.prototype,"scale",null),e([b()],it.prototype,"sublayerIds",void 0),e([b({readOnly:!0})],it.prototype,"isScaleDriven",null),e([b()],it.prototype,"title",void 0),e([b({readOnly:!0,dependsOn:["ready"],value:0})],it.prototype,"version",null),e([b()],it.prototype,"view",void 0),it=e([_("esri.widgets.Legend.support.ActiveLayerInfo")],it);export{it as default};
|
|
5
|
+
import{__decorate as e}from"tslib";import t from"../../../Color.js";import{addTokenParameter as i}from"../../../kernel.js";import s from"../../../request.js";import l from"../../../core/Accessor.js";import{isSome as r}from"../../../core/arrayUtils.js";import n from"../../../core/Collection.js";import has from"../../../core/has.js";import{JSONMap as a}from"../../../core/jsonMap.js";import o from"../../../core/Logger.js";import{clamp as u}from"../../../core/mathUtils.js";import{debounce as c}from"../../../core/promiseUtils.js";import{on as d,watch as y,initial as h,whenOnce as f}from"../../../core/reactiveUtils.js";import{px2pt as m}from"../../../core/screenUtils.js";import{parseWhereClause as p}from"../../../core/sql.js";import{addQueryParameters as g}from"../../../core/urlUtils.js";import{property as b}from"../../../core/accessorSupport/decorators/property.js";import{subclass as _}from"../../../core/accessorSupport/decorators/subclass.js";import{EffectView as S}from"../../../layers/effects/EffectView.js";import{getEffectiveDisplayFilter as w}from"../../../layers/support/displayFilterUtils.js";import{ExportImageParameters as v}from"../../../layers/support/ExportImageParameters.js";import{collectFields as L,collectArcadeFieldNames as E}from"../../../layers/support/fieldUtils.js";import{isFeatureLayer as F,supportsFieldConfiguration as C}from"../../../layers/support/layerUtils.js";import{getPixelValueRange as I}from"../../../layers/support/rasterFormats/pixelRangeUtils.js";import{fromJSON as R}from"../../../renderers/support/jsonUtils.js";import{isSupportedRenderer3D as V}from"../../../renderers/support/rendererConversion.js";import D from"../../../renderers/visualVariables/SizeVariable.js";import x from"../../../renderers/visualVariables/support/SizeVariableLegendOptions.js";import{updateReferenceSizeSymbol as z}from"../../../smartMapping/renderers/support/referenceSizeUtils.js";import T from"../../../symbols/SimpleFillSymbol.js";import j from"../../../symbols/SimpleMarkerSymbol.js";import{applyCIMSymbolColor as O}from"../../../symbols/support/cimSymbolUtils.js";import{renderSymbol as k}from"../../../symbols/support/renderUtils.js";import{renderColorRampPreviewHTML as M,renderDotDensityPreviewHTML as P,renderPieChartPreviewHTML as U,renderPreviewHTML as A}from"../../../symbols/support/symbolUtils.js";import{getCSSFilterFromEffectList as B,isVolumetricSymbol as N}from"../../../symbols/support/utils.js";import{getEffectiveClusterSizeVariable as $}from"./clusterUtils.js";import{getColorFromPointCloudStops as H,getRampStopsForPointCloud as q,getStretchRampStops as W,getRampStops as G}from"./colorRampUtils.js";import{getHeatmapRampStops as J}from"./heatmapRampUtils.js";import{getRotationAngleForFocus as Z,getRelationshipRampElement as Q}from"./relationshipRampUtils.js";import{getRampStops as K,realWorldMaxSize as X,realWorldMinSize as Y}from"./sizeRampUtils.js";import{specialCharsLessThan as ee,specialCharsGreaterThan as te,getAuthoringInfoVisualVariableByTheme as ie,getSymbolForFlowRenderer as se,formatValue as le,getFormatOptions as re,mergeWhereClauses as ne,getMedianColor as ae,rgbImgSource as oe,getFormatOptionsForVisualVariable as ue}from"./utils.js";import{formatNumberLabel as ce}from"../../smartMapping/support/utils.js";const de=16,ye="https://utility.arcgis.com/sharing/tools/legend",he="esri.layers.ImageryLayer",fe="esri.layers.ImageryTileLayer",me="esri.layers.WCSLayer",pe=/^\s*(return\s+)?\$view\.scale\s*(;)?\s*$/i,ge=new a({esriGeometryPoint:"point",esriGeometryMultipoint:"multipoint",esriGeometryPolyline:"polyline",esriGeometryPolygon:"polygon",esriGeometryMultiPatch:"multipatch"}),be=new j({size:6,outline:{color:[128,128,128,.5],width:.5}}),_e=new T({style:"solid"});function Se(e){return"flow"===e.type}function we(e){return"vector-field"===e.type}function ve(e){return"raster-colormap"===e.type}function Le(e){return"raster-stretch"===e.type}function Ee(e){return"raster-shaded-relief"===e.type}function Fe(e){return"esri.renderers.SimpleRenderer"===e.declaredClass}function Ce(e){return"esri.renderers.ClassBreaksRenderer"===e.declaredClass}function Ie(e){return"esri.renderers.UniqueValueRenderer"===e.declaredClass}function Re(e){return"esri.renderers.HeatmapRenderer"===e.declaredClass}function Ve(e){return xe(e)||ze(e)||Te(e)||De(e)}function De(e){return"esri.renderers.PointCloudRGBRenderer"===e.declaredClass}function xe(e){return"esri.renderers.PointCloudClassBreaksRenderer"===e.declaredClass}function ze(e){return"esri.renderers.PointCloudStretchRenderer"===e.declaredClass}function Te(e){return"esri.renderers.PointCloudUniqueValueRenderer"===e.declaredClass}function je(e){return"esri.renderers.DotDensityRenderer"===e.declaredClass}function Oe(e){return"esri.renderers.PieChartRenderer"===e.declaredClass}function ke(e,t){return Fe(e)||Ce(e)||Ie(e)||Re(e)||je(e)||Oe(e)?"2d"===t.type||V(e):Le(e)||ve(e)||Ee(e)||xe(e)||ze(e)||Te(e)||we(e)||Se(e)}function Me(e){return"esri.layers.BuildingSceneLayer"===e.declaredClass}function Pe(e){return"esri.layers.SubtypeGroupLayer"===e.declaredClass}function Ue(e){return"esri.layers.VoxelLayer"===e.declaredClass}function Ae(e){return"esri.layers.WMSLayer"===e.declaredClass}function Be(e){return"esri.layers.WMTSLayer"===e.declaredClass}function Ne(e){return"esri.layers.MapImageLayer"===e.declaredClass}function $e(e){return"esri.layers.TileLayer"===e.declaredClass}function He(e){return e.declaredClass===he}function qe(e){return e.declaredClass===fe}function We(e){return e.declaredClass===me}function Ge(e){return"stretch-ramp"===e.type}function Je(e){const t="authoringInfo"in e?e?.authoringInfo:null;return"univariate-color-size"===t?.type}function Ze(e){const t="authoringInfo"in e?e?.authoringInfo:null;return"univariate-color-size"===t?.type&&"above-and-below"===t?.univariateTheme}function Qe(e){return"sublayers"in e}function Ke(e){return e&&"symbol"in e}function Xe(e,t){const{field:i,field2:s,field3:l,fieldDelimiter:r,valueExpression:n}=e;if(!i)return null;const a=!(!i&&!n||!s&&!l)?t?.toString().split(r||""):[t],o=i?{[i]:a?.[0]}:null;return o&&(s&&(o[s]=a?.[1]),l&&(o[l]=a?.[2])),o}const Ye=new j({style:"path",path:"M10,5 L5,0 0,5 M5,0 L5,15",size:15,outline:{width:1,color:[85,85,85,1]}});let et={};const tt=new WeakMap;let it=class extends l{constructor(e){super(e),this._hasColorRamp=!1,this._hasOpacityRamp=!1,this._hasSizeRamp=!1,this._loading=!1,this._webStyleSymbolCache=new Map,this._dotDensityUrlCache=new Map,this._scaleDrivenSizeVariable=null,this._clusterSizeVariable=null,this._layerDefinitionExpression=null,this._layerDefinitionExpressionClause=null,this._layerDisplayFilter=null,this._layerDisplayFilterClause=null,this.children=new n,this.layerView=null,this.layer=null,this.legendElements=[],this.parent=null,this.hideLayersNotInCurrentView=!1,this.keepCacheOnDestroy=!1,this.respectLayerDefinitionExpression=!1,this.respectLayerVisibility=!0,this.sublayerIds=[],this.title=null,this.view=null}initialize(){const e=()=>this.notifyChange("ready");this.addHandles([d(()=>this.children,"change",t=>{const{added:i,removed:s}=t;i.forEach(t=>{const i=`activeLayerInfo-ready-watcher-${t.layer.uid}`;this.addHandles(y(()=>t.ready,e,h),i)}),s.forEach(e=>this.removeHandles(e.layer.uid)),e()})]),this.keepCacheOnDestroy||(et={})}destroy(){this._webStyleSymbolCache=null,this._dotDensityUrlCache=null,this._scaleDrivenSizeVariable=null,this.keepCacheOnDestroy||(et=null),this._layerDefinitionExpressionClause=null}get cssEffectFilter(){const{layer:e,scale:t}=this,i="effect"in e?e.effect:null;if(!i)return null;const s=new S({effect:i});return s.endTransition(),s.scale=t,B(s,!0)}get loading(){return this.children.length>0?this.children.some(e=>e.loading):this._loading}get opacity(){const e=this.layer.opacity,t=this.parent?.opacity,i=this.layer.parent,s=i&&"uid"in i?this._getParentLayerOpacity(i):null;return null!=t?t*e:null!=s?s*e:e}get ready(){return null===this.layer||(this.children.length>0?this._isGroupActive():this.legendElements.length>0)}get scale(){return this.view?.scale??0}get isScaleDriven(){const e=this.layer;if(null===e)return!1;if("effect"in e&&e.effect&&Array.isArray(e.effect))return!0;if("featureReduction"in e&&e.featureReduction){if("cluster"===e.featureReduction.type)return!0;if("binning"===e.featureReduction.type&&"renderer"in e.featureReduction&&e.featureReduction.renderer)return this._isRendererScaleDriven(e.featureReduction.renderer)}return"renderer"in e&&e.renderer?!!("displayFilterInfo"in e&&e.displayFilterInfo&&Ie(e.renderer))||this._isRendererScaleDriven(e.renderer):this._isLayerScaleDriven(this.layer)}get version(){return this._get("version")+1}async buildLegendElementsForFeatureCollections(e){this._loading=!0;if(!(!this.hideLayersNotInCurrentView||await this._isLayerInCurrentView()))return this.legendElements=[],this._loading=!1,void this.notifyChange("ready");const t=Array.from(e,e=>{if(F(e))return this._getRendererLegendElements(e.renderer,{title:e.title});if(e.featureSet?.features.length){const t=e.layerDefinition,i=t?.drawingInfo,s=i&&R(i.renderer),l=ge.read(t.geometryType);return s?this._getRendererLegendElements(s,{title:e.name,geometryType:l}):(o.getLogger(this).warn("drawingInfo not available!"),null)}return null});try{const e=[],i=await Promise.allSettled(t);for(const t of i)if("fulfilled"===t.status)for(const i of t.value??[])e.push(i);this.legendElements=e}catch(i){o.getLogger(this).warn("error while building legend for layer!",i)}finally{this._loading=!1,this.notifyChange("ready")}}async buildLegendElementsForRenderer(e){try{this._loading=!0;const t=!this.hideLayersNotInCurrentView||await this._isLayerInCurrentView();this.legendElements=t?await this._getRendererLegendElements(e):[]}catch(t){o.getLogger(this).warn("error while building legend for layer!",t)}finally{this._loading=!1,this.notifyChange("ready")}}async buildLegendElementsForFeatureReduction(e){try{this._loading=!0,await this._waitForLayerViewUpdate(this.layerView);const t=!this.hideLayersNotInCurrentView||await this._isLayerInCurrentView();this.legendElements=t?await this._getLegendElementsForFeatureReduction(e):[]}catch(t){o.getLogger(this).warn("error while building legend for layer!",t)}finally{this._loading=!1,this.notifyChange("ready")}}async buildLegendElementsForTools(){this._loading=!0;const e=this.layer;if(Ue(e))await this._constructLegendElementsForVoxelLayer();else if(Be(e))this._constructLegendElementsForWMTSlayer();else if(Ae(e))await this._constructLegendElementsForWMSSublayers();else if(Me(e))await this._constructLegendElementsForBuildingSceneLayer();else if(Ne(e)||$e(e)||Pe(e))await this._constructLegendElementsForSublayers();else{this.removeHandles("imageryLayers-watcher");let t="default";if(He(e)){const i=e;t=(i?.rasterFunction?.functionName||"default")+"_"+(e.bandIds?.length?e.bandIds.join(""):"###")}if(qe(e)||"link-chart"===e.type)return;await this._getLegendLayers(`${e.uid}-${t}`).then(async t=>{this.legendElements=[];const i=t.map(async t=>{if(He(e)){const t=y(()=>[e.rasterFunction,e.bandIds],()=>c(async()=>{et.default=null,e.renderer?await this.buildLegendElementsForRenderer(e.renderer):await this.buildLegendElementsForTools()})());this.addHandles(t,"imageryLayers-watcher")}const i=this._generateSymbolTableElementForLegendLayer(t);i?.infos.length&&(He(e)&&(i.title=e.title),this.legendElements.push(i))});await Promise.allSettled(i)}).catch(e=>{o.getLogger(this).warn("Request to server for legend has failed!",e)})}this._loading=!1,this.notifyChange("ready")}async _isLayerInCurrentView(e){return this._checkFeatureCountForExpression(e,this.view.extent)}_getParentLayerOpacity(e){let t=1;const i=e.parent;return i&&"uid"in i&&(t=this._getParentLayerOpacity(i)),e.opacity*t}_isGroupActive(){return this.children.some(e=>e.ready)}_isRendererScaleDriven(e){if("dot-density"===e.type)return!0;const t="valueExpression"in e?e.valueExpression:null;if(pe.test(t))return!0;const i="visualVariables"in e?e.visualVariables:null;return!!i?.some(e=>this._isScaleDrivenSizeVariable(e))||this._hasScaleDrivenSymbols(e)}_hasScaleDrivenSymbols(e){switch(e.type){case"simple":return this._isScaleDrivenSymbol(e.symbol);case"class-breaks":return this._isScaleDrivenSymbol(e.defaultSymbol)||e.classBreakInfos.some(e=>this._isScaleDrivenSymbol(e.symbol));case"unique-value":return this._isScaleDrivenSymbol(e.defaultSymbol)||!!e.uniqueValueInfos?.some(e=>this._isScaleDrivenSymbol(e.symbol))}return!1}_isScaleDrivenSymbol(e){if("cim"===e?.type){const{primitiveOverrides:t,minScale:i,maxScale:s}=e.data,l=t?.some(e=>(e.valueExpressionInfo?.expression||"").includes("$view.scale"))??!1;return null!=i||null!=s||l}return!1}_isScaleDrivenSizeVariable(e){if(e&&"size"!==e.type)return!1;const t=e,i=t.minSize,s=t.maxSize;return!("object"!=typeof i||!i||!this._isScaleDrivenSizeVariable(i))||(!("object"!=typeof s||!s||!this._isScaleDrivenSizeVariable(s))||pe.test(t.valueExpression))}_isLayerScaleDriven(e){if("minScale"in e&&e.minScale>0||"maxScale"in e&&e.maxScale>0)return!0;if("sublayers"in e&&e.sublayers)return e.sublayers.some(e=>this._isLayerScaleDriven(e));const t=e.parent;if(!1===e.loaded&&t&&Ne(t)&&"source"in e&&e.source&&"map-layer"===e.source.type)for(const i of t.sourceJSON.layers??[])if(i.id===e.source.mapLayerId&&(i.minScale>0||i.maxScale>0))return!0;return!1}async _constructLegendElementsForVoxelLayer(){this._loading=!0,this.legendElements=[],this.removeHandles("voxel-style-watcher"),this.removeHandles("voxel-current-variable");const e=this.layer;this.addHandles(y(()=>e.currentVariableId,()=>this._constructLegendElementsForVoxelLayer()),"voxel-current-variable"),this.addHandles(y(()=>e.getVariableStyles(),()=>this._constructLegendElementsForVoxelLayer()),"voxel-style-watcher");const t=e.getVariableStyle(null),i=[];if(t)if(t.uniqueValues?.length){const e=[];t.uniqueValues.forEach(t=>{t.enabled&&e.push({label:t.label||`${t.value}`,value:t.value,symbol:new T({color:t.color,outline:null})})}),e.length&&i.push({type:"symbol-table",title:t.label,infos:e})}else if(t.transferFunction){const{colorStops:e,stretchRange:s}=t.transferFunction,l=e.toArray().reverse(),r=s.map((e,t)=>`${0===t?ee:te} ${ce(e)}`).reverse(),n=l.map(e=>({color:e.color,value:null,label:null}));n[0].label=r[0],n[n.length-1].label=r[1],i.push({type:"color-ramp",title:t.label,infos:n,preview:M(l.map(e=>e.color))})}await this._generatePreviewsForLegendElements(i,{opacity:e.opacity}),this.legendElements=i,this._loading=!1,this.notifyChange("ready")}_constructLegendElementsForWMTSlayer(){this._loading=!0,this.legendElements=[],this.removeHandles("wmts-activeLayer-watcher");const e=this.layer.activeLayer;this.addHandles(y(()=>{const{layer:e}=this;return e&&"activeLayer"in e&&e.activeLayer},()=>this._constructLegendElementsForWMTSlayer()),"wmts-activeLayer-watcher");const t=e.styleId?e.styles?.find(({id:t})=>t===e.styleId)?.legendUrl:void 0;t&&(this.legendElements=[{type:"symbol-table",title:e.title,infos:[{src:t,opacity:this.opacity}]}]),this._loading=!1,this.notifyChange("ready")}async _constructLegendElementsForWMSSublayers(){this._loading=!0,this.legendElements=[],this.removeHandles("wms-sublayers-watcher");const e=this.layer;let t=null;(e.customParameters||e.customLayerParameters)&&(t={...e.customParameters,...e.customLayerParameters}),this.addHandles(y(()=>{const{layer:e}=this;return e&&"sublayers"in e&&e.sublayers},()=>this._constructLegendElementsForWMSSublayers()),"wms-sublayers-watcher"),this.legendElements=await this._generateLegendElementsForWMSSublayers(e.sublayers,t),this._loading=!1,this.notifyChange("ready")}async _generateLegendElementsForWMSSublayers(e,t){const i=this.layer,s=[];this.addHandles(e.on("change",()=>this._constructLegendElementsForWMSSublayers()),"wms-sublayers-watcher");const l=this.sublayerIds?.map(e=>i.findSublayerById(e))?.filter(r)??[],n=l.length?l:e.toArray();for(const r of n){const e=y(()=>[r.title,r.visible,r.legendEnabled],()=>this._constructLegendElementsForWMSSublayers());if(this.addHandles(e,"wms-sublayers-watcher"),!this.respectLayerVisibility||r.visible&&r.legendEnabled){const e=await this._generateSymbolTableElementForWMSSublayer(r,t);e?.infos.length&&s.unshift(e)}}return s}async _generateSymbolTableElementForWMSSublayer(e,t){if(!e.legendUrl&&e.sublayers){const i=(await this._generateLegendElementsForWMSSublayers(e.sublayers,t)).filter(e=>e);return{type:"symbol-table",title:e.title,infos:i}}return this._generateSymbolTableElementForLegendUrl(e,t)}async _generateSymbolTableElementForLegendUrl(e,t){let i=e.legendUrl;if(!i)return;const l={type:"symbol-table",title:e.title||e.name||String(e.id??""),infos:[]};t&&(i=g(i,t));let r=null;const n=e.layer?.opacity;try{r=(await s(i,{responseType:"image"})).data,r&&(r.style.opacity=n)}catch{}return l.infos.push({src:i,preview:r,opacity:n}),l}_getLegendLayers(e,t){const i=et&&et[e];return i?Promise.resolve(i):this._legendRequest(t).then(t=>{const i=t.layers;return et[e]=i,i})}_legendRequest(e){const t=this.layer;let i={f:"json",dynamicLayers:e};if(He(t)){const e=t.exportImageServiceParameters.rasterFunction;if(e&&(i.renderingRule=JSON.stringify(e.functionDefinition?.toJSON()||e.toJSON())),t.bandIds&&(i.bandIds=t.bandIds.join()),t.raster||t.viewId||t.customParameters){const{raster:e,viewId:s,customParameters:l}=t;i={raster:e,viewId:s,...i,...l}}}let l=t.url.replace(/(\/)+$/,"");if("version"in t&&+t.version>=10.01){const e=l.indexOf("?");e>-1?l=l.slice(0,e)+"/legend"+l.slice(e):l+="/legend"}else{const e=l.toLowerCase().indexOf("/rest/"),t=-1===e?l:l.slice(0,e)+l.slice(e+5);l=ye+"?soapUrl="+encodeURI(t)+"&returnbytes=true"}return s(l,{query:i}).then(e=>e.data)}async _constructLegendElementsForBuildingSceneLayer(){this._loading=!0,this.legendElements=[],this.removeHandles("sublayers-watcher");const e=this.layer;this.addHandles(y(()=>e.sublayers,()=>this._constructLegendElementsForBuildingSceneLayer()),"sublayers-watcher");try{this.legendElements=await this._generateLegendElementsForBuildingSublayers(e.sublayers,this.opacity)}catch(t){o.getLogger(this).warn("Request to server for legend has failed!",t)}finally{this._loading=!1,this.notifyChange("ready")}}async _generateLegendElementsForBuildingSublayers(e,t){let i=[];this.addHandles(e.on("change",()=>this._constructLegendElementsForBuildingSceneLayer()),"sublayers-watcher");const s=e.toArray();for(const l of s){const e=y(()=>["renderer"in l&&l.renderer,l.opacity,l.title,l.visible],()=>this._constructLegendElementsForBuildingSceneLayer());if(this.addHandles(e,"sublayers-watcher"),!this.respectLayerVisibility||l.visible){const e=null!=l?.opacity?l.opacity:null,s=null!=e?e*t:t;if("building-group"===l.type){const e={type:"symbol-table",title:l.title,infos:[]},t=await this._generateLegendElementsForBuildingSublayers(l.sublayers,s);e.infos.push(...t),i=[e,...i]}else if(l.renderer){i=[...await this._getRendererLegendElements(l.renderer,{title:l.title,opacity:s,sublayer:l}),...i]}}}return i.filter(e=>!!e&&(!("infos"in e)||!e.infos||e.infos.length>0))}async _constructLegendElementsForSublayers(){this._loading=!0,this.removeHandles("sublayers-watcher");const e=this.layer;if(!(Ne(e)||$e(e)||Pe(e))||this.hideLayersNotInCurrentView&&!await this._isLayerInCurrentView())return this.legendElements=[],this._loading=!1,void this.notifyChange("ready");this.addHandles(y(()=>e.sublayers,()=>this._constructLegendElementsForSublayers),"sublayers-watcher");try{this.legendElements=await this._generateLegendElementsForSublayers(e.sublayers,this.opacity)}catch(t){o.getLogger(this).warn("Request to server for legend has failed!",t)}finally{this._loading=!1,this.notifyChange("ready")}}async _generateLegendElementsForSublayers(e,t,i){const s=this.layer;let l=[];this.addHandles(e.on("change",()=>this._constructLegendElementsForSublayers()),"sublayers-watcher");let n=e.toArray();!i&&this.sublayerIds&&this.sublayerIds.length&&(n=Pe(s)?this.sublayerIds.map(e=>s.findSublayerForSubtypeCode(e)).filter(r):this.sublayerIds.map(e=>s.findSublayerById(e)).filter(r));for(const r of n){const e=y(()=>[r.renderer,r.opacity,r.title,r.visible,r.legendEnabled],()=>this._constructLegendElementsForSublayers());this.addHandles(e,"sublayers-watcher");const s=r.createQuery().where,n=!this.hideLayersNotInCurrentView||await this._isLayerInCurrentView(s),a=!this.respectLayerVisibility||r.visible&&r.legendEnabled&&this._isSublayerInScale(r);if(n&&a){const e=null!=r?.opacity?r.opacity:null,s=null!=e?e*t:t,n=!Qe(r)||r.originIdOf("renderer")>2&&!r.sublayers;if(r.renderer&&n){await r.load();l=[...await this._getRendererLegendElements(r.renderer,{title:r.title,opacity:s,sublayer:r}),...l]}else if(Qe(r)){const e=await this._generateSymbolTableElementForSublayer(r,s,i);e&&l.unshift(e)}}}return l.filter(e=>!!e&&(!("infos"in e)||!e.infos||e.infos.length>0))}async _generateSymbolTableElementForSublayer(e,t,i){if(!i){i=new Map;const t=this.layer,s=e.source;let l=null;if(!(!s||"map-layer"===s.type&&s.mapLayerId===e.id&&(!s.gdbVersion||s.gdbVersion===("gdbVersion"in t&&t.gdbVersion)))||e.originIdOf("renderer")>2||e.originIdOf("labelingInfo")>2||e.originIdOf("labelsVisible")>2){const e=new v({layer:this.layer});l=e.hasDynamicLayers?e.dynamicLayers:null,e.destroy()}const r=l||`${t.uid}-default`;(await this._getLegendLayers(r,l)).forEach(e=>i.set(e.layerId,e))}const s=i.get(e.id);if((!s||s?.subLayerIds&&s.defaultVisibility)&&e.sublayers){const s=await this._generateLegendElementsForSublayers(e.sublayers,t,i);return{type:"symbol-table",title:e.title,infos:s}}return this._generateSymbolTableElementForLegendLayer(s,e,t)}_generateSymbolTableElementForLegendLayer(e,t,i){if(!e?.legend||this.respectLayerVisibility&&!this._isLegendLayerInScale(e,t))return null;const s=t?.renderer;let l=t?.title||e.layerName;if(s&&(!t||t?.originIdOf("renderer")>2)){const e=t?.title||this._getRendererTitle(s,t);e&&(l&&"string"!=typeof e&&"title"in e&&(e.title=l),l=e)}const r={type:"symbol-table",title:l,legendType:e.legendType||null,infos:[]},n=t?this._sanitizeLegendForSublayer(e.legend.slice(),t):e.legend;return e.legendGroups&&e.legendGroups.length>0?e.legendGroups.forEach(s=>{const l={type:"symbol-table",title:s.heading,legendType:e.legendType||null,infos:this._generateSymbolTableElementInfosForLegendLayer(n.filter(e=>e.groupId===s.id),e.layerId,s.heading||r.title||t?.title,i)};l.infos?.length>0&&r.infos.push(l)}):r.infos=this._generateSymbolTableElementInfosForLegendLayer(n,e.layerId,r.title||t?.title,i),r.infos.length>0?r:null}_generateSymbolTableElementInfosForLegendLayer(e,t,s,l){return e.map(e=>{let r=e.url;if(e.imageData&&e.imageData.length>0)r=`data:image/png;base64,${e.imageData}`;else{if(r.startsWith("http"))return null;r=i(`${this.layer.url}/${t}/images/${r}`)}let n=e.label;return"<all other values>"===n&&(n="others"),{previewAriaLabel:n||s,label:n,src:r,opacity:l??this.opacity,width:e.width,height:e.height}}).filter(r)}_isSublayerInScale(e){const t=e.minScale||0,i=e.maxScale||0;return!(t>0&&t<this.scale||i>this.scale)}_isLegendLayerInScale(e,t){const i=t||this.layer;let s=null,l=null,r=!0;return!i.minScale&&0!==i.minScale||!i.maxScale&&0!==i.maxScale?(0===e.minScale&&i.tileInfo&&(s=i.tileInfo.lods[0].scale),0===e.maxScale&&i.tileInfo&&(l=i.tileInfo.lods[i.tileInfo.lods.length-1].scale)):(s=Math.min(i.minScale,e.minScale)||i.minScale||e.minScale,l=Math.max(i.maxScale,e.maxScale)),(s>0&&s<this.scale||l>this.scale)&&(r=!1),r}_sanitizeLegendForSublayer(e,t){if("version"in this.layer&&+this.layer.version<10.1||0===e.length)return e;const i=t.renderer,s=e.some(e=>e.values);let l=0,r=null;return s&&e.some((e,t)=>(e.values||(l=t,r=e,r.label||(r.label="others")),null!=r)),i?"unique-value"===i.type?r&&(e.splice(l,1),e.push(r)):"class-breaks"===i.type&&(r&&e.splice(l,1),i.legendOptions?.order||e.reverse(),r&&e.push(r)):r&&(e.splice(l,1),e.push(r)),e}async _getRendererLegendElements(e,t={}){if(!ke(e,this.view))return o.getLogger(this).warn(`Renderer of type '${e.type}' not supported!`),[];if(Ve(e))return this._constructPointCloudRendererLegendElements(e,t);if(je(e))return this._constructDotDensityRendererLegendElements(e);const i=await this._loadRenderer(e);return Oe(i)?this._constructPieChartRendererLegendElements(i):this._constructRendererLegendElements(i,t)}async _getLegendElementsForFeatureReduction(e){let t=null;return"binning"===e.type?t=e.renderer:"cluster"===e.type&&(t=this._getClusterRenderer(e)),t?this._getRendererLegendElements(t,{isFeatureReductionRenderer:!0}):[]}_getPointCloudRendererTitle(e){return(e.legendOptions?.title||e.field)??""}async _constructPointCloudRendererLegendElements(e,t={}){const i=t.title,s=[];let l=null,r=null;if(xe(e))l={type:"symbol-table",title:i||this._getPointCloudRendererTitle(e),infos:[]},e.colorClassBreakInfos.forEach(e=>{l.infos.unshift({label:e.label||e.minValue+" - "+e.maxValue,value:[e.minValue,e.maxValue],symbol:this._getAppliedCloneSymbol(be,e.color)})});else if(ze(e)){const t=e.stops;let s=null;if(t?.length&&(1===t.length&&(s=t[0].color),!s)){const e=t[0].value,i=t[t.length-1].value;if(null!=e&&null!=i){s=H(e+(i-e)/2,t)}}l={type:"symbol-table",title:null,infos:[{label:null,value:null,symbol:this._getAppliedCloneSymbol(be,s||be.color)}]};const n=q(e.stops??[])??[];r={type:"color-ramp",title:i||this._getPointCloudRendererTitle(e),infos:n,preview:M(n.map(e=>e.color))}}else Te(e)&&(l={type:"symbol-table",title:i||this._getPointCloudRendererTitle(e),infos:[]},e.colorUniqueValueInfos?.forEach(e=>{l.infos.push({label:e.label||e.values.join(", "),value:e.values.join(", "),symbol:this._getAppliedCloneSymbol(be,e.color)})}));return l?.infos.length&&s.push(l),r?.infos.length&&s.push(r),await this._generatePreviewsForLegendElements(s,{opacity:this.opacity,symbolConfig:{applyColorModulation:!!e.colorModulation}}),s}async _getElementInfoForDotDensity(e,t){const{color:i,label:s,valueExpressionTitle:l}=t,{backgroundColor:r,outline:n,dotSize:a}=e,o=this.cssEffectFilter,u=a+"-"+i+"-"+r+"-"+(n&&JSON.stringify(n.toJSON()))+"-"+o,c=this._dotDensityUrlCache,d=c.has(u)?c.get(u):P(e,i);c.set(u,d);const y={shape:{type:"image",x:0,y:0,width:d.width,height:d.height,src:d.src},fill:null,stroke:null,offset:[0,0]},h=k([[y]],[d.width,d.height],{cssEffectFilter:this.cssEffectFilter});return{opacity:1,src:d.src,preview:h,width:d.width,height:d.height,previewAriaLabel:s||l}}async _constructDotDensityRendererLegendElements(e){const t=e.calculateDotValue(this.view.scale),i=e.legendOptions?.unit,s={type:"symbol-table",title:{value:t&&Math.round(t),unit:i||""},infos:[]};for(const l of e.attributes){const t=await this._getElementInfoForDotDensity(e,l);t.label=l.label||l.valueExpressionTitle||l.field,s.infos.push(t)}return[s]}async _constructPieChartRendererLegendElements(e){const t=[];let i=null;const s=e.outline;e.attributes.forEach(e=>{const i=new j({color:e.color,outline:s}),l=e.label||e.valueExpressionTitle||e.field;t.push({label:l,symbol:i})});const l=t.length?[...t]:[];if(e.othersCategory?.color&&0!==e.othersCategory?.threshold){const l=new j({color:e.othersCategory.color,outline:s});i=e.othersCategory.label||"Other",t.push({label:i,symbol:l})}if(e.defaultColor?.a){const i=new j({color:e.defaultColor,outline:s});t.push({label:e.defaultLabel,symbol:i})}const r=await this._getVisualVariableLegendElements(e,this.layer)||[];if(t.length){r.unshift({type:"symbol-table",title:null,infos:t});const n=l.filter(e=>e.label!==i).map(e=>e.symbol.color).filter(Boolean),a=U(n,{holePercentage:e.holePercentage,backgroundColor:e.backgroundFillSymbol?.color,cssEffectFilter:this.cssEffectFilter,outline:s});r.unshift({type:"pie-chart-ramp",title:this._getRendererTitle(e,this.layer),infos:t,preview:a})}return await this._generatePreviewsForLegendElements(r,{opacity:this.layer.opacity,cssEffectFilter:this.cssEffectFilter}),r}async _getWhereClause(e,t,i){const s=await p(e,i),l=new Set,{field:r,field2:n,field3:a}=t;L(l,i,[r,n,a]),await E(l,i,null,t.valueExpression);const o=new Set(Array.from(l,e=>e.toLowerCase())),u=s?.fieldNames.map(e=>e.toLowerCase());return u?.some(e=>!o.has(e))?null:s}async _processDefinitionExpression(e,t){if(!("definitionExpression"in e))return;const i=e.definitionExpression;i&&this.respectLayerDefinitionExpression?this._layerDefinitionExpression!==i&&(this._layerDefinitionExpressionClause=await this._getWhereClause(i,t,e.fieldsIndex)):this._layerDefinitionExpressionClause=null,this._layerDefinitionExpression=i}async _processDisplayFilter(e,t){if(!("displayFilterInfo"in e))return;const i=e.displayFilterInfo?w(e.displayFilterInfo,this.view):null;return i?.where?this._layerDisplayFilter?.id!==i?.id&&(this._layerDisplayFilterClause=await this._getWhereClause(i.where,t,e.fieldsIndex)):this._layerDisplayFilterClause=null,this._layerDisplayFilter=i,i}async _constructRendererLegendElements(e,t={}){const{title:i,sublayer:s,isFeatureReductionRenderer:l}=t,r=s||this.layer,n=ie(e,"reference-size"),a=ie(e,"spike"),o=l&&"renderer"in r&&r.renderer?r.renderer:e;let u=null;Ie(o)&&(await this._processDefinitionExpression(r,o),u=await this._processDisplayFilter(r,o)),this._hasColorRamp=!1,this._hasOpacityRamp=!1,this._hasSizeRamp=!1,this._scaleDrivenSizeVariable=null;const c=await this._getVisualVariableLegendElements(e,r)||[],d={type:"symbol-table",title:i||this._getRendererTitle(e,r),infos:[]};let y=null,h=!1;const f=new Set;if(Se(e)&&!this._hasSizeRamp){const t=await se(e);d.infos.push({label:null,symbol:t})}else if(Je(e)){let t=i;const s=Ze(e)?"univariate-above-and-below-ramp":"univariate-color-size-ramp",l=c.findIndex(e=>"color-ramp"===e.type),r=-1!==l?c.splice(l,1)[0]:null,n=c.findIndex(e=>"size-ramp"===e.type),a=-1!==n?c.splice(n,1)[0]:null,o=[];r&&(t=r.title,o.push(r)),a&&(t=a.title,o.push(a)),o.length>0&&c.push({type:s,title:t,infos:o})}else if(Re(e)){const t=J(e);c.push({type:"heatmap-ramp",title:i||this._getRendererTitle(e,r),infos:t,preview:M(t.map(e=>e.color),{cssEffectFilter:this.cssEffectFilter})})}else if(Ie(e)){const t=e.authoringInfo;if(t&&"relationship"===t.type){const{numClasses:i,field1:s,field2:l}=t,n=t.focus;if(i&&s&&l){const t=[s,l];let a=Z(n)||0;for(const e of t){const{field:t,normalizationField:i,label:s}=e,l=s||{field:this._getFieldAlias(t,r),normField:i&&this._getFieldAlias(i,r)},n=Ye.clone();n.angle=a,d.infos.push({label:l,symbol:n}),f.add(n),a+=90}const o=Q({focus:n,numClasses:i,infos:e.uniqueValueInfos??[]});c.unshift(o)}}else if(He(this.layer)||qe(this.layer)){const{uniqueValueInfos:t}=e;if(t)for(const e of t)e.symbol&&await this._checkClausesForUVR(o,e.value)&&d.infos.push({label:e.label||e.value,value:e.value,symbol:e.symbol})}else{const{field:t,field2:s,field3:l,fieldDelimiter:a,valueExpression:c,defaultSymbol:y}=e,f=!(!t&&!c||!s&&!l),m=u?u.title:null,p=[],{uniqueValueGroups:g}=e;if(g)for(const e of g){const i={type:"symbol-table",title:m||e.heading,infos:[]},{classes:u}=e;if(u)for(const e of u){const{symbol:u,values:d}=e;if(u){const y=[],h=[];for(const e of d??[]){const{value:i,value2:n,value3:o}=e,u=[],d=[];(t||c)&&(u.push(i),d.push(this._getDomainName(t,i,r)??le(i,re(r,t,this.view.timeZone)))),s&&(u.push(n),d.push(this._getDomainName(s,n,r)??le(n,re(r,s,this.view.timeZone)))),l&&(u.push(o),d.push(this._getDomainName(l,o,r)??le(o,re(r,l,this.view.timeZone)))),y.push(f?u.join(a||""):u[0]),h.push(d.join(" - "))}const m=y.join(", ");let p=e.label;if(!p){const e=h.filter(Boolean);p=e.length?e.join(", "):m}let g=u;"cim"===g.type&&n&&(g=g.clone(),z(g,{innerDotSize:.5*de,outerRingSize:de}));let b=!1;for(const e of y)if(b=await this._checkClausesForUVR(o,e),b)break;b&&i.infos.push({label:p,value:m,symbol:g})}}i.infos.length&&p.push(i)}if(p.length){const t=p[0];if(1===p.length&&"title"in t&&!t.title){const e=t.infos?.filter(Ke)??[];d.infos.push(...e)}else y&&(p.push({type:"symbol-table",infos:[{label:e.defaultLabel||"others",symbol:y}]}),h=!0),d.infos.push(...p);i||e.legendOptions?.title||e.valueExpressionTitle||(d.title=null)}}e.defaultSymbol&&!h&&(d.infos.push({label:e.defaultLabel||"others",symbol:e.defaultSymbol}),h=!0)}else if(Ce(e)){if(!n&&!a){y=this._isUnclassedRenderer(e);if(!y||!this._hasSizeRamp){const t=e.classBreakInfos.filter(({symbol:e})=>e),i="ascending-values"===e.legendOptions?.order;for(const{label:e,minValue:s,maxValue:l,symbol:n}of t){const t=e||(y?null:`${s} - ${l}`),a={previewAriaLabel:t||d.title||r.title,label:t,value:[s,l],symbol:n};i?d.infos.push(a):d.infos.unshift(a)}y&&(d.title=null),this._updateInfosForClassedSizeRenderer(e,d.infos)}e.defaultSymbol&&!y&&(d.infos.push({label:e.defaultLabel||"others",symbol:e.defaultSymbol}),h=!0)}}else if(Le(e))if(qe(this.layer)||We(this.layer)){const t=await this._constructTileImageryStretchRendererElements(e);Ge(t)?c.push(t):d.infos=t}else{const t=this.layer;let i,s;e.customStatistics?.length&&({min:i,max:s}=e.customStatistics[0]);let l=[],r=t.serviceRasterInfo;if(t.rasterFunction)try{r=await t.generateRasterInfo(t.rasterFunction)}catch{}const n=I(r.pixelType);if(1===r.bandCount){const l=t.bandIds?.[0]||0;i=null!=i?i:r.statistics?r.statistics[l].min:n[0],s=null!=s?s:r.statistics?r.statistics[l].max:n[1],i||s?c.push(await this._getStretchLegendElements(e,{min:i,max:s})):this._getServerSideLegend()}else if(t.bandIds&&1===t.bandIds.length)i=null!=i?i:r.statistics?r.statistics[t.bandIds[0]].min:n[0],s=null!=s?s:r.statistics?r.statistics[t.bandIds[0]].max:n[1],i||s?c.push(await this._getStretchLegendElements(e,{min:i,max:s})):this._getServerSideLegend();else if(r.bandCount>=3){const{bandInfos:e}=r,{bandIds:i}=t;e.length>=r.bandCount?3===i?.length?(l=i.map(t=>e[t].name),d.infos=this._createSymbolTableElementMultiBand(l)):"lerc"===t.format?(l=[0,1,2].map(t=>e[t].name),d.infos=this._createSymbolTableElementMultiBand(l)):this._getServerSideLegend():"lerc"===t.format?(l=["band1","band2","band3"],d.infos=this._createSymbolTableElementMultiBand(l)):this._getServerSideLegend()}else this._getServerSideLegend()}else if(ve(e))e.colormapInfos.forEach(e=>{d.infos.push({label:e.label,value:e.value,symbol:this._getAppliedCloneSymbol(_e,e.color)})});else if(Fe(e)){let i=e.symbol;switch(t.geometryType){case"point":i="pointSymbol"in r?r.pointSymbol:null;break;case"polyline":i="lineSymbol"in r?r.lineSymbol:null;break;case"polygon":i="polygonSymbol"in r?r.polygonSymbol:null}const s=this._clusterSizeVariable&&this._getClusterSymbol()||!this._hasSizeRamp;e.symbol&&s&&d.infos.push({previewAriaLabel:e.label||d.title||r.title,label:e.label,symbol:i})}else if(we(e)){e.outputUnit&&(this.title="("+e.toJSON().outputUnit+")"),d.title=e.attributeField;const t=e.getClassBreakInfos();t?.length?t.forEach(e=>{d.infos.push({label:e.minValue+" - "+e.maxValue,symbol:e.symbol})}):d.infos.push({label:e.attributeField,symbol:e.getDefaultSymbol()})}else Ee(e)&&c.push(await this._getStretchLegendElements(e,{min:0,max:255}));const m=e.defaultSymbol;!m||h||Fe(e)||y&&!this._hasColorRamp&&!this._hasSizeRamp&&!this._hasOpacityRamp||c.push({type:"symbol-table",infos:[{label:e.defaultLabel||"others",symbol:m}]}),d.infos.length&&c.unshift(d);const p=null==t.opacity?this.opacity:t.opacity,g=this._isTallSymbol("visualVariables"in e?e.visualVariables:null),b=He(this.layer)||qe(this.layer);return await this._generatePreviewsForLegendElements(c,{opacity:p,symbolConfig:{isTall:g,isSquareFill:b},cssEffectFilter:this.cssEffectFilter},{arrowMarkerSymbols:f}),e=null,c}async _waitForLayerViewUpdate(e){await f(()=>!e.updating)}async _checkFeatureCountForExpression(e,t){const i=this.layerView;if(!(i&&"createQuery"in i&&"queryFeatureCount"in i))return!0;try{await this._waitForLayerViewUpdate(i);const s=i.createQuery();e&&(s.where=ne(s.where,e)),t&&(s.geometry=t);return await i.queryFeatureCount(s)>0}catch{return!0}}async _checkClausesForUVR(e,t){const i=Xe(e,t);if(!i)return!0;return(!!!(!this._layerDefinitionExpressionClause&&this._layerDefinitionExpression&&this.respectLayerDefinitionExpression||!this._layerDisplayFilterClause&&this._layerDisplayFilter?.where)||await this._checkFeatureCountForExpression(`${e.field} = ${t}`))&&(!this._layerDefinitionExpressionClause||this._layerDefinitionExpressionClause.testFeature(i))&&(!this._layerDisplayFilterClause||this._layerDisplayFilterClause.testFeature(i))}_getServerSideLegend(){setTimeout(()=>this.buildLegendElementsForTools(),0)}_getAllInfos(e){const t=e?.infos;return t?t.reduce((e,t)=>e.concat(this._getAllInfos(t)),[]):[e]}async _constructTileImageryStretchRendererElements(e){const t=this.layer,i=t.symbolizer.rasterInfo??t.raster.rasterInfo;let s,l;const r=e?.customStatistics?.length?e.customStatistics:i?.statistics;if(r)({min:s,max:l}=r[0]);else{const e=I(i.pixelType);s=e[0],l=e[1]}if(t.hasStandardTime()&&(s=t.getStandardTimeValue(s),l=t.getStandardTimeValue(l)),1===i.bandCount||1===t.bandIds?.length)return this._getStretchLegendElements(e,{min:s,max:l});const n=(t?.bandIds?.length?t.bandIds:Array.from(Array(Math.min(i.bandCount,3)).keys())).map(e=>i.bandInfos[e].name);return n.length<3?n.push(n[1]):n.length>3&&n.splice(3),this._createSymbolTableElementMultiBand(n)}async _getStretchLegendElements(e,t){const i=e.colorRamp?.toJSON(),s=W(i,t);return{type:"stretch-ramp",title:"",infos:s,preview:M(s.map(e=>e.color))}}_getClusterSymbol(){const e=this.layer,t="featureReduction"in e&&e.featureReduction,i=t&&"symbol"in t&&t.renderer;return i&&!0!==i?.authoringInfo?.isAutoGenerated?null:t&&"symbol"in t?t.symbol:null}async _getSizeLegendElement(e,t,i,s){return{type:"size-ramp",title:this._clusterSizeVariable?this._getClusterTitle(t):e,infos:await K(i,t,await ae(i),this.scale,this.view,s,this._clusterSizeVariable?this._getClusterSymbol():null)}}_createSymbolTableElementMultiBand(e){const t=[],i=["red","green","blue"];return e.forEach((e,s)=>{t.push({label:{colorName:i[s],bandName:e},src:oe[s],opacity:this.opacity??1})}),t}_updateInfosForClassedSizeRenderer(e,t){const i=e.authoringInfo&&"class-breaks-size"===e.authoringInfo.type,s=e.classBreakInfos.some(e=>N(e.symbol));if(i&&s){const i=X,s=Y,l=e.classBreakInfos.length,r=(i-s)/(l>1?l-1:l);t.forEach((e,t)=>{e.size=i-r*t})}}_isTallSymbol(e){let t=!1,i=!1;if(e)for(let s=0;s<e.length&&(!t||!i);s++){const l=e[s];"size"===l.type&&("height"===l.axis&&(t=!0),"width-and-depth"===l.axis&&(i=!0))}return t&&i}async _generatePreviewsForLegendElements(e,t,i){const s=[];for(const l of e)for(const e of l.infos??[])if("infos"in e&&e.infos&&s.push(this._generatePreviewsForLegendElements([e],t,i)),Ke(e)&&e.symbol&&!e.preview){let r=!0;if("cim"===e.symbol.type){const{minScale:t,maxScale:i}=e.symbol.data;(t&&t<this.scale||i&&i>this.scale)&&(r=!1)}r&&s.push(this._generateSymbolPreviewForInfo(e,{...t,clipBloomEffect:"theme"in l&&"spike"===l.theme,cssEffectFilter:i?.arrowMarkerSymbols?.has(e.symbol)?null:t.cssEffectFilter},i?{applyScaleDrivenSize:!i.arrowMarkerSymbols?.has(e.symbol)}:void 0))}await Promise.all(s)}async _getSize(e,t){let i=null==e.size&&this._hasSizeRamp?m(22):e.size;if(this._scaleDrivenSizeVariable&&t?.applyScaleDrivenSize){const{getSize:t}=await import("../../../renderers/visualVariables/support/visualVariableUtils.js");i=t(this._scaleDrivenSizeVariable,null,{view:this.view.type,scale:this.scale,shape:"simple-marker"===e.symbol.type?e.symbol.style:null})}return i}_getPreviewCIMOptions(e){return{style:"legend",cimOptions:{allowScalingUp:this._hasSizeRamp||!(!this._scaleDrivenSizeVariable||!e?.applyScaleDrivenSize),viewParams:this.isScaleDriven?{viewingMode:"2d"===this.view?.type?"map":this.view?.viewingMode,scale:this.view?.scale}:null}}}async _generateSymbolPreviewForInfo(e,t={},i){const{symbol:s}=e;try{if(t.size=await this._getSize(e,i),t.scale=!1,"cim"===s.type){const e=this._getPreviewCIMOptions(i);t={...t,...e}}e.preview=await A(s,t)}catch{e.preview=null,o.getLogger(this).warn(`Generating symbol preview failed for symbol type: ${s?.type}`)}}_getClusterRenderer(e){this._clusterSizeVariable=null;const t="renderer"in this.layer?this.layer.renderer:null,i=e.renderer?.clone()||t?.clone(),s=$(e,this.layerView,this.view);if(s&&null!=i&&"visualVariables"in i){const t=i.visualVariables?.some(e=>"size"===e.type&&"outline"!==e.target&&!pe.test(e.valueExpression));if(!t){if("clusterMinSize"in e&&"clusterMaxSize"in e){const{clusterMinSize:t,clusterMaxSize:i}=e;s.legendOptions=new x({showLegend:t!==i})}const t=i.visualVariables||[];i.visualVariables=t.concat([s]),this._clusterSizeVariable=s}}return i}async _loadRenderer(e){if(tt.has(e))return tt.get(e);const t=[],i=e.clone(),s=await ae(i);if(Ce(i)||Ie(i)){const e=(i.classBreakInfos||i.uniqueValueInfos).map(e=>this._fetchSymbol(e.symbol,s).then(t=>{e.symbol=t}).catch(()=>{e.symbol=null}));Array.prototype.push.apply(t,e)}return t.push(this._fetchSymbol(i.symbol||i.defaultSymbol,i.defaultSymbol?null:s).then(e=>{this._applySymbolToRenderer(i,e,Fe(i))}).catch(()=>{this._applySymbolToRenderer(i,null,Fe(i))})),await Promise.allSettled(t),tt.set(e,i),i}_applySymbolToRenderer(e,t,i){i?e.symbol=t:e.defaultSymbol=t}async _fetchSymbol(e,t){if(!e)throw new Error;if("web-style"===e.type){const i=this._webStyleSymbolCache;try{const s=await e.fetchSymbol({cache:i});return this._getAppliedCloneSymbol(s,t)}catch{throw o.getLogger(this).warn("Fetching web-style failed!"),new Error}}return this._getAppliedCloneSymbol(e,t)}_getAppliedCloneSymbol(e,i){if(!e||!i)return e;const s=e.clone(),l=i&&i.toRgba();return s.type.includes("3d")?this._applyColorTo3dSymbol(s,l):"cim"===s.type?O(s,i):s.color&&(s.color=new t(l||s.color)),s}_applyColorTo3dSymbol(e,i){i&&e.symbolLayers.forEach(e=>{e&&(e.material||(e.material={}),e.material.color=new t(i))})}async _getVisualVariableLegendElements(e,t){if(!("visualVariables"in e)||"vector-field"===e.type)return null;const i=e.visualVariables??[],s=[],l=[],n=[],a=ie(e,"reference-size")??ie(e,"spike");let o;const c=this._clusterSizeVariable;if(2===a?.sizeStops?.length&&(Ce(e)||Ie(e))){const[e,t]=a.sizeStops,i=c?c.minDataValue:e.value,s=c?c.maxDataValue:t.value;o=new D({field:a.field??void 0,normalizationField:a.normalizationField,minSize:u(e.size,10,100),maxSize:u(t.size,50,150),minDataValue:i,maxDataValue:s}),l.push(o)}for(const r of i)if("color"===r.type)s.push(r);else if("size"===r.type){if("cluster_count"===r.field&&o)continue;l.push(r)}else"opacity"===r.type&&n.push(r);const d=[...s,...l,...n];let y,h;if(0===s.length&&Ce(e)&&e.classBreakInfos&&1===e.classBreakInfos.length){const t=e.classBreakInfos[0];y=t&&t.symbol}if(0===s.length&&Fe(e)&&(y=e.symbol),y)if(y.type.includes("3d")){const e=y.symbolLayers.at(0);"water"===e.type?null!=e.color&&(h=e.color):null!=e.material?.color&&(h=e.material.color)}else y.url||(h=y.color);const f=this.cssEffectFilter;return(await Promise.all(d.map(async i=>{if(!i.legendOptions||!1!==i.legendOptions.showLegend){const s=Se(e)?i.field:this._getRampTitle(i,t);let l=null;const r=ue(t,i,this.view.timeZone);if("color"===i.type){const e=await G(i,null,r)??[];l={type:"color-ramp",title:s,infos:e,preview:M(e.map(e=>e.color),{cssEffectFilter:f})},this._hasColorRamp||(this._hasColorRamp=e.length>0)}else if("size"===i.type&&"outline"!==i.target)pe.test(i.valueExpression)?this._clusterSizeVariable||(this._scaleDrivenSizeVariable=i):(l=await this._getSizeLegendElement(s,i,e,r),o===i&&"spike"===a?.theme&&(l.theme=a.theme),this._hasSizeRamp||(this._hasSizeRamp=!(null==l.infos||!l.infos.length)));else if("opacity"===i.type){const e=await G(i,h,r)??[];l={type:"opacity-ramp",title:s,infos:e,preview:M(e.map(e=>e.color),{cssEffectFilter:f})},this._hasOpacityRamp||(this._hasOpacityRamp=e.length>0)}return l?.infos?l:null}}))).filter(r)}_getDomainName(e,t,i){if(e&&"function"!=typeof e){const s="getField"in i&&i.getField?.(e),l=s&&"getFieldDomain"in i&&i.getFieldDomain?i.getFieldDomain(s.name,{excludeImpliedDomains:has("esri-widget-legacy-field-domain-calculation")}):null;return"coded-value"===l?.type?l.getName(t):null}return null}_getClusterTitle(e){const t=this.layer,i=e.field;if("featureReduction"in t&&t.featureReduction&&"cluster"===t.featureReduction.type){const e=t.featureReduction,s="popupTemplate"in e&&e.popupTemplate,l=s&&s.fieldInfos;if(l)for(const t of l)if(t.fieldName===i)return"cluster_count"===i?t.label||{showCount:!0}:t.label}return{showCount:!0}}_getRampTitle(e,t){let i=e.field,s=e.normalizationField,l=!1,r=!1,n=!1,a=null;i="function"==typeof i?null:i,s="function"==typeof s?null:s;const o=e.legendOptions?.title;if(null!=o)a=o;else if(e.valueExpressionTitle)a=e.valueExpressionTitle;else{if("renderer"in t&&t.renderer&&"authoringInfo"in t.renderer&&t.renderer.authoringInfo?.visualVariables){const e=t.renderer.authoringInfo.visualVariables;for(let t=0;t<e.length;t++){const i=e[t];if("color"===i.type){if("ratio"===i.style){l=!0;break}if("percent"===i.style){r=!0;break}if("percent-of-total"===i.style){n=!0;break}}}}a={field:i&&this._getFieldAlias(i,t),normField:s&&this._getFieldAlias(s,t),ratio:l,ratioPercent:r,ratioPercentTotal:n}}return a}_getRendererTitle(e,t){const i=e;if(i.legendOptions?.title)return i.legendOptions.title;if(i.valueExpressionTitle)return i.valueExpressionTitle;let s=i.field,l=null,r=null;if(Ce(i)&&(l=i.normalizationField,r="percent-of-total"===i.normalizationType),s="function"==typeof s?null:s,l="function"==typeof l?null:l,Ie(i)){const{field2:e,field3:l,fieldDelimiter:r}=i;let n=s&&this._getFieldAlias(s,t);return e&&(n=`<${n}>${r}<${this._getFieldAlias(e,t)}>`,l&&(n=`${n}${r}<${this._getFieldAlias(l,t)}>`)),n}let n=null;return(s||l)&&(n={field:s&&this._getFieldAlias(s,t),normField:l&&this._getFieldAlias(l,t),normByPct:r}),n}_getFieldAlias(e,t){const i="featureReduction"in t&&t.featureReduction;if(C(t)&&!i)return t.getFieldAlias(e)||e;const s="popupTemplate"in t?t.popupTemplate:null,l=s?.fieldInfos;let r=l?.find(t=>e===t.fieldName),n=null;"getField"in t&&t.getField?n=t.getField(e):"fieldsIndex"in t&&t.fieldsIndex&&(n=t.fieldsIndex.get(e));let a=null;i&&(r??="popupTemplate"in i?i.popupTemplate?.fieldInfos?.find(t=>e?.toLowerCase()===t.fieldName?.toLowerCase()):void 0,"fields"in i&&i.fields&&(a=i.fields.find(t=>t.name?.toLowerCase()===e?.toLowerCase())));const o=r||n||a;let u=null;return o&&(u=r?.label||n?.alias||a?.alias||"name"in o&&o.name||"fieldName"in o&&o.fieldName||null),u}_isUnclassedRenderer(e){const t=e.visualVariables;let i=!1;return Ce(e)&&e.classBreakInfos&&1===e.classBreakInfos.length&&t&&(i=e.field?t.some(t=>!(!t||e.field!==t.field||(e.normalizationField||t.normalizationField)&&e.normalizationField!==t.normalizationField)):!!t.length),i}};e([b()],it.prototype,"_loading",void 0),e([b()],it.prototype,"children",void 0),e([b({readOnly:!0})],it.prototype,"cssEffectFilter",null),e([b()],it.prototype,"layerView",void 0),e([b()],it.prototype,"layer",void 0),e([b()],it.prototype,"legendElements",void 0),e([b({readOnly:!0})],it.prototype,"loading",null),e([b({readOnly:!0})],it.prototype,"opacity",null),e([b()],it.prototype,"parent",void 0),e([b({readOnly:!0,dependsOn:[]})],it.prototype,"ready",null),e([b()],it.prototype,"hideLayersNotInCurrentView",void 0),e([b()],it.prototype,"keepCacheOnDestroy",void 0),e([b()],it.prototype,"respectLayerDefinitionExpression",void 0),e([b()],it.prototype,"respectLayerVisibility",void 0),e([b({readOnly:!0})],it.prototype,"scale",null),e([b()],it.prototype,"sublayerIds",void 0),e([b({readOnly:!0})],it.prototype,"isScaleDriven",null),e([b()],it.prototype,"title",void 0),e([b({readOnly:!0,dependsOn:["ready"],value:0})],it.prototype,"version",null),e([b()],it.prototype,"view",void 0),it=e([_("esri.widgets.Legend.support.ActiveLayerInfo")],it);export{it as default};
|