Utilizing OpenLayers2 (v2.12) to render a map in the user's browser has been my go-to method. However, since Chrome's recent update, using the mousewheel to zoom in and out of the OpenLayers map also inadvertently scrolls the entire page up and down.
Prior to this Chrome change, zooming in and out within the map functioned smoothly without affecting the page scroll. It was only when I used the mousewheel outside the OpenLayers map that the page would scroll, as intended.
However, now an error message pops up when trying to use the mousewheel within the map:
OpenLayers.min.js:2 [Intervention] Unable to preventDefault inside passive
event listener due to target being treated as passive. See
https://www.chromestatus.com/features/6662647093133312
This error likely triggers the unwanted page scrolling behavior.
In response to similar queries related to this error, I attempted adding the
touch-action: none;
CSS style to the OL map container, but it failed to resolve the issue.
The error originates from code within the OpenLayers.js file rather than my own, creating uncertainty about how to rectify it.
The specific piece of code causing the error in the Openlayers.min.js file is:
OpenLayers.Event = {
stop: function(e, t) {
t || (e.preventDefault ? e.preventDefault() : e.returnValue = !1),
e.stopPropagation ? e.stopPropagation() : e.cancelBubble = !0
},
}
particularly the e.preventDefault() function.
The uncompressed version of the OpenLayers file I'm referencing can be found at: https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.12/OpenLayers.min.js
Here's the HTML code for the OL map:
<div class="container-fluid col-xs-12" style="height: 100%;">
<div class="row" style="height: 100%;">
<div class="custom-col-md-10 col-sm-9 col-xs-8" style="height: 100%; overflow-y: hidden; max-height:850px;max-width:1600px;">
<div class="panel" style="height: 100%; border: solid thin; border-color: darkblue;">
<div class="panel-body" style="height: 100%; padding: 0px;">
<div tabindex="0" id="map" style="height: 100%; width: 100%;">
</div>
</div>
</div>
</div>
</div>
</div>
I am seeking a solution that ensures using the mousewheel within the OpenLayers map solely zooms in and out without triggering page scrolling and eliminates the 'unable to preventDefault' error message.
This issue appears to be exclusive to Chrome, as Firefox and Edge behave correctly.
Appreciate any assistance provided.