Javascript 在OpenLayers中捕获鼠标滚轮缩放
我在OpenLayers中有一个地图,它有许多带有标记的图层。每次用户缩放地图时,我都调用一个将重叠标记分组的函数。当使用普通的缩放按钮进行缩放时,这很好,但是当用户使用鼠标滚轮进行缩放时,我也想调用此函数Javascript 在OpenLayers中捕获鼠标滚轮缩放,javascript,dom-events,openlayers,openstreetmap,Javascript,Dom Events,Openlayers,Openstreetmap,我在OpenLayers中有一个地图,它有许多带有标记的图层。每次用户缩放地图时,我都调用一个将重叠标记分组的函数。当使用普通的缩放按钮进行缩放时,这很好,但是当用户使用鼠标滚轮进行缩放时,我也想调用此函数 我想我必须使用OpenLayers.Handler.mouseweel来捕获这个事件,但我不知道如何捕获。有人有这样的例子吗?您应该使用map的zoomend事件,无论用户如何操作(按钮、双击或鼠标滚动),每次用户放大或缩小时都会触发该事件 代码应该如下所示: map.events.on({
我想我必须使用
OpenLayers.Handler.mouseweel
来捕获这个事件,但我不知道如何捕获。有人有这样的例子吗?您应该使用map的zoomend
事件,无论用户如何操作(按钮、双击或鼠标滚动),每次用户放大或缩小时都会触发该事件
代码应该如下所示:
map.events.on({ "zoomend": function(){
//Do whatever you need to do here
}});
使用最新版本的Openlayers v6.5.0。 我成功了
this.map = new Map({
controls: [],
interactions: defaultInteractions({
shiftDragZoom: false,
doubleClickZoom: false,
pinchRotate: false,
mouseWheelZoom: false,
}).extend([
new MouseWheelZoom({
condition: platformModifierKeyOnly,
handleEvent: (event) => {
if (event.type !== "wheel") return;
if (event.originalEvent.deltaY <= -3) {
//mouse wheel up
} else {
//mouse wheel down
}
},
}),
]),
target: "map",
layers,
});
this.map=新地图({
控件:[],
交互:默认交互({
shiftDragZoom:false,
双击缩放:错误,
平旋:假,
鼠标滚轮缩放:错误,
}).延伸([
新鼠标滚轮变焦({
条件:仅平台修改,
handleEvent:(事件)=>{
if(event.type!==“wheel”)返回;
如果(event.originalEvent.deltaY)谢谢这就是我要找的