Javascript Google地图绘制事件

Javascript Google maps drawing events

本文关键字:事件 绘制 地图 Google Javascript      更新时间:2023-09-26

我对Google maps API提供的事件侦听器有一个问题。问题是,有些事件可以运行,有些则不能。我有一个setListeners函数,它在多边形覆盖完成后设置侦听器。我想挂钩的事件是:set_at, insert_at, remove_at和点击。现在点击事件运行正确,但其他的不是。我能做错什么呢?下面是代码:

self.setListeners = function () {
        //this click event runs correctly
        google.maps.event.addListener(self.map, 'click', function (e) {
            self.clearSelection();
        })
        console.log(self.drost);
        if (typeof self.drost != 'undefined') {
            self.drost.addListener('set_at', function (e) {
                console.log(e.overlay);
            });
            self.drost.addListener('insert_at', function (e) {
                console.log(e.overlay);
            });
            self.drost.addListener('remove_at', function (e) {
                console.log(e.overlay);
            });
            //this click also runs correctly
            self.drost.addListener('click', function(e){
                self.setSelection(self.drost);
            })
        }
}

事件set_at, insert_at, remove_at需要添加到多边形的路径,而不是多边形本身

相关问题:

  • 将事件监听器应用于可编辑多边形

  • 计算在google地图上绘制多边形的面积javascript

尝试使用google.maps.event:

添加监听器
google.maps.event.addListener(self.drost, 'set_at', function() {
   console.log('it works!');
});