UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) • 8.41 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{clone as e}from"../../core/lang.js";import{getPixelValueRange as t}from"../raster/formats/pixelRangeUtils.js";import{schema as n}from"../raster/functions/rasterFunctionSchema.js";import r from"./RasterFunction.js";import{getRFxArgColorRampValue as o,convertColorRampToColormap as a,getColorRampName as i,convertRGBATo32Bit as u}from"../../renderers/support/colorRampUtils.js";import{stretchTypeJSONDict as s}from"../../renderers/support/stretchRendererUtils.js";import l from"../../renderers/visualVariables/SizeVariable.js";const c=new Set(["u1","u2","u4","u8","s8","u16","s16"]),m={simple_scalar:"Simple Scalar",wind_barb:"Wind Barb",single_arrow:"Single Arrow",beaufort_kn:"Beaufort Wind (Knots)",beaufort_m:"Beaufort Wind (MetersPerSecond)",ocean_current_m:"Ocean Current (MetersPerSecond)",ocean_current_kn:"Ocean Current (Knots)"},p=new Set(["raster-stretch","unique-value","class-breaks","raster-shaded-relief","vector-field","raster-colormap"]);function f(e){return p.has(e.type)}function g(t,n){if(!t||!n)return e(t||n);const r=e(t);if(r.functionDefinition&&n.rasterFunctionDefinition){const e=n.rasterFunctionDefinition;(e.thumbnail||e.thumbnailEx)&&(e.thumbnail=e.thumbnailEx=void 0),d(r.functionDefinition.arguments,n),r.rasterFunctionDefinition=r.functionDefinition.toJSON()}else if("none"!==n.functionName?.toLowerCase()){b(r.functionArguments).Raster=n}return r}function d(e,t){for(const n in e)"raster"===n.toLowerCase()&&("RasterFunctionVariable"===e[n].type?(e[n]=t.rasterFunctionDefinition,e[n].type="RasterFunctionTemplate"):"RasterFunctionTemplate"===e[n].type&&d(e[n].arguments,t))}function h(t){const r=e(n[t.functionName+"Function"]),o=t.functionArguments;for(const e in o)"raster"===e.toLowerCase()?(r.arguments[e]=h(o[e]),r.arguments[e].type="RasterFunctionTemplate"):"colormap"===e.toLowerCase()?(r.arguments[e].value=V(o[e]),r.arguments.ColorSchemeType.value=0):r.arguments[e].value=o[e];return t.outputPixelType&&r.function&&(r.function.pixelType=t.outputPixelType.toUpperCase()),r}function y(e,t){switch(t=t||{},e.type){case"raster-stretch":return x(e,t);case"class-breaks":return S(e,t);case"unique-value":return F(e,t);case"raster-colormap":return N(e,t);case"vector-field":return T(e,t);case"raster-shaded-relief":return v(e,t);case"flow":throw new Error("Unsupported rendering rule.")}}function b(e){const t=e?.Raster??e?.raster;return t&&"esri.layers.support.RasterFunction"===t.declaredClass?b(t.functionArguments):e}const R={none:0,standardDeviation:3,histogramEqualization:4,minMax:5,percentClip:6,sigmoid:9};function T(e,t){const n=new r;n.functionName="VectorFieldRenderer";const{dataType:o,bandNames:a}=t,i="vector-uv"===o;let u,s;if(2===a?.length){const e=a.map(e=>e.toLowerCase());u=e.indexOf("magnitude"),s=e.indexOf("direction")}-1!==u&&null!==u||(u=0,s=1);const c="arithmetic"===e.rotationType?1:2,p="flow-from"===e.flowRepresentation?0:1,f=e.visualVariables?e.visualVariables.find(e=>"Magnitude"===e.field):new l,g={magnitudeBandID:u,directionBandID:s,isUVComponents:i,referenceSystem:c,massFlowAngleRepresentation:p,symbolTileSize:50,symbolTileSizeUnits:100,calculationMethod:"Vector Average",symbologyName:m[e.style.toLowerCase().replace("-","_")],minimumMagnitude:f.minDataValue,maximumMagnitude:f.maxDataValue,minimumSymbolSize:f.minSize,maximumSymbolSize:f.maxSize};n.functionArguments=g;const d=h(n);return t.convertToRFT?r.fromJSON({rasterFunctionDefinition:d}):n}function v(e,t){const n=t.convertToRFT;if("elevation"!==t.dataType&&("generic"!==t.dataType||1!==t.bandCount||"s16"!==t.pixelType&&"s32"!==t.pixelType&&"f32"!==t.pixelType&&"f64"!==t.pixelType))return new r;const i=new r;i.functionName="Hillshade";const u="traditional"===e.hillshadeType?0:1,s="none"===e.scalingType?1:3,l={HillshadeType:u,SlopeType:s,ZFactor:e.zFactor};return 0===u&&(l.Azimuth=e.azimuth,l.Altitude=e.altitude),3===s&&(l.PSPower=e.pixelSizePower,l.PSZFactor=e.pixelSizeFactor),i.functionArguments=l,i.variableName="Raster",e.colorRamp&&(i.functionName="ShadedRelief",n?l.ColorRamp=o(e.colorRamp):l.Colormap=a(e.colorRamp)),n?new r({rasterFunctionDefinition:h(i)}):i}function x(e,t){const n=t.convertToRFT,u=new r;u.functionName="Stretch";const l=R[s.toJSON(e.stretchType)],c="u8",m=e.customStatistics?.map(e=>[e.min,e.max,e.avg??0,e.stddev??1]),p={StretchType:l,Statistics:m,DRA:e.dynamicRangeAdjustment,UseGamma:e.useGamma,Gamma:e.gamma,ComputeGamma:e.computeGamma};if(null!=e.outputMin&&(p.Min=e.outputMin),null!=e.outputMax&&(p.Max=e.outputMax),l===R.standardDeviation?(p.NumberOfStandardDeviations=e.numberOfStandardDeviations,u.outputPixelType=c):l===R.percentClip?(p.MinPercent=e.minPercent,p.MaxPercent=e.maxPercent,u.outputPixelType=c):l===R.minMax?u.outputPixelType=c:l===R.sigmoid&&(p.SigmoidStrengthLevel=e.sigmoidStrengthLevel),u.functionArguments=p,u.variableName="Raster",e.colorRamp){const s=e.colorRamp,l=new r;if(n)l.functionArguments={ColorRamp:o(s)};else{const n=i(s,!0);if(n)l.functionArguments={colorRampName:n};else if(!t.convertColorRampToColormap||"algorithmic"!==s.type&&"multipart"!==s.type){const t=e.colorRamp.toJSON();"algorithmic"===t.type?t.algorithm=t.algorithm||"esriCIELabAlgorithm":"multipart"===t.type&&t.colorRamps?.length&&t.colorRamps.forEach(e=>e.algorithm=e.algorithm||"esriCIELabAlgorithm"),l.functionArguments={colorRamp:t}}else l.functionArguments={Colormap:a(s)}}return l.variableName="Raster",l.functionName="Colormap",l.functionArguments.Raster=u,n?new r({rasterFunctionDefinition:h(l)}):l}return n?new r({rasterFunctionDefinition:h(u)}):u}function S(e,t){const n=[],o=[],a=[],i=[],u=1e-4,{pixelType:s,rasterAttributeTable:l}=t,c=null==l?null:l.features,m=C(l);if(m&&c&&Array.isArray(c)&&e.classBreakInfos){e.classBreakInfos.forEach((t,n)=>{const r=t.symbol?.color;let o;r?.a&&null!=t.minValue&&null!=t.maxValue&&c.forEach(a=>{null!=t.minValue&&null!=t.maxValue&&(o=a.attributes[e.field],(o>=t.minValue&&o<t.maxValue||n===e.classBreakInfos.length-1&&o>=t.minValue)&&i.push([a.attributes[m],r.r,r.g,r.b]))})});const n=s?w(i,s):i,o=new r;return o.functionName="Colormap",o.functionArguments={},o.functionArguments.Colormap=n,o.variableName="Raster",t.convertToRFT?new r({rasterFunctionDefinition:h(o)}):o}e.classBreakInfos.forEach((e,t)=>{if(null==e.minValue||null==e.maxValue)return;const r=e.symbol&&e.symbol.color;r?.a?(0===t?n.push(e.minValue,e.maxValue+u):n.push(e.minValue+u,e.maxValue+u),o.push(t),i.push([t,r.r,r.g,r.b])):a.push(e.minValue,e.maxValue)});const p=s?w(i,s):i,f=new r;f.functionName="Remap",f.functionArguments={InputRanges:n,OutputValues:o,NoDataRanges:a},f.variableName="Raster";const g=new r;return g.functionName="Colormap",g.functionArguments={Colormap:p,Raster:f},t.convertToRFT?new r({rasterFunctionDefinition:h(g)}):g}function w(e,n){const r=c.has(n)?t(n):null;return r&&e.push([Math.floor(r[0]-1),0,0,0],[Math.ceil(r[1]+1),0,0,0]),e}function C(e){if(null==e)return;const{fields:t}=e,n=t?.find(e=>e?.name&&"value"===e.name.toLowerCase());return n?.name}function F(e,t){const n=[],{pixelType:o,rasterAttributeTable:a}=t,i=null==a?null:a.features,u=C(a),s=e.defaultSymbol?.color?.toRgb(),l=e.uniqueValueInfos;if(l)if(i){if(u){const t=new Map;l.forEach(e=>{const n=e.value,r=A(e);null!=n&&r?.a&&t.set(String(n),r.toRgb())});const r=e.field;r&&i.forEach(({attributes:e})=>{const o=String(e[r]),a=e[u],i=t.get(o);i?n.push([a,...i]):s&&n.push([a,...s])})}}else for(let r=0;r<l.length;r++){const e=l[r],t=A(e),o=+e.value;if(t?.a){if(isNaN(o))return null;n.push([o,t.r,t.g,t.b])}}const c=o?w(n,o):n,m=new r;return m.functionName="Colormap",m.functionArguments={},m.functionArguments.Colormap=c,m.variableName="Raster",t.convertToRFT?new r({rasterFunctionDefinition:h(m)}):m}function A(e){return"polygon-3d"===e.symbol?.type?e.symbol.symbolLayers?.find(e=>"fill"===e.type)?.material?.color:e.symbol?.color}function N(e,t){const n=e.extractColormap();if(!n||0===n.length)return null;const{pixelType:o}=t,a=o?w(n,o):n,i=new r;return i.functionName="Colormap",i.functionArguments={},i.functionArguments.Colormap=a,t.convertToRFT?new r({rasterFunctionDefinition:h(i)}):i}function V(e){const t=[],n=[];return e.forEach(e=>{t.push(e[0]),n.push(u([...e.slice(1),255]))}),{type:"RasterColormap",values:t,colors:n}}export{g as combineRenderingRules,y as convertRendererToRenderingRule,h as convertRenderingRuleToRFT,f as isSupportedRendererType};