Add IIIF Image API tilesource with example

src/ol/source/IIIF.js contains a tile source for IIIF Image API services.
It supports Image API version 1 and 2 on compliance levels 0, 1 and 2.

To get working constructor options for IIIF from an IIIF image info.json,
use src/ol/format/IIIFInfo.js.

An example is available in examples/iiif.html respectivly examples/iiif.js.
This commit is contained in:
Lutz Helm
2019-03-13 14:56:53 +01:00
committed by Lutz Helm
parent f366eaea52
commit c00400c500
6 changed files with 577 additions and 0 deletions

48
examples/iiif.js Normal file
View File

@@ -0,0 +1,48 @@
import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js';
import TileLayer from '../src/ol/layer/Tile.js';
import IIIF from '../src/ol/source/IIIF.js';
import IIIFInfo from '../src/ol/format/IIIFInfo.js';
const layer = new TileLayer(),
map = new Map({
layers: [layer],
target: 'map'
});
const notifyDiv = document.getElementById('iiif-notification');
function refreshMap(imageInfoUrl) {
fetch(imageInfoUrl).then(function(response) {
response.json().then(function(imageInfo) {
const options = new IIIFInfo().readFromJson(imageInfo);
if (options === undefined || options.version === undefined) {
notifyDiv.textContent = 'Data seems to be no valid IIIF image information.';
return;
}
const extent = [0, -options.size[1], options.size[0], 0];
layer.setSource(new IIIF(options));
map.setView(new View({
resolutions: layer.getSource().getTileGrid().getResolutions(),
extent: extent,
constrainOnlyCenter: true
}));
map.getView().fit(extent);
notifyDiv.textContent = '';
}).catch(function(body) {
notifyDiv.textContent = 'Could not read image info json. ' + body;
});
}).catch(function() {
notifyDiv.textContent = 'Could not read data from URL.';
});
}
const urlInput = document.getElementById('imageInfoUrl');
const displayButton = document.getElementById('display');
displayButton.addEventListener('click', function() {
const imageInfoUrl = urlInput.value;
refreshMap(imageInfoUrl);
});
refreshMap(urlInput.value);