[GIS] Leaflet how move to search location

leaflet

i tried leaflet search control. Searching works great, i can see list with my points names, but when I want search it, it does not work, not move to search point. My JSON data are points. ` var data = us_states;

var map = new L.Map('map', {zoom: 5, center: new L.latLng([37.8, 16]) });

map.addLayer(new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png')); //base layer

var featuresLayer = new L.GeoJSON(data, {
        style: function(feature) {
            return {color: feature.properties.color };
        },
        onEachFeature: function(feature, marker) {
            marker.bindPopup('<h4 style="color:'+feature.properties.color+'">'+ feature.properties.OBJECTID +'</h4>');
        }
    });

map.addLayer(featuresLayer);

var searchControl = new L.Control.Search({
    layer: featuresLayer,
    propertyName: 'OBJECTID',
    marker: false,
    moveToLocation: function(latlng, OBJECTID, map) {

        var zoom = map.getBoundsZoom(latlng.layer.getBounds());
        map.setView(latlng, zoom); // access the zoom
    }
});

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

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

    //map.removeLayer(this._markerSearch)`

Best Answer

Maybe this will help. I manually figured out a zoom level that I wanted it to go to and set it in the control, after all it's just a marker. I would do it different if it was a polygon.

    var searchControl = new L.Control.Search({
    layer: bbTeam,                //layer name to search
    propertyName: 'Name',         //Search field
    marker: false,
    moveToLocation: function(latlng, title, map) {
        map.setView(latlng, 7);    // set the zoom
    }
});