Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LeafletJS: How to remove the zoom control

I'm trying to remove the zoom controls (+/-) on a LeafletJS map.

I'm using the MapBox.js version of Leaflet but most of the operations are the same as Leaflet. I implement my map like this:

var map = L.mapbox.map('map');  var layer = L.mapbox.tileLayer('MAPBOX-ID', {     format: 'jpg70',     minZoom: 13,     maxZoom: 15,     reuseTiles: true,      unloadInvisibleTiles: true }); map.addLayer(layer); map.setView([40.73547,-73.987856]); 

The documentation says there's a zoomControl option that will remove the zoom control from the map but I've had no luck in getting it to work.

How can I remove the zoom control with this implementation?

Thanks!

like image 485
Brett DeWoody Avatar asked May 14 '13 07:05

Brett DeWoody


People also ask

How to remove zoom control in Leaflet map?

Zoom − By default, this control exists at the top left corner of the map. It has two buttons "+" and "–", using which you can zoom-in or zoom-out the map. You can remove the default zoom control by setting the zoomControl option of the map options to false.


2 Answers

This worked for me:

var map = new L.map('map', { zoomControl: false }); 

With mapbox try:

var map = L.mapbox.map('map', { zoomControl: false }); 

See map creation and the zoomControl option in the Leaflet documentation.

like image 175
coordinate Avatar answered Sep 20 '22 11:09

coordinate


If you want to dynamically turn on and off zooming you can do something like this:

map.touchZoom.disable(); map.doubleClickZoom.disable(); map.scrollWheelZoom.disable(); map.boxZoom.disable(); map.keyboard.disable(); $(".leaflet-control-zoom").css("visibility", "hidden"); 
like image 21
Allie Hoch Janoch Avatar answered Sep 19 '22 11:09

Allie Hoch Janoch