追踪公共设施网络

字数统计: 1.4k
阅读时长: 约 3 分钟
当前版本: 4.29

追踪必须标识出满足指定条件的公共设施网络子集。追踪可以起始于一个或多个起点或起始于指定子网的子网控制器,它沿着连接要素和对象的路径,通过网络直到终点位置。终点位置可以是障碍或路径的终点。

按照以下步骤启用追踪:

  1. 定义追踪方式,NamedTraceConfigurationUNTraceConfigurationTraceLocationTraceParameters

  2. 使用追踪对象执行追踪。

  3. 获取并可视化追踪中的结果,这些结果将作为 TraceResult 对象返回。

注:从 Enterprise 3.0开始,追踪配置可用,并可与使用 GeoScene Pro 版本 2.1 或更高版本发布的 web 地图一起保存。

NamedTraceConfiguration

NamedTraceConfiguration 允许用户检索在公共设施网络中定义和存储的预配置追踪,然后通过 web 地图在整个组织中共享。

我们通过 sharedNamedTraceConfigurations 属性访问公共设施网络中的追踪配置。

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();

            // Loop through the shared named trace configuarations
            utilityNetwork.sharedNamedTraceConfigurations.forEach((namedTraceConfig) => {
                // Print to the console the globalIds and their corresponding trace configuration name
                console.log(namedTraceConfig.globalId + " - " + namedTraceConfig.title);
            });
        }
    });

UNTraceConfiguration

UNTraceConfiguration 描述了可用于在公共设施网络中运行的自定义追踪。其属性包括域网络名称、层名称、子网名称以及可遍历性、函数、过滤器和输出的其他设置 (继承自 TraceConfiguration)。 UNTraceConfiguration 旨在使用仅适用于公共设施网络的自定义追踪。

js
    const unTraceConfiguration = new UNTraceConfiguration({
        domainNetworkName: "Electric",
        tierName: "Electric Distribution",
        subnetworkName: "RMT003",
        includeContainers: true,
        validateConsistency: true,
        // Traversability
        conditionBarriers: [{
            name: "E:Device Status",
            type: "networkAttribute",
            operator: "equal",
            value: 1,
            combineUsingOr: false,
            isSpecificValue: true
        }],
        traversabilityScope: "junctionsAndEdges"
    });

UNTraceConfiguration 可用于覆盖或修改存储在公共设施网络中的现有追踪配置。包括过滤作为追踪结果返回的要素、控制追踪的内容、设置要执行的计算等。以下代码片段演示了如何从现有的共享指定追踪配置中覆盖子网名称属性。

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();

        // Get shared named trace configurations from your Utility Network
        const sharedNamedTraceConfigurations = utilityNetwork.sharedNamedTraceConfigurations;

        // Find a shared named trace configuration from the GlobalId and use it to create a new UNTraceConfiguration object
        const traceConfiguration = sharedNamedTraceConfigurations.find((sharedNamedTraceConfig) => sharedNamedTraceConfig.globalId === "{537295F6-BFE2-4E0F-AD0D-DA7F7719F9DD}");
        const unTraceConfiguration = new UNTraceConfiguration(traceConfiguration.traceConfiguration.toJSON());

        // Overwrite the subnetwork name property
        unTraceConfiguration.subnetworkName = "myNewSubnetwork";
    }
    });

TraceLocation

TraceLocation 可用于定义起点(追踪的起始位置)和障碍(网络中追踪无法行进的位置)。

以下代码片段显示了如何在现有线要素上添加追踪位置(起点)。

  1. 单击地图以使用 hitTest 获取线要素的 globalId。

  2. 过滤线要素的 hitTest 结果。

  3. 定义沿线的百分比以放置起点。针对此示例的目的,可将 percentAlong 值设置为 0.5。需要 PercentAlong 和 globalId 值来定义追踪位置。

  4. 创建 TraceLocation 实例,并传入在前面步骤中获得的值。还需设置追踪位置 type,在本例中为 "starting-point"

js
    // Fires after a user clicks on the view.
    view.on("click", async (mapEvent) => {
        // Prevent the event bubbling up the event chain.
        mapEvent.stopPropagation();

        // Check to see if any graphics in the view intersect the given screen x, y coordinates.
        const hitTestResult = await view.hitTest(mapEvent);

        // Get Electric Distribution Line features only by using the GlobalId.
        const electricLines = hitTestResult.results.filter((result) => result.graphic.layer.globalId === "{537295F6-BFE2-4E0F-AD0D-DA7F7719F9DD}");

        // Get the GlobalID of the feature where the trace will start traversing the Utility Network.
        myGlobalId = electricLines[0].graphic.attributes.globalid

        // Define percentage along line to place trace location.
        const myPercentageAlong = 0.5;

        // Create trace location (starting point).
        const startingPoint = new TraceLocation({
            globalId: myGlobalId,
            percentAlong: myPercentageAlong,
            type: "starting-point"
        });
    });

TraceParameters

TraceParameters 对象通过定义追踪位置、追踪类型、追踪配置、结果类型等来确定追踪的执行方式。

以下代码片段演示了如何创建 TraceParameters 对象。

js
    // Get named trace configurations.
    const sharedNamedTraceConfigurations = utilityNetwork.sharedNamedTraceConfigurations;

    // Find a specific named trace configuration from a GlobalId
    const namedTraceConfiguration = sharedNamedTraceConfigurations.find((traceConfig) => traceConfig.globalId === "{537295F6-BFE2-4E0F-AD0D-DA7F7719F9DD}");

    // Define an array with starting points, barriers.
    const myTraceLocations = [startingPoint, barrier];

    // Define how the trace will be executed.
    const traceParameters = new TraceParameters({
        namedTraceConfigurationGlobalId: namedTraceConfiguration.globalId,
        traceLocations: myTraceLocations
    });

TraceResult

TraceResult 包含执行追踪的输出。根据配置的 TraceParameters,将返回一组聚合几何、一组网络元素和一组函数聚合结果。

以下示例演示了如何获取 TraceResult。

js
    // Execute a trace to get a TraceResult.
    const traceResult = await trace.trace(utilityNetwork.networkServiceUrl, traceParameters);

    if (traceResult.aggregatedGeometry) {
        // Display results on the map.
        if (traceResult.aggregatedGeometry.multipoint) {
            const multipointGraphic = new Graphic({
                    geometry: {
                    type: "multipoint",
                    points: traceResult.aggregatedGeometry.multipoint.points,
                    spatialReference: utilityNetwork.spatialReference
                },
                symbol: myPointSymbol
            });

            traceResultsGraphicsLayer.graphics.add(multipointGraphic);
        }
    }

UtilityNetworkTrace 微件

UtilityNetworkTrace 微件是用于追踪的开箱即用型解决方案。使用此微件,请加载通过公共设施网络和 sharedNamedTraceConfigurations 一起发布的 WebMap

使用 UtilityNetworkTrace 微件运行追踪的步骤:

  1. 请确保有权限访问,因为大多数公共设施网络服务都受到保护,并且需要 GeoScene Utility Network用户类型扩展模块。

  2. 追踪类型下拉列表中选择要运行的一个或多个追踪。

  3. 添加起点和障碍 (可选),方法是单击起点障碍按钮,然后单击地图上的要素以放置点。

  4. 通过单击运行按钮运行追踪。

详细使用参见微件UtilityNetworkTrace说明。