Search 传单控件搜索:打开搜索结果弹出窗口

Search 传单控件搜索:打开搜索结果弹出窗口,search,popup,leaflet,Search,Popup,Leaflet,我正在使用这个很棒的插件来搜索地图上的标记(来自geoJson标记组),这非常有效 我现在只有一个简单的问题: 如何打开搜索结果标记的弹出窗口? 我使用的自定义标记图标与弹出窗口(点击打开)已绑定到它们-但我想在通过搜索找到相应的弹出窗口后自动打开 我的代码如下所示: var searchControl = new L.Control.Search({layer: markers2, propertyName: 'Name', circleLocation:true}); search

我正在使用这个很棒的插件来搜索地图上的标记(来自geoJson标记组),这非常有效

我现在只有一个简单的问题: 如何打开搜索结果标记的弹出窗口? 我使用的自定义标记图标与弹出窗口(点击打开)已绑定到它们-但我想在通过搜索找到相应的弹出窗口后自动打开

我的代码如下所示:

var searchControl = new L.Control.Search({layer: markers2, propertyName: 'Name', circleLocation:true});

    searchControl.on('search_locationfound', function(e) {

            e.layer.bindPopup(feature.properties.Name).openPopup();

    }).on('search_collapsed', function(e) {
            markers2.resetStyle(layer);
    });

    map.addControl( searchControl );  //inizialize search control
并认为这可能适用于这一行:

e.layer.bindPopup(feature.properties.Name).openPopup();
但不幸的是,它没有……)

哦,还有第二个问题:目前我只搜索1个geoJson层(“markers2”)——有人知道是否可以同时搜索多个层吗


有什么建议吗?如果有任何帮助,我将不胜感激,提前谢谢

明白了:它是这样工作的:e.layer.openPopup().openOn(map)

明白了:它是这样工作的:e.layer.openPopup().openOn(map)

event.layer仅在通过ajax、jsonp或callData搜索标记时为预加载层设置。。event.layer未定义

var geojsonLayer = new L.GeoJSON(data, {
        onEachFeature: function(feature, marker) {
            marker.bindPopup(feature.properties.name);
        }
    });

map.addLayer(geojsonLayer);

var controlSearch = new L.Control.Search({layer: geojsonLayer, initial: false});

controlSearch.on('search_locationfound', function(event) {
    event.layer.openPopup();
});
请看GeoJSON演示:

如果您通过ajax、jsonp或callData搜索标记,则仅为预加载的层设置event.layer。。event.layer未定义

var geojsonLayer = new L.GeoJSON(data, {
        onEachFeature: function(feature, marker) {
            marker.bindPopup(feature.properties.name);
        }
    });

map.addLayer(geojsonLayer);

var controlSearch = new L.Control.Search({layer: geojsonLayer, initial: false});

controlSearch.on('search_locationfound', function(event) {
    event.layer.openPopup();
});
请看GeoJSON演示:

您是否尝试过使用e.layer.bindpoppup(feature.properties.Name).addTo(map.openPopup();我想你必须告诉它在哪里开门。所以像addTo()或openOn()之类的东西可能会起作用。检查文档嗨,克里斯,谢谢你的指点!你的建议听起来似乎是对的,但似乎不起作用。。嗯,在上面的搜索代码之前的某个时刻,我已经定义了弹出内容,所以我想我不必为搜索弹出重复该内容,我只需要告诉它打开弹出。。但是怎么做?!;)弹出窗口的代码(在搜索之前)如下所示:var markers2=new L.MarkerClusterGroup();var geoJsonLayer2=L.geoJson(数据,{onEachFeature:function(feature,layer){layer.bindpoop(feature.properties.Name);}…明白了:它是这样工作的:e.layer.openPopup().openOn(map);你试过做e.layer.bindpoop(feature.properties.Name).addTo(map.openPopup());我想你必须告诉它在哪里打开。所以像addTo()或openOn()之类的东西可能有用。检查文档嗨,克里斯,谢谢你的指点!你的建议听起来不错,但似乎不是那样的..嗯,在上面的搜索代码之前的某个时刻,我已经定义了弹出内容,所以我想我不必在搜索弹出窗口中重复该内容,我只需要告诉它打开弹出窗口。。但是怎么做呢?!;)弹出窗口的代码(在搜索之前)是这样的:var markers2=newl.MarkerClusterGroup();var geoJsonLayer2=L.geoJson(数据,{onEachFeature:function(feature,layer){layer.bindpup(feature.properties.Name);}…明白了:它是这样工作的:e.layer.openPopup().openOn(map);至于我的第二个问题,有人给我一个提示吗?目前我只在1个geoJson层
L.Control.Search({layer:markers2,propertyName…
–有人知道是否可以同时在多个层中搜索吗?我这样尝试:
{layer:
不起作用…至于我的第二个问题,有人给我一个提示吗?目前我只在1个geoJson层
L.Control.Search中搜索({layer:markers2,propertyName…
–有人知道是否可以同时在多个层中搜索吗?我这样尝试:
{layer:(markers1,markers2),propertyName…
不起作用…