CartoDB / carto-vl

CARTO VL: a Javascript library to create vector-based visualizations
BSD 3-Clause "New" or "Revised" License
129 stars 26 forks source link

Fire a map-loaded event #48

Closed IagoLast closed 6 years ago

IagoLast commented 6 years ago

It would be nice to have a mechanism to know when the map is fully loaded.

IagoLast commented 6 years ago

As long as I know, we only have full control over the layer objects, and its better not to pollute the mapbox namespace. So my approach would be something like:

layer.on('loaded', callback);

Map loaded can be a syntetic-event fired when all layers are loaded.

@davidmanzanares any idea about how to implement this?

davidmanzanares commented 6 years ago

Should be layer.on('load', callback); to be Mapbox GL naming consistent.

The data layer should have an internal mechanism to let the layer know that everything needed is loaded. This could be another callback parameter to the _bindLayer() method. Once this is fired Layer must keep track of the "All data is here" state and then, after 2 repaints (in the moment the first repaint happens the data is painted over the GL context, but that the framebuffer hasn't been swapped yet) it should fire the event.

Regarding the implementation on the Dataset class, you need to keep track of the last requested tiles, and each time a new tile is returned from the server, you need to check if this is the last one you needed to inform the layer.

Jesus89 commented 6 years ago

Related to: https://github.com/CartoDB/renderer-prototype/issues/39

davidmanzanares commented 6 years ago

https://github.com/CartoDB/renderer-prototype/pull/113