如何在传单控件搜索结果中显示2个值(工具提示)

时间:2017-02-13 15:49:06

标签: javascript maps leaflet react-leaflet

我正在使用传单控制搜索来搜索标记。http://labs.easyblog.it/maps/leaflet-search/examples/outside.html 标记存储在json中,如此

[{"loc":["lat","lng"],"title":"black","region":"West-Kilimajaro"}]

在上面的脚本中只显示1个值:screen shot

我想显示2(两个)值'标题和'颜色';

2 个答案:

答案 0 :(得分:0)

来自项目' github repo的示例 Project's Github example html

////////////populate map with markers from sample data
for(i in data) {
    var title = data[i].title,  //value searched
        loc = data[i].loc,      //position found
        marker = new L.Marker(new L.latLng(loc), {title: title} );//se property searched
    marker.bindPopup('title: '+ title );
    markersLayer.addLayer(marker);
}

要为标记添加额外值,请使用额外字段

更新此行
marker.bindPopup('title: '+ title + ' color:' data[i].color);

答案 1 :(得分:0)

我终于找到了解决方案的第二个属性,假设要添加如下

 for(i in data) {
 var title = data[i].title,region=data[i].region,
 loc = data[i].loc, 
 marker = new L.Marker(new L.latLng(loc), {title: title,region:region} );
 marker.bindPopup('title: '+ title );
 markersLayer.addLayer(marker);}

标记存储在json中应该看起来像这样

{"loc":[-3.3869, 36.6830], "title": "aquamarinee", "region": "West-Kilimanaro"}