Skip to content

Commit

Permalink
Add onClose methods to Cesium views.
Browse files Browse the repository at this point in the history
The onClose methods remove listeners from the Cesium viewer.

Fixes #2549
  • Loading branch information
robyngit committed Oct 15, 2024
1 parent 586c019 commit 3f1b398
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/js/views/maps/CesiumWidgetView.js
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,12 @@ define([
);
}
},

/** Remove nav and mouse listeners when the view is closed */
onClose() {
this.removeMouseListeners();
this.removeNavigationListeners();
},
},
);

Expand Down
17 changes: 17 additions & 0 deletions src/js/views/maps/MapWidgetContainerView.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ define([
model: this.model,
});
mapWidget.render();
this.mapWidget = mapWidget;
},

/** Renders legend overlay. */
Expand All @@ -58,6 +59,7 @@ define([
});
legendContainerView.render();
this.$el.append(legendContainerView.el);
this.legendContainerView = legendContainerView;
},

/**
Expand All @@ -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
Expand All @@ -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();
}
});
},
},
);

Expand Down
3 changes: 3 additions & 0 deletions src/js/views/search/CatalogSearchView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 3f1b398

Please sign in to comment.