Skip to content

Commit d9baadd

Browse files
committed
【fix】ISVJ-6541 L对象转geojson时支持设置保留精度值
1 parent efddade commit d9baadd

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/leaflet/core/Base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function wrapToGeoJSON(objClassArray) {
3030
objClass.defaultFunction = objClass.prototype.toGeoJSON;
3131
objClass.include({
3232
toGeoJSON: function (precision) {
33-
return objClass.defaultFunction.call(this, precision || 10);
33+
return objClass.defaultFunction.call(this, precision || L.toGeoJSONPrecision || 15);
3434
}
3535
})
3636
return objClass;

test/leaflet/core/BaseSpec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import '../../../src/leaflet/core/Base';
2+
import L from "leaflet";
3+
4+
describe('Base', () => {
5+
it("toGeoJSON precision", () => {
6+
const p = L.marker([10.12345678912345, 4.12345678912345]);
7+
expect(p.toGeoJSON().geometry.coordinates[0]).toEqual(4.12345678912345);
8+
});
9+
it("toGeoJSON toGeoJSONPrecision", () => {
10+
L.toGeoJSONPrecision = 8;
11+
const p = L.marker([10.12345678912345, 4.12345678912345]);
12+
expect(p.toGeoJSON().geometry.coordinates[0]).toEqual(4.12345679);
13+
});
14+
});

test/test-main-leaflet.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import './leaflet/control/ChangeTileVersionSpec.js';
55
import './leaflet/core/NonEarthCRSSpec.js';
66
import './leaflet/core/TransformUtilSpec.js';
77
import './leaflet/core/Proj4LeafletSpec.js';
8+
import './leaflet/core/BaseSpec.js';
89

910
/*leaflet -- mapping*/
1011
import './leaflet/mapping/ImageMapLayerSpec.js';

0 commit comments

Comments
 (0)