如何定位谷歌地图自定义信息框上的元素



我为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();
        });
    };

对于click,您希望使用addDomListener而不是addListener,并且需要将其绑定到DOM元素:

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

最新更新