如何在arcGIS上还原默认的滚动行为?

时间:2018-11-21 15:04:17

标签: javascript scroll mousewheel arcgis-js-api stoppropagation

使用带有arcGIS API的地图时遇到一个问题:

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

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

有什么主意吗?

1 个答案:

答案 0 :(得分:0)

使用下面的代码(like the esri demo here)在视图上禁用滚动缩放不会阻止触发DOM元素<script> window.onscroll = function() { document.getElementById("toHide").style.display = "none"; } </script> 事件,这会阻止默认页面滚动;

wheel

因此,您需要做的是在处理esri wheel事件的DOM元素上添加wheel事件监听器,然后执行event.stopImmediatePropagation(),以便取消默认页面滚动的esri wheel事件不会触发。

使用API​​ v.4.9,您必须使用的DOM元素具有 //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-view-surface

在此处观看实时演示:https://codepen.io/anon/pen/bQLwwm