点聚类 - 高级配置

尝试一下在线预览

此示例演示如何使用多个 LabelClass 对象为聚类和单个要素创建高级标注配置。它还演示了如何使用各种聚合字段和表达式配置 popupTemplate,以汇总每个聚类中的要素。

高级标注

聚类标注被定义为 LabelClass 的数组。有关其他详细信息,请参阅 FeatureReductionCluster.labelingInfo

在大多数情况下,您需要在图层的 featureReduction 属性中设置一个 LabelClass 来传达有关聚类的信息。这通常涉及显示聚类中心内的要素总数。

                      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
layer.featureReduction = {
  type: "cluster",
  clusterRadius: "100px",
  clusterMinSize: "24px",
  clusterMaxSize: "60px",
  labelingInfo: [{
    deconflictionStrategy: "none",
    labelExpressionInfo: {
      expression: "Text($feature.cluster_count, '#,###')"
    },
    symbol: {
      type: "text",
      color: "#004a5d",
      font: {
        weight: "bold",
        family: "Noto Sans",
        size: "12px"
      }
    },
    labelPlacement: "center-center",
  }]
}

此示例演示了更高级的标注配置。由于所有 LabelClass 属性在 FeatureReductionCluster 中都可用,因此您可以更改表达式、最小/最大比例、文本/字体属性和过滤器以显示有关聚类中要素的各种信息。具有不同 where 子句的多个标注类可用于在同一要素上定义具有不同样式的多个标注。同样,可以使用多个标注分类来标注不同类型的聚类(例如,小聚类的蓝色标注和大型聚类的红色标注)。

此示例使用以下建议的做法:

  • 在标注聚类中心有计数的聚类时,关闭标注冲突消除。如果标注放置位于聚类之外,请保持标注消除冲突处于启用状态。
  • 增加 clusterMinSize 以将标注放入较小的聚类中(16pt 是一个很好的起点)。
  • 如果图层具有大小可视化变量,请增大最小要素的大小以改善聚类可视化效果。
  • 如果在 featureReduction.labelingInfo 上设置了多个标注类,请在 layer.labelingInfo 上设置匹配的标注类,特别是当渲染器中包含大小可视化变量时。这有助于最终用户区分聚类和单个要素。 

过滤

此示例还演示了如何在 MapView 中启用点聚类时使用滑块浏览和过滤图层。

此示例中的图层使用 UniqueValueRenderer 可视化全球发电厂。启用聚类后,将为每个聚类分配聚类中要素中最常见的 uniqueValueInfo 的符号。

聚类图层视图上的过滤器过滤基础要素并重新计算聚类客户端。更新后的聚类仅显示符合过滤的信息,包括要素数量和渲染器的主要类别(在本例中为燃料类型)。

由于 FeatureLayerView 使用 GPU 进行渲染,因此渲染器和过滤器更新会很快发生,因此您可以在用户滑动滑块拇指时更新过滤器。

                   
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const slider = new Slider({
  min: 0,
  max: 2000,
  values: [ 0 ],
  container: document.getElementById("sliderDiv"),
  rangeLabelsVisible: true,
  precision: 0
});

// filter features by power plant capacity when the user
// drags the slider thumb. If clustering is enabled,
// clusters will recompute and render based on the number
// and type of features that satisfy the filter where clause

slider.on(["thumb-change", "thumb-drag"], (event) => {
  layerView.filter = {
    where: "capacity_mw >= " + event.value
  };
});

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