Merge pull request #6893 from tchandelle/decimals
Fix decimals options when writing features
This commit is contained in:
@@ -183,14 +183,14 @@ ol.format.Feature.transformWithOptions = function(
|
|||||||
// FIXME this is necessary because ol.format.GML treats extents
|
// FIXME this is necessary because ol.format.GML treats extents
|
||||||
// as geometries
|
// as geometries
|
||||||
transformed = ol.proj.transformExtent(
|
transformed = ol.proj.transformExtent(
|
||||||
write ? geometry.slice() : geometry,
|
geometry,
|
||||||
write ? featureProjection : dataProjection,
|
dataProjection,
|
||||||
write ? dataProjection : featureProjection);
|
featureProjection);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
transformed = geometry;
|
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);
|
var power = Math.pow(10, opt_options.decimals);
|
||||||
// if decimals option on write, round each coordinate appropriately
|
// if decimals option on write, round each coordinate appropriately
|
||||||
/**
|
/**
|
||||||
@@ -203,11 +203,10 @@ ol.format.Feature.transformWithOptions = function(
|
|||||||
}
|
}
|
||||||
return coordinates;
|
return coordinates;
|
||||||
};
|
};
|
||||||
if (Array.isArray(transformed)) {
|
if (transformed === geometry) {
|
||||||
transform(transformed);
|
transformed = transformed.clone();
|
||||||
} else {
|
|
||||||
transformed.applyTransform(transform);
|
|
||||||
}
|
}
|
||||||
|
transformed.applyTransform(transform);
|
||||||
}
|
}
|
||||||
return transformed;
|
return transformed;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -826,6 +826,20 @@ describe('ol.format.GeoJSON', function() {
|
|||||||
});
|
});
|
||||||
expect(format.readGeometry(geojson).getCoordinates()).to.eql(
|
expect(format.readGeometry(geojson).getCoordinates()).to.eql(
|
||||||
[[42.123457, 38.987654], [43, 39]]);
|
[[42.123457, 38.987654], [43, 39]]);
|
||||||
|
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]]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user