leaflet-range
Version:
A simple HTML5 range control for Leaflet maps
37 lines (32 loc) • 1.17 kB
HTML
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Leaflet ZoomBox Control</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.1.0/dist/leaflet.css" />
<link rel="stylesheet" href="L.Control.Range.css" />
</head>
<body>
<script src="https://unpkg.com/leaflet@1.1.0/dist/leaflet-src.js"></script>
<script src="L.Control.Range.js"></script>
<div id="map" style="position: absolute; top: 0; left:0; bottom:0; right: 0;"></div>
<script>
var map = L.map('map').setView([44.07, -118.78], 6);
var layer = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
subdomains: 'abcd',
maxZoom: 10,
minZoom: 2
}).addTo(map);
var control = L.control.range({
orient: 'vertical',
value: 100
});
control.on('change input', function(e) {
console.log(e.value);
layer.setOpacity(e.value / 100);
})
map.addControl(control);
</script>
</body>
</html>