I'm rendering the mouse position like so:
map.addControl(new ol.control.MousePosition({
coordinateFormat: function (coordinate) {
return ol.coordinate.format(
coordinate,
'E {x} N {y} (' + projectionTitle + ')', 3
).replaceAll( '\.', ',' );
}
}));
The part with replaceAll works fine, but is hacky and I'd like to use a "recommended" way of formating coordinates in OL.
Any ideas?
If your users are all in the same country your solution is adequate. If you want to support individual users local number format in many countries you could use toLocaleString https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#using_options
map.addControl(new ol.control.MousePosition({
coordinateFormat: function (coordinate) {
const options = {minimumFractionDigits: 3, maximumFractionDigits: 3}
return 'E ' + coordinate[0].toLocaleString(undefined, options) +
' N ' + coordinate[1].toLocaleString(undefined, options) +
' (' + projectionTitle + ')';
}
}));