Rounds if decimals options = 0

This commit is contained in:
Thomas Chandelle
2017-06-08 12:06:40 +02:00
parent b8117b3931
commit d8dba61b0a
2 changed files with 13 additions and 1 deletions

View File

@@ -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
/**

View File

@@ -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]]);
});
});
});