如何放大传单保险丝搜索?

时间:2017-03-24 01:53:19

标签: javascript jquery leaflet mapbox

我正在使用传单和传单保险丝搜索来搜索地图中绘制的线条。 目前我的代码:

var map = L.map('map').setView([1.3096622448984000, 103.7689017333800], 12);

    L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=fhi', {
        maxZoom: 18,
        attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
            '<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
            'Imagery © <a href="http://mapbox.com">Mapbox</a>',
        id: 'mapbox.streets'
    }).addTo(map);
    map.doubleClickZoom.disable();

    var options = {
            position: 'topleft',
            title: 'Search',
            placeholder: 'enter link id ',
            maxResultLength: 15,
            threshold: 0.5,
            showInvisibleFeatures: true,
            showResultFct: function(feature, container) {
                props = feature.properties;
                var name = L.DomUtil.create('b', null, container);
                name.innerHTML = props.id;

                container.appendChild(L.DomUtil.create('br', null, container));

                var cat = props.id
                    info = '' + cat + ', ' + 'th link';
                container.appendChild(document.createTextNode(info));
            }
        };

    var searchCtrl = L.control.fuseSearch(options);

    searchCtrl.addTo(map);
searchCtrl.indexFeatures(zones.features, ['id']);
info.addTo(map);

所以现在当我搜索时我能够显示一个弹出窗口。但另外我想在我搜索时放大地图是否可能?感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

我在这里复制了我为How to zoom and change color in leaflet所做的答案:

我想我们必须修改createResultItem函数:

https://github.com/naomap/leaflet-fusesearch/blob/master/src/leaflet.fusesearch.js#L286

似乎该函数只允许openPoup / panAndpopup作为事件,在此步骤中添加其他事件或传递个人函数会很有用