I have a website with the carto.js library and some layers loaded. If I click on a feature, an Infowindow is opening up.

I know that there is an event for the feature click:

sublayer.on('featureClick', function(e, latlng, pos, data) {
          alert("Hey! You clicked " + data.cartodb_id);
  }).on('error', function() {
        //log the error

But I have not found any information on how to listen for the close event. Is it possible to create a listener on the close event of the infowindow?

Usecase: Change map content while the popup is open.


Check this example, it's using a custom infowindow but has the important bits you need. It's all about accessing the backbone model and then subscribing to the visibility change.


| improve this answer | |
  • 1
    Thanks, that looks good. Something I just saw is that if I switch between infowindows, without explicitly closing it, no event is fired. Do you know if there is a good solution to that or do I have to combine featureClick and visibility change? – Robin Dec 21 '16 at 7:52
  • I'd say so, yes – Jorge Sanz Dec 22 '16 at 8:57
  • I combined featureClick and visibility change and have nice results with that, thanks a lot! – Robin Dec 22 '16 at 21:53

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.