Skip to content

Commit

Permalink
【fix】修复某些投影的无法正确计算MeterPerMapUnit失败的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
songyumeng committed Apr 23, 2024
1 parent e5224fb commit ec84818
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/common/util/MapCalculateUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,21 @@ import { Unit } from '../REST';
* ```
*/
export var getMeterPerMapUnit = function(mapUnit) {
var earchRadiusInMeters = 6378137;
var meterPerMapUnit;
if (mapUnit === Unit.METER) {
meterPerMapUnit = 1;
} else if (mapUnit === Unit.DEGREE) {
// 每度表示多少米。
meterPerMapUnit = (Math.PI * 2 * earchRadiusInMeters) / 360;
} else if (mapUnit === Unit.KILOMETER) {
meterPerMapUnit = 1.0e-3;
} else if (mapUnit === Unit.INCH) {
meterPerMapUnit = 1 / 2.5399999918e-2;
} else if (mapUnit === Unit.FOOT) {
meterPerMapUnit = 0.3048;
} else {
return meterPerMapUnit;
}
return meterPerMapUnit;
var earchRadiusInMeters = 6378137;
var meterPerMapUnit;
if (['m','meter','meters'].indexOf(mapUnit.toLocaleLowerCase())>-1) {
meterPerMapUnit = 1;
} else if (['degrees','deg','degree','dd'].indexOf(mapUnit.toLocaleLowerCase())>-1) {
// 每度表示多少米。
meterPerMapUnit = (Math.PI * 2 * earchRadiusInMeters) / 360;
} else if (mapUnit === Unit.KILOMETER) {
meterPerMapUnit = 1.0e-3;
} else if (mapUnit === Unit.INCH) {
meterPerMapUnit = 1 / 2.5399999918e-2;
} else if (mapUnit === Unit.FOOT) {
meterPerMapUnit = 0.3048;
}
return meterPerMapUnit;
};

/**
Expand Down
24 changes: 24 additions & 0 deletions test/common/util/MapCalculateUtilSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { getMeterPerMapUnit } from '../../../src/common/util/MapCalculateUtil';

describe('MapCalculateUtil', () => {
it('getMeterPerMapUnit m', () => {
expect(getMeterPerMapUnit('m')).toBe(1);
expect(getMeterPerMapUnit('M')).toBe(1);
expect(getMeterPerMapUnit('meter')).toBe(1);
expect(getMeterPerMapUnit('meters')).toBe(1);
expect(getMeterPerMapUnit('METER')).toBe(1);
expect(getMeterPerMapUnit('METERS')).toBe(1);
expect(getMeterPerMapUnit('METRE')).toBeUndefined()
});
it('getMeterPerMapUnit dge', () => {
expect(getMeterPerMapUnit('degrees')).toBeCloseTo(111319.49079327358, 0.00001);;
expect(getMeterPerMapUnit('deg')).toBeCloseTo(111319.49079327358, 0.00001);;
expect(getMeterPerMapUnit('degree')).toBeCloseTo(111319.49079327358, 0.00001);;
expect(getMeterPerMapUnit('dd')).toBeCloseTo(111319.49079327358, 0.00001);;
expect(getMeterPerMapUnit('DEGREES')).toBeCloseTo(111319.49079327358, 0.00001);;
expect(getMeterPerMapUnit('DEG')).toBeCloseTo(111319.49079327358, 0.00001);;
expect(getMeterPerMapUnit('DEGREE')).toBeCloseTo(111319.49079327358, 0.00001);;
expect(getMeterPerMapUnit('DD')).toBeCloseTo(111319.49079327358, 0.00001);;
expect(getMeterPerMapUnit('degre')).toBeUndefined()
});
});
1 change: 1 addition & 0 deletions test/test-main-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,4 @@ import './common/components/chart/ChartViewSpec';

import './common/util/FetchRequestSpec';
import './common/lang/LangSpec.js';
import './common/util/MapCalculateUtilSpec';

0 comments on commit ec84818

Please sign in to comment.