Leaflet.MousePosition icon indicating copy to clipboard operation
Leaflet.MousePosition copied to clipboard

Formatter examples

Open patmccormick opened this issue 11 years ago • 1 comments

What is the syntax for the [formatter] config values?

patmccormick avatar Oct 26 '13 01:10 patmccormick

One example of a formatter which returns numbers formatted to 3 decimal places and adds a N, S, E or W as appropriate.

var mousePosition = L.control.mousePosition({
  emptyString: '0º N<br>0º E',
  separator: '<br>',
  lngFormatter: function(num) {
    var direction = (num < 0) ? 'W' : 'E';
    var formatted = Math.abs(L.Util.formatNum(num, 3)) + 'º ' + direction;
    return formatted; 
  },
  latFormatter: function(num) {
    var direction = (num < 0) ? 'S' : 'N';
    var formatted = Math.abs(L.Util.formatNum(num, 3)) + 'º ' + direction;
    return formatted;
  }
}).addTo(map);

dankarran avatar Mar 05 '14 15:03 dankarran