You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ArcGIS JS API 4.25:如何让弹窗默认显示Browse Features而非摘要

实现ArcGIS JS API 4.25聚类弹窗默认显示Browse Features

核心思路

聚类弹窗的内容由featureReduction.popupTemplate控制,默认包含摘要和浏览要素两个面板。要默认显示后者,可通过监听弹窗打开事件强制切换面板,或直接配置弹窗模板的默认内容索引。

具体实现代码

  1. 配置图层的聚类与弹窗模板
    创建带聚类功能的FeatureLayer,同时定义聚类弹窗的双面板内容:
const featureLayer = new FeatureLayer({
  url: "你的要素服务URL",
  featureReduction: {
    type: "cluster",
    popupTemplate: {
      title: "聚类: {cluster_count} 个要素",
      content: [
        // 摘要面板
        {
          type: "text",
          text: "包含 {cluster_count} 个空间要素,点击下方查看详情"
        },
        // 浏览要素面板(Browse Features)
        {
          type: "featureContent",
          layer: featureLayer,
          selectionEnabled: true,
          container: "table" // 可选"list"以列表形式展示
        }
      ]
    }
  }
});
  1. 监听弹窗打开事件,切换到浏览要素面板
    通过监听弹窗打开事件,判断当前为聚类弹窗后,强制切换到第二个面板:
view.popup.watch("open", () => {
  const isClusterPopup = view.popup.features?.[0]?.layer?.featureReduction?.type === "cluster";
  if (isClusterPopup) {
    // 直接设置当前显示的面板索引(1对应Browse Features)
    view.popup.selectedContentIndex = 1;
  }
});

补充说明

  • 若你沿用了示例中的弹窗模板配置,只需确保popupTemplate.content数组内,浏览要素对应的内容项处于索引1的位置,再添加上述监听逻辑即可。
  • 4.25版本中selectedContentIndex属性直接控制弹窗当前显示的面板,设置为1即可切换到Browse Features面板。

内容的提问来源于stack exchange,提问作者Samira Talebi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 04:11:19