Better drawer resolution, also supporting inline class spec. Fix minor review stuff.

This commit is contained in:
Aiosa 2023-07-26 23:55:46 +02:00
parent 3c3842bdce
commit 046612f8da
4 changed files with 32 additions and 35 deletions

View File

@ -67,7 +67,7 @@ module.exports = function(grunt) {
"src/tilecache.js",
"src/world.js",
// Aoisa's webgl drawer - needs optimization, polishing, trimming
// Aiosa's webgl drawer - needs optimization, polishing, trimming
// "src/webgl/webGLWrapper.js",
// "src/webgl/visualisationLayer.js",
// "src/webgl/dataLoader.js",

View File

@ -108,9 +108,7 @@ $.DrawerBase = class DrawerBase{
this._checkForAPIOverrides();
}
get isOpenSeadragonDrawer(){
return true;
}
get canvas(){
if(!this._renderingTarget){
this._renderingTarget = this.createDrawingElement();

View File

@ -1,8 +1,8 @@
/*
* OpenSeadragon - Mat3
*
* Copyright (C) 2010-2023 OpenSeadragon contributors
* Modified from https://webglfundamentals.org/webgl/lessons/webgl-2d-matrices.html
* Copyright (C) 2010-2023 webglfundamentals.org and OpenSeadragon contributors
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@ -36,7 +36,6 @@
/**
* Matrix left-to-right system representation
* Modified from https://webglfundamentals.org/webgl/lessons/webgl-2d-matrices.html
*/
$.Mat3 = class Mat3 {
constructor(values){

View File

@ -445,44 +445,44 @@ $.Viewer = function( options ) {
delete this.drawerOptions.useCanvas;
}
let drawerPriority = Array.isArray(this.drawer) ? this.drawer : [this.drawer];
let drawersToTry = drawerPriority.filter(d => ['webgl', 'canvas', 'html'].includes(d) || (d.prototype && d.prototype.isOpenSeadragonDrawer) );
if(drawerPriority.length !== drawersToTry.length){
$.console.error('An invalid drawer was requested.');
}
if(drawersToTry.length === 0){
drawersToTry = [$.DEFAULT_SETTINGS.drawer].flat(); // ensure it is a list
let drawerCandidates = Array.isArray(this.drawer) ? this.drawer : [this.drawer];
if (drawerCandidates.length === 0){
drawerCandidates = [$.DEFAULT_SETTINGS.drawer].flat(); // ensure it is a list
$.console.warn('No valid drawers were selected. Using the default value.');
}
// extend the drawerOptions object with additional properties to pass to the Drawer implementation
// TODO: how to deal with the possibility that none of the requested drawers are supported?
this.drawer = null;
for(let i = 0; i < drawersToTry.length; i++){
for (let i = 0; i < drawerCandidates.length; i++) {
//todo necessary? why not to use class names as drawer IDs
let optsKey = drawersToTry[i];
let Drawer = $.determineDrawer(optsKey);
if (!Drawer) {
optsKey = 'custom';
//todo will raise error anyway...
let drawerCandidate = drawerCandidates[i];
let Drawer = null;
//if inherits from a drawer base, use it
if (drawerCandidate && drawerCandidate.prototype instanceof $.DrawerBase) {
Drawer = drawerCandidate;
drawerCandidate = 'custom';
} else if (typeof drawerCandidate === "string") {
Drawer = $.determineDrawer(drawerCandidate);
} else {
// if the drawer is supported, create it and break the loop
if (Drawer.isSupported()){
this.drawer = new Drawer({
viewer: this,
viewport: this.viewport,
element: this.canvas,
debugGridColor: this.debugGridColor,
options: this.drawerOptions[optsKey],
});
this.drawerOptions.constructor = Drawer;
break;
}
$.console.warn('Unsupported drawer! Drawer must be an existing string type, or a class that extends OpenSeadragon.DrawerBase.');
continue;
}
// if the drawer is supported, create it and break the loop
if (Drawer.isSupported()) {
this.drawer = new Drawer({
viewer: this,
viewport: this.viewport,
element: this.canvas,
debugGridColor: this.debugGridColor,
options: this.drawerOptions[drawerCandidate],
});
this.drawerOptions.constructor = Drawer;
break;
}
}
if(this.drawer === null){
if (!this.drawer){
$.console.error('No drawer could be created!');
throw('Error with creating the selected drawer(s)');
}