Skip to content

Commit b2548f7

Browse files
committed
【fix】修复linem类型没有返回maxM minM length信息
1 parent 420ba03 commit b2548f7

File tree

2 files changed

+61
-14
lines changed

2 files changed

+61
-14
lines changed

src/common/format/GeoJSON.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -220,35 +220,39 @@ export class GeoJSON extends JSONFormat {
220220
/**
221221
* @function GeoJSONFormat.extract.feature
222222
* @description 返回一个表示单个要素对象的 GeoJSON 的一部分。
223-
* @param {SuperMap.ServerFeature} feature - SuperMap iServer 要素对象。
223+
* @param {SuperMap.ServerFeature} fea - SuperMap iServer 要素对象。
224224
* @returns {Object} 一个表示点的对象。
225225
*/
226-
'feature': function (feature, options) {
226+
'feature': function (fea, options) {
227227
var { parseProperties, extraKeys } = options || {};
228-
var geom = this.extract.geometry.apply(this, [feature.geometry]);
228+
var geom = this.extract.geometry.apply(this, [fea.geometry]);
229229
var json = {
230230
"type": "Feature",
231-
"properties": this.createAttributes(feature, parseProperties),
231+
"properties": this.createAttributes(fea, parseProperties),
232232
"geometry": geom
233233
};
234234

235-
if (feature.geometry && feature.geometry.type === 'TEXT') {
236-
json.properties.texts = feature.geometry.texts;
237-
json.properties.textStyle = feature.geometry.textStyle;
235+
if (fea.geometry && fea.geometry.type === 'TEXT') {
236+
json.properties.texts = fea.geometry.texts;
237+
json.properties.textStyle = fea.geometry.textStyle;
238238
}
239-
if (feature.fid) {
240-
json.id = feature.fid;
239+
if (fea.geometry && fea.geometry.type === 'LINEM') {
240+
json.length = fea.geometry.length;
241+
json.maxM = fea.geometry.maxM;
242+
json.minM = fea.geometry.minM;
241243
}
242-
if (feature.ID) {
243-
json.id = feature.ID;
244+
if (fea.fid) {
245+
json.id = fea.fid;
246+
}
247+
if (fea.ID) {
248+
json.id = fea.ID;
244249
}
245-
246250
var exceptKeys = ["fieldNames", "fieldValues", "geometry", "stringID", "ID"];
247-
for (var key in feature) {
251+
for (var key in fea) {
248252
if (exceptKeys.indexOf(key) > -1) {
249253
continue;
250254
}
251-
var value = this._transformValue(feature[key], parseProperties);
255+
var value = this._transformValue(fea[key], parseProperties);
252256
if (extraKeys) {
253257
json[key] = value;
254258
} else {

test/common/format/GeoJSONSpec.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,4 +978,47 @@ describe('GeoJSON', () => {
978978
expect(GeoJSON.getGeoJSONType({ type: 'GeometryCollection', geometries: [] })).toBe('Geometry');
979979
expect(GeoJSON.getGeoJSONType({ type: 'GeometryCollection', geometries: {} })).toBeNull();
980980
});
981+
it('LINEM', () => {
982+
const obj = {
983+
length: 1917.06710696352,
984+
minM: 0,
985+
type: 'LINEM',
986+
points: [
987+
{
988+
measure: 0,
989+
x: 4904.02504854072,
990+
y: -2859.76067773666,
991+
m: null
992+
},
993+
{
994+
measure: 5.02909324784013,
995+
x: 4908.0531496305,
996+
y: -2856.75409713806,
997+
m: null
998+
},
999+
{
1000+
measure: 95.3036432157134,
1001+
x: 4980.35942735994,
1002+
y: -2802.78458472214,
1003+
m: null
1004+
},
1005+
{
1006+
measure: 105.983393002926,
1007+
x: 4991.03087203703,
1008+
y: -2803.02359431299,
1009+
m: null
1010+
}
1011+
],
1012+
parts: [4],
1013+
maxM: 1918.07805168498,
1014+
style: null,
1015+
id: 0,
1016+
partTopo: null
1017+
};
1018+
const outObj = new GeoJSON().toGeoJSON(obj);
1019+
expect(outObj).not.toBeNull();
1020+
expect(outObj.maxM).toBe(1918.07805168498);
1021+
expect(outObj.length).toBe(1917.06710696352);
1022+
expect(outObj.minM).toBe(0);
1023+
});
9811024
});

0 commit comments

Comments
 (0)