OpenLayers 3:DragZoom,将快捷方式从 [Click + Shift] 更改为 [Click + Ctrl]
OpenLayers 3 : DragZoom, change shortcut from [Click + Shift] to [Click + Ctrl]
我正在尝试更改 ol3 在他的 DragZoom 事件中的默认行为:我想要这个功能,默认配置在 Click + Shift 上,而不是使用 Click + Ctrl.
你知道如何执行吗?
已查阅在线文档:
http://openlayers.org/en/latest/apidoc/ol.interaction.DragZoom.html
似乎是 "condition" 属性,但不知道该怎么做。
"condition" 值必须是事件发生时调用的函数。 OpenLayers 没有附带 ol.events.condition.ctrlKeyOnly
,但您可以定义自己的。您需要先禁用默认的 DragZoom 交互,然后添加您自己的交互:
var interactions = ol.interaction.defaults({
shiftDragZoom: false
});
interactions.push(new ol.interaction.DragZoom({
duration: 200,
condition: function(mapBrowserEvent) {
var originalEvent = mapBrowserEvent.originalEvent;
return (
originalEvent.ctrlKey &&
!(originalEvent.metaKey || originalEvent.altKey) &&
!originalEvent.shiftKey);
}
}));
在 JSFiddle demo 中查看实际效果。
我正在尝试更改 ol3 在他的 DragZoom 事件中的默认行为:我想要这个功能,默认配置在 Click + Shift 上,而不是使用 Click + Ctrl.
你知道如何执行吗?
已查阅在线文档: http://openlayers.org/en/latest/apidoc/ol.interaction.DragZoom.html
似乎是 "condition" 属性,但不知道该怎么做。
"condition" 值必须是事件发生时调用的函数。 OpenLayers 没有附带 ol.events.condition.ctrlKeyOnly
,但您可以定义自己的。您需要先禁用默认的 DragZoom 交互,然后添加您自己的交互:
var interactions = ol.interaction.defaults({
shiftDragZoom: false
});
interactions.push(new ol.interaction.DragZoom({
duration: 200,
condition: function(mapBrowserEvent) {
var originalEvent = mapBrowserEvent.originalEvent;
return (
originalEvent.ctrlKey &&
!(originalEvent.metaKey || originalEvent.altKey) &&
!originalEvent.shiftKey);
}
}));
在 JSFiddle demo 中查看实际效果。