@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 3.27 kB
JavaScript
import{isNone as e}from"../../../../../../core/maybe.js";import{toPt as t,pt2px as s}from"../../../../../../core/screenUtils.js";import{premultiplyAlpha as n}from"../../../../engine/webgl/color.js";import{NAN_MAGIC_NUMBER as o}from"../../../../engine/webgl/definitions.js";import{WGLVVFlag as i}from"../../../../engine/webgl/enums.js";import{getTypeOfSizeVisualVariable as l}from"../../../../engine/webgl/visualVariablesUtils.js";function r(e,t){if(!e||!t)return e;switch(t){case"radius":case"distance":return 2*e;case"diameter":case"width":return e;case"area":return Math.sqrt(e)}return e}function a(e){return{value:e.value,size:t(e.size)}}function u(e){return(e??[]).map((e=>a(e)))}function p(e){if("string"==typeof e||"number"==typeof e)return t(e);const s=e;return{type:"size",expression:s.expression,stops:u(s.stops)}}const c=e=>{const t=[],n=[],i=u(e),l=i.length;for(let r=0;r<6;r++){const e=i[Math.min(r,l-1)];t.push(e.value),n.push(null==e.size?o:s(e.size))}return{values:new Float32Array(t),sizes:new Float32Array(n)}};function f(e){const t=e&&e.length>0?{}:null,s=t?{}:null;if(!t||!s)return{vvFields:t,vvRanges:s};for(const n of e)if(n.field&&(t[n.type]=n.field),"size"===n.type){s.size||(s.size={});const e=n;switch(l(e)){case i.SIZE_MINMAX_VALUE:s.size.minMaxValue={minDataValue:e.minDataValue,maxDataValue:e.maxDataValue,minSize:p(e.minSize),maxSize:p(e.maxSize)};break;case i.SIZE_SCALE_STOPS:s.size.scaleStops={stops:u(e.stops)};break;case i.SIZE_FIELD_STOPS:if(e.levels){const t={};for(const s in e.levels)t[s]=c(e.levels[s]);s.size.fieldStops={type:"level-dependent",levels:t}}else s.size.fieldStops={type:"static",...c(e.stops)};break;case i.SIZE_UNIT_VALUE:s.size.unitValue={unit:e.valueUnit,valueRepresentation:e.valueRepresentation??void 0}}}else if("color"===n.type)s.color=g(n);else if("opacity"===n.type)s.opacity=m(n);else if("rotation"===n.type){const e=n;s.rotation={type:e.rotationType}}return{vvFields:t,vvRanges:s}}function m(e){const t={values:[0,0,0,0,0,0,0,0],opacities:[0,0,0,0,0,0,0,0]};if("string"==typeof e.field){if(!e.stops)return null;{if(e.stops.length>8)return null;const s=e.stops;for(let e=0;e<8;++e){const n=s[Math.min(e,s.length-1)];t.values[e]=n.value,t.opacities[e]=n.opacity}}}else{if(!(e.stops&&e.stops.length>=0))return null;{const s=e.stops&&e.stops.length>=0?e.stops[0].opacity:0;for(let e=0;e<8;e++)t.values[e]=1/0,t.opacities[e]=s}}return t}function v(e,t,s){e[4*t+0]=s.r/255,e[4*t+1]=s.g/255,e[4*t+2]=s.b/255,e[4*t+3]=s.a}function g(t){if(e(t))return null;if(t.normalizationField)return null;const s={field:null,values:[0,0,0,0,0,0,0,0],colors:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]};if("string"==typeof t.field){if(!t.stops)return null;{if(t.stops.length>8)return null;s.field=t.field;const e=t.stops;for(let t=0;t<8;++t){const n=e[Math.min(t,e.length-1)];s.values[t]=n.value,v(s.colors,t,n.color)}}}else{if(!(t.stops&&t.stops.length>=0))return null;{const e=t.stops&&t.stops.length>=0&&t.stops[0].color;for(let t=0;t<8;t++)s.values[t]=1/0,v(s.colors,t,e)}}for(let e=0;e<32;e+=4)n(s.colors,e,!0);return s}export{g as convertColorVariable,f as convertVisualVariables,r as getVisualVariableSizeValueRepresentationRatio,p as normalizeSizeElement,u as normalizeSizeStops,a as stopToSizeStop};