【问题标题】:Disable event click on Google Map v3禁用事件点击 Google Map v3
【发布时间】:2017-06-13 10:16:52
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

    这里是部分解决方案。不想花时间浏览和了解 InfoBox - Infowindow 已经解决了。

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

    您需要添加/更改:

    在脚本顶部添加:var listener;

    改变:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-21
      • 2011-02-22
      • 2012-06-17
      • 1970-01-01
      • 2012-01-30
      • 1970-01-01
      • 2011-09-23
      • 2012-08-19
      相关资源
      最近更新 更多