Skip to content

Instantly share code, notes, and snippets.

@mejackreed
Last active May 5, 2016 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mejackreed/6e3fb8e69189dadb4be7d0926a6a14a5 to your computer and use it in GitHub Desktop.
Save mejackreed/6e3fb8e69189dadb4be7d0926a6a14a5 to your computer and use it in GitHub Desktop.
Leaflet-IIIF Martellus Map example using IconLayers plugin

This example uses the Leaflet plugin Icon Layers.

The images being shown are multispectral versions of the Martellus map from Yale.

Using a Leaflet-IIIF and a IIIF Presentation API manifest, we can provide an attractive interface for viewing these images. One nice feature here is that the interface stays at the same place on each image change. This allows a researcher to inspect multiple parts of the map using varying multispectral images.

A few things to note about this visualization:

Selecting a subset of images in the manifest

// Only show certain images
if (showImages.indexOf(i + 1) === -1) {
  return true;
}

Creates each of the icons

iconLayers.push({
  title: value.label,
  layer: tileLayer,
  icon: value.images[0].resource['@id'].replace(
    'full/full/0/default.jpg',
    'full/1024,/0/default.jpg'
  )
});

Special thanks to Chet Van Duzer for help making this visualization possible. Additional thanks to the Beinecke Rare Book & Manuscript Library for providing these images. And last but not least, thanks to Ben Albritton for his work in accessioning the content and serving the images via IIIF.

var map;
map = L.map('map', {
center: [0, 0],
crs: L.CRS.Simple,
zoom: 0
});
var iconLayers = [];
var showImages = [1, 5, 6, 7];
// Grab images from a IIIF Manifest
$.getJSON('https://purl.stanford.edu/zf275jj8939/iiif/manifest.json', function(data) {
$.each(data.sequences[0].canvases, function(i, value) {
// Only show certain images
if (showImages.indexOf(i + 1) === -1) {
return true;
}
var tileLayer = L.tileLayer.iiif(
value.images[0].resource['@id'].replace('full/full/0/default.jpg', 'info.json'), {
fitBounds: false,
attribution: data.attribution
});
iconLayers.push({
title: value.label,
layer: tileLayer,
icon: value.images[0].resource['@id'].replace(
'full/full/0/default.jpg',
'full/1024,/0/default.jpg'
)
});
});
var iconLayersControl = new L.Control.IconLayers(
iconLayers, {
position: 'topright'
});
iconLayersControl.addTo(map);
// Only fit the bounds of the layer on first load
var firstTime = true;
iconLayers[0].layer.on('tileload', function() {
if (firstTime) {
this._fitBounds();
firstTime = false;
}
});
});
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.css" />
<link rel="stylesheet" href="https://rawgit.com/ScanEx/Leaflet-IconLayers/master/src/iconLayers.css" />
<link rel="stylesheet" href="styles.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://rawgit.com/mejackreed/Leaflet-IIIF/master/leaflet-iiif.js"></script>
<script src="https://rawgit.com/ScanEx/Leaflet-IconLayers/master/src/iconLayers.js"></script>
</head>
<body>
<div id="map">
</div>
<script src="app.js"></script>
</body>
</html>
MIT License
Copyright (c) 2016 Jack Reed
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
html, body, #map{
height: 100%;
margin: 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment