Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

map.fitBounds with callback after operation end #6417

Closed
edmsgists opened this issue Nov 28, 2018 · 4 comments
Closed

map.fitBounds with callback after operation end #6417

edmsgists opened this issue Nov 28, 2018 · 4 comments

Comments

@edmsgists
Copy link

edmsgists commented Nov 28, 2018

Would be nice to add a callback/then whenever map.fitBounds() ended its operation. Today we have to rely adding map.once('zoomend moveend', function()); to make something happen after.

For example, to make a marker bounce after appearing, i have to:

var marker = getMarker();
map.once('zoomend moveend', ()=>{bounceMarker(marker);});
map.fitBounds(marker.getBounds());

Would be nice to do something like:
map.fitBounds(marker.getBounds()).then(()=>{bounceMarker(marker);});

@ronikar
Copy link
Contributor

ronikar commented Feb 9, 2019

It would be great if map functions that modifying map state, will return Promise

@Kambyses
Copy link

Kambyses commented Aug 12, 2019

What i did was, adding method to my map (uses jquery promise, but can be easily replaced):

zoomToBounds: function () {
  var promise = $.Deferred();
  this.once("moveend", function () {setTimeout(function () {promise.resolve();}, 20);});
  this.fitBounds.call(this, arguments);
  return promise;
}

@ronikar
Copy link
Contributor

ronikar commented Aug 12, 2019

Can you replace $.Deferred() with new Promise() And then to create a pull request?

@johnd0e
Copy link
Collaborator

johnd0e commented Apr 5, 2021

This will not happen.
But you could make own wrappers (like @bieleckim suggested), and even publish them as plugin.

@johnd0e johnd0e closed this as completed Apr 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants