I want to update the content of my popup (it appears when clicking on a geojson-layer, and individuel for each feature).
Therefore I have to change "just" my variable of one column in the geojson.
Like this:
var co2= feature.properties.jahr1
and after updating it should be like this: co2 = feature.properties.jahr2
my initial onEachFeature from the layer looks like this:
onEachFeature: function(feature, layer ){
var name = feature.properties.name;
var co2 = feature.properties.__2013_1;
layer.bindPopup('<div id="infofenster_div">' +
'<h3>' + name + '</h3>' +
'<p><span>CO2-Emission: </span>' + co2 + ' %</p>' +
'</div>' )
}
And this is my function (without the variables it's working):
function change_popup(){
worldbankLayer.eachLayer(function (layer) {
layer._popup.setContent('<div id="infofenster_div">' +
'<h3>' + name + '</h3>' +
'<p><span>CO2-Emission: </span>' + co2 + ' %</p>' +
'</div>')
})
};
I call the function with click on a button. And like I said, without the try to call
feature.properties.mygeojsoncolumn
it's working just fine
I tried the
layer.setPopupContent(newContent);
too, and it's working just like the function before just without the properties... I also tried to declare the variables again, but the debugger always tells me, that 'feature is not defined'...
the code looks like this now:
function change_popup(){
var name = feature.properties.name;
var co2 = feature.properties.__2010_1;
worldbankLayer.eachLayer(function (layer) {
layer.setPopupContent('<div id="infofenster_div">' +
'<h3>' + name + '</h3>' +
'<p><span>CO2-Emission: </span>' + co2 + ' %</p>' +
'</div>')
})};
change_popup? – IvanSanchez Jun 26 '17 at 08:00