@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 2.46 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{getAssetUrl as t}from"../../assets.js";import e from"../../Color.js";import o from"../../request.js";import{LRUCache as s}from"../../core/LRUCache.js";import{pt2px as r}from"../../core/screenUtils.js";import{getCIMSymbolColor as n}from"./cimSymbolUtils.js";const i="picture-fill",a="simple-fill",l="simple-line",c="simple-marker",h="text",d="cim",m=new Map([["dash",[4,3]],["dashdot",[4,3,1,3]],["dot",[1,3]],["longdash",[8,3]],["longdashdot",[8,3,1,3]],["longdashdotdot",[8,3,1,3,1,3]],["shortdash",[4,1]],["shortdashdot",[4,1,1,1]],["shortdashdotdot",[4,1,1,1,1,1]],["shortdot",[1,1]],["solid",[]]]),p=new s(1e3);function u(e){const o=e.style;let s=null;if(e)switch(e.type){case c:"cross"!==o&&"x"!==o&&(s=e.color);break;case a:o&&"solid"!==o?"none"!==o&&(s={type:"pattern",x:0,y:0,src:t(`esri/symbols/patterns/${o}.png`),width:5,height:5}):s=e.color;break;case i:s={type:"pattern",src:e.url,width:r(e.width)*e.xscale,height:r(e.height)*e.yscale,x:r(e.xoffset),y:r(e.yoffset)};break;case h:s=e.color;break;case d:s=n(e)}return s}function f(t,e){const s=t+"-"+e;return void 0!==p.get(s)?Promise.resolve(p.get(s)):o(t,{responseType:"image"}).then((t=>{const o=t.data,r=o.naturalWidth,n=o.naturalHeight,i=document.createElement("canvas");i.width=r,i.height=n;const a=i.getContext("2d");a.fillStyle=e,a.fillRect(0,0,r,n),a.globalCompositeOperation="destination-in",a.drawImage(o,0,0);const l=i.toDataURL();return p.put(s,l),l}))}function y(t){if(!t)return null;let e=null;switch(t.type){case a:case i:case c:e=y(t.outline);break;case l:{const o=r(t.width);null!=t.style&&"none"!==t.style&&0!==o&&(e={color:t.color,style:w(t.style),width:o,cap:t.cap,join:"miter"===t.join?r(t.miterLimit):t.join},e.dashArray=g(e).join(",")||"none");break}default:e=null}return e}function g(t){if(!t?.style)return[];const{dashArray:e,style:o,width:s}=t;if("string"==typeof e&&"none"!==e)return e.split(",").map((t=>Number(t)));const r=s??0,n=m.has(o)?m.get(o).map((t=>t*r)):[];if("butt"!==t.cap)for(const[i,a]of n.entries())n[i]=i%2==1?a+r:Math.max(a-r,1);return n}const w=(()=>{const t={};return e=>{if(t[e])return t[e];const o=e.replaceAll("-","");return t[e]=o,o}})(),b=new e([128,128,128]);export{b as defaultThematicColor,w as dekebabifyLineStyle,g as getDashArray,u as getFill,f as getPatternUrlWithColor,y as getStroke};