Skip to content

Feature/landsat tiles refactor #3708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions app/javascript/components/maps/components/basemaps/basemaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,21 @@ class BasemapsContainer extends React.Component {
static propTypes = {
activeDatasets: PropTypes.array,
activeBoundaries: PropTypes.object,
setMapSettings: PropTypes.func.isRequired,
setLandsatBasemap: PropTypes.func.isRequired
setMapSettings: PropTypes.func.isRequired
};

selectBasemap = (basemap, year) => {
const { labels, setLandsatBasemap, setMapSettings } = this.props;
const { labels, setMapSettings } = this.props;
const label = labels[basemap.labelsKey] || labels.default;
if (basemap.value === 'landsat') {
setLandsatBasemap({ basemap, year, label: label.value });
setMapSettings({
basemap: {
value: basemap.value,
year,
url: basemap.url.replace('{year}', year)
},
label: label.value
});
} else {
setMapSettings({ basemap: { value: basemap.value }, label: label.value });
}
Expand Down
52 changes: 0 additions & 52 deletions app/javascript/components/maps/map/actions.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createThunkAction, createAction } from 'redux-tools';
import axios from 'axios';

import { setComponentStateToUrl } from 'utils/stateToUrl';
import { addToDate } from 'utils/dates';

export const setMapLoading = createAction('setMapLoading');

Expand All @@ -17,53 +15,3 @@ export const setMapSettings = createThunkAction(
})
)
);

export const setLandsatBasemap = createThunkAction(
'setLandsatBasemap',
({ basemap, year, zoom }) => dispatch => {
const { url } = basemap;
const landsat = {
key: `GFW__GEE_LANDSAT_BASEMAP_URL_${year}`,
get geeUrl() {
const item = localStorage.getItem(this.key);
if (item) {
const parsed = JSON.parse(item);
return parsed.expires > Date.now() ? parsed.url : null;
}
return null;
},
set geeUrl(newUrl) {
const value = {
url: newUrl,
expires: addToDate(Date.now(), 1).getTime()
};
return localStorage.setItem(this.key, JSON.stringify(value));
},
get url() {
if (zoom > 11) {
return this.geeUrl;
}
return url && url.replace('{year}', year);
}
};
if (landsat.geeUrl === null) {
axios
.get(`${process.env.GFW_API}/v1/landsat-tiles/${year}`)
.then(({ data: res }) => {
landsat.geeUrl = res.data.attributes.url;
});
}
if (landsat.url !== null && landsat.url !== basemap.url) {
dispatch(
setMapSettings({
basemap: {
year,
key: 'landsat',
url: landsat.url
},
label: basemap.labelsKey
})
);
}
}
);
3 changes: 2 additions & 1 deletion app/javascript/components/maps/map/basemaps-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export default {
dynamic: true,
color: '#0C0045',
image: landsatImage,
url: 'https://storage.googleapis.com/landsat-cache/{year}/{z}/{x}/{y}.png',
url:
'https://production-api.globalforestwatch.org/v2/landsat-tiles/{year}/{z}/{x}/{y}',
availableYears: [2017, 2016, 2015, 2014, 2013]
}
};
22 changes: 13 additions & 9 deletions app/javascript/components/maps/map/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ const actions = {
class MapContainer extends PureComponent {
static propTypes = {
basemap: PropTypes.object,
mapOptions: PropTypes.object,
setLandsatBasemap: PropTypes.func
mapOptions: PropTypes.object
};

state = {
Expand All @@ -34,16 +33,21 @@ class MapContainer extends PureComponent {
bbox,
geostoreBbox,
setMapSettings,
layerBbox,
setLandsatBasemap
layerBbox
} = this.props;

// update landsat basemap when changing zoom
if (basemap.value === 'landsat' && zoom !== prevProps.zoom) {
setLandsatBasemap({
basemap,
year: basemap.year,
zoom
if (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the zoom is now part of the url and is fetched from the service I don't think this is still needed?

basemap.value === 'landsat' &&
prevProps.mapOptions &&
zoom !== prevProps.mapOptions.zoom
) {
setMapSettings({
basemap: {
value: basemap.value,
url: basemap.url.replace('{year}', basemap.year),
year: basemap.year
}
});
}

Expand Down