Vizzuality / cartodb-leaflet

Use your CartoDB table with Leaflet
http://vizzuality.github.com/cartodb-leaflet
62 stars 26 forks source link

Popup not working after setQuery #26

Closed alecsGarza closed 12 years ago

alecsGarza commented 12 years ago

Hello,

After changing the sql query to a layer, the Popup stops working.

Any suggestions or tips?

---- Edit --- This happens when having two different CartoDB layers and resetting the query on one of them

alecsGarza commented 12 years ago

For popups in different layers use

map.addLayer(popup);

instead of

map.openPopup(popup);

Example

         featureClick: function(ev,latlng,pos,data) {
           hideTooltip();
          // Stop propagation
          ev.stopPropagation();

            var html = "";

            html += "<br><label>Nombre del Centro</label><p>" + data["nombre_centro"] +"</p>";
            html += "<br><label>Domicilio</label><p>" + data["domicilio"] +"</p>";
            html += "<br><label>Codigo Postal</label><p>" + data["codigo_postal"] +"</p>";
            html += "<br><label>Municipio</label><p>" + data["nom_mun"] +"</p>";
            html += "<br><label>Estado</label><p>" + data["nom_estado"] +"</p>";
            html += "<br><label>Estatus</label><p>" + data["status"] +"</p>";
            html += "<br><label>Dependancia</label><p>" + data["dependencia"] +"</p>";
            html += "<br><label>Programa</label><p>" + data["programa"] +"</p>";
            html += "<br><label>Tipo</label><p>" + data["tipo"] +"</p>";

          popup.setContent(html);
          console.log(html ); 
          // Set latlng
          popup.setLatLng(latlng);

          // Show it!
          //map.openPopup(popup);

          map.addLayer(popup);
        },