@@ -259,8 +259,8 @@ export class GeoJSON extends JSONFormat {
259
259
if ( ! geometry . parts && geometry . points ) {
260
260
geometry . parts = [ geometry . points . length ] ;
261
261
}
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 ;
264
264
var data ;
265
265
if ( geometryType === "LinearRing" ) {
266
266
geometryType = "LineString" ;
@@ -502,12 +502,18 @@ export class GeoJSON extends JSONFormat {
502
502
*/
503
503
fromGeoJSON ( json , type , filter ) {
504
504
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
+ } )
506
511
}
512
+
507
513
/**
508
514
* @function SuperMap.Format.GeoJSON.prototype.toGeoJSON
509
515
* @version 9.1.1
510
- * @description 将 GeoJSON 对象或者GeoJSON 对象字符串转换为iServer Feature JSON。
516
+ * @description 将 iServer Feature JSON 对象转换为 GeoJSON 对象 。
511
517
* @param {Object } obj - iServer Feature JSON。
512
518
* @returns {GeoJSONObject } GeoJSON 对象。
513
519
*/
@@ -533,6 +539,8 @@ export class GeoJSON extends JSONFormat {
533
539
let feature = { } ;
534
540
feature . geometry = obj ;
535
541
geojson = this . extract . feature . apply ( this , [ feature ] ) ;
542
+ } else {
543
+ geojson = this . extract . feature . apply ( this , [ obj ] ) ;
536
544
}
537
545
538
546
function isGeometry ( input ) {
@@ -553,10 +561,10 @@ export class GeoJSON extends JSONFormat {
553
561
switch ( type ) {
554
562
case "Geometry" :
555
563
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 ) {
560
568
// unsupported geometry type
561
569
//SuperMap.Console.error("Unsupported geometry type: " +
562
570
// obj.type);
@@ -682,7 +690,22 @@ export class GeoJSON extends JSONFormat {
682
690
}
683
691
return crs ;
684
692
}
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
+ }
686
709
createAttributes ( feature ) {
687
710
if ( ! feature ) {
688
711
return null ;
0 commit comments