0

My goal

After I've executed a function like setCenter or setZoom on the Map, I want to know when the map is done loading tiles so I can add my markers without distractions to the user.

The "obvious" solution

Listen to the tilesloaded events, it will fire when the map is done loading tiles.

The problem

If the map doesn't move, or moves so little that no new tiles are loaded, the event never fires. There doesn't seem to be a way to know beforehand if a move is going to cause new tiles to be loaded, and there is no property or method on the Map class to indicate whether or not tiles are currently being fetched.


So my question is, after I've executed a map.setCenter or setZoom function, how do I know for sure when the map has stopped moving (in the case of an animated move) and all tiles are loaded?

Hubro
  • 56,214
  • 69
  • 228
  • 381
  • What distraction are you causing to your users by adding markers before tiles are loaded? – sabotero Feb 19 '15 at 15:09
  • @sabotero: If I move the map center, then immediately add a marker with an animation, a couple of undesired effects happen: #1 the marker is added using an animated drop effect while tiles are still popping in all over the place, which can cause the user to not notice the marker, especially if it's a small marker among many other markers. #2 because of all the stuff going on at once, the frame rate drops and the animation is choppy and ugly, especially in Firefox. It looks much smoother and cleaner if the tiles load in first, and the markers are added after. – Hubro Feb 19 '15 at 15:14
  • have you tried `map.panTo(center)` instead of `map.SetCenter`and listen to the `idle`event. As well as listening to `tilesloaded` when the map is first load – sabotero Feb 19 '15 at 15:30
  • @sabotero: According to the documentation, the `idle` event fires when the map stops moving, but it doesn't wait for tiles to finish loading. I'm not sure what you mean by listening to `tilesloaded` when the map first loads – Hubro Feb 19 '15 at 15:33
  • You are right. there is no way, only listen for both events `idle` and `tilesloaded`and if `tilesloaded`is not fired you can animate your marker after a timeout. – sabotero Feb 19 '15 at 15:36
  • @sabotero: I have thought of that too, but I want my marker to drop immediately if the map is already idle and ready. In other cases, loading all the tiles can take several seconds because of slow internet connections. – Hubro Feb 19 '15 at 15:37
  • well you can maybe check also if all images being downloaded have finished, in other terms if there is no pending transactions, that is effectively (maybe) that all tiles have loaded – sabotero Feb 19 '15 at 15:46
  • @sabotero: How do I check that? – Hubro Feb 19 '15 at 15:47
  • check [this](http://stackoverflow.com/a/5202999/2776550) or [this](http://stackoverflow.com/a/3597640/2776550) – sabotero Feb 19 '15 at 15:59

0 Answers0