Skip to content

Commit

Permalink
fix(layer-selector-ui): display appropriate error messages for failed…
Browse files Browse the repository at this point in the history
… layers

Different error messages are displayed when layers fail in layer selector.
There are only three types for now: layer failed on init load (server down, etc.),
error failed because internet connection is down, everything else.

Closes #7724
  • Loading branch information
AleksueiR committed Mar 13, 2015
1 parent de21ce1 commit afd2601
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 134 deletions.
52 changes: 38 additions & 14 deletions src/js/RAMP/Modules/layerLoader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global define, console, RAMP, $ */
/* global define, console, RAMP, $, i18n */

/**
*
Expand Down Expand Up @@ -82,8 +82,9 @@ define([
* @param {String} layerId config id of the layer
* @param {String} newState the state to set the layer to in the layer selector
* @param {Boolean} abortIfError if true, don't update state if current state is an error state
* @param {Object} [options] additional options for layer item (mostly error messages in this case)
*/
function updateLayerSelectorState(layerId, newState, abortIfError) {
function updateLayerSelectorState(layerId, newState, abortIfError, options) {
if (abortIfError) {
var layerState;
layerState = FilterManager.getLayerState(layerId);
Expand All @@ -95,7 +96,7 @@ define([
}

//set layer selector to new state
FilterManager.setLayerState(layerId, newState);
FilterManager.setLayerState(layerId, newState, options);
}

/**
Expand Down Expand Up @@ -162,10 +163,11 @@ define([
*/
function _loadLayer(layer, reloadIndex) {
var insertIdx,
layerSection,
map = RampMap.getMap(),
layerConfig = layer.ramp.config,
lsState;
layerSection,
map = RampMap.getMap(),
layerConfig = layer.ramp.config,
lsState,
options = {};

if (!layer.ramp) {
console.log('you failed to supply a ramp.type to the layer!');
Expand Down Expand Up @@ -223,6 +225,12 @@ define([
lsState = LayerItem.state.LOADING;
break;
case "error":
options.notices = {
error: {
message: i18n.t("filterManager.notices.error.connect")
}
};

lsState = LayerItem.state.ERROR;
break;
}
Expand All @@ -234,9 +242,10 @@ define([

//add entry to layer selector
if (UtilMisc.isUndefined(reloadIndex)) {
FilterManager.addLayer(layerSection, layer.ramp.config, lsState, layer.ramp.user);
options.state = lsState; // pass initial state in the options object
FilterManager.addLayer(layerSection, layer.ramp, options);
} else {
updateLayerSelectorState(layerConfig.id, lsState);
updateLayerSelectorState(layerConfig.id, lsState, false, options);
}
layer.ramp.load.inLS = true;

Expand Down Expand Up @@ -367,19 +376,34 @@ define([
* @param {Object} evt.error the error object
*/
onLayerError: function (evt) {
console.log("failed to load layer " + evt.layer.url);
console.log(evt.error.message);

console.error("failed to load layer " + evt.layer.url, evt.error);

evt.layer.ramp.load.state = "error";

var layerId = evt.layer.id;
var layerId = evt.layer.id,
// generic error notice
errorMessage = i18n.t("filterManager.notices.error.load"),
options;

//get that failed layer outta here
removeFromMap(layerId);

// customize error notices based on the error type as much as possible
if (evt.error.code === 400) {
errorMessage = i18n.t("filterManager.notices.error.draw");
}

options = {
notices: {
error: {
message: errorMessage
}
}
};

//if layer is in layer selector, update the status
if (evt.layer.ramp.load.inLS) {
updateLayerSelectorState(evt.layer.ramp.config.id, LayerItem.state.ERROR, false);
updateLayerSelectorState(evt.layer.ramp.config.id, LayerItem.state.ERROR, false, options);
}
},

Expand Down

0 comments on commit afd2601

Please sign in to comment.