UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 2.42 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{id as t}from"../../kernel.js";import e from"../../request.js";import{toHSV as i,toRGB as r}from"../../core/colorUtils.js";import n from"../../core/Error.js";import has from"../../core/has.js";import"../../libs/maquette/projection.js";import{createProjector as o}from"../../libs/maquette/projector.js";import{renderSVG as a}from"./svgUtils.js";import{getCSSFilterFromEffectList as c}from"./utils.js";const s=o();function h(t,e){s.append(t,e),s.detach(e)}function l(t,e,i){const r=Math.ceil(e[0]),n=Math.ceil(e[1]);if(!t.some((t=>!!t.length)))return null;const o=i?.node||document.createElement("div");null!=i.opacity&&(o.style.opacity=i.opacity.toString()),null!=i.effectView&&(o.style.filter=c(i.effectView));return h(o,(()=>a(t,r,n,i))),o}function m(t,e){t=Math.ceil(t),e=Math.ceil(e);const i=document.createElement("canvas");i.width=t,i.height=e,i.style.width=t+"px",i.style.height=e+"px";const r=i.getContext("2d");return r.clearRect(0,0,t,e),r}function g(t,i,r){return t?e(t,{responseType:"image"}).then((t=>{const e=t.data,n=e.width,o=e.height,a=n/o;let c=i;if(r){const t=Math.max(n,o);c=Math.min(c,t)}return{image:e,width:a<=1?Math.ceil(c*a):c,height:a<=1?c:Math.ceil(c/a)}})):Promise.reject(new n("renderUtils: imageDataSize","href not provided."))}function u(t,e){return!(!t||"ignore"===e)&&("multiply"!==e||255!==t.r||255!==t.g||255!==t.b||1!==t.a)}function f(t,e,n,o,a){switch(a){case"multiply":t[e]*=n[0],t[e+1]*=n[1],t[e+2]*=n[2],t[e+3]*=n[3];break;default:{const a=i({r:t[e],g:t[e+1],b:t[e+2]});a.h=o.h,a.s=o.s,a.v=a.v/100*o.v;const c=r(a);t[e]=c.r,t[e+1]=c.g,t[e+2]=c.b,t[e+3]*=n[3];break}}}function d(e,r,n,o,a){return g(e,r,a).then((a=>{const c=a.width??r,s=a.height??r;if(a.image&&u(n,o)){let t=a.image.width,r=a.image.height;has("edge")&&/\.svg$/i.test(e)&&(t-=1,r-=1);const h=m(c,s);h.drawImage(a.image,0,0,t,r,0,0,c,s);const l=h.getImageData(0,0,c,s),g=[n.r/255,n.g/255,n.b/255,n.a],u=i(n);for(let e=0;e<l.data.length;e+=4)f(l.data,e,g,u,o);h.putImageData(l,0,0),e=h.canvas.toDataURL("image/png")}else{const i=t?.findCredential(e);if(i?.token){const t=e.includes("?")?"&":"?";e=`${e}${t}token=${i.token}`}}return{url:e,width:c,height:s}})).catch((()=>({url:e,width:r,height:r})))}export{h as renderOnce,l as renderSymbol,d as tintImageWithColor};