如何在arcGIS上恢复默认滚动行为



我在使用arcGIS API地图时遇到一个问题:

当鼠标指针位于地图上方时,默认页面滚动被阻止。我知道我可以通过鼠标滚轮上的stopPropagation((事件来抑制滚动时的地图缩放,但这只会导致禁用缩放。页面仍然无法滚动。。。

这会导致糟糕的用户体验,尤其是在页面内使用大屏幕/全屏地图时。

知道吗?

使用下面的代码禁用视图上的滚动缩放(如这里的esri演示(不会阻止触发DOM元素wheel事件,该事件会阻止默认页面滚动;

//this prevent the mapView to zoom on wheel but does not make the page to scroll as wanted
view.on("mouse-wheel", function(event) {
// disable mouse wheel scroll zooming on the view
event.stopPropagation();
});

因此,您需要做的是在处理esri轮子事件的DOM元素上添加一个轮子事件侦听器,然后执行event.stopImmediatePropagation(),这样就不会触发取消默认页面滚动的esri轮子活动。

对于API v.4.9,您必须使用的DOM元素具有esri-view-surface

var viewSurfaceElem = document.getElementsByClassName("esri-view-surface")[0];
viewSurfaceElem.addEventListener("wheel", function(event) { event.stopImmediatePropagation(); });

请在此处查看现场演示:https://codepen.io/anon/pen/bQLwwm

最新更新