Skip to content

Instantly share code, notes, and snippets.

@balrog-kun
Forked from tyrasd/index.html
Last active August 29, 2015 14:17
Show Gist options
  • Save balrog-kun/e37b92b537860c77e463 to your computer and use it in GitHub Desktop.
Save balrog-kun/e37b92b537860c77e463 to your computer and use it in GitHub Desktop.
Compare .png with .bpg OSM tiles
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="http://c.tile.openstreetmap.pl/leaflet/dist/leaflet.css" />
<script type="application/javascript" src="http://c.tile.openstreetmap.pl/leaflet.bpg/bpgdec.js"></script>
<script type="application/javascript" src="http://c.tile.openstreetmap.pl/leaflet/dist/leaflet.js"></script>
<script type="application/javascript" src="http://c.tile.openstreetmap.pl/leaflet.bpg/TileLayer.BPG.js"></script>
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<style type='text/css'>
body {
font:20px/20px 'Helvetica Neue',sans-serif;
background:#f2efe9;
}
#swipe {
background:#222;
position:absolute;
bottom:0;
left:0;
right:0;
z-index:1000;
padding:10px;
height:30px;
}
#swipe #handle {
position:absolute;
height:20px;
padding:5px;
background:#fff;
font-weight:bold;
border:1px solid #333;
color:blue;
cursor:pointer;
-webkit-user-select: none;
}
.map-attribution {
bottom: 50px;
}
#osm1 {
position:absolute;
left:10px;
top:0px;
z-index:99;
}
#osm2 {
position:absolute;
right:10px;
top:0px;
z-index:99;
}
</style>
<div id='swipe'>
<div id='handle'>drag</div>
</div>
<div id='map' />
<h1 id='osm1'>.png</h1>
<h1 id='osm2'>.bpg at -q 32 (62% ratio)</h1>
<script>
var map = L.map('map');
var l0 = new L.TileLayer(
'http://c.tile.openstreetmap.pl/osmapa.pl/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Dane <a href="http://osm.org/">OpenStreetMap</a>',
});
var l1 = new L.TileLayer.BPG(
'http://c.tile.openstreetmap.pl/osmapa.pl.bpg/{z}/{x}/{y}.bpg', {
maxZoom: 18,
attribution: 'Dane <a href="http://osm.org/">OpenStreetMap</a>',
});
map.addLayer(l0);
map.addLayer(l1);
map.setView(new L.LatLng(52, 21), 16);
var handle = document.getElementById('handle'),
dragging = false,
divide;
handle.onmousedown = function() { dragging = true; return false; }
document.onmouseup = function() { dragging = false; }
document.onmousemove = function(e) {
if (!dragging)
return;
setDivide(map.mouseEventToContainerPoint(e).x);
}
function setDivide(x) {
var size = map.getSize();
divide = Math.max(40, Math.min(x, size.x - 40));
handle.style.left = (divide - 40) + 'px';
updateClip();
}
function updateClip() {
var size = map.getSize();
var offset = map.containerPointToLayerPoint(L.point(0, 0));
l0.getContainer().style.clip = 'rect(' + offset.y + 'px ' +
(offset.x + divide) + 'px ' +
(offset.y + size.y) + 'px ' +
offset.x + 'px)';
l1.getContainer().style.clip = 'rect(' + offset.y + 'px ' +
(offset.x + size.x) + 'px ' +
(offset.y + size.y) + 'px ' +
(offset.x + divide) + 'px)';
}
setDivide(400);
map.on('move', updateClip);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment