传单控制搜索:打开弹出窗口以显示搜索结果 [英] Leaflet Control Search: open Popup for search result
问题描述
我正在使用很棒的插件 Leaflet.Control.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" )中进行搜索–是否有人可以一次在多个图层中进行搜索? /p>
有什么建议吗?我将不胜感激,在此先感谢您!
明白了:它的工作原理如下:e.layer.openPopup().openOn(map);
I'm using the wonderful plugin Leaflet.Control.Search in order to search for markers (from a geoJson marker group) on my map – which works great.
I only have one simple question now: how can I open a popup for the search result marker? I'm using custom marker icons with popups (which open on click) already bound to them – but I would like to open the respective popup automatically once it has been found via the search.
My code looks like this:
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
and thought it might work with that line:
e.layer.bindPopup(feature.properties.Name).openPopup();
but unfortunately it doesn't.. ;)
–
Oh, and a second question: at the moment I'm searching only in 1 geoJson layer ("markers2") – does anyone know whether it's possible to search in multiple layers at once?
Any suggestions? I'd be grateful for any help, thanks in advance!
got it: it works like this: e.layer.openPopup().openOn(map);
这篇关于传单控制搜索:打开弹出窗口以显示搜索结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!