[GIS] Remove the Leaflet zoom control on mobile

leafletmobile

Leaflet includes a simple zoom in/out control on the map, unless otherwise specified:

zoomControl: Whether a zoom control is added to the map by default.

This control is unnecessary on a mobile device, where the device's pinch/zoom gestures work better, but the control is included anyway:

enter image description here

Is it possible to detect whether the user is on a mobile device, and remove the control if so (while leaving the control in place for desktop users)?

Best Answer

According the Leaflet documentation, there's Browser, "a namespace with static properties for browser/feature detection used by Leaflet internally". More in detail, its mobile property is "true for all browsers running in a mobile device".

var map = L.map('map', {zoomControl: true});
if (L.Browser.mobile) {
   map.removeControl(map.zoomControl);
}