mirror of
https://github.com/cds-astro/aladin-lite.git
synced 2026-01-07 02:24:59 -08:00
🎨 Change implementation from Buffer to ArrayBuffer
This commit is contained in:
@@ -53,7 +53,6 @@
|
||||
"vite-plugin-top-level-await": "^1.4.1",
|
||||
"vite-plugin-wasm": "^3.2.2",
|
||||
"vite-plugin-wasm-pack": "^0.1.12",
|
||||
"vitest": "^0.32.2",
|
||||
"buffer": "^6.0.3"
|
||||
"vitest": "^0.32.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
* Author: Thomas Boch[CDS], Matthieu Baumann[CDS]
|
||||
*
|
||||
*****************************************************************************/
|
||||
import { Buffer } from "buffer";
|
||||
|
||||
import { version } from "./../../package.json";
|
||||
import { View } from "./View.js";
|
||||
@@ -2182,8 +2181,7 @@ aladin.on("positionChanged", ({ra, dec}) => {
|
||||
};
|
||||
|
||||
Aladin.prototype.getViewImageBuffer = async function (withLogo) {
|
||||
const viewDataURL = await this.view.getCanvasDataURL("image/png", null, null, withLogo);
|
||||
return Buffer.from(viewDataURL.split(",")[1], "base64");
|
||||
return await this.view.getCanvasBuffer("image/png", null, null, withLogo);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -446,10 +446,7 @@ export let View = (function () {
|
||||
this.catalogCanvas.style.cursor = cursor;
|
||||
};
|
||||
|
||||
/**
|
||||
* return dataURL string corresponding to the current view
|
||||
*/
|
||||
View.prototype.getCanvasDataURL = async function (imgType, width, height, withLogo=true) {
|
||||
View.prototype.getCanvasContext = async function (imgType, width, height, withLogo=true) {
|
||||
const loadImage = function (url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const image = new Image()
|
||||
@@ -480,9 +477,24 @@ export let View = (function () {
|
||||
ctx.drawImage(logo, offX, offY);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* return dataURL string corresponding to the current view
|
||||
*/
|
||||
View.prototype.getCanvasDataURL = async function (imgType, width, height, withLogo=true) {
|
||||
const c = await this.getCanvasContext(imgType, width, height, withLogo);
|
||||
return c.toDataURL(imgType);
|
||||
};
|
||||
|
||||
/**
|
||||
* return ArrayBuffer corresponding to the current view
|
||||
*/
|
||||
View.prototype.getCanvasBuffer = async function (imgType, width, height, withLogo=true) {
|
||||
const c = await this.getCanvasContext(imgType, width, height, withLogo);
|
||||
return c.getContext('2d').getImageData(0, 0, c.width, c.height).data.buffer;
|
||||
}
|
||||
|
||||
View.prototype.selectLayer = function (layer) {
|
||||
if (!this.imageLayers.has(layer)) {
|
||||
|
||||
Reference in New Issue
Block a user