0

I combined two plugins: Leaflet search and cluster. But I want search points and automatically move to a location and view its popup. But it is not working, I can search, move to location but there's no automatic popup.

var markers = L.markerClusterGroup();

var geoJsonLayer = L.geoJson(data, {
    onEachFeature: function (feature, layer, marker) {
        layer.bindPopup( "ID vzorku "    + feature.properties.catalogNumber +
"</br> nadmořská výška "+ feature.properties.elevation + " m n.m."+
"<br> průměrná roční teplota "+feature.properties.t_year +"°C"+
"<br>  roční úhrn srážek    "+feature.properties.preci2 +" mm " );
    }
});
markers.addLayer(geoJsonLayer);

map.addLayer(markers);

//vytvoření panelu pro vyhledávání
var searchControl = new L.Control.Search({
    layer: markers,
    propertyName: 'catalogNumber',  // pole přes které se vyhledává
circleLocation: true,
marker: false,


moveToLocation: function(latlng, catalogNumber, map) { console.log(latlng); map.setView(latlng, 10); } 
});

searchControl.on('search:locationfound', function(e) {

    //console.log('search:locationfound', );



        e.layer.openPopup("OBJECTID");

}).on('search:collapsed', function(e) {

featuresLayer.eachLayer(function(layer) {   //restore feature color
featuresLayer.resetStyle(layer);

1 Answer 1

1

This might help. Once you have the selected feature, use the .fire('click'); it's like you clicking on a feature with the mouse. In my code 'a' is the selected feature, I also use this to zoom to the selected feature.

// fire off click event and zoom to polygon
function polySelect(a){
    map._layers[a].fire('click');
    var layer = map._layers[a];
    map.fitBounds(layer.getBounds());
}// END...fire off click event and zoom to polygon
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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