Skip to content

Commit

Permalink
✨ Change layerChanged event trigger strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed Jul 16, 2024
1 parent 626c00a commit 905556f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions examples/al-event-listeners.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
console.log(proj)
});

aladin.on('layerChanged', function(imageLayer, layer){
console.log(imageLayer, layer)
aladin.on('layerChanged', function(imageLayer, layer, state){
console.log(imageLayer, layer, state)
});

cat.sources[0].actionClicked();
Expand Down
11 changes: 11 additions & 0 deletions src/js/Aladin.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,17 @@ export let Aladin = (function () {

const self = this;

ALEvent.HIPS_LAYER_ADDED.listenedBy(aladinDiv, (imageLayer) => {
this.callbacksByEventName["layerChanged"] &&
this.callbacksByEventName["layerChanged"](imageLayer.detail.layer, imageLayer.detail.layer.layer, "ADDED");
});

ALEvent.HIPS_LAYER_REMOVED.listenedBy(aladinDiv, (imageLayer) => {
console.log(imageLayer)
this.callbacksByEventName["layerChanged"] &&
this.callbacksByEventName["layerChanged"](imageLayer.detail.layer, imageLayer.detail.layer.layer, "REMOVED");
});

// if not options was set, try to retrieve them from the query string
if (requestedOptions === undefined) {
requestedOptions = this.getOptionsFromQueryString();
Expand Down
3 changes: 0 additions & 3 deletions src/js/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -1760,9 +1760,6 @@ export let View = (function () {
self.renameLayer(this.overlayLayers[0], "base");
}
}

const layerChangedFn = this.aladin.callbacksByEventName["layerChanged"];
(typeof layerChangedFn === "function") && layerChangedFn(imageLayer, layer);
})
}

Expand Down

0 comments on commit 905556f

Please sign in to comment.