UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 2 kB
import{px2pt as e,pt2px as t}from"../../core/screenUtils.js";import{OverrideHelper as i,CIMSymbolHelper as o}from"../cim/CIMSymbolHelper.js";import{CIMSymbolRasterizer as l,GeometryStyle as n}from"../cim/CIMSymbolRasterizer.js";import{mapCIMSymbolToGeometryType as r}from"../cim/utils.js";import{SymbolSizeDefaults as s}from"./previewUtils.js";import{renderSymbol as a}from"./renderUtils.js";const h=new l(null,!0),m=e(s.size),c=e(s.maxSize),u=e(s.lineWidth),f=1;function y(e){const t=e?.size;if("number"==typeof t)return{width:t,height:t};return{width:null!=t&&"object"==typeof t&&"width"in t?t.width:null,height:null!=t&&"object"==typeof t&&"height"in t?t.height:null}}async function d(e,l={}){const{node:s,opacity:d,symbolConfig:p}=l,g="object"==typeof p&&"isSquareFill"in p&&p.isSquareFill,w=l.cimOptions||l,b=w.geometryType||r(e?.data?.symbol),M=y(l),{feature:j,fieldMap:v}=w;if(null==M.width||null==M.height){const t=await i.resolveSymbolOverrides(e.data,j,null,v,b);if(!t)return null;(e=e.clone()).data={type:"CIMSymbolReference",symbol:t},e.data.primitiveOverrides=void 0;const l=[];o.fetchResources(t,h.resourceManager,l),l.length>0&&await Promise.all(l);const n=o.getEnvelope(t,null,h.resourceManager),r=n?.width,s=n?.height;M.width="esriGeometryPolygon"===b?m:"esriGeometryPolyline"===b?u:null!=r&&isFinite(r)?Math.min(r,c):m,M.height="esriGeometryPolygon"===b?m:null!=s&&isFinite(s)?Math.max(Math.min(s,c),f):m}const S=await h.rasterizeCIMSymbolAsync(e,j,M,g||"esriGeometryPolygon"!==b?n.Preview:n.Legend,v,b);if(!S)return null;const{width:C,height:I}=S,P=document.createElement("canvas");P.width=C,P.height=I;P.getContext("2d").putImageData(S,0,0);const x=t(M.width),z=t(M.height),F=new Image(x,z);F.src=P.toDataURL(),null!=d&&(F.style.opacity=`${d}`);let G=F;if(null!=l.effectView){const e={shape:{type:"image",x:0,y:0,width:x,height:z,src:F.src},fill:null,stroke:null,offset:[0,0]};G=a([[e]],[x,z],{effectView:l.effectView})}return s&&G&&s.appendChild(G),G}export{d as previewCIMSymbol};