Skip to content

Commit

Permalink
Merge pull request #2550 from NCEAS/bugfix-2549-remove-cesium-listeners
Browse files Browse the repository at this point in the history
Remove cesium listeners when map is removed from DOM
  • Loading branch information
rushirajnenuji authored Dec 3, 2024
2 parents 5089123 + 3b8a3b2 commit 2453bc2
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 2453bc2

Please sign in to comment.