enedis_carto/com_leaflet/media/js/leaflet-panel-layers-master/examples/layer-thumbnails.html

113 lines
3.9 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<title>Leaflet Panel Layers</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css" integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==" crossorigin=""/>
<link rel="stylesheet" href="../src/leaflet-panel-layers.css" />
<link rel="stylesheet" href="icons.css" />
<link rel="stylesheet" href="style.css" />
<style type="text/css">
.leaflet-panel-layers-item span {
display: block;
background: #fff:
}
.panel-thumb {
height: 50px;
width: 150px;
float: left;
cursor: pointer;
outline: 2px solid gray;
}
</style>
</head>
<body>
<h3><a href="../"><big></big> Leaflet Panel Layers</a></h3>
<h4> Build custom panel layer contains thumbnail by tile layer</h4>
<br />
<div id="map"></div>
<div id="copy"><a href="https://opengeo.tech/">Labs</a> &bull; <a rel="author" href="https://opengeo.tech/stefano-cudini/">Stefano Cudini</a></div>
<a href="https://github.com/stefanocudini/leaflet-panel-layers"><img id="ribbon" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
<!--
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js" integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew==" crossorigin=""></script>
-->
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js" integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew==" crossorigin=""></script>
<script src="../src/leaflet-panel-layers.js"></script>
<script>
function getXYZ(latlng, zoom) {
function toRad(n) {
return n * Math.PI / 180;
}
return {
z: zoom,
x: parseInt(Math.floor( (latlng.lng + 180) / 360 * (1<<zoom) )),
y: parseInt(Math.floor( (1 - Math.log(Math.tan(toRad(latlng.lat)) + 1 / Math.cos(toRad(latlng.lat))) / Math.PI) / 2 * (1<<zoom) ))
}
}
var map = L.map('map', {
zoom: 10,
attributionControl: false,
center: L.latLng([42,12])
// maxBounds: L.latLngBounds([[42.41281,12.28821],[42.5589,12.63805]]).pad(0.5)
});
var baselayers = [
{
active: true,
name: "Open Street Map",
<<<<<<< HEAD
layer: L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png'),
=======
layer: L.tileLayer('http://tile.openstreetmap.org/{z}/{x}/{y}.png')
>>>>>>> 3da7706db0a544915594a22035119f5362178e9f
},
{
name: "Landscape",
layer: L.tileLayer('https://{s}.tile3.opencyclemap.org/landscape/{z}/{x}/{y}.png')
},
{
name: "Open Cycle Map",
layer: L.tileLayer('https://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png')
},
{
name: "Transports",
layer: L.tileLayer('https://{s}.tile2.opencyclemap.org/transport/{z}/{x}/{y}.png')
}
];
L.control.panelLayers(baselayers, null, {
buildItem: function(item) {
var xyz = getXYZ(map.getCenter(), map.getZoom() );
if (typeof item.layer._tileZoom === 'undefined') item.layer._tileZoom = map.getZoom(); // a hack for layers that are not active
var url = item.layer.getTileUrl( xyz );
var node = L.DomUtil.create('div','panel-thumb');
node.style.background = "url('"+url+"') no-repeat top left";
// node.innerHTML = item.name;
return node;
}
}).addTo(map);
//---- Debugging: Look at the console when clicking on the map: ----
map.on('click', function(e) {
var layer = baselayers[0].layer;
//var url = getTileURL(e.latlng.lat, e.latlng.lng, map.getZoom());
var xyz = getXYZ(e.latlng, map.getZoom());
if (typeof layer._tileZoom === 'undefined') layer._tileZoom = map.getZoom(); // a hack for layers that are not active
var url = layer.getTileUrl( xyz );
console.log(url)
});
</script>
<script type="text/javascript" src="/labs-common.js"></script>
</body>
</html>