Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize Zoom in/out button in leaflet.js

I am trying to customize zoom control (+/-), so it should appear in the right side like Google maps (https://www.google.com/maps/)

I tried to add float:right; but it didn't work.

From the CSS file :

/* zoom control */  .leaflet-control-zoom-in, .leaflet-control-zoom-out {   font: bold 18px 'Lucida Console', Monaco, monospace;   text-indent: 1px;   } .leaflet-control-zoom-out {   font-size: 20px;   }  .leaflet-touch .leaflet-control-zoom-in {   font-size: 22px;   } .leaflet-touch .leaflet-control-zoom-out {   font-size: 24px;   } 

http://jsfiddle.net/hsy7v/1/

like image 986
user3378649 Avatar asked Apr 08 '14 02:04

user3378649


People also ask

How do you change the zoom on a leaflet?

To enable it, use the map's zoomSnap option. The zoomSnap option has a default value of 1 (which means that the zoom level of the map can be 0 , 1 , 2 , and so on). If you set the value of zoomSnap to 0.5 , the valid zoom levels of the map will be 0 , 0.5 , 1 , 1.5 , 2 , and so on.

Is leaflet API free?

Leaflet, unlike Google Maps and other all-in-one solutions, is just a JavaScript library. It's free to use, but doesn't provide map imagery on its own — you have to choose a tile service to combine with it.

What is tile layer in leaflet?

Used to load and display tile layers on the map, implements ILayer interface.

Is leaflet JS an API?

Leaflet is designed with simplicity, performance and usability in mind. It works efficiently across all major desktop and mobile platforms, can be extended with lots of plugins, has a beautiful, easy to use and well-documented API and a simple, readable source code that is a joy to contribute to.


2 Answers

Your zoom in/out controls are wrapped with absolutely positioned element with left:0 (due to .leaflet-left class), so float:left wouldn't help, you could align it to right by overriding left:0 by right:0, or changing .leaflet-left class to .leaflet-right

But more correct way would be to use provided api.

//disable zoomControl when initializing map (which is topleft by default) var map = L.map("map", {     zoomControl: false     //... other options });  //add zoom control with your options L.control.zoom({      position:'topright' }).addTo(map); 

see updated fiddle

api reference for the library you use can be found here

like image 105
paulitto Avatar answered Sep 24 '22 13:09

paulitto


Currently you can use:

var map = L.map('map', {   zoomControl: true }); map.zoomControl.setPosition('topright'); 
like image 35
Sebastian Nowak Avatar answered Sep 24 '22 13:09

Sebastian Nowak