Google maps Google Maps v3信息框添加事件侦听器
我有一张谷歌地图(v3),上面有20个标记。我有一个InfoBox实例,其中填充了一个div,其中包含作为innerHTML填充框的文本 我希望能够单击信息框并导航到其他页面,但我无法让信息框或其中的div响应单击事件 我试着添加一个事件监听器,我试着添加一个DOMStener,但两个都不能工作 下面是我的代码中的一些片段Google maps Google Maps v3信息框添加事件侦听器,google-maps,Google Maps,我有一张谷歌地图(v3),上面有20个标记。我有一个InfoBox实例,其中填充了一个div,其中包含作为innerHTML填充框的文本 我希望能够单击信息框并导航到其他页面,但我无法让信息框或其中的div响应单击事件 我试着添加一个事件监听器,我试着添加一个DOMStener,但两个都不能工作 下面是我的代码中的一些片段 //setting up the infobox var infobox = new InfoBox({ disableAutoPan: tr
//setting up the infobox
var infobox = new InfoBox({
disableAutoPan: true
,isHidden:false
,pixelOffset: new google.maps.Size(-10, -10)
,closeBoxURL: ""
,pane: "mapPane"
,enableEventPropagation: true
});
//setting up the div
var boxText1 = document.createElement("div");
boxText1.id = "boxText1";
boxText1.className = "labelText";
boxText1.innerHTML = title1;//this is created earlier
//the marker event listener - the marker and coordinates are also set up earlier
google.maps.event.addListener(_marker1, 'click', function() {
infobox.content_ = boxText1;
infobox.position_ = mkLatLng1;
infobox.open(map);
});
//so far everything ok. When the user clicks the marker the infobox pops up - but.....
google.maps.event.addDomListener(boxText1,'click',function(){ alert('clicked!') });//doesn't work
我尝试过很多其他的选择,但都是在黑暗中拍摄的。在信息框上收听点击事件的最佳方式是什么
谢谢,问题解决了。在信息框选项中,您必须确保
pane: "floatPane"
而不是
pane: "mapPane"
正如我所拥有的。现在一切正常
有趣的是,谷歌文档说
Set the pane to "mapPane" if the InfoBox is being used as a map label.
他们没有说的是,如果你想让地图标签可以点击,你就不能使用这个选项。小十字架会关闭信息框吗?你的信息框的文本可以包含html,对吗?所以你可以在它上面划一个div,然后听一下这个div上的点击。没有小十字架。你在想信息窗口吗?信息框里面确实有一个div,我一直在尝试听它的点击,但没有运气。是的,我在想信息窗口。哦!在我的情况下,我必须从
floatPane