Skip to content

Instantly share code, notes, and snippets.

@mejackreed
Last active July 25, 2018 12:47
Show Gist options
  • Save mejackreed/8942bbb988e3f7bb38f9e00df5986d30 to your computer and use it in GitHub Desktop.
Save mejackreed/8942bbb988e3f7bb38f9e00df5986d30 to your computer and use it in GitHub Desktop.
var map;
map = L.map('map', {
center: [0, 0],
crs: L.CRS.Simple,
zoom: 0
});
var handle = document.getElementById('handle'),
start = false,
startTop;
var overlay;
$.getJSON('http://dms-data.stanford.edu/data/manifests/Stanford/qc810zp6213/manifest.json', function(data) {
var mainImage = data.sequences[0].canvases[0].images[0].resource.default['@id'].replace('full/full/0/default.jpg', 'info.json');
var overlayImage = data.sequences[0].canvases[0].images[0].resource.item[0]['@id'].replace('full/full/0/default.jpg', 'info.json');
var main = L.tileLayer.iiif(mainImage).addTo(map);
overlay = L.tileLayer.iiif(overlayImage, {
opacity: 0.7,
});
main.on('load', function() {
overlay.addTo(map);
});
overlay.on('load', function(){
overlay.bringToFront();
});
// Via https://www.mapbox.com/mapbox.js/example/v1.0.0/opacity/
document.onmousemove = function(e) {
if (!start) return;
// Adjust control.
handle.style.top = Math.max(-5, Math.min(195, startTop + parseInt(e.clientY, 10) - start)) + 'px';
// Adjust opacity.
overlay.setOpacity(1 - (handle.offsetTop / 200));
};
handle.onmousedown = function(e) {
// Record initial positions.
start = parseInt(e.clientY, 10);
startTop = handle.offsetTop - 5;
return false;
};
document.onmouseup = function(e) {
start = null;
};
});
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.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://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/mejackreed/Leaflet-IIIF/v2.0.1/leaflet-iiif.js"></script>
</head>
<body>
<div id="map"></div>
<div id='control' class='ui-opacity'>
<div id='handle' class='handle'></div>
</div>
<script src="app.js"></script>
</body>
</html>
html, body, #map{
height: 100%;
margin: 0;
}
.ui-opacity {
background:#FFF;
position:absolute;
left:10px;
top:70px;
height:200px;
width:28px;
border:1px solid rgba(0,0,0,0.4);
border-radius:3px;
z-index:1000;
}
.ui-opacity .handle {
position:absolute;
background:#404040;
left:0;
top:60px;
width:26px;
height:10px;
border-radius:1px;
cursor:pointer;
cursor:ns-resize;
}
.ui-opacity .handle:hover {
background:#303030;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment