阅读量: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 } }) })