7

I'm working with Wax with Leaflet. I'm setting up a map of the US, drawing state boundaries with GeoJSON using leaflet's L.GeoJSON.

I'm able to get everything set during the map load, but I need to be able to adjust the content in the popups after the map is drawn. Here's a stripped down version of what I'm doing:

var gjStates = new L.GeoJSON(null, null);
wax.tilejson(url, function(tilejson) {  
    map = new L.Map('map').addLayer(new wax.leaf.connector(tilejson)).addLayer(gjStates);

    gjStates.on("featureparse", function (e) {
        if (e.properties && e.properties.name){
            pops[e.id.substring(4)] = e.layer.bindPopup('<h4>Hello ' + e.properties.name + '!</h4>');
        }
    });
    for (s in usStateData) {
        gjStates.addGeoJSON(usStateData[s]);
    }
});

Now, everything draws fine, popups have good conent, but then I want to alter it later and there's no way to reference it. I saw in the source that bindPopup() returns 'this', which I thought was the L.Popup object, but ended up something else. So for instance, the following code will udpate the active popup, not the specific one for the specific L.Path object(state) I'm trying to get at.

pops['AK']._map._popup.setContent('I am ALASKA!');

Digging through the DOM with firebug, I can also see that the popup content is set in an internal variable and I can update it. However, updating this does not update the HTML, and there's no way for me to find out that Alaska has the key of 52. _layers[52] also does not have the setContent() method I'd hope for if it was an L.Popup object.

gjStates._layers[52]._popupContent = 'I am ALASKA!';

So, I'm kind of stuck and not finding what I need. Is there any way for me to reference, and update the content for, a specific popup on the map after the initial rendering?

2

1 Answer 1

1

I'm pretty sure you can just keep references to all the layers, and then call layer.bindPopup() at a later time to change the popup content.

2
  • What layers? gjStates? That imports all the different state content and I just want to change the popup content on each object on that layer. Commented Mar 23, 2012 at 20:55
  • e.layer in the featureparse event handler
    – Acorn
    Commented Mar 23, 2012 at 22:05

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