我在 Google 地图图表上添加 onclick 事件侦听器时遇到问题,使用 Angular 7 中的 google.visualization.ChartWrapper
该事件不起作用,我没有收到任何错误或日志。地图绘制得很好,"准备好"的听众也像一个魅力。
官方文档 : https://developers.google.com/chart/interactive/docs/reference#chartwrapperobject
//My Html-Element
<div id="chart"></div>
//I Initilize the ChartWrapper
map: google.visualization.ChartWrapper = new google.visualization.ChartWrapper({
chartType: 'Map',
dataTable: [["Latitude", "Longitude", "Name"], [lat, long, company]],
options: {
showTooltip: true,
enableScrollWheel: true,
useMapTypeControl: true,
tooltip: { isHtml: true }
},
containerId: 'chart'
});
//In NgOnInit im loading the package and call my draw function
ngOnInit() {
google.charts.load('current', { 'packages': ['map'] });
google.charts.setOnLoadCallback(this.drawMap.bind(this));
}
drawMap() {
//I set the ready eventlistener
google.visualization.events.addListener(this.map,'ready',this.onReady.bind(this));
this.map.draw();
}
onReady() {
//This Event works and i get the alert
alert('Ready');
google.visualization.events.addListener(this.map.getChart(), 'click', this.onClick);
}
onClick($event) {
//This never works
alert('Click');
}
我希望任何人都可以提供帮助
根据Map
图的事件文档,
没有'click'
事件。
尝试改用'select'
...
google.visualization.events.addListener(this.map.getChart(), 'select', this.onClick);