Leaflet: Is it possible to determine how 'moveend' event was triggered?

Created on 17 May 2013  路  7Comments  路  Source: Leaflet/Leaflet

Hi! I need to determine how 'moveend' event was fired - by mouse or programmatically. Is it possible?

Most helpful comment

I have another usecase. On button click I want map view to follow GPS (calling map.locate({ setView: true, watch: true })) but when user moves the map manually I want to stop the map to follow GPS (calling map.locate({ setView: false, watch: true })).

Or is there a workaround for this usecase, @mourner?

All 7 comments

Not at the moment, what's your use case?

I have an issue with routing. In the example below when RouteHandler has fired 'moveend' event is fired next and brakes the history.

new Router.RouteHandler('center/:lat/:lng/:zoom/', function (lat, lng, zoom) {
   map.setView([lat, lng], zoom);
});

map.on('moveend', function () {
   mapRoute.navigate(map.getCenter().lat, map.getCenter().lng, map.getZoom());
});

You're just updating the URL on moveend, right? I think most router implementations have a switch that allows them to update an URL without triggering the corresponding action.

Right, I use it this way. I added a flag to control if the moving came from route. But I think it would be useful to attach dom events to leaflet internal event system. Don't know if there is some issue for that. Thanks anyway!

No need to add this in Leaflet for now I think.

My use case is the following:

I want to capture all position-related changes on the map with only the moveend event handler (so that no replication exists if also using the zoomend one).

So, I just want a way to determine if zoom was the reason of the moveend so that I can do some extra stuff on the 'movend' handler.

I see that you have e.type: "moveend" but I would also need the extra property of e.subtype: "zoom" (for example)

I have another usecase. On button click I want map view to follow GPS (calling map.locate({ setView: true, watch: true })) but when user moves the map manually I want to stop the map to follow GPS (calling map.locate({ setView: false, watch: true })).

Or is there a workaround for this usecase, @mourner?

Was this page helpful?
0 / 5 - 0 ratings