diff --git a/src/ol/PluggableMap.js b/src/ol/PluggableMap.js index eb13f51999..a6e524988b 100644 --- a/src/ol/PluggableMap.js +++ b/src/ol/PluggableMap.js @@ -22,7 +22,7 @@ import {listen, unlistenByKey} from './events.js'; import EventType from './events/EventType.js'; import {clone, createOrUpdateEmpty, equals, getForViewAndSize, isEmpty} from './extent.js'; import {TRUE} from './functions.js'; -import {DEVICE_PIXEL_RATIO, IMAGE_DECODE} from './has.js'; +import {DEVICE_PIXEL_RATIO, IMAGE_DECODE, PASSIVE_EVENT_LISTENERS} from './has.js'; import LayerGroup from './layer/Group.js'; import {hasArea} from './size.js'; import {DROP} from './structs/PriorityQueue.js'; @@ -313,7 +313,8 @@ class PluggableMap extends BaseObject { const handleBrowserEvent = this.handleBrowserEvent.bind(this); this.viewport_.addEventListener(EventType.CONTEXTMENU, handleBrowserEvent, false); - this.viewport_.addEventListener(EventType.WHEEL, handleBrowserEvent, false); + this.viewport_.addEventListener(EventType.WHEEL, handleBrowserEvent, + PASSIVE_EVENT_LISTENERS ? {passive: false} : false); /** * @type {Collection} diff --git a/src/ol/has.js b/src/ol/has.js index c71bc12d1c..bfc8aabef3 100644 --- a/src/ol/has.js +++ b/src/ol/has.js @@ -44,3 +44,23 @@ export const DEVICE_PIXEL_RATIO = window.devicePixelRatio || 1; * @type {boolean} */ export const IMAGE_DECODE = typeof Image !== 'undefined' && Image.prototype.decode; + +/** + * @type {boolean} + */ +export const PASSIVE_EVENT_LISTENERS = (function() { + let passive = false; + try { + const options = Object.defineProperty({}, 'passive', { + get: function() { + passive = true; + } + }); + + window.addEventListener('_', null, options); + window.removeEventListener('_', null, options); + } catch (error) { + // passive not supported + } + return passive; +})();