sebap123
sebap123

Reputation: 2685

Finding center of Leaflet.js map after mouse move

I would like to detect after user move where the center of the map is. Currently I have this piece of code responsible for detecting what is the latitude and longitude of beginning of the mouse move:

var lat, lng;

    mymap.addEventListener('mousemove', function(ev) {
       lat = ev.latlng.lat;
       lng = ev.latlng.lng;
    });

    document.getElementById("mapid").addEventListener("click", function (event) {
        console.log(lat + ' - ' + lng);

        return false;
    });

Unfortunately it is not working as I'd imagine. I tried to find some event responsible for stopping of moving and beside drag end event which is only for markers, not just move I couldn't find such. Also the second problem would be then - how to detect the center of map.

Does anyone has any solution for this?

Upvotes: 7

Views: 11269

Answers (1)

IvanSanchez
IvanSanchez

Reputation: 19049

If you want to keep track of the center of the map, you should be using mymap.getCenter() instead of ev.latlng.

Upvotes: 15

Related Questions