From cd6c1bdc5400eac56f8966bc3a72dbe078e99b5c Mon Sep 17 00:00:00 2001 From: Norbert Renner Date: Mon, 7 Aug 2017 11:26:49 +0200 Subject: [PATCH] Leaflet 1.0: revert touch style in desktop browsers, fixes #69 --- gulpfile.js | 1 + js/Browser.js | 24 ++++++++++++++++++++++++ js/index.js | 9 +++++++++ 3 files changed, 34 insertions(+) create mode 100644 js/Browser.js diff --git a/gulpfile.js b/gulpfile.js index 7aee969..1db27e4 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -31,6 +31,7 @@ var paths = { '!**/*.min.js', '!**/url-search-params/**/*.js' ]).concat([ + 'js/Browser.js', 'js/Util.js', 'js/Map.js', 'js/router/BRouter.js', diff --git a/js/Browser.js b/js/Browser.js new file mode 100644 index 0000000..0c71316 --- /dev/null +++ b/js/Browser.js @@ -0,0 +1,24 @@ +(function () { + + var touchScreen = (function () { + var result = null; + + if ('maxTouchPoints' in navigator) { + result = navigator.maxTouchPoints > 0; + } else if (window.matchMedia && window.matchMedia('(any-pointer:coarse),(any-pointer:fine),(any-pointer:none)').matches) { + result = window.matchMedia("(any-pointer:coarse)").matches; + } else if ('msMaxTouchPoints' in navigator) { + result = navigator.msMaxTouchPoints > 0; + }; + + return result; + }()), + touchScreenDetectable = touchScreen !== null; + + + BR.Browser = { + touchScreen: touchScreen, + touchScreenDetectable: touchScreenDetectable + }; + +}()); \ No newline at end of file diff --git a/js/index.js b/js/index.js index 6aaa573..1c66415 100644 --- a/js/index.js +++ b/js/index.js @@ -8,6 +8,14 @@ var mapContext; + function verifyTouchStyle(mapContext) { + // revert touch style (large icons) when touch screen detection is available and negative + // see https://github.com/nrenner/brouter-web/issues/69 + if (L.Browser.touch && BR.Browser.touchScreenDetectable && !BR.Browser.touchScreen) { + L.DomUtil.removeClass(mapContext.map.getContainer(), 'leaflet-touch'); + } + } + function initApp(mapContext) { var map = mapContext.map, layersControl = mapContext.layersControl, @@ -340,6 +348,7 @@ } mapContext = BR.Map.initMap(); + verifyTouchStyle(mapContext); initApp(mapContext); })();