diff --git a/changelog/upgrade-notes.md b/changelog/upgrade-notes.md index 3825d1df6a..19c397bb76 100644 --- a/changelog/upgrade-notes.md +++ b/changelog/upgrade-notes.md @@ -4,9 +4,19 @@ #### Backwards incompatible changes +#### Removal of `TOUCH` constant from `ol/has` + +If you were previously using this constant, you can check if `'ontouchstart'` is defined in `window` instead. + +```js +if ('ontouchstart' in window) { + // ... +} +``` + #### Removal of `GEOLOCATION` constant from `ol/has` -If you were previously using this constant, you can check if `'geolocation'` is define in `navigator` instead. +If you were previously using this constant, you can check if `'geolocation'` is defined in `navigator` instead. ```js if ('geolocation' in navigator) { diff --git a/src/ol/PluggableMap.js b/src/ol/PluggableMap.js index d4c57c4d4a..e6035259cc 100644 --- a/src/ol/PluggableMap.js +++ b/src/ol/PluggableMap.js @@ -22,7 +22,7 @@ import {listen, unlistenByKey, unlisten} from './events.js'; import EventType from './events/EventType.js'; import {createEmpty, clone, createOrUpdateEmpty, equals, getForViewAndSize, isEmpty} from './extent.js'; import {TRUE} from './functions.js'; -import {DEVICE_PIXEL_RATIO, TOUCH} from './has.js'; +import {DEVICE_PIXEL_RATIO} from './has.js'; import LayerGroup from './layer/Group.js'; import {hasArea} from './size.js'; import {DROP} from './structs/PriorityQueue.js'; @@ -230,7 +230,7 @@ class PluggableMap extends BaseObject { * @type {!HTMLElement} */ this.viewport_ = document.createElement('div'); - this.viewport_.className = 'ol-viewport' + (TOUCH ? ' ol-touch' : ''); + this.viewport_.className = 'ol-viewport' + ('ontouchstart' in window ? ' ol-touch' : ''); this.viewport_.style.position = 'relative'; this.viewport_.style.overflow = 'hidden'; this.viewport_.style.width = '100%'; diff --git a/src/ol/has.js b/src/ol/has.js index 93b1e93431..c59288907c 100644 --- a/src/ol/has.js +++ b/src/ol/has.js @@ -39,30 +39,4 @@ export const MAC = ua.indexOf('macintosh') !== -1; */ export const DEVICE_PIXEL_RATIO = window.devicePixelRatio || 1; - -/** - * True if browser supports touch events. - * @const - * @type {boolean} - * @api - */ -export const TOUCH = 'ontouchstart' in window; - - -/** - * True if browser supports pointer events. - * @const - * @type {boolean} - */ -export const POINTER = 'PointerEvent' in window; - - -/** - * True if browser supports ms pointer events (IE 10). - * @const - * @type {boolean} - */ -export const MSPOINTER = !!(navigator.msPointerEnabled); - - export {HAS as WEBGL} from './webgl.js'; diff --git a/src/ol/pointer/PointerEventHandler.js b/src/ol/pointer/PointerEventHandler.js index 2501efa12b..7f983ef9d9 100644 --- a/src/ol/pointer/PointerEventHandler.js +++ b/src/ol/pointer/PointerEventHandler.js @@ -34,7 +34,6 @@ import {listen, unlisten} from '../events.js'; import EventTarget from '../events/Target.js'; -import {POINTER, MSPOINTER, TOUCH} from '../has.js'; import PointerEventType from './EventType.js'; import MouseSource, {prepareEvent as prepareMouseEvent} from './MouseSource.js'; import MsSource from './MsSource.js'; @@ -124,15 +123,15 @@ class PointerEventHandler extends EventTarget { * that generate pointer events. */ registerSources() { - if (POINTER) { + if ('PointerEvent' in window) { this.registerSource('native', new NativeSource(this)); - } else if (MSPOINTER) { + } else if (window.navigator.msPointerEnabled) { this.registerSource('ms', new MsSource(this)); } else { const mouseSource = new MouseSource(this); this.registerSource('mouse', mouseSource); - if (TOUCH) { + if ('ontouchstart' in window) { this.registerSource('touch', new TouchSource(this, mouseSource)); } } diff --git a/test/spec/ol/map.test.js b/test/spec/ol/map.test.js index 521891a6a6..28b401494a 100644 --- a/test/spec/ol/map.test.js +++ b/test/spec/ol/map.test.js @@ -5,7 +5,6 @@ import MapEvent from '../../../src/ol/MapEvent.js'; import Overlay from '../../../src/ol/Overlay.js'; import View from '../../../src/ol/View.js'; import {LineString, Point} from '../../../src/ol/geom.js'; -import {TOUCH} from '../../../src/ol/has.js'; import {focus} from '../../../src/ol/events/condition.js'; import {defaults as defaultInteractions} from '../../../src/ol/interaction.js'; import {get as getProjection} from '../../../src/ol/proj.js'; @@ -45,7 +44,7 @@ describe('ol.Map', function() { it('creates the viewport', function() { const map = new Map({}); const viewport = map.getViewport(); - const className = 'ol-viewport' + (TOUCH ? ' ol-touch' : ''); + const className = 'ol-viewport' + ('ontouchstart' in window ? ' ol-touch' : ''); expect(viewport.className).to.be(className); });