禁用Google地图v3上的活动点击

时间:2017-06-13 10:16:53

标签: google-maps google-maps-api-3

我为GMap v3添加了自定义Google地图信息窗口 如何停用'点击'当我点击InfoWindow内容和InfoWindow关闭按钮时的事件?

示例代码我放在https://codepen.io/anon/pen/rwLdxG

function InfoBox(opts) {
    google.maps.OverlayView.call(this);
    this.latlng_ = opts.latlng;
    this.map_ = opts.map;
    this.content = opts.content;
    this.offsetVertical_ = -195;
    this.offsetHorizontal_ = 5;
    this.height_ = 165;
    this.width_ = 266;
    var me = this;
    this.boundsChangedListener_ =
        google.maps.event.addListener(this.map_, "bounds_changed", function () {
            return me.panMap.apply(me);
        });
    // Once the properties of this OverlayView are initialized, set its map so
    // that we can display it. This will trigger calls to panes_changed and
    // draw.
    this.setMap(this.map_);
}

enter image description here

1 个答案:

答案 0 :(得分:1)

这是部分解决方案。不想花时间浏览和了解InfoBoxes - Infowindow本来可以解决。

以下内容将在您单击/打开infoBOX时删除单击事件。关闭InfoBOX时需要找到重新添加的方法。 InfoBox!= Infowindow,我没有API可以做到。

您需要添加/更改:

ADD:var listener到脚本顶部;

CHANGE:

google.maps.event.addListener(map, 'click', function(event) {

              alert("google.maps.event.addListener");
            });

 listener = google.maps.event.addListener(map, 'click', function(event) {
          alert("google.maps.event.addListener");
        });

变化:

google.maps.event.addListener(markers[i], "click", function (e) {
            var infoBox = new InfoBox({
                latlng: this.getPosition(),
                map: map,
                content: this.content
            });
            google.maps.event.removeListener(listener)
          });

 google.maps.event.addListener(markers[i], "click", function (e) {
        var infoBox = new InfoBox({
            latlng: this.getPosition(),
            map: map,
            content: this.content
        });
        google.maps.event.removeListener(listener)
      });

CODEPEN: https://codepen.io/anon/pen/rwLrYJ?editors=0010