Loading...

Note: Support for 3D on mobile devices may vary, view the system requirements for more information.

This sample demonstrates how to explore and filter a layer by category with point clustering enabled in a MapView. Clustering is enabled via the featureReduction property of the FeatureLayer.

layer.featureReduction = {
  type: "cluster"
};

Since a layer's featureReduction property is independent of its renderer, the symbol and popupTemplate of the cluster graphics can be used to summarize features comprising the cluster. See Clustering styles and configurations for more information about the various ways clusters can summarize the points they represent.

The layer in this sample visualizes places of worship with a UniqueValueRenderer. When clustering is enabled, each cluster is assigned the symbol of the most common uniqueValueInfo among the features in the cluster.

Display all pointsDisplay clustered features
clustering-type-disabledclustering-type-enabled

You can reference the predominant value of a cluster in the popupTemplate. For layers with a UniqueValueRenderer, the summary field name follows this format: {cluster_type_fieldName}. In this case, the renderer visualizes unique values in the religion field, so the aggregate field name to reference in the popupTemplate is {cluster_type_religion}.

layer.featureReduction = {
  type: "cluster",
  popupTemplate: {
    content: [{
      type: "text",
      text: "This cluster represents <b>{cluster_count}</b> features."
    }, {
      type: "text",
      text: "The predominant place of worship in this cluster is <b>{cluster_type_religion}</b>."
    }]
  }
};

clustering-types-popup

When a filter is applied to the layer view of a clustered layer, the clusters will recompute client-side and only display information complying with the filter.

filterSelect.addEventListener("change", function(event){
  const newValue = event.target.value;
  const whereClause = newValue ? "religion = '" + newValue + "'" : null;
  layerView.filter = {
    where: whereClause
  };
  // close popup for former cluster that no longer displays
  view.popup.close();
});

Clustering currently is not supported in layers with renderers containing at least one valueExpression in the renderer or visual variables. Support will be added for these renderers in a future release.

Click here to read more information about clustering limitations.

Sample search results

TitleSample
Loading...