3

I'm loading a map data tilelayer onto a Leaflet map using cartodb.

Upon user input, the map reconfigures its CartoCSS to display data differently. Example below.

layer.on({
    click: function(e){
        dataLayer.getSubLayer(0).set({
            cartocss: "#export { polygon-opacity: 0; }"         
        }).on("load", function(){ console.log("load"); });
     }
});

I'd like to be able to detect when the reconfigured layer has loaded -- there's sometimes a considerable lag -- with a "done" or "load" event. But neither works as drafted above, and the documentation doesn't give any hints as to any special promise/event for .set().

3

Load events seems to be supported (but aren't documented) on the dataLayer, but since promises aren't supported you would would have to setup the listener before you call the set, e.g:

dataLayer.on("load", function() { console.log('layer changed'); }); dataLayer.getSubLayer(0).set({ cartocss: "#export { polygon-opacity: 0; }"
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.