File tree Expand file tree Collapse file tree 6 files changed +156
-3
lines changed Expand file tree Collapse file tree 6 files changed +156
-3
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ export const Util = {
4545 if ( geoJSON && geoJSON . type ) {
4646 var format = new GeoJSONFormat ( ) ;
4747 var result = format . read ( geoJSON , "FeatureCollection" ) ;
48- return result [ 0 ] . geometry ;
48+ return result && result [ 0 ] . geometry ;
4949 }
5050 } ,
5151
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ export const Util = {
4545 if ( geoJSON && geoJSON . type ) {
4646 var format = new GeoJSONFormat ( ) ;
4747 var result = format . read ( geoJSON , "FeatureCollection" ) ;
48- return result [ 0 ] . geometry ;
48+ return result && result [ 0 ] . geometry ;
4949 }
5050 } ,
5151
Original file line number Diff line number Diff line change 7272 return null ;
7373 }
7474 const result = new GeoJSONFormat ( ) . read ( geoJSON , 'FeatureCollection' ) ;
75- return result [ 0 ] . geometry ;
75+ return result && result [ 0 ] . geometry ;
7676 } ,
7777
7878 /**
Original file line number Diff line number Diff line change 1+ import { Util } from '../../../src/mapboxgl/core/Util' ;
2+
3+ describe ( 'Util' , ( ) => {
4+ it ( 'toSuperMapGeometry' , ( ) => {
5+ var geoJSON = {
6+ type : 'FeatureCollection' ,
7+ features : [
8+ {
9+ type : 'Feature' ,
10+ properties : {
11+ attributes : {
12+ SmArea : '1.6060069623493825E15' ,
13+ SmGeoPosition : '65536' ,
14+ SmID : '1' ,
15+ SmPerimeter : '1.6030006674231339E8'
16+ } ,
17+ id : 1 ,
18+ layerName : 'World@China' ,
19+ searchValues : '' ,
20+ type : 'REGION'
21+ } ,
22+ geometry : {
23+ type : 'MultiPolygon' ,
24+ coordinates : [
25+ [
26+ [
27+ [ - 2 , 258 ] ,
28+ [ 258 , 258 ] ,
29+ [ - 2 , 258 ] ,
30+ [ - 2 , 258 ]
31+ ]
32+ ]
33+ ]
34+ }
35+ }
36+ ]
37+ } ;
38+ var result = Util . toSuperMapGeometry ( geoJSON ) ;
39+ expect ( result ) . not . toBeNull ( ) ;
40+
41+ var geoJSON2 = {
42+ type : 'FeatureCollection' ,
43+ features : [
44+ {
45+ type : 'Feature' ,
46+ properties : {
47+ attributes : {
48+ SmArea : '1.6060069623493825E15' ,
49+ SmGeoPosition : '65536' ,
50+ SmID : '1' ,
51+ SmPerimeter : '1.6030006674231339E8'
52+ } ,
53+ id : 1 ,
54+ layerName : 'World@China' ,
55+ searchValues : '' ,
56+ type : 'REGION'
57+ } ,
58+ geometry : null
59+ }
60+ ]
61+ } ;
62+ var result2 = Util . toSuperMapGeometry ( geoJSON2 ) ;
63+ expect ( result2 ) . toBeNull ( ) ;
64+ } ) ;
65+ } ) ;
Original file line number Diff line number Diff line change 1+ import { Util } from '../../../src/maplibregl/core/Util' ;
2+
3+ describe ( 'Util' , ( ) => {
4+ it ( 'toSuperMapGeometry' , ( ) => {
5+ var geoJSON = {
6+ type : 'FeatureCollection' ,
7+ features : [
8+ {
9+ type : 'Feature' ,
10+ properties : {
11+ attributes : {
12+ SmArea : '1.6060069623493825E15' ,
13+ SmGeoPosition : '65536' ,
14+ SmID : '1' ,
15+ SmPerimeter : '1.6030006674231339E8'
16+ } ,
17+ id : 1 ,
18+ layerName : 'World@China' ,
19+ searchValues : '' ,
20+ type : 'REGION'
21+ } ,
22+ geometry : {
23+ type : 'MultiPolygon' ,
24+ coordinates : [
25+ [
26+ [
27+ [ - 2 , 258 ] ,
28+ [ 258 , 258 ] ,
29+ [ - 2 , 258 ] ,
30+ [ - 2 , 258 ]
31+ ]
32+ ]
33+ ]
34+ }
35+ }
36+ ]
37+ } ;
38+ var result = Util . toSuperMapGeometry ( geoJSON ) ;
39+ expect ( result ) . not . toBeNull ( ) ;
40+
41+ var geoJSON2 = {
42+ type : 'FeatureCollection' ,
43+ features : [
44+ {
45+ type : 'Feature' ,
46+ properties : {
47+ attributes : {
48+ SmArea : '1.6060069623493825E15' ,
49+ SmGeoPosition : '65536' ,
50+ SmID : '1' ,
51+ SmPerimeter : '1.6030006674231339E8'
52+ } ,
53+ id : 1 ,
54+ layerName : 'World@China' ,
55+ searchValues : '' ,
56+ type : 'REGION'
57+ } ,
58+ geometry : null
59+ }
60+ ]
61+ } ;
62+ var result2 = Util . toSuperMapGeometry ( geoJSON2 ) ;
63+ expect ( result2 ) . toBeNull ( ) ;
64+ } ) ;
65+ } ) ;
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