UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 3.1 kB
import{pt2px as t}from"../../../../../core/screenUtils.js";import{CIMSymbolHelper as e}from"../../../../../symbols/cim/CIMSymbolHelper.js";import r from"../../../../../symbols/cim/Rect.js";import{AVERAGE_GLYPH_MOSAIC_ITEM as i}from"../../../engine/webgl/definitions.js";import{getTextSymbolSize as n}from"../../graphics/graphicsUtils.js";import{expandSymbol as s}from"../../support/cimSymbolUtils.js";const a={"simple-marker":1,"picture-marker":1,text:0,"simple-line":0,"simple-fill":0,"picture-fill":0,cim:1,"web-style":1},o=.707;function m(t,e){if(!("visualVariables"in t))return 0;if(!t.hasVisualVariables("size"))return 0;const r=t.getVisualVariablesForType("size");if(!r[0])return 0;const i=r[0];if(e&&"cluster_count"===i.field&&"cluster"===e.type)return e.clusterMaxSize;if("outline"===i.target)return 0;if("stops"===i.transformationType)return i.stops.map((t=>t.size)).reduce(g,0);if("clamped-linear"===i.transformationType){let t=-1/0,e=-1/0;return t="number"==typeof i.maxSize?i.maxSize:i.maxSize.stops.map((t=>t.size)).reduce(g,0),e="number"==typeof i.minSize?i.minSize:i.minSize.stops.map((t=>t.size)).reduce(g,0),Math.max(t,e)}return"real-world-size"===i.transformationType?30:void 0}function u(t){return t.type in a}async function c(e,r,i,n,s,a){if(!e||a&&"cluster"===a.type)return 0;if("heatmap"===e.type)return Math.round(t(e.radius));if("dot-density"===e.type)return 0;if("dictionary"===e.type)return"esriGeometryPoint"===r||"esriGeometryMultipoint"===r?100:200;const o=e.getSymbols(),u=m(e),c=[];for(const t of o)c.push(x(t,u,i,r,n,s));const l=await Promise.all(c);return t(l.reduce(g,0))}const l=[0,0,0,0];function p(t,e){return t??e}function f(t,e){return null==t.outline?e:p(t.outline.width,e)}const y={sdf:!0,code:99,metrics:i.metrics,rect:new r(0,0,24,24),page:0,textureBinding:2};function h(t){const e=t.text&&t.text.length;if(!e)return{glyphMosaicItems:[y]};const r=[];for(let i=0;i<e;i++)r.push({...y,code:t.text.charCodeAt(i)});return{glyphMosaicItems:r}}async function d(t,r,i,a,m,u){if("simple-marker"===t.type){const e=Math.max(p(t.size,12),r);return M(t)+e*o}if("picture-marker"===t.type){const e=Math.max(p(t.height,12),r),i=p(t.width,12)*(e/p(t.height,12))/2,n=e/2;return M(t)+Math.sqrt(i*i+n*n)}if("text"===t.type){const e=h(t);n(l,t.toJSON(),e);const r=Math.abs(l[0]),i=Math.abs(l[1]),s=l[2],a=l[3];return Math.max(r,i)+Math.max(s,a)}if("simple-line"===t.type){const e=t,i=Math.max(p(e.width,.75),r)/2;return e.marker?Math.max(6*e.width,2*r):i}if("simple-fill"===t.type||"picture-fill"===t.type)return Math.max(f(t,0),r)/2;if("cim"===t.type){const n={geometryType:a,fields:m,spatialReference:u},o={type:"cim",rendererKey:0,data:t.data,maxVVSize:r};await s(o,n,i);const c=e.getEnvelope(t.data,null,i);return c?Math.sqrt(c.width*c.width+c.height*c.height):0}return"web-style"===t.type?d(await t.fetchCIMSymbol(),r,i,a,m,u):0}async function x(t,e,r,i,n,s){return u(t)?Math.min(await d(t,e,r,i,n,s),75):0}function M(t){const e=p(t.xoffset,0),r=p(t.yoffset,0);return Math.sqrt(e*e+r*r)}function g(t,e){return Math.max(t,e)}export{c as computePxBuffer,m as getPtMaxVVSize};