Leaflet: L.Browser.touch is incorrectly being set when on desktop (Chrome)

Created on 18 Jan 2017  ·  3Comments  ·  Source: Leaflet/Leaflet

It appears that recent updates to Chrome (on Mac, at least) have changed their implementation of window.PointerEvent. This causes the current version of Leaflet (1.0.2) to misdiagnose the browser as a touch device and adds the leaflet-touch class.

This line seems to be the culprit:

pointer = window.PointerEvent || msPointer

...it can be found here: https://github.com/Leaflet/Leaflet/blob/v1.0.2/src/core/Browser.js#L33

The problem is that window.PointerEvent is a function, which will always return 'truthy'.

How to reproduce

  • Browser: Mac OSX El Capitan (10.11.6), Chrome Version 55.0.2883.95 (64-bit)
  • Go to www.leafletjs.com and look at the demo example...the Zoom In/Out buttons are enlarged, due to the leaflet-touch class being applied to the leaflet map container.

Most helpful comment

So, what's the point of detecting touch if it's not going to accurately detect touch? Shouldn't that whole logic be removed from leaflet then?

All 3 comments

I can reproduce this as well...

Duplicate of https://github.com/Leaflet/Leaflet/issues/3944. There is no way to know if the browser is running on a computer with a touchscreen or not, it's only possible to know if the browser supports touch/pointer events or not. See also http://www.stucox.com/blog/you-cant-detect-a-touchscreen/

So, what's the point of detecting touch if it's not going to accurately detect touch? Shouldn't that whole logic be removed from leaflet then?

Was this page helpful?
0 / 5 - 0 ratings