Leaflet 1.0: revert touch style in desktop browsers, fixes #69

This commit is contained in:
Norbert Renner 2017-08-07 11:26:49 +02:00
parent 6c316c8688
commit cd6c1bdc54
3 changed files with 34 additions and 0 deletions

24
js/Browser.js Normal file
View file

@ -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
};
}());

View file

@ -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);
})();