1

For example if coordinates are 17.12345678, -82.12345678, and I want to convert them to 3 decimal digits.

Expected result: 17.123, -82.123

Is there any API in OpenLayers 2 to truncate coordinates (LonLat) to decimal precision?

  • Your meaning is unclear. Do you really want to snap vertices to the nearest degree? – Vince Dec 20 '18 at 11:30
  • if coordinates are 17.12345678, -82.12345678, For eg. If I want to convert them to 3 decimal digits, Expected result: 17.123, -82.123 Is there any api in openLayers 2 to achieve this? – Gunasekaran SP Dec 21 '18 at 6:00
1

If you are referring to the LonLat object you could define your own method

OpenLayers.LonLat.prototype.truncate = function(digits) {
    var pow = Math.pow(10, digits);
    return new OpenLayers.LonLat(Math.round(this.lon * pow)/pow, Math.round(this.lat * pow)/pow);
}
  • Thanks! So I presume there is no built-in api in OpenLayers 2 – Gunasekaran SP Dec 21 '18 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.