2013-08-05 64 views
0

我爲InfoBox創建了一個自定義關閉按鈕,但無法關閉它。我試圖創建一個eventlistener,當點擊該框時,但目前還沒有運氣。代碼如下:如何定位Google地圖自定義InfoBox上的元素?

InfoPopupbox.prototype = new google.maps.OverlayView(); 

    InfoPopupbox.prototype.onAdd = function() { 
     //add is after the map has been initiated 
     var div = document.createElement('div'); 
     var classname = "infoWrapper "; 
     if (this.customclass){ 
      classname += this.customclass; 
     } 
     div.className = classname ; 
     div.style.border = "none"; 
     div.style.borderWidth = "0px"; 
     div.style.position = "absolute"; 

     div.appendChild(this.content_); 
     this.div_ = div; 

     var panes = this.getPanes(); 
     //panes.overlayLayer.appendChild(div); 

     //float the Pane above the map 
     panes.floatPane.appendChild(div); 

     google.maps.event.addListener(this , 'click' , function(){ 
      console.log('click close'); 
      that.infotoggle(); 
     }); 

    }; 

回答

0

你想用addDomListener,而不是addListenerclick,你需要將它綁定到DOM元素:

google.maps.event.addDomListener(this.div, 'click', function() { ... }); 
+0

這完美地工作!謝謝。 – jon

相關問題