Skip to content

Commit

Permalink
wait for layers tool to be loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
r03ert0 committed Jun 16, 2024
1 parent 8bbdd14 commit c01cee3
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions app/public/js/microdraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -1999,6 +1999,33 @@ const Microdraw = (function () {
me.updateLabelDisplay();
},

/** Configuration of the layers from the URL parameters.
* The function waits for the layers tool to be loaded before configuring the layers.
* @returns {void}
*/
_configureLayersFromParams: () => {
const timer = setInterval(async () => {
if (me.tools.layers) {
console.log("layers tool loaded");
clearInterval(timer);
const layers = me.params.layers.split(";").map( (layer) => layer.split(",") );
for (const layer of layers) {
let [source, name, opacity] = layer;
opacity = parseFloat(opacity);
// eslint-disable-next-line no-await-in-loop, dot-notation
const dzi = await me.tools["layers"].fetchDZI(source);
if (!dzi) {
continue;
}
// eslint-disable-next-line dot-notation
me.tools["layers"].addLayer(name, source, opacity * 100, dzi);
}
} else {
console.log("layers tool not loaded yet");
}
}, 200);
},

/**
* @param {Object} obj DZI json configuration object
* @returns {void}
Expand Down Expand Up @@ -2150,18 +2177,7 @@ const Microdraw = (function () {

// initialise layers
if( me.params.layers ) {
const layers = me.params.layers.split(";").map( (layer) => layer.split(",") );
for (const layer of layers) {
let [source, name, opacity] = layer;
opacity = parseFloat(opacity);
// eslint-disable-next-line no-await-in-loop, dot-notation
const dzi = await me.tools["layers"].fetchDZI(source);
if (!dzi) {
continue;
}
// eslint-disable-next-line dot-notation
me.tools["layers"].addLayer(name, source, opacity * 100, dzi);
}
me._configureLayersFromParams();
}

if( me.debug>1 ) { console.log("< initOpenSeadragon resolve: success"); }
Expand Down

0 comments on commit c01cee3

Please sign in to comment.