OpenSeadragon.EmptyTileSource = class EmptyTileSource extends OpenSeadragon.TileSource {
constructor(options) {
options.ready = true;
options.height = options.height || 256;
options.width = options.width || 256;
options.tileSize = options.tileSize || 256;
super(options);
this.tilesUrl = 'empty';
this.color = "rgba(0,0,0,0)";
this.errorMessage = options.error || null;
}
supports( data, url ){
return false;
}
configure( data, url, postData ){
return {};
}
getTileUrl( level, x, y ) {
return 'empty';
}
getMetadata() {
return {error: this.errorMessage || 'No data available. The layer is empty.'};
}
getDisplayMetadata() {
return [{
title: "Empty layer",
description: "This layer is a placeholder. No image data is attached to it."
}];
}
setColor(color) {
this.color = color;
}
getTileHashKey(level, x, y, url, ajaxHeaders, postData) {
return this.tilesUrl;
}
tileExists( level, x, y ) {
return true;
}
downloadTileStart(context) {
let size = context.tile.size || {x: 0, y: 0};
let canvas = document.createElement("canvas");
let ctx = canvas.getContext('2d');
if (size.x < 1 || size.y < 1) {
canvas.width = 512;
canvas.height = 512;
} else {
canvas.width = Math.floor(size.x);
canvas.height = Math.floor(size.y);
}
ctx.fillStyle = this.color;
ctx.fillRect(0, 0, canvas.width, canvas.height);
context.finish(ctx, null, "context2d");
}
downloadTileAbort(context) {
}
};