0

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.

1 Answer 1

1

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.

http://bl.ocks.org/jsanz/d74d38a3410ab9b9816defea31e7d401

3
  • 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
    Commented Dec 21, 2016 at 7:52
  • I'd say so, yes
    – Jorge Sanz
    Commented Dec 22, 2016 at 8:57
  • I combined featureClick and visibility change and have nice results with that, thanks a lot!
    – Robin
    Commented Dec 22, 2016 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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