File tree Expand file tree Collapse file tree 6 files changed +148
-3
lines changed Expand file tree Collapse file tree 6 files changed +148
-3
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ export const Util = {
4242 if ( geoJSON && geoJSON . type ) {
4343 var format = new GeoJSONFormat ( ) ;
4444 var result = format . read ( geoJSON , "FeatureCollection" ) ;
45- return result [ 0 ] . geometry ;
45+ return result && result [ 0 ] . geometry ;
4646 }
4747 } ,
4848
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ export const Util = {
4242 if ( geoJSON && geoJSON . type ) {
4343 var format = new GeoJSONFormat ( ) ;
4444 var result = format . read ( geoJSON , "FeatureCollection" ) ;
45- return result [ 0 ] . geometry ;
45+ return result && result [ 0 ] . geometry ;
4646 }
4747 } ,
4848
Original file line number Diff line number Diff line change 7676 return null ;
7777 }
7878 const result = new GeoJSONFormat ( ) . read ( geoJSON , 'FeatureCollection' ) ;
79- return result [ 0 ] . geometry ;
79+ return result && result [ 0 ] . geometry ;
8080 } ,
8181
8282 /**
Original file line number Diff line number Diff line change @@ -39,4 +39,65 @@ describe('Util', () => {
3939 expect ( Util . isMatchAdministrativeName ( '北京' , '北京市' ) ) . toBeTruthy ( ) ;
4040 expect ( Util . isMatchAdministrativeName ( '北京' , null ) ) . toBeFalsy ( ) ;
4141 } ) ;
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+ } ) ;
42103} ) ;
Original file line number Diff line number Diff line change @@ -39,4 +39,65 @@ describe('Util', () => {
3939 expect ( Util . isMatchAdministrativeName ( '北京' , '北京市' ) ) . toBeTruthy ( ) ;
4040 expect ( Util . isMatchAdministrativeName ( '北京' , null ) ) . toBeFalsy ( ) ;
4141 } ) ;
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+ } ) ;
42103} ) ;
Original file line number Diff line number Diff line change @@ -121,6 +121,29 @@ describe('openlayers_Util', () => {
121121 expect ( point instanceof Point ) . toBeTruthy ( ) ;
122122 expect ( point . x ) . toBe ( - 2 ) ;
123123 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 ( ) ;
124147 } ) ;
125148
126149 it ( 'resolutionToScale' , ( ) => {
You can’t perform that action at this time.
0 commit comments