Openlayers 3 如何将鼠标滚轮缩放限制为仅在openlayers3中按下shift键时应用
我希望mouseWheelZoom仅在按下shift键时缩放地图。 但是ol.interaction.mouseweelZoom选项不包括条件。但是有一个handleEvent()方法 我可以看到,只要按下shift键,ol.events.condition.shiftKeyOnly(mapBrowserEvent)就会返回true 那么如何重写handleEvent()方法呢 使用typescript:Openlayers 3 如何将鼠标滚轮缩放限制为仅在openlayers3中按下shift键时应用,openlayers-3,Openlayers 3,我希望mouseWheelZoom仅在按下shift键时缩放地图。 但是ol.interaction.mouseweelZoom选项不包括条件。但是有一个handleEvent()方法 我可以看到,只要按下shift键,ol.events.condition.shiftKeyOnly(mapBrowserEvent)就会返回true 那么如何重写handleEvent()方法呢 使用typescript: export class ShiftMouseWheelInteraction exten
export class ShiftMouseWheelInteraction extends ol.interaction.MouseWheelZoom {
public handleEvent = function(evt){
if (ol.events.condition.shiftKeyOnly(evt) === true) {
return ol.interaction.MouseWheelZoom.handleEvent(evt);
}
else {
return false;
}
}
}
然后我将此交互添加到地图中,并将MouseWheelZoom作为默认交互启用
this.map = new ol.Map({
layers: layers,
interactions: ol.interaction.defaults({
mouseWheelZoom: true
})
});
this.map.addInteraction(shiftMouseWheelInteraction);
但它不是在缩放地图吗
ol.interaction.mouseweelzoom扩展了ol.interaction
基本交互构造函数具有handleEvent选项,但子类不允许将此参数传递给基本交互
ol.interaction.MouseWheelZoom = function(opt_options) {
ol.interaction.Interaction.call(this, {
handleEvent: ol.interaction.MouseWheelZoom.handleEvent
});
我使用一个防止默认行为的事件侦听器解决了这个问题
map.on('wheel', function(evt) {
wheelZoomHandler(evt);
});
wheelZoomHandler(evt) {
if (ol.events.condition.shiftKeyOnly(evt) !== true) {
evt.browserEvent.preventDefault();
}
}
我使用一个防止默认行为的事件侦听器解决了这个问题
map.on('wheel', function(evt) {
wheelZoomHandler(evt);
});
wheelZoomHandler(evt) {
if (ol.events.condition.shiftKeyOnly(evt) !== true) {
evt.browserEvent.preventDefault();
}
}