opacity
require(["esri/renderers/smartMapping/creators/opacity"], function(opacityVariableCreator) { /* code goes here */ });esri/renderers/smartMapping/creators/opacityThis object contains a helper method for generating data-driven visualizations with continuous opacity based on data returned from a field value or expression in a Layer.
The createVisualVariable() method generates an opacity visual variable with default alpha values that are optimally mapped to data values based on the statistics of the indicated field.
Known Limitations
- Currently, 3D symbols cannot be generated for layers with a polylineorpolygongeometry type.
- Only FeatureLayer, SceneLayer, and CSVLayer layer types are currently supported, except in the following scenarios:- SceneLayers without the supportsRendererandsupportsLayerQuerycapabilities enabled, unless a predefined statistics object is passed to thestatisticsparameter of the method in conjunction with the layer. To check a SceneLayer's capabilities, use the getFieldInfoUsage() method.
 
- SceneLayers without the 
- You cannot generate renderers and visual variables using SQL expressions for client-side FeatureLayers in a SceneView.
- See also:
Method Overview
| Name | Return Type | Summary | Object | |
|---|---|---|---|---|
| Promise<VisualVariableResult> | This method generates an opacity visual variable with default alpha values optimally mapped to data values based on the statistics queried for the indicated field or expression.more details | more details | opacity | 
Method Details
- createVisualVariable(params){Promise<VisualVariableResult>}
- This method generates an opacity visual variable with default alpha values optimally mapped to data values based on the statistics queried for the indicated field or expression. - There are several ways this method may be called. The most common case is by providing a - layerand a- field. This is the scenario where the statistics of the data aren't well known and the user doesn't know the which alpha values to map to data values. You can optionally use a- valueExpressioninstead of a field to visualize features based on a numeric value returned from a script executed at runtime.- The other options are provided for convenience for more involved custom visualization authoring applications. For example, if you already generated statistics in another operation, you can pass the stats in the - statisticsparameter to avoid making an extra call to the server.Parameters:params Object- Input parameters for generating an opacity visual variable based on data returned from a given field or expression. See the table below for details of each parameter. Specification:layer FeatureLayer|SceneLayer|CSVLayer- The layer for which the visual variable is generated. field Stringoptional- The name of the field whose data will be queried for statistics and used for the basis of the data-driven visualization. This property is ignored if a - valueExpressionis used.normalizationField Stringoptional- The name of the field to normalize the values of the given - field. Providing a normalization field helps minimize some visualization errors and standardizes the data so all features are visualized with minimal bias due to area differences or count variation. This option is commonly used when visualizing densities.valueExpression Stringoptional- An Arcade expression that returns a number. This expression can reference field values using the - $featureglobal variable. This property overrides the- fieldproperty and therefore is used instead of an input- fieldvalue.valueExpressionTitle Stringoptional- Text describing the value returned from the - valueExpression. This is used by the Legend widget.sqlExpression Stringoptional- A SQL expression evaluating to a number. sqlWhere Stringoptional- A SQL where clause used to filter features for the statistics query. For example, this is useful in situations where you want to avoid dividing by zero as is the case with creating a predominance visualization. legendOptions Objectoptional- Provides options for setting a title to a field when an expression is provided instead of a field name. This title will represent the field in the Legend. Specification:title Stringoptional- The title used to represent the given field or expression in the Legend. statistics SummaryStatisticsResultoptional- A statistics object generated from the summaryStatistics function. If statistics for the field have already been generated, then pass the object here to avoid making a second statistics query to the server. minValue Numberoptional- A custom minimum value set by the user. Use this in conjunction with - maxValueto generate statistics between lower and upper bounds. This will be the lowest stop in the returned visual variable.maxValue Numberoptional- A custom maximum value set by the user. Use this in conjunction with - minValueto generate statistics between lower and upper bounds. This will be the uppermost stop in the returned visual variable.view Viewoptional- A SceneView or MapView instance is required when a - valueExpressionis specified.Returns:- Type - Description - Promise<VisualVariableResult> - Resolves to an instance of VisualVariableResult. Examples:- var layer = new FeatureLayer({ url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/counties_politics_poverty/FeatureServer/0" }); // visualization based on field and normalization field var params = { layer: layer, field: "POP_POVERTY", normalizationField: "TOTPOP_CY" }; // when the promise resolves, apply the visual variable to the renderer opacityVariableCreator.createVisualVariable(params) .then(function(response){ var renderer = layer.renderer.clone(); renderer.visualVariables = [ response.visualVariable ]; layer.renderer = renderer; });- var layer = new FeatureLayer({ url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/counties_politics_poverty/FeatureServer/0" }); // visualization based off Arcade expression var params = { layer: layer, valueExpression: "($feature.POP_POVERTY / $feature.TOTPOP_CY) * 100", view: view, valueExpressionTitle: "% of people living in poverty" }; // when the promise resolves, apply the visual variable to the renderer opacityVariableCreator.createVisualVariable(params) .then(function(response){ var renderer = layer.renderer.clone(); renderer.visualVariables = [ response.visualVariable ]; layer.renderer = renderer; });
Type Definitions
- VisualVariableResult
- The result object of the createVisualVariable() method. See the table below for details of each property. - Properties:
- visualVariable OpacityVisualVariableAn opacity visual variable configured based on the statistics of the data. statistics SummaryStatisticsResultBasic statistics returned from a query to the service for the given field or expression. defaultValuesUsed BooleanIndicates whether default values are used in the absence of sufficient data and/or statistics from the layer. Default values are typically used when all features have the same field value or no value at all. authoringInfo AuthoringInfoAuthoring information related to the creation of the visual variable. This includes information related to UI inputs from sliders and selected themes.