Question

I'm trying to build a map that pans by a few relative degrees a second by longitude, but I'm only seeing a way to pan by a number of pixels. This means it pans farther when zoomed out than zoomed in. What's a clean way to do this?

Here's the code I'm using to pan right now:

var map = L.map('map', {
    minZoom: 1,
    maxZoom: 6,
    worldCopyJump: true,
}).setView([0, 0], 3);

L.tileLayer('maps/{z}/{x}/{y}.png', { 
    maxNativeZoom: 3,
    reuseTiles: true,
    unloadInvisibleTiles: false
}).addTo(map);

setInterval(function(){map.panBy([100, 0], {animate: true, duration: 1});}, 1000);
Was it helpful?

Solution

You can always convert latlng to pixels http://leafletjs.com/reference.html#map-project

Or you just use panTo http://leafletjs.com/reference.html#map-panto Which takes latlng

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top