clusters

AMD: require(["esri/smartMapping/labels/clusters"], (clusterLabelCreator) => { /* code goes here */ });
ESM: import * as clusterLabelCreator from "@arcgis/core/smartMapping/labels/clusters.js";
Object: esri/smartMapping/labels/clusters
Since: ArcGIS Maps SDK for JavaScript 4.16

This object contains a helper method for generating default labels to be set on a layer's cluster configuration. The default label is based on the layer's renderer. In most cases the default label configuration will be the total number of features in the cluster. This value will be rounded and formatted (e.g. instead of 2385, the cluster label will display 2.4k). In some cases, such as renderers with a SizeVariable, the default label will display the average value of the attribute represented by the size variable.

clustering-generated-labels

This includes secondary labeling schemes you can experiment with in your clusters. This module only applies to layers with a point geometry type.

Method Overview

Name Return Type Summary Object
Promise<Schemes>

Generates default labelingInfo schemes to be set on a FeatureLayer's featureReduction configuration.

clusters

Method Details

getLabelSchemes

Method
getLabelSchemes(params){Promise<Schemes>}

Generates default labelingInfo schemes to be set on a FeatureLayer's featureReduction configuration. Returns one or more suggested LabelClasses for a given layer based on its renderer. It also returns a suggested clusterMinSize to ensure labels fit inside clusters.

If a renderer has a non-scale dependent SizeVariable, then the average value of the field or expression used to determine the cluster size will be suggested as the default label value. In all other scenarios, the suggested label will display the cluster count in the center of the label.

Parameters
Specification
params Object

See the table below for details of each parameter that may be passed to this function.

Specification

The point layer that has or will have clustering enabled.

view MapView

The view where the input layer will be rendered.

field String
optional

The name of the AggregateField to use in the primary label scheme. If not specified, then the label will be based on the data used to vary cluster size.

renderer Renderer
optional

The renderer to set on the input layer when clustering is enabled. Specify this parameter if the layer's renderer does not match the renderer that will be used when clustering is enabled. This cannot be a HeatmapRenderer.

Returns
Type Description
Promise<Schemes> Returns an object containing suggested primary and secondary labeling schemes to be set on the layer's featureReduction property.
Example
// Sets suggested labels on the clusters based on the underlying renderer
clusterLabelCreator.getLabelSchemes({
  layer: featureLayer,
  view: view
}).then(function(labelSchemes){
  const featureReduction = featureLayer.featureReduction.clone();
  const { labelingInfo, clusterMinSize } = labelSchemes.primaryScheme;
  featureReduction.labelingInfo = labelingInfo;
  featureReduction.clusterMinSize = clusterMinSize;

  featureLayer.featureReduction = featureReduction;
}).catch(function(error){
  console.error(error);
});

Type Definitions

Scheme

Type Definition
Scheme

Contains a suggested labelingInfo to be set on the layer's featureReduction.labelingInfo.

Properties
name String

The name of the generated cluster labeling scheme. This can be used in the UI of web map authoring apps.

fieldName String

The name of the aggregate field the labeling scheme is based on. This can be used in the UI of web map authoring apps.

labelingInfo LabelClass[]

An array of LabelClass objects to set on the layer's featureReduction.labelingInfo property.

clusterMinSize Number

The suggested featureReduction.clusterMinSize required to fit labels within clusters.

Schemes

Type Definition
Schemes

The return object of the getLabelSchemes() method.

Properties
primaryScheme Scheme

Includes the primary labeling scheme suggested for the input layer's clusters.

secondarySchemes Scheme[]

Includes secondary labeling schemes suggested for the input layer's clusters.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.