当滤波器特征布局ArcGI带有JavaScript时,如何显示结果计数

发布于 2025-02-09 12:55:00 字数 2633 浏览 3 评论 0原文

我在对象中定义的一个项目中有多个布局:

const layersByYears = [ 
    { year: 1918, layers: [ 
        { layerID: "443709212b894e9297888b3194b51100", opacity: 1.0, name: "ORP", featureLayer: null },
        { layerID: "61a605dca69c4aa0ac1b3858ba328fd3", opacity: 1.0, name: "obceSouc", featureLayer: null }
    ] },
    { year: 1936, layers: [ 
        { layerID: "a2e007238e304f1ea58005fc69c921e9", opacity: 1.0, name: "ORP", featureLayer: null },
        { layerID: "61a605dca69c4aa0ac1b3858ba328fd3", opacity: 1.0, name: "obceSouc", featureLayer: null }
    ] },
    { year: 1950, layers: [ 
        { layerID: "23bcd52310854d6185e5f22a4eca0303", opacity: 1.0, name: "ORP", featureLayer: null },
        { layerID: "61a605dca69c4aa0ac1b3858ba328fd3", opacity: 1.0, name: "obceSouc", featureLayer: null }
    ] },
    { year: 1981, layers: [ 
        { layerID: "401e9530ba074936800a8f596fc49d70", opacity: 1.0, name: "ORP", featureLayer: null },
        { layerID: "61a605dca69c4aa0ac1b3858ba328fd3", opacity: 1.0, name: "obceSouc", featureLayer: null }
    ] },    
]

然后,我创建变量来设置所有层:

const createFL = (layer) => {
        if(layer.featureLayer !== null && layer.featureLayer !== undefined)
            return;

        layer.featureLayer = new FeatureLayer({ portalItem: {
            id: layer.layerID,
            opacity: layer.opacity !== undefined ? layer.opacity : 1.0,
            visible: false,
        } })

        layer.featureLayer.load().then(function() {
            $("loadingProgressbar").value = ++loadingProgress.value;
            $("loadingProgressbar").max = loadingProgress.max;
            if(loadingProgress.max === loadingProgress.value)
                $("loadingProgressbar").style.display = "none";
        });
    }

最后我提供了这样的过滤器:

function doQuery() {
    var selModul = document.getElementById("jevSelect");
    var attributeName = selModul.options[selModul.selectedIndex].value;
    

    const expressionSign = document.getElementById("signSelect");
    
    var selJev = document.getElementById("jevSelect");
    var inputValue = selJev.options[selJev.selectedIndex].text;

    let expression;
        
    expression = `${attributeName}${expressionSign.value}'${inputValue}'`;
        document.getElementById("printResults").innerHTML = expression;

        layersByYears.forEach(layerByYear =>
            layerByYear.layers.forEach(layer => {
                layer.featureLayer.definitionExpression = expression;   
            })
        )
        
    }

我需要在地图中的点上显示每个过滤器上的结果计数(数字)作为标签。 项目在这里

I have multiple layouts in one project defined in object like this:

const layersByYears = [ 
    { year: 1918, layers: [ 
        { layerID: "443709212b894e9297888b3194b51100", opacity: 1.0, name: "ORP", featureLayer: null },
        { layerID: "61a605dca69c4aa0ac1b3858ba328fd3", opacity: 1.0, name: "obceSouc", featureLayer: null }
    ] },
    { year: 1936, layers: [ 
        { layerID: "a2e007238e304f1ea58005fc69c921e9", opacity: 1.0, name: "ORP", featureLayer: null },
        { layerID: "61a605dca69c4aa0ac1b3858ba328fd3", opacity: 1.0, name: "obceSouc", featureLayer: null }
    ] },
    { year: 1950, layers: [ 
        { layerID: "23bcd52310854d6185e5f22a4eca0303", opacity: 1.0, name: "ORP", featureLayer: null },
        { layerID: "61a605dca69c4aa0ac1b3858ba328fd3", opacity: 1.0, name: "obceSouc", featureLayer: null }
    ] },
    { year: 1981, layers: [ 
        { layerID: "401e9530ba074936800a8f596fc49d70", opacity: 1.0, name: "ORP", featureLayer: null },
        { layerID: "61a605dca69c4aa0ac1b3858ba328fd3", opacity: 1.0, name: "obceSouc", featureLayer: null }
    ] },    
]

Then I create variable to setup all layers:

const createFL = (layer) => {
        if(layer.featureLayer !== null && layer.featureLayer !== undefined)
            return;

        layer.featureLayer = new FeatureLayer({ portalItem: {
            id: layer.layerID,
            opacity: layer.opacity !== undefined ? layer.opacity : 1.0,
            visible: false,
        } })

        layer.featureLayer.load().then(function() {
            $("loadingProgressbar").value = ++loadingProgress.value;
            $("loadingProgressbar").max = loadingProgress.max;
            if(loadingProgress.max === loadingProgress.value)
                $("loadingProgressbar").style.display = "none";
        });
    }

Finally I provide filter like this:

function doQuery() {
    var selModul = document.getElementById("jevSelect");
    var attributeName = selModul.options[selModul.selectedIndex].value;
    

    const expressionSign = document.getElementById("signSelect");
    
    var selJev = document.getElementById("jevSelect");
    var inputValue = selJev.options[selJev.selectedIndex].text;

    let expression;
        
    expression = `${attributeName}${expressionSign.value}'${inputValue}'`;
        document.getElementById("printResults").innerHTML = expression;

        layersByYears.forEach(layerByYear =>
            layerByYear.layers.forEach(layer => {
                layer.featureLayer.definitionExpression = expression;   
            })
        )
        
    }

What I need is to display count of results (number) on each filter as label on point in map.
Project is here map project - the problem is in year 1936.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软甜啾 2025-02-16 12:55:01

如果您需要符合条件的功能计数,则可以仅使用诸如QUERYFEATURECOUNT farmaturelayer的方法使用计数查询( arcgis js js api-featureLeLayer )。在您的情况下,您可以在结构中添加额外的属性,例如count,并在每次更改定义表达式时填充它,类似这样,

const layerQueryFeatureCount = function (layer, where) {
    if (!where) {
        where = "1==1";
    }
    layer.featureLayer.queryFeatureCount(new Query({where})).then(
        function (results) {
            layer.count = results;
            console.log(`${layer.name}: ${where} (count=${results})`);
        }, function (error) {
            console.log(error);
            layer.count = "-";
            console.log(`${layer.name}: ${where} (count=${error})`);
        }
    );
}

If you want the count of features that complied to the condition, you can use just a count query using for example queryFeatureCount method of FeatureLayer (ArcGIS JS API - FeatureLayer). In your case you could add an extra property to your structure, count for example and fill it each time you change the definition expression, something like this,

const layerQueryFeatureCount = function (layer, where) {
    if (!where) {
        where = "1==1";
    }
    layer.featureLayer.queryFeatureCount(new Query({where})).then(
        function (results) {
            layer.count = results;
            console.log(`${layer.name}: ${where} (count=${results})`);
        }, function (error) {
            console.log(error);
            layer.count = "-";
            console.log(`${layer.name}: ${where} (count=${error})`);
        }
    );
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文