How to add a scale bar to a leaflet map?

1,536 views
Skip to first unread message

Tom Porteus

unread,
Oct 14, 2015, 9:40:05 AM10/14/15
to Shiny - Web Framework for R
Hi everyone,

I'm creating an interactive map using leaflet which I want to incorporate into a shiny app.  I am pretty much there with it but am stuck on how to add a scale bar to a leaflet map.  I can only think it is via addControl() but I have not been able to get it to work.  The relevant leaflet js command is L.control.scale().addTo(map);.  I'm not sure how to translate this into something which R will use with the addControl() function.  Or perhaps I am just barking up the wrong tree?

A scale bar seems a fairly generic feature so presumably someone out there has managed to get it to work?  I'll look forward to hearing from you!

Many thanks,

Tom

John Goldin

unread,
Jun 29, 2016, 10:13:01 PM6/29/16
to Shiny - Web Framework for R
Did you ever figure this out? I have been doing some googling, but have not found any examples of how to use addControl with any of the variations in the Leaflet api documentation.

Martin Lavoie

unread,
Jun 30, 2016, 7:00:23 AM6/30/16
to Shiny - Web Framework for R
Hi!

you just need to add addScaleBar(position = c("bottomleft")) to your map!

Martin

John Goldin

unread,
Jun 30, 2016, 9:19:35 PM6/30/16
to Shiny - Web Framework for R
With Leaflet 1.0.1 from the repository I don't have addScaleBar. I Installed leaflet_1.0.1.9004 from github and it worked.  I'll wait until a leaflet update is released before I try to use addScaleBar with my published map.
Reply all
Reply to author
Forward
0 new messages