Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

leaflet.js fire event when map pans

I use this function on my backbone view when a new GPS coordinate comes in:

onLocationFound: function(position){
    // this function runs every time we get a valid GPS fix
    
    // here I have some preparation code, like getting "position"

    if(myApp.mapView.hasCenter){
      this.map.panTo(position.coords.latlng);
    }
  },

Then, on another pice of code I run this function:

this.map.on("moveend", function(s){
    that.doDrawReports();
});

My Problem is that the moveend event isn't catching my panTo operation. How can I catch it?

like image 946
otmezger Avatar asked Mar 04 '16 16:03

otmezger


1 Answers

Could not reproduce your issue sorry:

  • With Leaflet 0.7.7: http://jsfiddle.net/ve2huzxw/186/
  • With Leaflet 1.0.0-beta.2: http://jsfiddle.net/3v7hd2vx/20/

Test code:

var map = L.map("map").setView([48.86, 2.35], 12);

setInterval(function () {
  var currentPos = map.getCenter();

  map.panTo([
    currentPos.lat,
    currentPos.lng + 0.1
  ])
}, 2000);

map.on("moveend", function () {
  console.log(map.getCenter().toString());
});

Even by decreasing the interval down to 50ms, the moveend listener is still called.

like image 80
ghybs Avatar answered Oct 15 '22 14:10

ghybs