From 3f1b39877b5060e61e212e230c36db1fd45c7672 Mon Sep 17 00:00:00 2001 From: robyngit Date: Tue, 15 Oct 2024 09:51:21 -0400 Subject: [PATCH] Add onClose methods to Cesium views. The onClose methods remove listeners from the Cesium viewer. Fixes #2549 --- src/js/views/maps/CesiumWidgetView.js | 6 ++++++ src/js/views/maps/MapWidgetContainerView.js | 17 +++++++++++++++++ src/js/views/search/CatalogSearchView.js | 3 +++ 3 files changed, 26 insertions(+) diff --git a/src/js/views/maps/CesiumWidgetView.js b/src/js/views/maps/CesiumWidgetView.js index 41c9c7548..c10f7ec6a 100644 --- a/src/js/views/maps/CesiumWidgetView.js +++ b/src/js/views/maps/CesiumWidgetView.js @@ -1662,6 +1662,12 @@ define([ ); } }, + + /** Remove nav and mouse listeners when the view is closed */ + onClose() { + this.removeMouseListeners(); + this.removeNavigationListeners(); + }, }, ); diff --git a/src/js/views/maps/MapWidgetContainerView.js b/src/js/views/maps/MapWidgetContainerView.js index 9e11c9e7e..393d95225 100644 --- a/src/js/views/maps/MapWidgetContainerView.js +++ b/src/js/views/maps/MapWidgetContainerView.js @@ -49,6 +49,7 @@ define([ model: this.model, }); mapWidget.render(); + this.mapWidget = mapWidget; }, /** Renders legend overlay. */ @@ -58,6 +59,7 @@ define([ }); legendContainerView.render(); this.$el.append(legendContainerView.el); + this.legendContainerView = legendContainerView; }, /** @@ -80,6 +82,7 @@ define([ pointModel: interactions.get("mousePosition"), }); scaleBar.render(); + this.scaleBar = scaleBar; this.$el.append(scaleBar.el); // If the interaction model or relevant sub-models are ever completely @@ -95,6 +98,20 @@ define([ this.renderScaleBar, ); }, + + /** Call the onClose method of each subview. */ + onClose() { + const subViews = [ + this.scaleBar, + this.legendContainerView, + this.mapWidget, + ]; + subViews.forEach((subView) => { + if (subView && typeof subView.onClose === "function") { + subView.onClose(); + } + }); + }, }, ); diff --git a/src/js/views/search/CatalogSearchView.js b/src/js/views/search/CatalogSearchView.js index a5168b71e..7bde46048 100644 --- a/src/js/views/search/CatalogSearchView.js +++ b/src/js/views/search/CatalogSearchView.js @@ -893,6 +893,9 @@ define([ // Remove the JSON-LD from the page document.getElementById("jsonld")?.remove(); + + // Remove the map + this.mapView?.onClose(); } catch (e) { console.error("Couldn't close search view. ", e); }