@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 7.33 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import{JSONMap as t}from"../../core/jsonMap.js";import i from"../../core/Logger.js";import{property as s,subclass as r}from"../../core/accessorSupport/decorators.js";import n from"./VisualVariable.js";import{castSizeFromStringOrNumber as a}from"./support/castSizeVariable.js";import o from"./support/SizeStop.js";import l from"./support/SizeVariableLegendOptions.js";import{isSizeVariable as p,getInputValueType as u,getTransformationType as m}from"./support/sizeVariableUtils.js";import{viewScaleRE as h}from"./support/visualVariableUtils.js";import{addPropertyUnsupportedError as d,addUnsupportedMessage as y}from"../../webdoc/support/unsupportedErrors.js";import{reader as c}from"../../core/accessorSupport/decorators/reader.js";import{writer as S}from"../../core/accessorSupport/decorators/writer.js";var z;const x=new t({width:"width",depth:"depth",height:"height",widthAndDepth:"width-and-depth",all:"all"}),w=new t({unknown:"unknown",inch:"inches",foot:"feet",yard:"yards",mile:"miles","nautical-mile":"nautical-miles",millimeter:"millimeters",centimeter:"centimeters",decimeter:"decimeters",meter:"meters",kilometer:"kilometers"});function v(e){if(null!=e)return"string"==typeof e||"number"==typeof e?a(e):"size"===e.type?p(e)?e:(delete(e={...e}).type,new V(e)):void 0}function g(e,t,i){if("object"!=typeof e)return e;if("web-scene"===i.origin)return;const s=new V;return s.read(e,i),s}function f(e,t,i,s){"number"!=typeof e?"web-scene"!==s?.origin?t[i]=e.toJSON(s):y(s,"error","property",`Size variable '${i}' can only be a number in web scenes.`):t[i]=e}let V=z=class extends n{constructor(e){super(e),this.axis=null,this.legendOptions=null,this.normalizationField=null,this.scaleBy=null,this.target=null,this.type="size",this.useSymbolValue=null,this.valueExpression=null,this.valueRepresentation=null,this.valueUnit=null}get cache(){return{ipData:this._interpolateData(),hasExpression:!!this.valueExpression,compiledFunc:null,isScaleDriven:null!=this.valueExpression&&h.test(this.valueExpression)}}set index(e){p(this.maxSize)&&(this.maxSize.index=`visualVariables[${e}].maxSize`),p(this.minSize)&&(this.minSize.index=`visualVariables[${e}].minSize`),this._set("index",e)}get inputValueType(){return u(this)}set maxDataValue(e){e&&this.stops&&(i.getLogger(this).warn("cannot set maxDataValue when stops is not null."),e=null),this._set("maxDataValue",e)}get maxSize(){return this._get("maxSize")}set maxSize(e){e&&this.stops&&(i.getLogger(this).warn("cannot set maxSize when stops is not null."),e=null),this._set("maxSize",v(e))}readMaxSize(e,t,i){return g(e,t,i)}writeMaxSize(e,t,i,s){return f(e,t,i,s)}set minDataValue(e){e&&this.stops&&(i.getLogger(this).warn("cannot set minDataValue when stops is not null."),e=null),this._set("minDataValue",e)}get minSize(){return this._get("minSize")}set minSize(e){e&&this.stops&&(i.getLogger(this).warn("cannot set minSize when stops is not null."),e=null),this._set("minSize",v(e))}readMinSize(e,t,i){return g(e,t,i)}writeMinSize(e,t,i,s){return f(e,t,i,s)}get arcadeRequired(){return!!this.valueExpression||(null!=this.minSize&&"object"==typeof this.minSize&&this.minSize.arcadeRequired||null!=this.maxSize&&"object"==typeof this.maxSize&&this.maxSize.arcadeRequired)}set stops(e){null==this.minDataValue&&null==this.maxDataValue&&null==this.minSize&&null==this.maxSize?e&&Array.isArray(e)&&(e=e.filter(e=>!!e)).sort((e,t)=>e.value-t.value):e&&(i.getLogger(this).warn("cannot set stops when one of minDataValue, maxDataValue, minSize or maxSize is not null."),e=null),this._set("stops",e)}get transformationType(){return m(this,this.inputValueType)}readValueExpression(e,t){return e||t.expression&&"$view.scale"}writeValueExpressionWebScene(e,t,i,s){if("$view.scale"===e){if(s?.messages){const e=this.index;d(s,`visualVariables[${"string"==typeof e?e:`visualVariables[${e}]`}].valueExpression`,"SizeVariable with '$view.scale' valueExpression is not supported in Web Scene. Please remove this property to save the Web Scene.")}}else t[i]=e}readValueUnit(e){return e?w.read(e):null}clone(){return new z({axis:this.axis,field:this.field,valueExpression:this.valueExpression,valueExpressionTitle:this.valueExpressionTitle,maxDataValue:this.maxDataValue,maxSize:p(this.maxSize)?this.maxSize.clone():this.maxSize,minDataValue:this.minDataValue,minSize:p(this.minSize)?this.minSize.clone():this.minSize,normalizationField:this.normalizationField,stops:this.stops?.map(e=>e.clone()),target:this.target,useSymbolValue:this.useSymbolValue,valueRepresentation:this.valueRepresentation,valueUnit:this.valueUnit,legendOptions:this.legendOptions?.clone()})}flipSizes(){if("clamped-linear"===this.transformationType){const{minSize:e,maxSize:t}=this;return this.minSize=t,this.maxSize=e,this}if("stops"===this.transformationType){const e=this.stops;if(!e)return this;const t=e.map(e=>e.size).reverse(),i=e.length;for(let s=0;s<i;s++)e[s].size=t[s];return this}return this}getAttributeHash(){return`${super.getAttributeHash()}-${this.target}-${this.normalizationField}`}_interpolateData(){return this.stops?.map(e=>e.value||0)}};e([s({readOnly:!0})],V.prototype,"cache",null),e([s({type:x.apiValues,json:{type:x.jsonValues,origins:{"web-map":{read:!1}},read:x.read,write:x.write}})],V.prototype,"axis",void 0),e([s()],V.prototype,"index",null),e([s({type:String,readOnly:!0})],V.prototype,"inputValueType",null),e([s({type:l,json:{write:!0}})],V.prototype,"legendOptions",void 0),e([s({type:Number,value:null,json:{write:!0}})],V.prototype,"maxDataValue",null),e([s({type:Number,useTypeForAutocast:!1,value:null,json:{write:!0}})],V.prototype,"maxSize",null),e([c("maxSize")],V.prototype,"readMaxSize",null),e([S("maxSize")],V.prototype,"writeMaxSize",null),e([s({type:Number,value:null,json:{write:!0}})],V.prototype,"minDataValue",null),e([s({type:Number,useTypeForAutocast:!1,value:null,json:{write:!0}})],V.prototype,"minSize",null),e([c("minSize")],V.prototype,"readMinSize",null),e([S("minSize")],V.prototype,"writeMinSize",null),e([s({type:String,json:{write:!0}})],V.prototype,"normalizationField",void 0),e([s({readOnly:!0})],V.prototype,"arcadeRequired",null),e([s({type:String})],V.prototype,"scaleBy",void 0),e([s({type:[o],value:null,json:{write:!0}})],V.prototype,"stops",null),e([s({type:["outline"],json:{write:!0}})],V.prototype,"target",void 0),e([s({type:String,readOnly:!0})],V.prototype,"transformationType",null),e([s({type:["size"],json:{type:["sizeInfo"]}})],V.prototype,"type",void 0),e([s({type:Boolean,json:{write:!0,origins:{"web-map":{read:!1}}}})],V.prototype,"useSymbolValue",void 0),e([s({type:String,json:{write:!0}})],V.prototype,"valueExpression",void 0),e([c("valueExpression",["valueExpression","expression"])],V.prototype,"readValueExpression",null),e([S("web-scene","valueExpression")],V.prototype,"writeValueExpressionWebScene",null),e([s({type:["radius","diameter","area","width","distance"],json:{write:!0}})],V.prototype,"valueRepresentation",void 0),e([s({type:w.apiValues,json:{write:w.write,origins:{"web-map":{read:!1},"web-scene":{write:!0},"portal-item":{write:!0}}}})],V.prototype,"valueUnit",void 0),e([c("valueUnit")],V.prototype,"readValueUnit",null),V=z=e([r("esri.renderers.visualVariables.SizeVariable")],V);export{V as default};