GDIM地图弹窗 (Map POI Popup)

本章说明如何为 GDIM 地图应用中的兴趣点(POI)弹窗 编写 Pipeline。 用户在地图上点击某个点(钻孔、监测点……)时,GDIM 打开弹窗并运行 Pipeline, 把被点击点的某个字段自动传给 Pipeline,Pipeline 返回的内容显示在弹窗里。

应用类型的整体划分见 GDIM应用类型 (App Types),共用构建步骤见 工作流构建 (Pipeline Build)。

平台如何运行

  1. 用户在地图上点击一个兴趣点。

  2. 前端从该点对应的数据行中取出 bind_field 指定的字段(未指定时取 POI 标签),写入声明了 auto_bind="poi_field" 的 Pipeline 属性。

  3. GDIM 运行 Pipeline,把 return_results_config 指定的端口内容显示在弹窗中。

poi_field 属性 不在属性面板里渲染,用户无需也无法手动填写。其它普通属性(例如选择要画的指标)仍按常规控件显示在弹窗里。

规则

  • 用 auto_bind="poi_field" 接收被点击点。 通常绑定到读表模块的过滤参数,例如 GdimTableReader.primary_key_value_filter,只读取这个点的数据。

  • 优先指定 bind_field 。 绑定稳定的业务字段(如 point_name、孔号),不要依赖地图显示标签;地图的标签字段可能被改成展示用字段,应用会随之失效。bind_field 可写字段名或字段标题。

  • 不要给 poi_field 属性设置 ui_schema_overrides / ui_schema_function_name 。 前端不渲染它,这些设置会被忽略并产生警告。

  • 返回适合弹窗显示的内容。 通常是一个图表的 OutputPlotData,或一张行数不多的表。避免返回大表或多个大结果。

  • 绘图模块关闭文件生成。 设 generate_files = False,弹窗只需要 OutputPlotData。

  • 一个弹窗只放一个 Pipeline 的内容。 同一批监测点要显示不同图表时,每个图表各写一个 Pipeline(各自一个文件夹),分别挂到地图上。

推荐拓扑

GdimTableReader (主表 + 子表, primary_key_value_filter ← poi_field)
     │ OutputTable
     ▼
清洗 / 转换模块(如 ContaDataToNumeric、TableSelector)
     │
     ▼
LineChartPlotter / BarChartPlotter / TablePlotter
     │ OutputPlotData  ← return_results_config

完整示例

点击地下水监测点时,读取该点的监测因子表,把浓度值转成数值,绘制时程曲线。 factor_name 是弹窗里的普通下拉框,选项由本地函数 factor_ui_schema 根据数据动态生成。

from pathlib import Path

from gdisdk.connectors import log_in
from gdisdk.modules.contaDataProcess import ContaDataToNumeric
from gdisdk.modules.plotters import LineChartPlotter
from gdisdk.modules.readers import GdimTableReader
from gdisdk.pipeline import PipeLine

_SCRIPT_DIR = Path(__file__).resolve().parent
WORKSPACE_DIR = _SCRIPT_DIR / "workspace"


def build_pipeline() -> PipeLine:
    pipeline = PipeLine(
        app_name="GroundwaterHydrograph",
        app_title="地下水时程曲线",
        workspace=WORKSPACE_DIR,
    )
    pipeline.update_gdim_state(token=log_in(), proj_id="你的GDIM项目ID")
    pipeline.local_functions_path = str(_SCRIPT_DIR / "localFunctions.py")

    read_factors = GdimTableReader("GroundwaterTable")
    read_factors.table_fields = [
        "ground_water_monitor_point_table",
        "ground_water_detection_factor_table",
    ]
    read_factors.output_table_name = "ground_water_detection_factor_table"

    to_numeric = ContaDataToNumeric("ContaToNumeric")
    to_numeric.process_type = "auto"
    to_numeric.detect_limit = 0.0

    line_chart = LineChartPlotter("LineChart")
    line_chart.x_column = "采样时间"
    line_chart.y_columns = "ph"
    line_chart.generate_files = False

    pipeline.add_links(
        read_factors.OutputTable >> to_numeric.InputTable
        | to_numeric.OutputTable >> line_chart.InputData
    )

    # 被点击监测点的 point_name 注入到读表的主键过滤条件
    pipeline.add_attribute(
        attr_name="primary_key_value_filter",
        module_name="GroundwaterTable",
        param_name="primary_key_value_filter",
        attr_title="点位名称",
        auto_bind="poi_field",
        bind_field="point_name",
    )
    # 弹窗里的普通控件:选择要绘制的监测因子
    pipeline.add_attribute(
        attr_name="factor_name",
        module_name="LineChart",
        param_name="y_columns",
        attr_title="检测因子名称",
        ui_schema_function_name="factor_ui_schema",
    )

    pipeline.return_results_config = {"LineChart": "OutputPlotData"}
    pipeline.save_pipeline(f"{pipeline.workspace}/{pipeline.app_name}.pipe")
    return pipeline


if __name__ == "__main__":
    pipeline = build_pipeline()
    # 本地模拟 GDIM 注入被点击点的字段值
    pipeline.set_attributes(primary_key_value_filter="DX1", factor_name="ph")
    result = pipeline.run(return_results=pipeline.return_results_config)
    print(result.get_result("LineChart", "OutputPlotData"))

factor_ui_schema 是 Pipeline 层 UI schema 函数:接收 pipeline,返回单个 UIAttributeSchema, 写在 localFunctions.py 中并用 @local_function 装饰。写法见 UI控件 (UI Schema) 和 modules.widgets 模块帮助。

本地测试

  • 用 pipeline.set_attributes(<attr_name>=<值>) 模拟前端注入,值取地图上某个真实点的 bind_field 字段值。

  • 传 return_results=pipeline.return_results_config,确认返回的正是弹窗要显示的端口。

常见错误

  • 普通表单应用用了 poi_field 。 该属性不会渲染,用户无法填写,应用拿不到值。

  • 依赖 POI 标签。 没写 bind_field,地图标签字段改动后应用失效。

  • 给 poi_field 属性配置 UI schema。 会被忽略。

  • 返回了本地 HTML / 图片路径。 弹窗需要 OutputPlotData;绘图模块设 generate_files = False。

  • 一个脚本目录里放了多个弹窗 Pipeline。 每个 Pipeline 应有自己的文件夹和 workspace/。

  • 脚本里写了账号密码。 用 log_in(),不要把 user_name / password 写进脚本。

与其它文档的关系