From 90fdc5cd9e7b1bf3283c35180679c22d08fa4da5 Mon Sep 17 00:00:00 2001 From: Robyn Thiessen-Bock Date: Wed, 20 Sep 2023 18:01:36 -0400 Subject: [PATCH] Ensure layer is visible after load error is fixed Issues #2189, 2180 --- src/js/models/maps/assets/CesiumVectorData.js | 13 +++++---- src/js/models/maps/assets/MapAsset.js | 14 +++++----- src/js/views/maps/CesiumWidgetView.js | 28 ++++++++++--------- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/js/models/maps/assets/CesiumVectorData.js b/src/js/models/maps/assets/CesiumVectorData.js index 060c0b6d4..7972cd173 100644 --- a/src/js/models/maps/assets/CesiumVectorData.js +++ b/src/js/models/maps/assets/CesiumVectorData.js @@ -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) @@ -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); } }, @@ -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' diff --git a/src/js/models/maps/assets/MapAsset.js b/src/js/models/maps/assets/MapAsset.js index b47b0e42e..f50d34bc9 100644 --- a/src/js/models/maps/assets/MapAsset.js +++ b/src/js/models/maps/assets/MapAsset.js @@ -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"); }, @@ -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"); diff --git a/src/js/views/maps/CesiumWidgetView.js b/src/js/views/maps/CesiumWidgetView.js index fd8ea913c..641592e87 100644 --- a/src/js/views/maps/CesiumWidgetView.js +++ b/src/js/views/maps/CesiumWidgetView.js @@ -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); @@ -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