[Maps] ensure url has been resolved before syncing (#30750)

This commit is contained in:
Thomas Neirynck 2019-02-13 13:29:35 -05:00 committed by GitHub
parent 53ddf51b60
commit 6bf127e107
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 5 deletions

View file

@ -118,10 +118,25 @@ export function setLayerErrorStatus(layerId, errorMessage) {
}
export function toggleLayerVisible(layerId) {
return {
type: TOGGLE_LAYER_VISIBLE,
layerId
return async (dispatch, getState) => {
//if the current-state is invisible, we also want to sync data
//e.g. if a layer was invisible at start-up, it won't have any data loaded
const layer = getLayerList(getState()).find(layer => {
return layerId === layer.getId();
});
if (!layer) {
return;
}
const makeVisible = !layer.isVisible();
await dispatch({
type: TOGGLE_LAYER_VISIBLE,
layerId
});
if (makeVisible) {
dispatch(syncDataForLayer(layerId));
}
};
}
export function setSelectedLayer(layerId) {

View file

@ -107,8 +107,6 @@ export const getRefreshConfig = ({ map }) => map.mapState.refreshConfig;
export const getRefreshTimerLastTriggeredAt = ({ map }) => map.mapState.refreshTimerLastTriggeredAt;
export const getMetadata = ({ config }) => config && config.meta;
export const getDataFilters = createSelector(
getMapExtent,
getMapBuffer,

View file

@ -34,6 +34,10 @@ export class TileLayer extends AbstractLayer {
if (!this.isVisible() || !this.showAtZoomLevel(dataFilters.zoom)) {
return;
}
const sourceDataRequest = this.getSourceDataRequest();
if (sourceDataRequest) {//data is immmutable
return;
}
const sourceDataId = 'source';
const requestToken = Symbol(`layer-source-refresh:${ this.getId()} - source`);
startLoading(sourceDataId, requestToken, dataFilters);
@ -52,6 +56,12 @@ export class TileLayer extends AbstractLayer {
if (!source) {
const sourceDataRequest = this.getSourceDataRequest();
if (!sourceDataRequest) {
//this is possible if the layer was invisible at startup.
//the actions will not perform any data=syncing as an optimization when a layer is invisible
//when turning the layer back into visible, it's possible the url has not been resovled yet.
return;
}
const url = sourceDataRequest.getData();
if (!url) {
return;