Creating a Basic Image Viewer

We have already had success in setting up a IIIF Image Server, now lets put that to use.

IIIF Image API Client Libraries

There are several widely used IIIF Image API client libraries, available for multiple languages including JavaScript and Swift. For this workshop (at least for today) we are going to focus on working with Leaflet-IIIF. Why Leaflet-IIIF, well the facilitator of the workshop is the author of the library. Later in the week we will cover some more technologies.

Adopting an existing basic example

For this basic example we want to adopt some pre-existing code hosted as Gist and available at

Go ahead and check that link out. Now let's download the code to get started.

  1. Visit
  2. Download the code example, "Download ZIP" is probably the easiest way.
  3. Unzip downloaded ZIP file and then open the directory in a code editor.
  4. Lets run the code as is. Change into the downloaded directory (using cd) in a terminal
    $ cd b0aba2ff6f5a54f197767313fbc5a26e-7ece2b016005fb9454dad91d5fcabf5a3ddc934f
    Hint: Use tab to autocomplete directory or file names in the terminal
  5. Run a webserver in the directory. There are two options here, you can use the Nodejs package "http-server" if you installed Nodejs. npm install --global http-server and then run it using http-server. Or if you have Python installed you can run python -m SimpleHTTPServer.
  6. We should now be able to visit the page in our browser: Visit or You should see the example we saw on the bl.ocks site. basic leaflet-iiif example
  7. Let's change the image to use one we setup in the last step. In your code editor modify the following line in app.js.
- L.tileLayer.iiif('').addTo(map);
+ L.tileLayer.iiif('').addTo(map);

Now when we reload the webpage, we should see our image similar to the last example. basic leaflet-iiif example

Adding annotation

One advantage of using Leaflet-IIIF is the vast plugin ecosystem. We can quickly add the ability to add annotations to our image using a Leaflet plugin, Leaflet-Draw.

  1. Add the Leaflet.Draw CSS and JavaScript dependencies to our index.html file.
<!DOCTYPE html>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <link rel="stylesheet" href=""
+   <link rel="stylesheet" href="" />
    <link rel="stylesheet" href="styles.css">
    <script src=""
    <script src=""></script>
    <script src=""></script>
+   <script src=""></script>
    <div id="map"></div>
    <script src="app.js"></script>
  1. Initialize the Leaflet.Draw plugin and a data structure to hold the annotations.
// Initialize the FeatureGroup to store editable layers
var drawnItems = new L.FeatureGroup();

// Initialize the draw control and pass it the FeatureGroup of editable layers
var drawControl = new L.Control.Draw({
  edit: {
    featureGroup: drawnItems


map.on(L.Draw.Event.CREATED, function (e) {
  var type = e.layerType
  var layer = e.layer;

  // Do whatever else you need to. (save to db, add to map etc)

  1. You should now be able to reload your webpage and add annotation shapes to your image. leaflet-iiif-annotation

This example is online at

Last modified by Jack Reed 2018-06-03 19:35:37
Created by Jack Reed 2018-06-03 19:35:37

results matching ""

    No results matching ""