@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 1.71 kB
JavaScript
import{getAssetUrl as e}from"../../assets.js";import t from"../../Color.js";import r from"../../request.js";import o from"../../core/ItemCache.js";import{pt2px as s}from"../../core/screenUtils.js";import{getCIMSymbolColor as i}from"./cimSymbolUtils.js";const n="picture-fill",l="simple-fill",c="simple-line",a="simple-marker",m="text",p="cim",u=new o(1e3);function f(t){const r=t.style;let o=null;if(t)switch(t.type){case a:"cross"!==r&&"x"!==r&&(o=t.color);break;case l:"solid"===r?o=t.color:"none"!==r&&(o={type:"pattern",x:0,y:0,src:e(`esri/symbols/patterns/${r}.png`),width:5,height:5});break;case n:o={type:"pattern",src:t.url,width:s(t.width)*t.xscale,height:s(t.height)*t.yscale,x:s(t.xoffset),y:s(t.yoffset)};break;case m:o=t.color;break;case p:o=i(t)}return o}function h(e,t){const o=e+"-"+t;return void 0!==u.get(o)?Promise.resolve(u.get(o)):r(e,{responseType:"image"}).then((e=>{const r=e.data,s=r.naturalWidth,i=r.naturalHeight,n=document.createElement("canvas");n.width=s,n.height=i;const l=n.getContext("2d");l.fillStyle=t,l.fillRect(0,0,s,i),l.globalCompositeOperation="destination-in",l.drawImage(r,0,0);const c=n.toDataURL();return u.put(o,c),c}))}function y(e){if(!e)return null;let t=null;switch(e.type){case l:case n:case a:t=y(e.outline);break;case c:{const r=s(e.width);null!=e.style&&"none"!==e.style&&0!==r&&(t={color:e.color,style:d(e.style),width:r,cap:e.cap,join:"miter"===e.join?s(e.miterLimit):e.join});break}default:t=null}return t}const d=(()=>{const e={};return t=>{if(e[t])return e[t];const r=t.replace(/-/g,"");return e[t]=r,r}})(),g=new t([128,128,128]);export{g as defaultThematicColor,d as dekebabifyLineStyle,f as getFill,h as getPatternUrlWithColor,y as getStroke};