UNPKG

@arcgis/core

Version:

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

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