Skip to content

Commit 0d8fa18

Browse files
authored
Merge pull request #3702 from Vizzuality/feature/mapbox-gl
GFW 4.0: MapboxGL + Vector Plantations Layer
2 parents 0c4fc5d + 8f65ac2 commit 0d8fa18

File tree

41 files changed

+2099
-926
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2099
-926
lines changed

app/javascript/app/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import 'babel-polyfill';
2+
3+
// babel -> core-js shims that aren't yet fully supported
4+
import 'core-js/modules/es7.promise.finally'; // eslint-disable-line import/no-extraneous-dependencies
5+
import 'core-js/modules/es7.promise.try'; // eslint-disable-line import/no-extraneous-dependencies
6+
27
import React from 'react';
38
import { Provider } from 'react-redux';
49
import { HelmetProvider } from 'react-helmet-async';
Loading

app/javascript/components/maps/components/analysis/selectors.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export const getLayerEndpoints = createSelector(
119119
);
120120

121121
const groupedEndpoints = groupBy(endpoints, 'slug');
122-
const parsedEndpoints = Object.keys(groupedEndpoints).map(slug => {
122+
const parsedEndpoints = Object.keys(groupedEndpoints).filter(slug => slug !== 'undefined').map(slug => {
123123
let params = {};
124124
groupedEndpoints[slug].forEach(e => {
125125
params = {

app/javascript/components/maps/components/menu/components/sections/explore/explore-sections.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const stories = {
3636
lat: 27,
3737
lng: 12
3838
},
39-
zoom: 3,
39+
zoom: 2,
4040
datasets: [
4141
// admin boundaries
4242
{
@@ -82,7 +82,7 @@ export const stories = {
8282
lat: 27,
8383
lng: 12
8484
},
85-
zoom: 3,
85+
zoom: 2,
8686
datasets: [
8787
// admin boundaries
8888
{
@@ -128,7 +128,7 @@ export const stories = {
128128
lat: 27,
129129
lng: 12
130130
},
131-
zoom: 3,
131+
zoom: 2,
132132
datasets: [
133133
// admin boundaries
134134
{
@@ -170,7 +170,7 @@ export const topics = {
170170
lat: 27,
171171
lng: 12
172172
},
173-
zoom: 3,
173+
zoom: 2,
174174
datasets: [
175175
// admin boundaries
176176
{
@@ -221,7 +221,7 @@ export const topics = {
221221
lat: 27,
222222
lng: 12
223223
},
224-
zoom: 3,
224+
zoom: 2,
225225
datasets: [
226226
// admin boundaries
227227
{
@@ -269,7 +269,7 @@ export const topics = {
269269
lat: 27,
270270
lng: 12
271271
},
272-
zoom: 3,
272+
zoom: 2,
273273
datasets: [
274274
// admin boundaries
275275
{
@@ -305,7 +305,7 @@ export const topics = {
305305
// wood fiber
306306
{
307307
dataset: '93e67a77-1a31-4d04-a75d-86a4d6e35d54',
308-
layers: ['557dc2cf-0ba7-4410-813c-99d692725fe7'],
308+
layers: ['f680828e-be68-4895-b1ed-1d0915d07457'],
309309
opacity: 1,
310310
visibility: true
311311
},
@@ -341,7 +341,7 @@ export const topics = {
341341
lat: 27,
342342
lng: 12
343343
},
344-
zoom: 3,
344+
zoom: 2,
345345
datasets: [
346346
// admin boundaries
347347
{

app/javascript/components/maps/components/menu/components/sections/explore/explore-selectors.js

+62-48
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { createSelector, createStructuredSelector } from 'reselect';
2+
import bbox from 'turf-bbox';
3+
import lineString from 'turf-linestring';
24

35
import {
46
getActiveDatasetsFromState,
@@ -12,58 +14,70 @@ const selectSection = (state, { exploreType }) => exploreType;
1214
const selectPTWLoading = state => state.ptw && state.ptw.loading;
1315
const selectPTWData = state => {
1416
const { data } = state.ptw || {};
17+
1518
return (
1619
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'
6241
},
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+
}
6478
}
65-
}
66-
}))
79+
};
80+
})
6781
);
6882
};
6983

app/javascript/components/maps/main-map/components/data-analysis-menu/component.jsx

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class DataAnalysisMenu extends PureComponent {
1414
links,
1515
clearAnalysisError,
1616
setMainMapSettings,
17+
setMapSettings,
1718
showAnalysis,
1819
hidden
1920
} = this.props;
@@ -27,6 +28,7 @@ class DataAnalysisMenu extends PureComponent {
2728
(showAnalysis && l.active && !hidden) ||
2829
(!showAnalysis && l.active && !hidden)
2930
});
31+
setMapSettings({ draw: false });
3032
clearAnalysisError();
3133
}
3234
}));
@@ -70,6 +72,7 @@ DataAnalysisMenu.propTypes = {
7072
menuSection: PropTypes.object,
7173
links: PropTypes.array,
7274
setMainMapSettings: PropTypes.func,
75+
setMapSettings: PropTypes.func,
7376
clearAnalysisError: PropTypes.func,
7477
embed: PropTypes.bool
7578
};

app/javascript/components/maps/main-map/components/data-analysis-menu/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { connect } from 'react-redux';
22

33
import { clearAnalysisError } from 'components/maps/components/analysis/actions';
44
import { setMainMapSettings } from 'components/maps/main-map/actions';
5+
import { setMapSettings } from 'components/maps/map/actions';
56
import { getDataAnalysisMenuProps } from './selectors';
67
import Component from './component';
78

89
export default connect(getDataAnalysisMenuProps, {
910
clearAnalysisError,
10-
setMainMapSettings
11+
setMainMapSettings,
12+
setMapSettings
1113
})(Component);

app/javascript/components/maps/main-map/components/map-controls/map-controls-component.jsx

+8-12
Original file line numberDiff line numberDiff line change
@@ -196,29 +196,29 @@ class MapControlsButtons extends PureComponent {
196196

197197
renderZoomButtons = () => {
198198
const { mapSettings, setMapSettings } = this.props;
199-
const { zoom, minZoom, maxZoom } = mapSettings || {};
199+
const { minZoom, maxZoom, zoom } = mapSettings || {};
200200

201201
return (
202202
<Fragment>
203203
<Button
204204
theme="theme-button-map-control"
205205
onClick={() => {
206-
setMapSettings({ zoom: zoom - 1 });
206+
setMapSettings({ zoom: zoom - 1 < minZoom ? minZoom : zoom - 1 });
207207
track('zoomOut');
208208
}}
209209
tooltip={{ text: 'Zoom out' }}
210-
disabled={zoom === minZoom}
210+
disabled={zoom <= minZoom}
211211
>
212212
<Icon icon={minusIcon} className="minus-icon" />
213213
</Button>
214214
<Button
215215
theme="theme-button-map-control"
216216
onClick={() => {
217-
setMapSettings({ zoom: zoom + 1 });
217+
setMapSettings({ zoom: zoom + 1 > maxZoom ? maxZoom : zoom + 1 });
218218
track('zoomIn');
219219
}}
220220
tooltip={{ text: 'Zoom in' }}
221-
disabled={zoom === maxZoom}
221+
disabled={zoom >= maxZoom}
222222
>
223223
<Icon icon={plusIcon} className="plus-icon" />
224224
</Button>
@@ -298,16 +298,12 @@ class MapControlsButtons extends PureComponent {
298298
);
299299

300300
renderMapPosition = () => {
301-
const { mapSettings } = this.props;
302-
const { zoom, center } = mapSettings || {};
301+
const { mapSettings: { center: { lat, lng }, zoom } } = this.props;
303302

304303
return (
305304
<div className="map-position">
306-
<span>zoom: {zoom}</span>
307-
<span>
308-
lat,lon:{' '}
309-
{`${format('.5f')(center.lat)}, ${format('.5f')(center.lng)}`}
310-
</span>
305+
<span>zoom: {format('.2f')(zoom)}</span>
306+
<span>lat,lon: {`${format('.5f')(lat)}, ${format('.5f')(lng)}`}</span>
311307
</div>
312308
);
313309
};

app/javascript/components/maps/main-map/index.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ class MainMapContainer extends PureComponent {
3636
const {
3737
selectedInteraction,
3838
setMainMapAnalysisView,
39-
oneClickAnalysis
39+
setMainMapSettings,
40+
oneClickAnalysis,
41+
analysisActive,
42+
geostoreId
4043
} = this.props;
4144

4245
// set analysis view if interaction changes
@@ -48,6 +51,10 @@ class MainMapContainer extends PureComponent {
4851
) {
4952
setMainMapAnalysisView(selectedInteraction);
5053
}
54+
55+
if (!analysisActive && geostoreId && geostoreId !== prevProps.geostoreId) {
56+
setMainMapSettings({ showAnalysis: true });
57+
}
5158
}
5259

5360
handleShowTooltip = (show, data) => {
@@ -75,8 +82,11 @@ MainMapContainer.propTypes = {
7582
setMainMapAnalysisView: PropTypes.func,
7683
selectedInteraction: PropTypes.object,
7784
setMenuSettings: PropTypes.func,
85+
setMainMapSettings: PropTypes.func,
7886
activeDatasets: PropTypes.array,
79-
menuSection: PropTypes.string
87+
menuSection: PropTypes.string,
88+
analysisActive: PropTypes.bool,
89+
geostoreId: PropTypes.string
8090
};
8191

8292
export default connect(getMapProps, actions)(MainMapContainer);

0 commit comments

Comments
 (0)