openlayers-3 - 打开和关闭 MouseWheelZoom

标签 openlayers-3

如何切换鼠标滚轮缩放功能?

我知道您可以在创建 map 时设置 mousewheelzoom 默认值:

    interactions: ol.interaction.defaults({
        mouseWheelZoom: false
    }),

但是我如何在创建 map 后更改它,即当用户单击 map 时我想运行一个例程来重新打开鼠标滚轮缩放?

我知道这在 Openlayers2 中很棘手 - 你必须循环控制:

function PMA_Mapping_Enable_Mouse_Wheel_Zoom(map) {
//Need to go through all controls - don't know why!
controls = map.getControlsByClass('OpenLayers.Control.Navigation');
for (var i = 0; i < controls.length; ++i)
    controls[i].enableZoomWheel();};

不知道这是否有帮助,但我认为我应该包括它。

有谁知道如何在 openlayers 3 中实现这一点?

最佳答案

Mouseweel 是一种交互而非控件。 所以,你总是可以使用

interaction.setActive(true), interaction.setActive(false) 切换交互。

像这样开始你的 map 初始化:

......交互:ol.interaction.defaults({ 鼠标滚轮缩放:假 }), .......

然后,一旦您的 map 准备就绪,就可以像这样创建 mouseWheel 交互:

var mouseWheelInt = new ol.interaction.MouseWheelZoom(); map.addInteraction(mouseWheelInt)

然后切换它:

mouseWheelInt.setActive(!mouseWheelInt.getActive())

关于openlayers-3 - 打开和关闭 MouseWheelZoom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38240737/

相关文章:

openlayers-3 - LineString 和 multiLine openlayers 3

javascript - 使用 Openlayers 3 在 map 图 block 上绘制多边形,其中使用自定义图 block 服务器

javascript - OpenLayers3 : more than one overlay at a time?

openlayers-3 - 开放层 3 : Change the vectors layers when the zoom level change

openlayers-3 - Openlayers 3. 如何为功能制作tootlip

css - OpenLayers 3 - 在 map 外添加比例线

javascript - 无法删除 OpenLayers 3 中的功能

javascript - 如何将样式应用于 OpenLayers 3 中的修改交互?

javascript - 如何从 Openlayers 3 中的功能中获取图层?

map - Openlayer 3 坐标