Skip to content

Commit

Permalink
✨ Add removeOverlayByName function
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed Aug 12, 2024
1 parent cedea78 commit 6d3baf8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelogs

## [Unreleased]

* [feat] Add `removeOverlayByName` method to remove an overlay by its name

## 3.4.5-beta

* [feat] add `layerChanged` event when a layer is added or removed
Expand Down
11 changes: 7 additions & 4 deletions src/js/Aladin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1485,13 +1485,16 @@ export let Aladin = (function () {
Aladin.prototype.removeLayers = Aladin.prototype.removeOverlays;

/**
* Remove a overlay by its layer name
*
* Remove an overlay by its layer name
*
* @memberof Aladin
* @param {string} layer
* @param {string|Layer} layer - The name of the layer to remove or the layer object itself
*/
Aladin.prototype.removeOverlay = function (layer) {
this.view.removeLayer(layer);
if(layer instanceof String)
this.view.removeOverlayByName(layer);
else
this.view.removeOverlay(layer);
};

/**
Expand Down
13 changes: 11 additions & 2 deletions src/js/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -2064,13 +2064,13 @@ export let View = (function () {
this.requestRedraw();
};

View.prototype.removeLayer = function (layer) {
View.prototype.removeOverlay = function (layer) {
let indexToDelete = this.allOverlayLayers.indexOf(layer);
this.allOverlayLayers.splice(indexToDelete, 1);

if (layer.type == 'catalog' || layer.type == 'progressivecat') {
indexToDelete = this.catalogs.indexOf(layer);

this.catalogs.splice(indexToDelete, 1);

this.unselectObjects();
Expand All @@ -2093,6 +2093,15 @@ export let View = (function () {
this.requestRedraw();
};

View.prototype.removeOverlayByName = function (layerName) {
let layer = this.allOverlayLayers.find(l => l.name === layerName);
if (!layer) {
console.error(`Layer with name "${layerName}" not found.`);
return;
}
this.removeOverlay(layer);
};

View.prototype.addCatalog = function (catalog) {
catalog.name = this.makeUniqLayerName(catalog.name);
this.allOverlayLayers.push(catalog);
Expand Down

0 comments on commit 6d3baf8

Please sign in to comment.