UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 2.78 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{px2pt as e,pt2px as t}from"../../core/screenUtils.js";import{CIMSymbolHelper as i}from"../cim/CIMSymbolHelper.js";import{CIMSymbolRasterizer as l}from"../cim/CIMSymbolRasterizer.js";import{OverrideHelper as r}from"../cim/OverrideHelper.js";import{mapCIMSymbolToGeometryType as o}from"../cim/utils.js";import{SymbolSizeDefaults as n}from"./previewUtils.js";import{renderSymbol as a}from"./renderUtils.js";const s=new l(null),m=e(n.size),h=e(n.maxSize),c=e(n.lineWidth),y=1;async function u(e,t,i){const l=t?.size;let r=null!=l&&"object"==typeof l&&"width"in l?l.width:l,o=null!=l&&"object"==typeof l&&"height"in l?l.height:l;if(null==r||null==o)if("esriGeometryPolygon"===i)r=o=t.maxSize?Math.min(t.maxSize,m):m;else{const l=await f(e,t,i);l&&(r=l.width,o=l.height),"esriGeometryPolyline"===i&&(r=t.maxSize?Math.min(t.maxSize,c):c),r=null!=r&&isFinite(r)?Math.min(r,h):m,o=null!=o&&isFinite(o)?Math.max(Math.min(o,h),y):m}return"legend"===t.style&&"esriGeometryPolyline"===i&&(r=c),{width:r,height:o}}async function f(e,t,l){const{feature:o,fieldMap:n,viewParams:a}=t.cimOptions||t,m=await r.resolveSymbolOverrides(e.data,o,null,n,l,null,a);if(!m)return null;(e=e.clone()).data={type:"CIMSymbolReference",symbol:m},e.data.primitiveOverrides=void 0;const h=[];return i.fetchResources(m,s.resourceManager,h),i.fetchFonts(m,s.resourceManager,h),h.length>0&&await Promise.all(h),i.getEnvelope(m,null,s.resourceManager)}async function g(i,l={}){const{node:r,opacity:n,symbolConfig:m}=l,h=null!=m&&"object"==typeof m&&"isSquareFill"in m&&m.isSquareFill,c=l.cimOptions||l,y=c.geometryType||o(i?.data?.symbol),f=await u(i,l,y),{feature:g,fieldMap:d}=c,p=l?.geometry||h||"esriGeometryPolygon"!==y?"preview":"legend";let w=f;const b=f;if(l?.geometry&&("esriGeometryPolygon"===y||"esriGeometryPolyline"===y)){const i=200;if(t(f.width)<i||t(f.height)<i){const t=f.width>f.height?e(i)*f.height/f.width:e(i);w={width:f.width>f.height?e(i):e(i)*f.width/f.height,height:t}}}const M=await s.rasterizeCIMSymbolAsync(i,g,w,p,d,y,null,c.viewParams,c.allowScalingUp,l?.geometry?.toJSON());if(!M)return null;const{width:S,height:v}=M,j=document.createElement("canvas");j.width=S,j.height=v;j.getContext("2d").putImageData(M,0,0);const x=t(b.width),z=t(b.height),P=new Image(x,z);P.src=j.toDataURL(),P.ariaLabel=l.ariaLabel??null,P.alt=l.ariaLabel??"",null!=n&&(P.style.opacity=`${n}`);let C=P;if(null!=l.effectView){const e={shape:{type:"image",x:0,y:0,width:x,height:z,src:P.src},fill:null,stroke:null,offset:[0,0]};C=a([[e]],[x,z],{effectView:l.effectView,ariaLabel:l.ariaLabel})}return r&&C&&r.appendChild(C),C}export{g as previewCIMSymbol};