Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

354
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!