Javascript Google maps drawing events

2019-09-03 08:42发布

I'm having a problem with the event listeners provided by Google maps API. The thing is, that some events run, some not. I have a setListeners function which sets the listeners after the polygon overlay is complete. The events I would like to hook are: set_at, insert_at, remove_at and click. Now the click events run correctly, but the others not. What could I do wrong? Here is the code:

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);
            })
        }
}

2条回答
甜甜的少女心
2楼-- · 2019-09-03 09:36

Try adding the listener with google.maps.event:

google.maps.event.addListener(self.drost, 'set_at', function() {
   console.log('it works!');
});
查看更多
老娘就宠你
3楼-- · 2019-09-03 09:41

The events set_at, insert_at, remove_at need to be added to the path of the polygon, not the polygon itself.

related questions:

查看更多
登录 后发表回答