Manually Open Popup

224 views
Skip to first unread message

Bryan McBride

unread,
Dec 11, 2012, 12:37:49 PM12/11/12
to leaflet-ve...@googlegroups.com
LVL seems to handle popups differently than Leaflet. With a typical Leaflet GeoJSON layer, you can open a popup based on a property like so:

geojson.eachLayer(function (layer) {
    var id = layer._leaflet_id;
    if (name === 'California') {
    map._layers[id].openPopup();
    }
});

I've tried iterating over an LVL layer to get the properties and Leaflet ID, but I'm stuck as far as triggering the popup. It looks like there is a _showPopup function, but I'm not quite sure how to wire it all up properly. Here's what I've got so far (using the map1 example on http://geojason.info/leaflet-vector-layers/demos/cartodb/):

for (each in cartodb_man_hole._vectors) {
//console.log(cartodb_man_hole._vectors[each]);
//console.log(cartodb_man_hole._vectors[each].vector._leaflet_id);
if (cartodb_man_hole._vectors[each].properties.cartodb_id == 2921) {
  var layer = cartodb_man_hole._vectors[each];
  cartodb_man_hole._showPopup(layer);
}
}

Any help you could provide would be most appreciated!

BRYAN

Bryan McBride

unread,
Dec 13, 2012, 12:13:41 AM12/13/12
to leaflet-ve...@googlegroups.com
So it looks like _showPopup expects an event as well as a feature... is there any proper way to manually trigger a popup based on a feature property? It is possible to create a new popup and add it to the map with something like this, but I'm guessing there's a better way...

function search(id) {
    for (each in cartodb_man_hole._vectors) {
        if (cartodb_man_hole._vectors[each].properties.cartodb_id == id) {
           var feature = cartodb_man_hole._vectors[each];
           var popup = new L.popup(cartodb_man_hole.options.popupOptions)
            .setLatLng(feature.vector._latlng)
            .setContent(feature.popupContent)
            .openOn(map1);
            }
    }
}

Thanks!

BRYAN
Reply all
Reply to author
Forward
0 new messages