如何在OpenLayers 3中禁用DragPan? [英] How to disable DragPan in OpenLayers 3?

查看:385
本文介绍了如何在OpenLayers 3中禁用DragPan?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Openlayers 3(已定义地图)中禁用DragPan交互?

How to disable DragPan interaction in Openlayers 3 (when map is already defined)?

此外,为什么我无法使用mousemove事件?
我正在这样做:map.on('mousemove',function(e){ ...});,它不起作用.

Also, why I'm unable to use mousemove event?
I'm doing this: map.on('mousemove',function(e){ ...}); and it doesn't work.

推荐答案

要禁用互动,您需要从地图上将其删除.如果您没有对交互的引用,则可以使用getInteractions map方法找到它:

To disable an interaction, you need to remove it from the map. If you don't have a reference to your interaction, you can find it using the getInteractions map method:

var dragPan;
map.getInteractions().forEach(function(interaction) {
  if (interaction instanceof ol.interaction.DragPan) {
    dragPan = interaction;
  }
}, this);
if (dragPan) {
  map.removeInteraction(dragPan);
}

对于鼠标移动事件,要使用的正确事件是' pointermove ',请参见此处的使用示例:

For the mouse move event, the correct event to use is 'pointermove', see an example of use here: http://openlayers.org/en/v3.3.0/examples/icon.html

知道您可以配置要创建的交互,并默认将其添加到地图中.例如,如果您要创建一个没有dragPan交互的地图,则可以这样做:

Know that you can configure the interactions you want created and added by default to your map. If, for example, you wanted to create a map without the dragPan interaction, you could do so like this:

var map = new ol.Map({
  layers: layers,
  interactions: ol.interaction.defaults({
    dragPan: false
  }),
  view: new ol.View({
    center: [0, 0],
    zoom: 2
  })
});

有关此处. >.

这篇关于如何在OpenLayers 3中禁用DragPan?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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