Using leaflet, I call below function when I add a layer to the map. This function adds popups to each feature.
They work when I click on them but I can't get the bindPopup.openPopup()
to work so it opens without being clicked on.
There aren't any errors but the popup doesn't open without being clicked on.
var popupToOpen = null;
var clickedLocationId = 0;
function onEachFeature(feature, layer) {
if (feature.properties && feature.properties.UserName) {
if (feature.properties.MarkerId == clickedLocationId) {
layer.bindPopup("<div id='unlockLocationId'>" + feature.properties.MarkerId + "</div><div>" + feature.properties.UserName + "</div>").openPopup();
} else {
layer.bindPopup("<div id='unlockLocationId'>" + feature.properties.MarkerId + "</div><div>" + feature.properties.UserName + "</div>");
}
}
}