uniqueValues
require(["esri/renderers/smartMapping/statistics/uniqueValues"], function(uniqueValues) { /* code goes here */ });
esri/renderers/smartMapping/statistics/uniqueValues
A function that queries for unique values from a field in a Layer.
Known Limitations
- Only FeatureLayer, SceneLayer, CSVLayer, and PointCloudLayer layer types are currently supported, except in the following scenarios:
- SceneLayers without the
supportsRenderer
andsupportsLayerQuery
capabilities enabled, unless a predefined statistics object is passed to thestatistics
parameter of the method in conjunction with the layer. To check a SceneLayer's capabilities, use the getFieldInfoUsage() method.
- SceneLayers without the
- You cannot generate unique values using SQL expressions for client-side FeatureLayers in a SceneView.
Method Overview
Name | Return Type | Summary | Function | |
---|---|---|---|---|
Promise<UniqueValuesResult> | Returns an object containing an array of unique values queried from a given field (or values returned from an expression) in a Layer along with the total count of features that belong to the given category. more details | more details | uniqueValues |
Method Details
- uniqueValues(params){Promise<UniqueValuesResult>}
Returns an object containing an array of unique values queried from a given field (or values returned from an expression) in a Layer along with the total count of features that belong to the given category.
Parameters:params ObjectSee the table below for details of each parameter.
Specification:The layer from which to query for unique values.
field StringoptionalThe name of the numeric or string field from which the unique values will be obtained. This property is ignored if a
valueExpression
is used.valueExpression StringoptionalAn Arcade expression that returns a number or string. This expression can reference field values using the
$feature
global variable. This property overrides thefield
property and therefore is used instead of an inputfield
value.sqlExpression StringoptionalA SQL expression evaluating to a number or string.
sqlWhere StringoptionalA 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.
returnAllCodedValues BooleanoptionalIndicates that all domain codes should be returned if the given field has domain values.
view ViewoptionalA SceneView or MapView instance is required when a
valueExpression
is specified.features Graphic[]optionalA subset of features for which to generate the unique values.
Returns:Type Description Promise<UniqueValuesResult> Returns a promise that resolves to UniqueValuesResult. Example:var layer = new FeatureLayer({ portalItem: { id: "5ce5374a461e45bab714b43ffedf151d" } }); uniqueValues({ layer: layer, field: "Candidate" }).then(function(response){ // prints each unique value and the count of features containing that value var infos = response.uniqueValueInfos; infos.forEach(function(info){ console.log("CANDIDATE: ", info.value, " # OF CAMPAIGN STOPS: ", info.count); }); });
Type Definitions
- UniqueValuesResult
An object that contains the unique values returned from the uniqueValues() query of a layer's field.
- Properties:
- uniqueValueInfos Object[]
An array of objects, each containing a unique value/type/category present in the field specified in the uniqueValues() query. See table below for the specification of each object.
- Specification:
A unique value representing a type or category of features in the layer.
count NumberThe number of features assigned the given
value
(or belonging to the given category).