OpenGeoscience/geojs — pull request #170 by jbeezley (2014-08-07 18:30:12+00:00)
Title: implement osmLayer tilesLoaded event

This implements my original idea from #133, but I'm not sure it is a good idea now that I look at the result.

Changes:
* New `osmLayer.tilesLoading` method to query whether there are currently any tile operations pending
* New `geo.event.osmTilesLoaded` that fires when all current tile operations are finished

Possible usage would be something like this:
```javascript
if (map.baseLayer().tilesLoading()) {
map.on(geo.event.osmTilesLoaded, function handler () {
doSomething();
map.off(geo.event.osmTilesLoaded, handler);
})
} else {
doSomething();
}
```

This is overly verbose and could cause a race condition between querying `tilesLoaded()` and binding the event. I'm not sure what to do to improve it in a way that works in general. One idea is to add something like `layer.getDeferred` that returns a `$.Deferred` object when they layer is busy. Then there could be
```javascript
map.onIdle = function (handler) {
$.when.apply($, m_this.layers().map(function (layer) { return layer.getDeferred(); })
.done(handler);
}
```

So the above example becomes simply, `map.onIdle(doSomething);`. I think this would guarantee the handler will actually be called. I'm open to any suggestions.