'How to display 2 values on leaflet control search result(tooltip)
i'm using leaflet-control-search to search for markers.http://labs.easyblog.it/maps/leaflet-search/examples/outside.html markers are stored in json like this
[{"loc":["lat","lng"],"title":"black","region":"West-Kilimajaro"}]
in the script above its only displaying 1 value:screen shot
i want to display 2(two) values 'title and 'colour';
Solution 1:[1]
i finally found the solution second attribute is suppose to be added as follows
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);}
markers are stored in json should look like this
{"loc":[-3.3869, 36.6830], "title": "aquamarinee", "region": "West-Kilimanaro"}
Solution 2:[2]
From the example on project's github repo at 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);
}
To add extra values to the marker , you update this line with the extra fields
marker.bindPopup('title: '+ title + ' color:' data[i].color);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Kiwagi |
Solution 2 | Glorfindel |