OpenLayers使用Popups窃取点击事件 [英] OpenLayers steals click events with Popups

查看:93
本文介绍了OpenLayers使用Popups窃取点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么FramedCloud popup会在弹出窗口中窃取点击事件?

Why does FramedCloud popup steal click events inside the popup?

current_popup = new OpenLayers.Popup.FramedCloud(
    "featurePopup",
    f.geometry.getBounds().getCenterLonLat(),
    new OpenLayers.Size(0,0),
    "<b>Наблюдения</b><br/>" + $.map(features, function(fe) { return fe.attributes.description; }).join('<br/>'),
    null, false, null);
    map.addPopup(current_popup, true);



$('#map').on('click', function() { console.log('test'); return false; });

除非我点击弹出窗口内的链接,否则始终捕获点击事件。弹出窗口和锚点是 #map 的后代。

Captures click events always except when I click a link inside a popup. The popup and the anchors are descendants of #map.


  • 点击map = >回调被解雇

  • 点击一个标记=>回调被触发,弹出窗口显示

  • 点击弹出内部(不在链接上)=>回调未被解雇

  • 点击弹出窗口内的链接=>同样,没有任何反应

  • Click the map => callback is fired
  • Click a marker => callback is fired, popup is shown
  • click inside popup (not on a link) => callback is not fired
  • click a link inside a popup => same way, nothing happens

OL的那部分代码非常模糊。

The code in that part of OL is quite obscure.

为什么它会捕获弹出窗口内的点击?如何取回它们?

Why does it catch clicks inside the popup? How do I take them back?

编辑:在OL中进行更深入的调试:触发此功能:

edit: debugging deeper in OL: this function is fired:

bindAsEventListener: function(func, object) {
    return function(event) {
        return func.call(object, event || window.event);
    };

event.target 是锚点,完全是我期待的是:

event.target is the anchor, exactly what I expect:

<a class="edit-card-link" href="/form/?id=806">...</a>

func 是:

handleBrowserEvent: function(evt) {
    var type = evt.type, listeners = this.listeners[type];
    if (!listeners || listeners.length == 0) {
        return;
    }
    var touches = evt.touches;
    if (touches && touches[0]) {
        var x = 0;
        var y = 0;
        var num = touches.length;
        var touch;
        for (var i = 0; i < num; ++i) {
            touch = touches[i];
            x += touch.clientX;
            y += touch.clientY;
        }
        evt.clientX = x / num;
        evt.clientY = y / num;
    }
    if (this.includeXY) {
        evt.xy = this.getMousePosition(evt);
    }
    this.triggerEvent(type, evt);
}

是OpenLayers .Event类实例, evt.target 仍然是那个锚,监听器包含1个监听器:

this is OpenLayers.Event class instance, evt.target is still that anchor, listeners contains 1 listener:

function (evt){OpenLayers.Event.stop(evt,true);}

这是原因吗?我怎么把它拿出来?

Is this the reason? How do I take it out?

推荐答案

我是用另一种方式做的。我让OpenLayers捕获事件,但在此之前我触发另一个事件。

I did it another way. I let OpenLayers capture the event, but before that I trigger another one.

 $('a', current_popup.contentDiv).on('click', function(evt) {
      var jtarget = $(evt.target);
      hide_popup();  // hides OpenLayers popup
      $(document).trigger('edit_link_clicked', {
           feature: features[jtarget.parent().find('a').index(jtarget)],
           cluster: f,
           url: jtarget.attr('href')
      });
      return false;
 });

这篇关于OpenLayers使用Popups窃取点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆