Adding Map scale and North Arrow to a Leaflet powered map

This post will demonstrate how to add a North Arrow and map scale to a leaflet powered map.

 

 

– Add the Leaflet L.scale control to add a map scale.

 

L.control.scale().addTo(map);

 

For the North arrow, we got a png image from the internet and using image

tag to add it as an inner div element on the map.Leaflet L.control to position

the image within the canvas of the web map.

 

var north = L.control({position: “topright”});
north.onAdd = function(map) {
var div = L.DomUtil.create(“div”, “info legend”);
div.innerHTML = ‘<img src=”http://inkwellideas.com/wp-content/uploads/2014/01/north_arrow_2.png” width=50 height=50 />’;
return div;
};
north.addTo(map);

 

Screenshot of example with North arrow(red boxed in upper right corner of the screenshot)

and scale bar in the lower left corner of the screenshot.

Capture-4

 

See live map by clicking:

https://htmlpreview.github.io/?https://github.com/mayotunde/simple/blob/gh-pages/scalebarnortharrow

 

Download the plain text version of the source code here- https://www.dropbox.com/s/6by419p0mry5m2a/Adding%20scale%20and%20north%20arrow%20to%20leaflet%20map.txt?dl=0

 

Source code below:
Document3-001

Thank you for following the blog.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s