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

avatar
作者
猴君
阅读量:0

需求: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博客

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!