查看关联

字数统计: 542
阅读时长: 约 1 分钟
当前版本: 4.29

什么是关联?

公共设施网络中的关联是对资产的连通性、包含和结构附件关系进行建模。关联本身不具有空间特性,无法在地图上可视化,但 GeoScene Maps SDK for JavaScript 中提供了一个函数,该函数可在给定的特定范围内合成并返回关联的几何实体。本指南将展示如何在包含公共设施网络的 WebMap 中返回和可视化关联。

通过公共设施网络和关联模拟的雨水网络。

定义查询参数

SynthesizeAssociationGeometriesParameters 类用来定义查询关联的参数。在以下代码片段中,WebMap 加载了公共设施网络后,定义一个SynthesizeAssociationGeometriesParameters参数,设置为返回结构附件和连通性关联,设置当前视图范围内返回最多 500 个关联。

js
    view.when(async () => {
        // Check if webMap contains utility networks.
        if (webMap.utilityNetworks.length > 0 ) {

            // Assigns the utility network at index 0 to utilityNetwork.
            utilityNetwork = webMap.utilityNetworks.getItemAt(0);

            // Triggers the loading of the UtilityNetwork instance.
            await utilityNetwork.load();

            // Define parameters needed to query associations
            const associationParameters = new SynthesizeAssociationGeometriesParameters({
                extent: view.extent,
                returnAttachmentAssociations: true,
                returnConnectivityAssociations: true,
                returnContainerAssociations: false,
                outSR: utilityNetwork.spatialReference,
                maxGeometryCount: 500
            });
        }
    });

获取关联

接下来,将定义的查询参数传递到 synthesizeAssociationGeometries() 方法。此方法将返回设定范围内的关联。

js
    // Obtain the associations returned
    const viewAssociationsResult = await synthesizeAssociationGeometries.
    synthesizeAssociationGeometries(utilityNetwork.networkServiceUrl, associationParameters);

将结果以图形展示

然后,将 synthesizeAssociationGeometries() 返回的关联以图形方式展示。每个关联都以返回的几何图形来代表。在以下示例中,associationType 定义了关联图形的线符号的颜色。

association-graphic
js
    // Define parameters needed to query associations
    const associationParameters = new SynthesizeAssociationGeometriesParameters({
        extent: view.extent,
        returnAttachmentAssociations: true,
        returnConnectivityAssociations: true,
        returnContainerAssociations: false,
        outSR: utilityNetwork.spatialReference,
        maxGeometryCount: 500
    });

    // Synthesize associations
    const associationResults = await synthesizeAssociationGeometries.synthesizeAssociationGeometries(utilityNetwork.networkServiceUrl, associationParameters);

    // Loop through returned associations and create graphics with the geometries
    // Association type decides what color the line symbol
    const associationGraphics = associationResults.associations.map((association) => {
        return new Graphic({
            geometry: {
                type: "polyline",
                paths: association.geometry.paths,
                spatialReference: association.geometry.spatialReference,
            },
            symbol: {
                type: "simple-line", // autocasts as SimpleLineSymbol()
                style: "dot",
                color: (association.associationType === "connectivity") ? [190, 41, 236] : [57, 255, 20], // Connectivity: Purple; Attachment: Green
                width: 4
            }
        });
    });

    // Add the graphics to the view
    view.graphics.addMany(associationGraphics);