gpt4 book ai didi

Openlayers 3 - 交互和指针移动

转载 作者:行者123 更新时间:2023-12-03 16:55:50 24 4
gpt4 key购买 nike

我试图在鼠标悬停在某个功能内时激活交互。

它工作得很好......问题是如果你慢慢移动鼠标,交互会保持活跃。

这是 OL3 上的错误,还是我应该换一种方式?

代码:http://jsfiddle.net/gmaq54dm/3/

olMap.on("pointermove", function (e) {
if (e.dragging) {
return;
}
var map = e.map;
console.log(e.pixel);
var feature = map.forEachFeatureAtPixel(e.pixel, function(feature, layer) {
return feature;
});
var hit = (feature) ? true : false;
console.log(hit);
olDraw.setActive(hit);
});

谢谢

最佳答案

这是您的应用程序中的错误,而不是 OpenLayers 中的错误。您需要确保仅从矢量图层而不是绘图层中命中检测特征。将您的 forEachFeatureAtPixel 函数更改为

var feature = map.forEachFeatureAtPixel(e.pixel, function(feature, layer) {
return feature;
}, null, function(layer) {
return layer == vectorLayer
});

最后一个参数添加了一个图层过滤器,以仅在矢量图层上命中检测特征。

已更新,正在运行的 JSFiddle:http://jsfiddle.net/gmaq54dm/4/

关于Openlayers 3 - 交互和指针移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38573214/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com