popupTemplate: { title: action, content: ‘点击了‘ }
title: function(event) { return popupTile[action] + event.graphic.getAttribute(‘OBJECTID‘) }
actions:[ { title: ‘删除‘, id: ‘deleteGraphic‘, className: ‘esri-icon-trash‘ } ]
this.mapView.popup.on("trigger-action", event => { const { id } = event.action if(id === ‘delete-graphic‘) this.deleteGraphic() })
deleteGraphic() { const selectedFeature = this.mapView.popup.selectedFeature const { layer } = selectedFeature layer.applyEdits({ deleteFeatures: [selectedFeature] }).then(res => { console.log(res) }) },
完整代码
// 创建弹窗模板 const popupTemplate = { title: function(event) { return popupTile[action] + ‘-------‘ + event.graphic.getAttribute(‘OBJECTID‘) }, actions:[ { title: ‘删除‘, id: ‘delete-graphic‘, className: ‘esri-icon-trash‘ } ] } // 把模板设置到geojsonLayer上 const GeojsonLayer = new esri.GeoJSONLayer({ url: url, copyright: ‘RHgis‘, id: layerID, renderer: customRenderer || renderer, popupTemplate }) // 监听popup上的按钮事件 this.mapView.popup.on("trigger-action", event => { console.log(event) const { id } = event.action if(id === ‘delete-graphic‘) this.deleteGraphic() }) // 删除 deleteGraphic() { const selectedFeature = this.mapView.popup.selectedFeature const { layer } = selectedFeature layer.applyEdits({ deleteFeatures: [selectedFeature] }).then(res => { console.log(res) }) },
arcgis js4.x在geojson数据上点击显示弹窗,并添加删除按钮
原文:https://www.cnblogs.com/yhllx999/p/15353029.html