JavaScript谷歌地图绘画事件 [英] Javascript google maps drawing events
问题描述
我在google maps api提供的事件侦听器中遇到问题。事情是,有些事件运行,有些不是。我有一个setListeners函数,用于在多边形叠加完成后设置侦听器。我想要挂钩的事件是:set_at,insert_at,remove_at并单击。现在,点击事件正确运行,但其他人没有。我能做什么错?这里是代码:
self.setListeners = function(){
//这个点击事件正确运行
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);
});
//此点击也正确运行
self.drost.addListener('click',function(e){
self.setSelection(self.drost);
})$
$ b $ p
$ p
事件 set_at
, insert_at
, remove_at
需要添加到多边形的路径中,而不是多边形本身。
相关问题:
-
.com / questions / 12671077 / calculate-area-of-a-drawn-polygon-on-google-map-javascript>计算在Google地图上绘制的多边形的面积javascript
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);
})
}
}
Thanks in advance!
解决方案 The events set_at
, insert_at
, remove_at
need to be added to the path of the polygon, not the polygon itself.
related questions:
这篇关于JavaScript谷歌地图绘画事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!