File tree 6 files changed +148
-3
lines changed
6 files changed +148
-3
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ export const Util = {
42
42
if ( geoJSON && geoJSON . type ) {
43
43
var format = new GeoJSONFormat ( ) ;
44
44
var result = format . read ( geoJSON , "FeatureCollection" ) ;
45
- return result [ 0 ] . geometry ;
45
+ return result && result [ 0 ] . geometry ;
46
46
}
47
47
} ,
48
48
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ export const Util = {
42
42
if ( geoJSON && geoJSON . type ) {
43
43
var format = new GeoJSONFormat ( ) ;
44
44
var result = format . read ( geoJSON , "FeatureCollection" ) ;
45
- return result [ 0 ] . geometry ;
45
+ return result && result [ 0 ] . geometry ;
46
46
}
47
47
} ,
48
48
Original file line number Diff line number Diff line change 76
76
return null ;
77
77
}
78
78
const result = new GeoJSONFormat ( ) . read ( geoJSON , 'FeatureCollection' ) ;
79
- return result [ 0 ] . geometry ;
79
+ return result && result [ 0 ] . geometry ;
80
80
} ,
81
81
82
82
/**
Original file line number Diff line number Diff line change @@ -39,4 +39,65 @@ describe('Util', () => {
39
39
expect ( Util . isMatchAdministrativeName ( '北京' , '北京市' ) ) . toBeTruthy ( ) ;
40
40
expect ( Util . isMatchAdministrativeName ( '北京' , null ) ) . toBeFalsy ( ) ;
41
41
} ) ;
42
+ it ( 'toSuperMapGeometry' , ( ) => {
43
+ var geoJSON = {
44
+ type : 'FeatureCollection' ,
45
+ features : [
46
+ {
47
+ type : 'Feature' ,
48
+ properties : {
49
+ attributes : {
50
+ SmArea : '1.6060069623493825E15' ,
51
+ SmGeoPosition : '65536' ,
52
+ SmID : '1' ,
53
+ SmPerimeter : '1.6030006674231339E8'
54
+ } ,
55
+ id : 1 ,
56
+ layerName : 'World@China' ,
57
+ searchValues : '' ,
58
+ type : 'REGION'
59
+ } ,
60
+ geometry : {
61
+ type : 'MultiPolygon' ,
62
+ coordinates : [
63
+ [
64
+ [
65
+ [ - 2 , 258 ] ,
66
+ [ 258 , 258 ] ,
67
+ [ - 2 , 258 ] ,
68
+ [ - 2 , 258 ]
69
+ ]
70
+ ]
71
+ ]
72
+ }
73
+ }
74
+ ]
75
+ } ;
76
+ var result = Util . toSuperMapGeometry ( geoJSON ) ;
77
+ expect ( result ) . not . toBeNull ( ) ;
78
+
79
+ var geoJSON2 = {
80
+ type : 'FeatureCollection' ,
81
+ features : [
82
+ {
83
+ type : 'Feature' ,
84
+ properties : {
85
+ attributes : {
86
+ SmArea : '1.6060069623493825E15' ,
87
+ SmGeoPosition : '65536' ,
88
+ SmID : '1' ,
89
+ SmPerimeter : '1.6030006674231339E8'
90
+ } ,
91
+ id : 1 ,
92
+ layerName : 'World@China' ,
93
+ searchValues : '' ,
94
+ type : 'REGION'
95
+ } ,
96
+ geometry : null
97
+ }
98
+ ]
99
+ } ;
100
+ var result2 = Util . toSuperMapGeometry ( geoJSON2 ) ;
101
+ expect ( result2 ) . toBeNull ( ) ;
102
+ } ) ;
42
103
} ) ;
Original file line number Diff line number Diff line change @@ -39,4 +39,65 @@ describe('Util', () => {
39
39
expect ( Util . isMatchAdministrativeName ( '北京' , '北京市' ) ) . toBeTruthy ( ) ;
40
40
expect ( Util . isMatchAdministrativeName ( '北京' , null ) ) . toBeFalsy ( ) ;
41
41
} ) ;
42
+ it ( 'toSuperMapGeometry' , ( ) => {
43
+ var geoJSON = {
44
+ type : 'FeatureCollection' ,
45
+ features : [
46
+ {
47
+ type : 'Feature' ,
48
+ properties : {
49
+ attributes : {
50
+ SmArea : '1.6060069623493825E15' ,
51
+ SmGeoPosition : '65536' ,
52
+ SmID : '1' ,
53
+ SmPerimeter : '1.6030006674231339E8'
54
+ } ,
55
+ id : 1 ,
56
+ layerName : 'World@China' ,
57
+ searchValues : '' ,
58
+ type : 'REGION'
59
+ } ,
60
+ geometry : {
61
+ type : 'MultiPolygon' ,
62
+ coordinates : [
63
+ [
64
+ [
65
+ [ - 2 , 258 ] ,
66
+ [ 258 , 258 ] ,
67
+ [ - 2 , 258 ] ,
68
+ [ - 2 , 258 ]
69
+ ]
70
+ ]
71
+ ]
72
+ }
73
+ }
74
+ ]
75
+ } ;
76
+ var result = Util . toSuperMapGeometry ( geoJSON ) ;
77
+ expect ( result ) . not . toBeNull ( ) ;
78
+
79
+ var geoJSON2 = {
80
+ type : 'FeatureCollection' ,
81
+ features : [
82
+ {
83
+ type : 'Feature' ,
84
+ properties : {
85
+ attributes : {
86
+ SmArea : '1.6060069623493825E15' ,
87
+ SmGeoPosition : '65536' ,
88
+ SmID : '1' ,
89
+ SmPerimeter : '1.6030006674231339E8'
90
+ } ,
91
+ id : 1 ,
92
+ layerName : 'World@China' ,
93
+ searchValues : '' ,
94
+ type : 'REGION'
95
+ } ,
96
+ geometry : null
97
+ }
98
+ ]
99
+ } ;
100
+ var result2 = Util . toSuperMapGeometry ( geoJSON2 ) ;
101
+ expect ( result2 ) . toBeNull ( ) ;
102
+ } ) ;
42
103
} ) ;
Original file line number Diff line number Diff line change @@ -121,6 +121,29 @@ describe('openlayers_Util', () => {
121
121
expect ( point instanceof Point ) . toBeTruthy ( ) ;
122
122
expect ( point . x ) . toBe ( - 2 ) ;
123
123
expect ( point . y ) . toBe ( 258 ) ;
124
+ var geoJSON2 = {
125
+ type : 'FeatureCollection' ,
126
+ features : [
127
+ {
128
+ type : 'Feature' ,
129
+ properties : {
130
+ attributes : {
131
+ SmArea : '1.6060069623493825E15' ,
132
+ SmGeoPosition : '65536' ,
133
+ SmID : '1' ,
134
+ SmPerimeter : '1.6030006674231339E8'
135
+ } ,
136
+ id : 1 ,
137
+ layerName : 'World@China' ,
138
+ searchValues : '' ,
139
+ type : 'REGION'
140
+ } ,
141
+ geometry : null
142
+ }
143
+ ]
144
+ } ;
145
+ var result2 = Util . toSuperMapGeometry ( geoJSON2 ) ;
146
+ expect ( result2 ) . toBeNull ( ) ;
124
147
} ) ;
125
148
126
149
it ( 'resolutionToScale' , ( ) => {
You can’t perform that action at this time.
0 commit comments