根据条件渲染FeatureLayer以及FindTask使用注意事项

 


1、条件渲染

arcgis api for js 提供了多种渲染方式 根据需求自行设置

下面分别为4.x 和3.x 提供的方式

 

 

 2、FindTask 使用注意事项

在使用FindTask时 查询出的数据中 geometry为空

原因:参数FindParameters 的returnGeometry默认为false 将其改为true

3、查出结果 并进行缩放示例代码

复制代码
function zoomFourMap(filedValue) {

    require([
        "esri/tasks/FindTask",
        "esri/tasks/FindParameters",
        "esri/geometry/Extent",
        "esri/SpatialReference",
        "dojo/domReady!"
    ], function(
        FindTask, FindParameters,
        Extent,
        SpatialReference
    ) {
        let find, params;
        find = new FindTask("url");
        params = new FindParameters();
        params.layerIds = [1];
        params.searchFields = ["Filed"];
        params.searchText = filedValue
        params.returnGeometry = true;
        find.execute(params, (res) => {

            let xArr = [];
            let yArr = [];
            if (res.length > 0) {
                for (let j = 0; j < res.length; j++) {
                    const o = res[j];
                    o.feature.geometry.rings[0].forEach(xy => {
                        xArr.push(xy[0])
                        yArr.push(xy[1])
                    });
                }
            }
            const xMax = Math.max(...xArr);
            const xMin = Math.min(...xArr)
            const yMax = Math.max(...yArr)
            const yMin = Math.min(...yArr)

            const spatialReference = new SpatialReference({
                wkt: 'PROJCS["CGCS2000_3_Degree_GK_CM_118.52E",GEOGCS["GCS_China_Geodetic_Coordinate_System_2000",DATUM["D_China_2000",SPHEROID["CGCS2000",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Gauss_Kruger"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",118.86666667],PARAMETER["Scale_Factor",1.0],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]'
            })
            const myExtent = new Extent(xMin, yMin, xMax, yMax, spatialReference)

            map.setExtent(myExtent)

        });
    })

}
复制代码

 

posted @   小七要走  阅读(151)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
点击右上角即可分享
微信分享提示