Leaflet.MousePosition
Leaflet.MousePosition copied to clipboard
Formatter examples
What is the syntax for the [formatter] config values?
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);