| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 420ba03 commit b2548f7
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -220,35 +220,39 @@ export class GeoJSON extends JSONFormat { | |||
| 220 | 220 | /** | |
| 221 | 221 | * @function GeoJSONFormat.extract.feature | |
| 222 | 222 | * @description 返回一个表示单个要素对象的 GeoJSON 的一部分。 | |
| 223 | - * @param {SuperMap.ServerFeature} feature - SuperMap iServer 要素对象。 | ||
| 223 | + * @param {SuperMap.ServerFeature} fea - SuperMap iServer 要素对象。 | ||
| 224 | 224 | * @returns {Object} 一个表示点的对象。 | |
| 225 | 225 | */ | |
| 226 | - 'feature': function (feature, options) { | ||
| 226 | + 'feature': function (fea, options) { | ||
| 227 | 227 | var { parseProperties, extraKeys } = options || {}; | |
| 228 | - var geom = this.extract.geometry.apply(this, [feature.geometry]); | ||
| 228 | + var geom = this.extract.geometry.apply(this, [fea.geometry]); | ||
| 229 | 229 | var json = { | |
| 230 | 230 | "type": "Feature", | |
| 231 | - "properties": this.createAttributes(feature, parseProperties), | ||
| 231 | + "properties": this.createAttributes(fea, parseProperties), | ||
| 232 | 232 | "geometry": geom | |
| 233 | 233 | }; | |
| 234 | 234 | ||
| 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; | ||
| 238 | 238 | } | |
| 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; | ||
| 241 | 243 | } | |
| 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; | ||
| 244 | 249 | } | |
| 245 | - | ||
| 246 | 250 | var exceptKeys = ["fieldNames", "fieldValues", "geometry", "stringID", "ID"]; | |
| 247 | - for (var key in feature) { | ||
| 251 | + for (var key in fea) { | ||
| 248 | 252 | if (exceptKeys.indexOf(key) > -1) { | |
| 249 | 253 | continue; | |
| 250 | 254 | } | |
| 251 | - var value = this._transformValue(feature[key], parseProperties); | ||
| 255 | + var value = this._transformValue(fea[key], parseProperties); | ||
| 252 | 256 | if (extraKeys) { | |
| 253 | 257 | json[key] = value; | |
| 254 | 258 | } else { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -978,4 +978,47 @@ describe('GeoJSON', () => { | |||
| 978 | 978 | expect(GeoJSON.getGeoJSONType({ type: 'GeometryCollection', geometries: [] })).toBe('Geometry'); | |
| 979 | 979 | expect(GeoJSON.getGeoJSONType({ type: 'GeometryCollection', geometries: {} })).toBeNull(); | |
| 980 | 980 | }); | |
| 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 | + }); | ||
| 981 | 1024 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments