1

How I can use the leaflet popups events through CartoDB. I have seen that some events are working like 'click', 'movestart',but 'popupclose' and 'popupopen' are not working. My goal is to do some tasks when the user closes the popup.

Can be the problem that I am using SVG in the infowindow?

I am using cartodb.createVis or should I use cartodb.createLayer instead? am I not noticing something?

cartodb.createVis('map', url) .done(function(vis, layers) { layers[1].setInteraction(true); layers[1].on('featureClick', function(e, latlng, pos, data, layerNumber) { cartodb.log.log(e, latlng, pos, data, layerNumber); }); var map = vis.getNativeMap(); map.on('click', function(e) { }); map.on('popupclose', function(e) { var marker = e.popup._source; }); map.on('popupopen', function(e) { var marker = e.popup._source; }); }); } 

1 Answer 1

1

A possible 'workaround' could be this

Basically, the 'trick' is to have a function that handles the infowindows visibility.

 var infowindow; var infowindowOpened = false; .done(function(vis, layers) { var layer = layers[1]; infowindow = layer.infowindow; infowindowOpened = false; $('#map').click(closeInfowindow); layer.on('featureClick',function(e, latlng, pos, data, subLayerIndex) { infowindowOpened = true; }); }) function closeInfowindow() { setTimeout(function() { if (!infowindowOpened) { infowindow.set('visibility', false); console.log('DO YOUR STUFF HERE'); } infowindowOpened = false; }, 250); } 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.