// Copyright 2013 - UDS/CNRS
// The Aladin Lite program is distributed under the terms
// of the GNU General Public License version 3.
//
// This file is part of Aladin Lite.
//
// Aladin Lite is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Aladin Lite is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// The GNU General Public License is available in COPYING file
// along with Aladin Lite.
//
/******************************************************************************
* Aladin Lite project
*
* File gui/Stack.js
*
*
* Author: Thomas Boch[CDS]
*
*****************************************************************************/
import { AladinUtils } from "../AladinUtils.js";
import { Color } from "../Color.js";
import { ALEvent } from "../events/ALEvent.js";
import { CatalogSelector } from "./CatalogSelector.js";
import { HiPSLayer } from "./HiPSLayer.js";
import { Utils } from "../Utils.js";
import $ from 'jquery';
export class Stack {
// Constructor
constructor(parentDiv, aladin, view) {
this.aladin = aladin;
this.view = view;
this.mainDiv = document.createElement('div');
this.mainDiv.style.display = 'none';
this.mainDiv.classList.add('aladin-box', 'aladin-layerBox', 'aladin-cb-list');
this.aladinDiv = parentDiv;
parentDiv.appendChild(this.mainDiv);
this.imgLayers = new Map();
this.backgroundColor = '#6699ff';
let self = this;
this.unselectAllLayers = () => {
self.aladin.getImageOverlays()
.forEach((layer) => {
let selectedHipsLayer = self.imgLayers.get(layer);
let layerElement = selectedHipsLayer.headerDiv[0];
layerElement.style.backgroundColor = "gainsboro";
let headerLayerElement = layerElement.querySelector(".aladin-layer-header")
headerLayerElement.style.backgroundColor = "gainsboro";
})
};
this.selectLayer = (hipsLayer) => {
// Change the color currently selected layer
const layer = hipsLayer.layer.layer;
let layerElement = hipsLayer.headerDiv[0];
layerElement.style.backgroundColor = "darkgray";
let headerLayerElement = layerElement.querySelector(".aladin-layer-header")
headerLayerElement.style.backgroundColor = "gray";
// Set the active hips layer
self.aladin.setActiveHiPSLayer(layer);
};
this.updateSelectedLayer = () => {
self.unselectAllLayers();
const selectedLayer = self.aladin.getActiveHiPSLayer();
let selectedHipsLayer = self.imgLayers.get(selectedLayer);
self.selectLayer(selectedHipsLayer);
}
this._createComponent();
this._addListeners();
}
_createComponent() {
let self = this;
// first, update
let layerBox = $(this.mainDiv);
layerBox.empty();
layerBox.append('×' +
'
Stack
'
)
layerBox.append('' +
'
Image layers
' +
''
);
$(this.mainDiv).find('.add-layer-hips').click(function () {
let layerName = Utils.uuidv4();
// A HIPS_LAYER_ADDED will be called after the hips is added to the view
self.aladin.setOverlayImageLayer('CDS/P/DSS2/color', layerName);
});
if (this.imgLayers.size > 1) {
layerBox.append('
Overlay layers
')
Array.from(self.aladin.getImageOverlays()).reverse().forEach((layer) => {
let imgLayer = self.imgLayers.get(layer);
if (imgLayer && imgLayer.layer.layer !== "base") {
imgLayer.attachTo(layerBox);
}
});
}
layerBox.append('
Base layer
');
if (this.imgLayers.has("base")) {
this.imgLayers.get("base").attachTo(layerBox);
}
layerBox.append('
Background color
');
let backgroundColorInput = $('');
layerBox.append(backgroundColorInput);
// Set a default background color
backgroundColorInput.val(this.backgroundColor);
self.aladin.setBackgroundColor(Color.hexToRgb(this.backgroundColor));
backgroundColorInput.on('input', () => {
self.backgroundColor = backgroundColorInput.val();
self.aladin.setBackgroundColor(Color.hexToRgb(self.backgroundColor));
});
layerBox.append('' +
'
Overlay layers
');
// loop over all overlay layers
var layers = this.aladin.getOverlays();
var str = '
';
for (var k = layers.length - 1; k >= 0; k--) {
var layer = layers[k];
var name = layer.name;
var checked = '';
if (layer.isShowing) {
checked = 'checked="checked"';
}
var tooltipText = '';
var iconSvg = '';
if (layer.type == 'catalog' || layer.type == 'progressivecat') {
var nbSources = layer.getSources().length;
tooltipText = nbSources + ' source' + (nbSources > 1 ? 's' : '');
iconSvg = AladinUtils.SVG_ICONS.CATALOG;
}
else if (layer.type == 'moc') {
tooltipText = 'Coverage: ' + (100 * layer.skyFraction()).toFixed(3) + ' % of sky';
iconSvg = AladinUtils.SVG_ICONS.MOC;
}
else if (layer.type == 'overlay') {
iconSvg = AladinUtils.SVG_ICONS.OVERLAY;
}
var rgbColor = $('').css('color', layer.color).css('color'); // trick to retrieve the color as 'rgb(,,)' - does not work for named colors :(
var labelColor = Color.getLabelColorForBackground(rgbColor);
// retrieve SVG icon, and apply the layer color
var svgBase64 = window.btoa(iconSvg.replace(/FILLCOLOR/g, layer.color));
str += '