1

Using OpenLayers, I have a OpenLayers.Control.SelectFeature installed on a layer, with the hover option set to true. When creating the layer I call

<layer>.events.register("featureselected",...) 

and

<layer>.events.register("featureunselected",...)

to register functions that create and destroy a popup. This all works fine. Now I want to add a small delay before the popup is created in order to avoid the popup flickering that currently occurs when moving the mouse across multiple features. However, I can't seem to figure out how to do this. I did find the OpenLayers.Handler.Hover handler, which has a delay option, but I don't know how to combine that with the SelectFeature control (if I even can).

4

2 回答 2

1

我认为这篇文章有一些有价值的信息,我将对其进行验证。有人回答下来,有人议论忽悠。

编辑:如果您制作自己的标签,我注意到当您提高labelOutlineWidth时效果会变小。似乎只有标签的字母算作“悬停”,而不是整个 PointRadius 半径。当您使标签轮廓过大时,标签看起来就像一只撞到挡风玻璃上的苍蝇(不是正方形,但它遵循标签轮廓,更具体地说是字母)。

更新:显然这就是为什么当您悬停文本标签时,请查看:指针事件属性。在您的 OpenLayers.Style 中设置此属性 (pointerEvents: ) 并尝试值 'all' 和其他值。这对我来说肯定会有所不同。

于 2012-10-09T20:26:44.530 回答
0

我绑定我的功能选择有点不同,这是一个快速(未经测试)的示例,应该可以满足您的需求。

var timer,
delay = 500, //delay in ms
hover = new OpenLayers.Control.SelectFeature( <layer> , {

    hover: true,

    onSelect: function (feature) {

        // setup a timer to run select function
        timer = window.setTimeout(function () {

            // your select code

        }, delay);
    },

    onUnselect: function () {

        // first cancel the pending timer (no side effects)
        window.clearTimeout(timer);

        // your unselect code
    }

});

<map>.addControl(hover);

hover.activate();
于 2012-10-17T22:02:30.377 回答