leaflet.polyline.snakeanim
Version:
Animates Leaflet polylines so they creep into full length
62 lines (42 loc) • 1.92 kB
HTML
<html>
<head>
<title>Leaflet debug page</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css"
integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ=="
crossorigin=""/>
<!--<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet-src.js"
crossorigin=""></script>-->
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"
integrity="sha512-/Nsx9X4HebavoBvEBuyp3I7od5tA0UzAxs+j83KgC8PU0kgB4XiK4Lfe4y4cgBtaRJQEIFCW+oC506aPT2L1zw=="
crossorigin=""></script>
<script src="L.Polyline.SnakeAnim.js"></script>
</head>
<body>
<div id="map" style="width: 800px; height: 600px; border: 1px solid #ccc"></div>
<div><p>Badger badger badger badger badger badger badger<br> badger badger badger badger badger mushroom mushroom!<p>
<p>Badger badger badger badger badger badger badger<br> badger badger badger badger badger <button onclick='snake()'>SNAKE! IT'S A SNAKE!</button></p></div>
<script src="route.js"></script>
<script>
for (var i = 0, latlngs = [], len = route.length; i < len; i++) {
latlngs.push(new L.LatLng(route[i][0], route[i][1]));
}
var path = L.polyline(latlngs);
var map = L.map('map');
var positron = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', {
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>'
}).addTo(map);
map.fitBounds(L.latLngBounds(latlngs));
map.addLayer(L.marker(latlngs[0]));
map.addLayer(L.marker(latlngs[len - 1]));
map.addLayer(path);
path.bindPopup("Hello world");
function snake() {
path.snakeIn();
}
path.on('snakestart snake snakeend', function(ev){
console.log(ev.type);
});
</script>
</body>
</html>