自学内容网 自学内容网

arcgis api for js4.x实现点击GraphicsLayer上绘制的Graphic获取Graphic中的attributes中的信息

需求:arcgis api for js4.x
在Map地图中添加GraphicsLayer图层,在GraphicsLayer图层添加绘制graphics点,点击绘制的点,获取graphics点中的attributes中的信息

var cityCenter = new Point(116, 36, new SpatialReference({ wkid: 4490 }));
var map = new Map({
    basemap: {
      baseLayers: [layer1]
    },
    layers:[layer2,layer3]
});
//视图
var view = new MapView({
    container: "viewDiv",
    map: map,
center: cityCenter,
zoom: 12,
});
//创建一个图层
var graphicsLayer = new GraphicsLayer({
    graphics: [],
    visible: true,
    id:"layerid"
});
//创建要素graphic
var graphic = new Graphic({
    geometry: point,
    symbol: symbol,
attributes:{
'aa':'aaaa',
'bb':'bbbb'
    }
});
//添加要素
graphicsLayer.graphics.add(graphic)

view.on("click", (event) => {
    view.hitTest(event).then(function(response) {
        if (response.results.length) {
            var graphic = response.results.filter(function(result) {
            // check if the graphic belongs to the layer of interest
                return result.graphic.layer.id === 'layerid';
            })[0].graphic;
console.log(graphic.attributes);//获取graphic中的attributes
        }
    })
})

参考:arcgis api for js4.x实现点击图层上的绘制的Graphics点,弹出点信息。_accessor#set invalid property value, value needs t-CSDN博客


原文地址:https://blog.csdn.net/wangchaohpu/article/details/140640286

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!