@@ -41,6 +41,8 @@ function locationToFeature(locationmode, location, features) {
41
41
var filteredFeatures ;
42
42
var f , i ;
43
43
44
+ var allParts = [ ] ;
45
+
44
46
if ( locationId ) {
45
47
if ( locationmode === 'USA-states' ) {
46
48
// Filter out features out in USA
@@ -67,8 +69,7 @@ function locationToFeature(locationmode, location, features) {
67
69
f . properties &&
68
70
f . properties . iso3cd === locationId
69
71
) {
70
- // TODO: we may need to collect all the polygons instead?
71
- return f ;
72
+ allParts . push ( f ) ;
72
73
}
73
74
}
74
75
@@ -78,10 +79,35 @@ function locationToFeature(locationmode, location, features) {
78
79
] . join ( ' ' ) ) ;
79
80
}
80
81
82
+ if ( allParts . length ) {
83
+ return allParts ; //[allParts.length - 1];
84
+ }
85
+
81
86
return false ;
82
87
}
83
88
84
89
function feature2polygons ( feature ) {
90
+ if ( ! Array . isArray ( feature ) ) {
91
+ return _feature2polygons ( feature ) ;
92
+ }
93
+
94
+ var polygons ;
95
+ for ( var i = 0 ; i < feature . length ; i ++ ) {
96
+ var pts = _feature2polygons ( feature [ i ] ) ;
97
+
98
+ if ( pts . length ) {
99
+ if ( ! polygons ) {
100
+ polygons = pts ;
101
+ } else {
102
+ polygons . push ( polygon . tester ( pts ) ) ;
103
+ }
104
+ }
105
+ }
106
+
107
+ return polygons ;
108
+ }
109
+
110
+ function _feature2polygons ( feature ) {
85
111
var geometry = feature . geometry ;
86
112
var coords = geometry . coordinates ;
87
113
var loc = feature . properties . iso3cd || feature . id ;
@@ -373,9 +399,35 @@ function fetchTraceGeoData(calcData) {
373
399
return promises ;
374
400
}
375
401
402
+
403
+ function computeBbox ( d ) {
404
+ if ( ! Array . isArray ( d ) ) {
405
+ return _computeBbox ( d ) ;
406
+ }
407
+
408
+ var minLon = Infinity ;
409
+ var maxLon = - Infinity ;
410
+ var minLat = Infinity ;
411
+ var maxLat = - Infinity ;
412
+
413
+ for ( var i = 0 ; i < d . length ; i ++ ) {
414
+ var p = _computeBbox ( d [ i ] ) ;
415
+
416
+ minLon = Math . min ( minLon , p [ 0 ] ) ;
417
+ minLat = Math . min ( minLat , p [ 1 ] ) ;
418
+ maxLon = Math . max ( maxLon , p [ 2 ] ) ;
419
+ maxLat = Math . max ( maxLat , p [ 3 ] ) ;
420
+ }
421
+
422
+ return [
423
+ minLon , minLat ,
424
+ maxLon , maxLat
425
+ ] ;
426
+ }
427
+
376
428
// TODO `turf/bbox` gives wrong result when the input feature/geometry
377
429
// crosses the anti-meridian. We should try to implement our own bbox logic.
378
- function computeBbox ( d ) {
430
+ function _computeBbox ( d ) {
379
431
return turfBbox ( d ) ;
380
432
}
381
433
0 commit comments