Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

356
Vistas
How to pause a leaflet panTo() animation

I am trying to make a map that automatically pan to several locations, one after the other, using Leaflet 1.7.1. This is working quite well using the panTo() function :

index.html

<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8' />
    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
    <script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
    <style>
        html,body,#map {
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
    <div id='map'></div>
</body>
<script type='text/javascript' src='script.js'></script>
</html>

script.js

var map = L.map('map');
var osm = new L.TileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    attribution: '<a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
map.dragging.disable();
map.setView([48.980, 4.373], 7);

var athens = [37.9844, 23.7398]
var stockholm = [59.3272, 18.0830]

setTimeout(function() {
    map.panTo([athens[0], athens[1]], {
        animate: true,
        duration: 20,
        easeLinearity: 0.9
    })
}, 2000);
setTimeout(function() {
    map.panTo([stockholm[0], stockholm[1]], {
        animate: true,
        duration: 15,
        easeLinearity: 0.9
    })
}, 22000);

I would like to add a pause/resume function, but I cannot figure how to do this. I am able to stop the animation using the following command :

map.setView(map.getCenter(), map.getZoom(), {"animate": false});

But I cannot resume the animation afterwards, and the later timed panTo events will happen anyway.

Any leads or ideas on how to achieve that ?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda