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

Add "Map#isMoving" method #2792

Closed
lucaswoj opened this issue Jun 28, 2016 · 7 comments
Closed

Add "Map#isMoving" method #2792

lucaswoj opened this issue Jun 28, 2016 · 7 comments

Comments

@lucaswoj
Copy link
Contributor

lucaswoj commented Jun 28, 2016

It is useful to know whether the map is currently moving (i.e. because of a flyTo call). This method would sit alongside Map#loaded (to be renamed to Map#isTilesLoaded?) as a guard against expensive operations during times of rapid map change

map.on('render', function() {
    if (!map.isMoving() && map.isTilesLoaded()) {
        map.queryRenderedFeatures(...)
    }
});

cc @peterqliu

@lucaswoj
Copy link
Contributor Author

I think this is a solid alternate solution for #2471

@peterqliu
Copy link
Contributor

👍 I think this would be useful for expensive operations that need to happen regularly ("keep doing this, unless the map is moving").

However, it shouldn't replace #2471 altogether. For occasional operations, it's easier to reason about what's going on via event callbacks (moveend, dataend, renderstable, etc), rather than constantly checking the map state before executing something.

@averas
Copy link
Contributor

averas commented Jan 10, 2017

There is currently issues with Mapbox GL JS Draw in regards to adding/removing draw in a controlled fashion (mapbox/mapbox-gl-draw#572). This is in part related to that adding Draw currently depends on Map#loaded returning true, which during long transitions can take a while. If draw is removed before it has been successfully enabled (i.e. loaded returns true) Draw enters a degenerate state which is hard to recover from.

Even though this is more a concern for the Draw project rather than Mapbox GL JS I wonder if Map#isMoving and Map#isTilesLoaded covers the potential state queries a client or plugin would want to make. I imagine that adding draw would be possible before these states are fulfilled, but after the map's style is initialised.

I guess my question boils down to: What is the earliest state the map can reach when it is reasonable to add/remove controls/sources/layers and is it possible to query for this state?

@lucaswoj
Copy link
Contributor Author

What is the earliest state the map can reach when it is reasonable to add/remove controls/sources/layers and is it possible to query for this state?

This state is when Map#loaded returns true, also marked by the Map#load event. If that doesn't work, I'd consider it a bug.

@averas
Copy link
Contributor

averas commented Jan 11, 2017

@lucaswoj Currently Map#loaded returns false during any kind of transition, meaning that a 10s flyTo transition will block a plugin/client (such as Draw) from enabling itself if it is specifically waiting for Map#loaded to return true (which Draw is).

If I understand this ticket correctly Map#isMoving will take Map#loaded's place semantically while Map#loaded will instead return true once all tiles are loaded (and then possibly be renamed to Map#isTilesLoaded)

  1. Isn't it viable to mutate sources/layers/controls before all tiles loaded but after the style is loaded?
  2. Wouldn't a transition like a 10s flyTo mean that new tile requests would continuously get queued effectively meaning that Map#isTilesLoaded would also return false until the flyTo is completed?

@lucaswoj
Copy link
Contributor Author

Currently Map#loaded returns false during any kind of transition, meaning that a 10s flyTo transition will block a plugin/client (such as Draw) from enabling itself if it is specifically waiting for Map#loaded to return true (which Draw is).

Good point. This is a real hole in our API.

If I understand this ticket correctly Map#isMoving will take Map#loaded's place semantically while Map#loaded will instead return true once all tiles are loaded (and then possibly be renamed to Map#isTilesLoaded)

Not exactly. Map#loaded returns true because as the map moves, new tiles have to be loaded; renaming the method to Map#isTilesLoaded would not change this behavior. Adding a Map#isStyleLoaded may be more useful.

  1. Isn't it viable to mutate sources/layers/controls before all tiles loaded but after the style is loaded?

Yes. If this isn't already allowed, we should allow it.

  1. Wouldn't a transition like a 10s flyTo mean that new tile requests would continuously get queued effectively meaning that Map#isTilesLoaded would also return false until the flyTo is completed?

Yes.

stepankuzmin added a commit to stepankuzmin/mapbox-gl-js that referenced this issue Jan 19, 2017
stepankuzmin added a commit to stepankuzmin/mapbox-gl-js that referenced this issue Jan 19, 2017
lucaswoj pushed a commit that referenced this issue Jan 20, 2017
* add "Map#isMoving" method #2792

* move Map#isMoving to Camera #2792

* fix Camera isMoving docs #2792
@mourner
Copy link
Member

mourner commented Apr 18, 2017

This was done in #3941

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

No branches or pull requests

4 participants