1
1
import { createSelector , createStructuredSelector } from 'reselect' ;
2
+ import bbox from 'turf-bbox' ;
3
+ import lineString from 'turf-linestring' ;
2
4
3
5
import {
4
6
getActiveDatasetsFromState ,
@@ -12,58 +14,70 @@ const selectSection = (state, { exploreType }) => exploreType;
12
14
const selectPTWLoading = state => state . ptw && state . ptw . loading ;
13
15
const selectPTWData = state => {
14
16
const { data } = state . ptw || { } ;
17
+
15
18
return (
16
19
data &&
17
- data . map ( d => ( {
18
- id : d . cartodb_id ,
19
- image : d . image ,
20
- imageCredit : d . image_source ,
21
- title : d . name ,
22
- summary : d . description ,
23
- buttons : [
24
- {
25
- text : 'READ MORE' ,
26
- extLink : d . link ,
27
- theme : 'theme-button-light theme-button-small'
28
- } ,
29
- {
30
- text : 'VIEW ON MAP' ,
31
- theme : 'theme-button-small'
32
- }
33
- ] ,
34
- payload : {
35
- mergeQuery : true ,
36
- map : {
37
- datasets : [
38
- // admin boundaries
39
- {
40
- dataset : 'fdc8dc1b-2728-4a79-b23f-b09485052b8d' ,
41
- layers : [
42
- '6f6798e6-39ec-4163-979e-182a74ca65ee' ,
43
- 'c5d1e010-383a-4713-9aaa-44f728c0571c'
44
- ] ,
45
- opacity : 1 ,
46
- visibility : true
47
- } ,
48
- // GLADs
49
- {
50
- dataset : 'e663eb09-04de-4f39-b871-35c6c2ed10b5' ,
51
- layers : [
52
- '581ecc62-9a70-4ef4-8384-0d59363e511d' ,
53
- 'dd5df87f-39c2-4aeb-a462-3ef969b20b66'
54
- ] ,
55
- opacity : 1 ,
56
- visibility : true ,
57
- bbox : d . bbox
58
- }
59
- ] ,
60
- basemap : {
61
- value : 'default'
20
+ data . map ( d => {
21
+ const bboxCoords = d . bbox . slice ( 0 , 4 ) ;
22
+ const bboxFromCoords = bbox ( lineString ( bboxCoords ) ) ;
23
+ const reverseBbox = [
24
+ bboxFromCoords [ 1 ] ,
25
+ bboxFromCoords [ 0 ] ,
26
+ bboxFromCoords [ 3 ] ,
27
+ bboxFromCoords [ 2 ]
28
+ ] ;
29
+
30
+ return {
31
+ id : d . cartodb_id ,
32
+ image : d . image ,
33
+ imageCredit : d . image_source ,
34
+ title : d . name ,
35
+ summary : d . description ,
36
+ buttons : [
37
+ {
38
+ text : 'READ MORE' ,
39
+ extLink : d . link ,
40
+ theme : 'theme-button-light theme-button-small'
62
41
} ,
63
- label : 'default'
42
+ {
43
+ text : 'VIEW ON MAP' ,
44
+ theme : 'theme-button-small'
45
+ }
46
+ ] ,
47
+ payload : {
48
+ mergeQuery : true ,
49
+ map : {
50
+ datasets : [
51
+ // admin boundaries
52
+ {
53
+ dataset : 'fdc8dc1b-2728-4a79-b23f-b09485052b8d' ,
54
+ layers : [
55
+ '6f6798e6-39ec-4163-979e-182a74ca65ee' ,
56
+ 'c5d1e010-383a-4713-9aaa-44f728c0571c'
57
+ ] ,
58
+ opacity : 1 ,
59
+ visibility : true
60
+ } ,
61
+ // GLADs
62
+ {
63
+ dataset : 'e663eb09-04de-4f39-b871-35c6c2ed10b5' ,
64
+ layers : [
65
+ '581ecc62-9a70-4ef4-8384-0d59363e511d' ,
66
+ 'dd5df87f-39c2-4aeb-a462-3ef969b20b66'
67
+ ] ,
68
+ opacity : 1 ,
69
+ visibility : true ,
70
+ bbox : reverseBbox
71
+ }
72
+ ] ,
73
+ basemap : {
74
+ value : 'default'
75
+ } ,
76
+ label : 'default'
77
+ }
64
78
}
65
- }
66
- } ) )
79
+ } ;
80
+ } )
67
81
) ;
68
82
} ;
69
83
0 commit comments