Edit

IIIF Image API

IIIF1 IIIFImageAPI1 tilesource1

 

Example of a IIIF Image API source.

Example of a tile source for an International Image Interoperability Framework (IIIF) Image Service. Try any Image API version 1 or 2 service.

main.js
import 'ol/ol.css';
import IIIF from 'ol/source/IIIF';
import IIIFInfo from 'ol/format/IIIFInfo';
import Map from 'ol/Map';
import TileLayer from 'ol/layer/Tile';
import View from 'ol/View';

const layer = new TileLayer(),
  map = new Map({
    layers: [layer],
    target: 'map',
  }),
  notifyDiv = document.getElementById('iiif-notification'),
  urlInput = document.getElementById('imageInfoUrl'),
  displayButton = document.getElementById('display');

function refreshMap(imageInfoUrl) {
  fetch(imageInfoUrl)
    .then(function (response) {
      response
        .json()
        .then(function (imageInfo) {
          const options = new IIIFInfo(imageInfo).getTileSourceOptions();
          if (options === undefined || options.version === undefined) {
            notifyDiv.textContent =
              'Data seems to be no valid IIIF image information.';
            return;
          }
          options.zDirection = -1;
          const iiifTileSource = new IIIF(options);
          layer.setSource(iiifTileSource);
          map.setView(
            new View({
              resolutions: iiifTileSource.getTileGrid().getResolutions(),
              extent: iiifTileSource.getTileGrid().getExtent(),
              constrainOnlyCenter: true,
            })
          );
          map.getView().fit(iiifTileSource.getTileGrid().getExtent());
          notifyDiv.textContent = '';
        })
        .catch(function (body) {
          notifyDiv.textContent = 'Could not read image info json. ' + body;
        });
    })
    .catch(function () {
      notifyDiv.textContent = 'Could not read data from URL.';
    });
}

displayButton.addEventListener('click', function () {
  refreshMap(urlInput.value);
});

refreshMap(urlInput.value);
index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>IIIF Image API</title>
    <!-- Pointer events polyfill for old browsers, see https://caniuse.com/#feat=pointer -->
    <script src="https://unpkg.com/elm-pep"></script>
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
    <script src="https://cdn.polyfill.io/v3/polyfill.min.js?features=fetch,requestAnimationFrame,Element.prototype.classList,URL,TextDecoder,Number.isInteger"></script>
    <style>
      .map {
        width: 100%;
        height:400px;
      }
    </style>
  </head>
  <body>
    <div id="map" class="map"></div>
    <div class="controls">
      <div id="iiif-notification">&nbsp;</div>
      <label for="imageInfoUrl">Enter <code>info.json</code> URL:</label>
      <input type="text" id="imageInfoUrl" value="https://iiif.ub.uni-leipzig.de/iiif/j2k/0000/0107/0000010732/00000072.jpx/info.json">
      <button id="display">Display image</button>
    </div>
    <script src="main.js"></script>
  </body>
</html>
package.json
{
  "name": "iiif",
  "dependencies": {
    "ol": "6.8.1"
  },
  "devDependencies": {
    "parcel": "^2.0.0-beta.1"
  },
  "scripts": {
    "start": "parcel index.html",
    "build": "parcel build --public-url . index.html"
  }
}