Google Maps v3 InfoBox添加事件监听器

Phi*_*ohn 6 google-maps

我有一个带有20个标记的Google Map(v3).我有一个InfoBox实例,其中填充了一个div,其中包含填充框作为innerHTML的文本.

我希望能够点击信息框并导航到另一个页面,但我无法获取信息框或其中的div来响应点击事件.

我已经尝试添加一个事件监听器,我尝试添加一个domListener,但我无法工作.

以下是我的代码中的一些代码段

//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
Run Code Online (Sandbox Code Playgroud)

我尝试过各种其他选择,但它们都是在黑暗中拍摄的.在信息框上收听点击事件的最佳方法是什么?

谢谢

Phi*_*ohn 12

问题解决了.在信息框选项中,您必须确保拥有

pane: "floatPane" 
Run Code Online (Sandbox Code Playgroud)

并不是

pane: "mapPane"
Run Code Online (Sandbox Code Playgroud)

因为我有它.现在工作正常.

有趣的是Google Docs说

Set the pane to "mapPane" if the InfoBox is being used as a map label.
Run Code Online (Sandbox Code Playgroud)

他们没有说的是,如果您希望地图标签可以点击,则无法使用此选项.