0

我正在尝试使用 ESRI ArcGIS for JavaScript 4.10 中的uniqueValues函数。

但是,此消息失败:

消息:“从 layerView 查询统计信息需要查看”名称:“feature-layer-adapter:insufficient-data”

我有一个FeatureLayerwith features 和一个名为sStatus. 我也有一个基于此字段的Legend设置可以正常工作。UniqueValueRenderersStatus

这是我的代码:

uniqueValues({
    layer: layer,
    field: "sStatus"
}).then(function (response) {
    // prints each unique value and the count of features containing that value
    var infos = response.uniqueValueInfos;

    console.log('test');

    infos.forEach(function (info) {

        console.log("Wells : ", info.value, " # of Wells ", info.count);
    });
}).catch(errback);

注意:如果我将字段名称更改为“ status”,则控制台中的错误消息会更改:

消息:“未知字段:状态。您只能使用层架构中定义的字段”名称:“唯一值:无效参数”

这表明我的领域sStatus是正确的,但我不明白为什么它不能开箱即用。

任何想法为什么这会失败?

4

1 回答 1

0

在我发布问题后,我通过重新阅读uniqueValues函数文档得到了答案。

首先,信息很明确:它缺少视图。

该函数的view参数uniqueValues不是示例代码的一部分...

查看 查看可选

指定 valueExpression 时需要 SceneView 或 MapView 实例。

所以我必须做的是:

niqueValues({
    layer: layer,
    field: "sStatus",
    view: mapView
}).then(function (response) {
    // prints each unique value and the count of features containing that value
    var infos = response.uniqueValueInfos;

    console.log('test');

    infos.forEach(function (info) {

        console.log("Wells : ", info.value, " # of Wells ", info.count);
    });
}).catch(errback);
于 2019-01-24T20:27:25.513 回答