@@ -259,8 +259,8 @@ export class GeoJSON extends JSONFormat {
259259 if ( ! geometry . parts && geometry . points ) {
260260 geometry . parts = [ geometry . points . length ] ;
261261 }
262- var geo = new ServerGeometry ( geometry ) . toGeometry ( ) || geometry ;
263- var geometryType = geo . geometryType || geo . type ;
262+ var geo = new ServerGeometry ( geometry ) . toGeometry ( ) || geometry ;
263+ var geometryType = geo . geometryType || geo . type ;
264264 var data ;
265265 if ( geometryType === "LinearRing" ) {
266266 geometryType = "LineString" ;
@@ -502,12 +502,18 @@ export class GeoJSON extends JSONFormat {
502502 */
503503 fromGeoJSON ( json , type , filter ) {
504504 let feature = this . read ( json , type , filter ) ;
505- return ServerGeometry . fromGeometry ( feature ) ;
505+ if ( ! Util . isArray ( feature ) ) {
506+ return this . _toiSevrerFeature ( feature ) ;
507+ }
508+ return feature . map ( ( element ) => {
509+ return this . _toiSevrerFeature ( element ) ;
510+ } )
506511 }
512+
507513 /**
508514 * @function SuperMap.Format.GeoJSON.prototype.toGeoJSON
509515 * @version 9.1.1
510- * @description 将 GeoJSON 对象或者GeoJSON 对象字符串转换为iServer Feature JSON。
516+ * @description 将 iServer Feature JSON 对象转换为 GeoJSON 对象 。
511517 * @param {Object } obj - iServer Feature JSON。
512518 * @returns {GeoJSONObject } GeoJSON 对象。
513519 */
@@ -533,6 +539,8 @@ export class GeoJSON extends JSONFormat {
533539 let feature = { } ;
534540 feature . geometry = obj ;
535541 geojson = this . extract . feature . apply ( this , [ feature ] ) ;
542+ } else {
543+ geojson = this . extract . feature . apply ( this , [ obj ] ) ;
536544 }
537545
538546 function isGeometry ( input ) {
@@ -553,10 +561,10 @@ export class GeoJSON extends JSONFormat {
553561 switch ( type ) {
554562 case "Geometry" :
555563 if ( Util . indexOf (
556- [ "Point" , "MultiPoint" , "LineString" , "MultiLineString" ,
557- "Polygon" , "MultiPolygon" , "Box" , "GeometryCollection"
558- ] ,
559- obj . type ) == - 1 ) {
564+ [ "Point" , "MultiPoint" , "LineString" , "MultiLineString" ,
565+ "Polygon" , "MultiPolygon" , "Box" , "GeometryCollection"
566+ ] ,
567+ obj . type ) == - 1 ) {
560568 // unsupported geometry type
561569 //SuperMap.Console.error("Unsupported geometry type: " +
562570 // obj.type);
@@ -682,7 +690,22 @@ export class GeoJSON extends JSONFormat {
682690 }
683691 return crs ;
684692 }
685-
693+ _toiSevrerFeature ( feature ) {
694+ const attributes = feature . attributes ;
695+ const attrNames = [ ] ;
696+ const attrValues = [ ] ;
697+ for ( var attr in attributes ) {
698+ attrNames . push ( attr ) ;
699+ attrValues . push ( attributes [ attr ] ) ;
700+ }
701+ const newFeature = {
702+ fieldNames : attrNames ,
703+ fieldValues : attrValues ,
704+ geometry : ServerGeometry . fromGeometry ( feature . geometry )
705+ } ;
706+ newFeature . geometry . id = feature . fid ;
707+ return newFeature ;
708+ }
686709 createAttributes ( feature ) {
687710 if ( ! feature ) {
688711 return null ;
0 commit comments