3

I have two different layers in a leaflet map. I have one layer in which I would like the popup to return some text from the layer's attributes. They other layer I would like the popup to return an image which I have embedded the link to in the layers attributes. I have successfully implemented both of the layer.bindpopup functions successfully individually but I'm having no luck implementing them together.

function onPlot(feature, layer) {
    if (feature.properties) {
        layer.bindPopup(
            '<img src= "' + feature.properties.Plot + 
            '" "alt="Elk Hunting Success Trends Plot"' + 
            ' height="500" width="500">');
    }
};

function onEachFeature(feature, layer) {
    if (feature.properties) {
        layer.bindPopup( 
            '<center>' + feature.properties.Anum + 
            '<br><center> Hunting District: ' + 
            feature.properties.DISTRICT + 
            "<br><center> Elk Hunter Success " + 
            feature.properties.Success +" %");
    }
};

function style (feature,layer){
    if (feature.properties) {
        return  {
            color: feature.properties.color, 
            fillColor: feature.properties.fillColor, 
            fillOpacity: feature.properties.fillOpacity
        };
    }
};

var Plot= new L.geoJson(Plots, {
    onPlot:onPlot
    style:style
}).addTo(map);

var S_2006= new L.geoJson(Success_2006, {
    onEachFeature: onEachFeature,
    style:style
}).addTo(map);
3

It turns out I just needed to use an else if statement in the onEachFeature function, which uses layer.bindPopup.

function onEachFeature(feature, layer) {
if (feature.properties.Anum) {
    layer.bindPopup( '<center>' +feature.properties.Anum +'<br><center> Hunting District: ' +feature.properties.DISTRICT+ "<br><center> Elk Hunter Success " +feature.properties.Success +" %");
}
else if (feature.properties.Plot) {
    layer.bindPopup('<img src= "' +feature.properties.Plot +'" "alt="Elk Hunting Success Trends Plot" height="500" width="500">');
}
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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