UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) • 6.82 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import e from"../../../Color.js";import{getColorLuminance as t}from"../../../core/colorUtils.js";import{round as l,numDigits as o,percentChange as i}from"../../../renderers/support/numberUtils.js";import{updateReferenceSizeSymbol as n}from"../../../smartMapping/renderers/support/referenceSizeUtils.js";import{updateSpikeSymbol as r}from"../../../smartMapping/renderers/support/spikeUtils.js";import s from"../../../symbols/SimpleLineSymbol.js";import a from"../../../symbols/SimpleMarkerSymbol.js";import{applyCIMSymbolColor as u}from"../../../symbols/support/cimSymbolUtils.js";import{getCIMSymbolPreviewSize as c}from"../../../symbols/support/previewCIMSymbol.js";import{isSymbol3D as m}from"../../../symbols/support/typeUtils.js";import{isVolumetricSymbol as p,getSymbolOutlineSize as f}from"../../../symbols/support/utils.js";import{getAuthoringInfoVisualVariableByTheme as y,getSymbolForFlowRenderer as b,createStopLabel as d}from"./utils.js";import"../../support/widgetUtils.js";import{isDarkMode as h}from"../../../support/modeUtils.js";const w=30,S=12,g=24,v=[255,255,255],z=[200,200,200],k=[128,128,128],j=20,I=5;function V(e){return"esri.symbols.SimpleMarkerSymbol"===e.declaredClass}function x(e){return"esri.symbols.PictureMarkerSymbol"===e.declaredClass}function M(e){return"esri.symbols.SimpleLineSymbol"===e.declaredClass}function U(e){return"esri.symbols.TextSymbol"===e.declaredClass}function C(e,t){const l=e.length-1;return e.map(((e,o)=>d(e,o,l,t)))}async function L(e,t,o,i,n,r,s){const a=t.legendOptions,u=a?.customValues,m=s||await B(e,o),b=t.stops,d=!!m,h=!!u,w=null!=t.minSize&&null!=t.maxSize,S=b&&b.length>1,v=!!t.target;if(!d||!h&&!(w||S&&!v))return;const z=p(m);let k=!1,j=null,I=null;j=z&&!S?l([t.minDataValue,t.maxDataValue]):u??await H(t,m,i,n?.type);const V=e?.authoringInfo,x="univariate-color-size"===V?.type,M=x&&"above-and-below"===V?.univariateTheme,U=!!y(e,"reference-size"),L=!!y(e,"spike");if(!j&&S&&(j=b.map((e=>e.value)),k=b.some((e=>!!e.label)),"flow"===e.type&&(j=l(j)),k&&(I=b.map((e=>e.label)))),z&&null!=j&&j?.length>2&&!M&&(j=[j[0],j[j.length-1]]),!j)return null;x&&5!==j?.length&&(j=O({minSize:j[0],maxSize:j[j.length-1]}));const T=z?D(e,j):null,q=f(m),E=k?null:C(j,r),P=await Promise.all(j.map((async(l,o)=>{let r=z?T[o]:await G(t,m,l,i,n?.type),s=r;U&&(r*=g/t.maxSize||1,s=g);const a=J(m,r,e,o);L&&"cim"===a.type&&(s=await c(a));return{value:l,symbol:a,label:k?I[o]:E[o],size:s,outlineSize:q}})));return P.reverse()}function D(e,t){const l=e?.authoringInfo,o="univariate-color-size"===l?.type;let i=[S,w];if(o){const e=t[0],l=t[t.length-1],o=S,n=w;i=t.map((t=>o+(t-e)/(l-e)*(n-o)))}return o&&"below"===l?.univariateTheme&&i.reverse(),i}function T(t,l,o,i){const r="class-breaks"===t.type,s=r?t.classBreakInfos?.[0]?.symbol?.clone():t.uniqueValueInfos?.[0]?.symbol?.clone();return s&&"type"in s&&"cim"===s.type?(n(s,{color:i??(r?null:new e(z)),innerDotSize:l*(g/o)||1,outerRingSize:g}),s):null}function q(e,t){const l=e.classBreakInfos,o=l.length,i=o<2||!(t>=2)?l[0].symbol.clone():l[o-1].symbol.clone(),n=e.visualVariables?.some((e=>"color"===e.type));return n&&(i.type.includes("3d")?P(i):R(i)),i}async function B(l,o){if("flow"===l.type)return b(l,o);if("pie-chart"===l.type)return new a({color:null,outline:l.outline?.width?l.outline:new s});let i=null,u=null;if("simple"===l.type)i=l.symbol;else if("class-breaks"===l.type){const e=l.classBreakInfos;i=e&&e[0]&&e[0].symbol,u=e.length>1}else if("unique-value"===l.type){const e=l.uniqueValueInfos;i=e?.[0]?.symbol,u=null!=e&&e.length>1}if(!i||E(i))return null;if(i=i.clone(),o||u)if(i.type.includes("3d"))P(i);else if(y(l,"reference-size")&&"cim"===i.type)n(i,{color:o??("class-breaks"!==l.type?new e(z):null)});else if(y(l,"spike")&&"cim"===i.type){const l=new e(z),n=new e(k),s="CIMPointSymbol"===i.data.symbol?.type?i.data.symbol:null,a=!!s?.symbolLayers?.find((({type:e})=>"CIMSolidStroke"===e))?.colorLocked;let u,c=o??void 0;if(c){const e=t(c),o=h();(!o&&e>225||o&&e<25)&&(c=l,u=a?n:l)}else c=l,u=a?n:l;r(i,{color:c,strokeColor:u})}else R(i);return i}function E(e){return m(e)?e.symbolLayers?.some((e=>"fill"===e?.type))??!1:e?.type.includes("fill")??!1}function P(e){"line-3d"===e.type?e.symbolLayers.forEach((e=>{e.material={color:k}})):e.symbolLayers.forEach((e=>{"icon"!==e.type||e.resource?.href?e.material={color:z}:(e.material={color:v},e.outline={color:k,size:1.5})}))}function R(t){const l=h();if("cim"===t.type)u(t,new e(z));else if(t.type.includes("line"))t.color=k;else if(t.color=l?k:v,"simple-marker"===t.type)if(t.outline){const e=t.outline?.color?.toHex();"#ffffff"===e&&(t.outline.color=k)}else t.outline={color:k,width:1.5}}async function H(e,t,o,i){const n=(await import("../../../renderers/visualVariables/support/visualVariableUtils.js")).getSizeRangeAtScale(e,o,i),r=n&&O(n);if(!n||!r)return;let s=r.map((t=>A(t,e,n)));s=l(s);for(let l=1;l<s.length-1;l++){const n=await F(e,t,s[l],s[l-1],o,i);n&&(s[l]=n[0],r[l]=n[1])}return s}function O(e){const t=e.minSize,l=e.maxSize,o=I,i=(l-t)/(o-1),n=[];for(let r=0;r<o;r++)n.push(t+i*r);return n}function A(e,t,l){const o=l.minSize,i=l.maxSize,n=t.minDataValue,r=t.maxDataValue;let s;if(e<=o)s=n;else if(e>=i)s=r;else{s=(e-o)/(i-o)*(r-n)+n}return s}async function F(e,t,n,r,s,a){const u=await G(e,t,n,s,a),c=await G(e,t,r,s,a),m=o(n),p=m.fractional,f=j;let y=m.integer,b=null,d=null;n>0&&n<1&&(b=10**p,y=o(n*=b).integer);for(let o=y-1;o>=0;o--){const r=10**o;let m=Math.floor(n/r)*r,p=Math.ceil(n/r)*r;null!=b&&(m/=b,p/=b);let y=(m+p)/2;[,y]=l([m,y,p],{indexes:[1]});const h=await G(e,t,m,s,a),w=await G(e,t,p,s,a),S=await G(e,t,y,s,a),g=i(u,h,c,null),v=i(u,w,c,null),z=i(u,S,c,null);let k=g.previous<=f,j=v.previous<=f;if(k&&j&&(g.previous<=v.previous?(k=!0,j=!1):(j=!0,k=!1)),k?d=[m,h]:j?d=[p,w]:z.previous<=f&&(d=[y,S]),d)break}return d}async function G(e,t,l,o,i){const{getSize:n}=await import("../../../renderers/visualVariables/support/visualVariableUtils.js");return n(e,l,{scale:o,view:i,shape:"simple-marker"===t.type?t.style:null})}function J(e,t,l,o){"univariate-color-size"===l?.authoringInfo?.type&&"above-and-below"===l?.authoringInfo?.univariateTheme&&"class-breaks"===l.type&&(e=q(l,o));const i=e.clone();if(m(i))p(i)||i.symbolLayers.forEach((e=>{"fill"!==e.type&&(e.size=t)}));else if(V(i))i.size=t;else if(x(i)){const e=i.width,l=i.height;i.height=t,i.width=t*(e/l)}else M(i)?i.width=t:U(i)?i.font&&(i.font.size=t):"cim"===i.type&&y(l,"reference-size")?n(i,{innerDotSize:t,outerRingSize:g}):"cim"===i.type&&y(l,"spike")&&r(i,{defaultHeight:t,primitiveOverrides:null});return i}export{L as getRampStops,T as getReferenceSizeSymbol,w as realWorldMaxSize,S as realWorldMinSize};