Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
Open layers: coordinates with comma in decimal format

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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 + ')';
  }
}));
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!