Skip to content

Commit

Permalink
Ensure layer is visible after load error is fixed
Browse files Browse the repository at this point in the history
Issues #2189, 2180
  • Loading branch information
robyngit committed Sep 20, 2023
1 parent e2d5bde commit 90fdc5c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
13 changes: 8 additions & 5 deletions src/js/models/maps/assets/CesiumVectorData.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ define(
const data = cesiumOptions.data;
delete cesiumOptions.data

if(!dataSource){
model.set('status', 'error')
model.set('statusDetails', 'Failed to create a Cesium DataSource model.')
return
}

dataSource.load(data, cesiumOptions)
.then(function (loadedData) {
model.set('cesiumModel', loadedData)
Expand Down Expand Up @@ -228,10 +234,7 @@ define(
}
}
catch (error) {
console.log(
'Failed to create a Cesium Model for a CesiumVectorData model' +
'. Error details: ' + error
);
console.log('Failed to create a VectorData Cesium Model.', error);
}
},

Expand All @@ -240,7 +243,7 @@ define(
*/
setListeners: function () {
try {
this.constructor.__super__.setListeners.call(this);
MapAsset.prototype.setListeners.call(this)
const appearEvents =
'change:visible change:opacity change:color change:outlineColor' +
' change:temporarilyHidden'
Expand Down
14 changes: 7 additions & 7 deletions src/js/models/maps/assets/MapAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ define([
* @since x.x.x
*/
handleError: function () {
this.set("originalVisibility", this.get("visible"));
this.set("visible", false);
this.stopListening(this, "change:visible");
},
Expand All @@ -352,17 +353,16 @@ define([
if (status === "error") {
this.handleError();
return;
} else {
const vis = this.get("originalVisibility")
if(typeof vis === "boolean"){
this.set("visible", vis);
}
}
// The map asset cannot be visible on the map if there was an error
// loading the asset
this.stopListening(this, "change:status");
this.listenTo(this, "change:status", function (model, status) {
if (status === "error") {
this.handleError();
} else {
this.setListeners();
}
});
this.listenTo(this, "change:status", this.setListeners);

// Listen for changes to the cesiumOptions object
this.stopListening(this, "change:cesiumOptions");
Expand Down
28 changes: 15 additions & 13 deletions src/js/views/maps/CesiumWidgetView.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,15 @@ define([

// Listen for addition or removal of layers TODO: Add similar listeners
// for terrain
view.stopListening(layers, "add");
view.listenTo(layers, "add", view.addAsset);
view.stopListening(layers, "remove");
view.listenTo(layers, "remove", view.removeAsset);

// Each layer fires 'appearanceChanged' whenever the color, opacity,
// etc. has been updated. Re-render the scene when this happens.
view.stopListening(layers, "appearanceChanged");
view.listenTo(layers, "appearanceChanged", view.requestRender);

if(layers){
view.stopListening(layers);
view.listenTo(layers, "add", view.addAsset);
view.listenTo(layers, "remove", view.removeAsset);

// Each layer fires 'appearanceChanged' whenever the color, opacity,
// etc. has been updated. Re-render the scene when this happens.
view.listenTo(layers, "appearanceChanged", view.requestRender);
}
// Reset asset listeners if the layers collection is replaced
view.stopListening(model, "change:layers");
view.listenTo(model, "change:layers", view.setAssetListeners);
Expand Down Expand Up @@ -620,9 +619,12 @@ define([
// property. Add in reverse order for layers to appear in the correct
// order on the map.
const layers = view.model.get("layers");
_.each(layers.last(layers.length).reverse(), function (mapAsset) {
view.addAsset(mapAsset);
});
if (layers && layers.length) {
const layersReverse = layers.last(layers.length).reverse();
layersReverse.forEach(function (layer) {
view.addAsset(layer);
})
}

// The Cesium Widget will support just one terrain option to start.
// Later, we'll allow users to switch between terrains if there is more
Expand Down

0 comments on commit 90fdc5c

Please sign in to comment.