fix: remove overlay by name

This commit is contained in:
Matthieu Baumann
2024-09-18 15:00:17 +02:00
parent 504cab42bb
commit 64d013618f
2 changed files with 11 additions and 4 deletions

View File

@@ -1482,10 +1482,11 @@ export let Aladin = (function () {
* @param {string|Overlay} overlay - The name of the overlay to remove or the overlay object itself
*/
Aladin.prototype.removeOverlay = function (overlay) {
if(overlay instanceof String)
if(typeof overlay === 'string' || overlay instanceof String) {
this.view.removeOverlayByName(overlay);
else
} else {
this.view.removeOverlay(overlay);
}
};
/**

View File

@@ -2060,6 +2060,11 @@ export let View = (function () {
View.prototype.removeOverlay = function (overlay) {
let indexToDelete = this.allOverlayLayers.indexOf(overlay);
if (indexToDelete === -1) {
// overlay not found
return;
}
this.allOverlayLayers.splice(indexToDelete, 1);
if (overlay.type == 'catalog' || overlay.type == 'progressivecat') {
@@ -2088,9 +2093,10 @@ export let View = (function () {
};
View.prototype.removeOverlayByName = function (overlayName) {
let overlay = this.allOverlayLayers.find(l => l.name === overlayName);
let overlay = this.allOverlayLayers.find(o => o.name === overlayName);
console.log("jkj", overlay)
if (!overlay) {
console.error(`Layer with name "${overlayName}" not found.`);
console.error(`Overlay "${overlayName}" not found.`);
return;
}
this.removeOverlay(overlay);