From d8dba61b0a989bfd8584dab5c49d0a67aa3440ee Mon Sep 17 00:00:00 2001 From: Thomas Chandelle Date: Thu, 8 Jun 2017 12:06:40 +0200 Subject: [PATCH] Rounds if decimals options = 0 --- src/ol/format/feature.js | 2 +- test/spec/ol/format/geojson.test.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ol/format/feature.js b/src/ol/format/feature.js index 0a5e53b751..5887dcc106 100644 --- a/src/ol/format/feature.js +++ b/src/ol/format/feature.js @@ -190,7 +190,7 @@ ol.format.Feature.transformWithOptions = function( } else { transformed = geometry; } - if (write && opt_options && opt_options.decimals) { + if (write && opt_options && opt_options.decimals !== undefined) { var power = Math.pow(10, opt_options.decimals); // if decimals option on write, round each coordinate appropriately /** diff --git a/test/spec/ol/format/geojson.test.js b/test/spec/ol/format/geojson.test.js index 95b4271b92..a6b20bc652 100644 --- a/test/spec/ol/format/geojson.test.js +++ b/test/spec/ol/format/geojson.test.js @@ -829,6 +829,18 @@ describe('ol.format.GeoJSON', function() { expect(linestring.getCoordinates()).to.eql( [[42.123456789, 38.987654321], [43, 39]]); }); + + it('rounds a linestring with decimals option = 0', function() { + var linestring = new ol.geom.LineString([[42.123456789, 38.987654321], + [43, 39]]); + var geojson = format.writeGeometry(linestring, { + decimals: 0 + }); + expect(format.readGeometry(geojson).getCoordinates()).to.eql( + [[42, 39], [43, 39]]); + expect(linestring.getCoordinates()).to.eql( + [[42.123456789, 38.987654321], [43, 39]]); + }); }); });