For reference: I use L.Control.Search
to search for my Marker.
It's this Plugin: https://github.com/stefanocudini/leaflet-search/blob/master/examples/multiple-layers.html
And this is the working search function: https://labs.easyblog.it/maps/leaflet-search/examples/multiple-layers.html
My problem: Now, I want the popup of the marker I searched for to open automatically without me clicking. I butchered the code from a polygon layer, but can I make it work for only markers? I don't get any errors but don't get a popup either.
var searchControl = new L.Control.Search({
layer: myLayer,
propertyName: 'name',
collapsed: false,
container: 'findbox',
textPlaceholder: 'Search',
marker: false,
initial: false,
buildTip: function (text, val) {
var type = val.layer.feature.properties.iconcategory;
return '<a href="#" class="' + type + '">' + text + '<b>' + type + '</b></a>';
},
moveToLocation: function (latlng, title, map, feature) {
var zoom = 16;
map.setView(latlng, zoom);
},
});
searchControl.on('search:locationfound', function(e, feature) {
if(e.layer._popup)
e.layer.openPopup("test");
}).on('search:collapsed', function(e) {
filterLayer.eachLayer(function(layer) {
filterLayer.resetStyle(layer);
});
});
map.addControl(searchControl);
This is a glimpse of the code I used for the popups.
onEachFeature: function forEachFeature(feature, layer) {
var popups = "Name <b>" +
feature.properties.name + "</b>;
if (feature.properties && feature.properties.popups) {
popups += feature.properties.popups;
} layer.bindPopup(popups);
},
feature.properties.name + "</b>;
, but you should get error for that), so it's impossible to say what's wrong without possibility to test complete code. What do you see if you inspecte.layer._popup
in the browser debugger?