I can't figure out grouping external data with leaflet. I have a CSV with my markers and put the markers with omnivore on my map.
How can I group the markers?
For example: I have 4 markers and they have a "type" specified in the csv. Let's say the type is called "freibad". How could I group all markers with the type "freibad" and put them in a layergroup called "freibad" as well to be able to filter them with the layer control?
//MARKERCLUSTER
//VARS II
var freibad=[];
function eachLayer(marker) {
var ltg = marker.toGeoJSON();
if(ltg.properties.type != ""){
marker.setIcon(L.icon({iconUrl:'/icons/'+ltg.properties.type+'.png'}));
}
if(ltg.properties.img != ""){
marker.bindPopup('<strong>' + ltg.properties.name + '</strong>' + '<br>' +
ltg.properties.description + '<br> <img src="/icons/' + ltg.properties.img +'">')
} else {
marker.bindPopup('<strong>' + ltg.properties.name + '</strong>' + '<br>' +
ltg.properties.description)
}
}
var points = omnivore.csv('/csv/POI.csv', {delimiter:'|'})
.on('ready', function() {
var markers = L.markerClusterGroup({
showCoverageOnHover: false,
maxClusterRadius: 50
});
markers.addLayer(points);
map.addLayer(markers);
points.eachLayer(eachLayer);
});
//LAYERGROUPS
var ebenengruppen = {
"<strong>Wanderrouten</strong>": {
"Wanderroute 1": wroute1,
"Wanderroute 2": wroute2,
"Wanderroute 3": wroute3,
"Freibad": freibad
}
};
//TILEMAPS
var basemaps = {
"Standard": standardTiles
}
var layerControlMobile = L.control.groupedLayers(basemaps, ebenengruppen, {collapsed:true}),
layerControl = L.control.groupedLayers(basemaps, ebenengruppen);
if(mobileDevices){
map.addControl(layerControlMobile);
}else{
map.addControl(layerControl);
}