Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display the map scale in leaflet.js

I wonder how to display the scale map in leafleat.js. That is: I want this enter image description here instead of this enter image description here (taken to leaflet tutorial). See the left corner of the picture.

like image 572
somenxavier Avatar asked Oct 23 '16 08:10

somenxavier


People also ask

How to add a scale control to the map using leaflet?

To add a scale control of your own to the map using Leaflet JavaScript library, follow the steps given below − Step 1 − Create a Map object by passing a < div > element (String or object) and map options (optional). Step 2 − Create a Layer object by passing the URL of the desired tile.

What is leaflet JS?

Leaflet.js is a JavaScript library that makes it extremely easy to show maps on a webpage and interact with it. This guide would attempt to give a simple introduction to using Leaflet.js to display map and display the required area on the map. We will start by declaring the HTML needed to display the map.

How to zoom in/out of the map in leaflet?

Leaflet provides various controls such as zoom, attribution, scale, etc., where −. 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.

How to add map to web page using leaflet?

To add map to our web page, simple web technologies like HTML, CSS and JavaScript are required. To use Leaflet in your code, you need to add the Leaflet CSS and Leaflet JS.


1 Answers

You can take use of L.control.scale(). Here is an EXAMPLE. In it's options you can set width, position and scale system.

like image 96
Manuel Avatar answered Oct 19 '22 13:10

Manuel