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:
16
examples/iiif.html
Normal file
16
examples/iiif.html
Normal file
@@ -0,0 +1,16 @@
|
||||
---
|
||||
layout: example.html
|
||||
title: IIIF Image API
|
||||
shortdesc: Example of a IIIF Image API source.
|
||||
docs: >
|
||||
Example of a tile source for an International Image Interoperability Framework (IIIF) Image Service.
|
||||
Try any Image API version 1 or 2 service.
|
||||
tags: "IIIF, IIIF Image API, tile source"
|
||||
---
|
||||
<div id="map" class="map"></div>
|
||||
<div class="controls">
|
||||
<div id="iiif-notification"> </div>
|
||||
Enter <code>info.json</code> URL:
|
||||
<input type="text" id="imageInfoUrl" value="https://iiif.ub.uni-leipzig.de/iiif/j2k/0000/0102/0000010218/00000061.jpx/info.json">
|
||||
<button id="display">Display image</button>
|
||||
</div>
|
||||
48
examples/iiif.js
Normal file
48
examples/iiif.js
Normal 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);
|
||||
Reference in New Issue
Block a user