Учитывая ваш предоставленный массив, я бы
- Это
bindPopup
, а не bindpopup
- построил
markers
как Object {}
- Получить все (не NULL) POI "props" (например,
"toddler"
, "wc"
et c) - Итерировать извлечены реквизиты, вставив
newMarker()
в markers
объект.
const markers = {};
const newMarker = poi => L.marker([poi.lat, poi.lng], {icon: poi.icon})
.bindPopup(`<a href="${poi.url}">${poi.name}</a>`);
const parks = [
['Spårvagnsparken', 59.3298868, 18.0031605, 'http://leksplay.com/sparvagnsparken', "greenIcon", "wc", "grill", null, null, "pfence", null, null, null, null],
['Fredhällsparkens plaskdamm', 59.3320485, 18.0029481, 'http://leksplay.com/fredhallsparkensplaskdamm', "greenIcon", "wc", null, null, null, null, null, null, "water", null],
['Uggleparken', 59.3343715, 18.0040208, 'http://leksply.com/uggleparken', "greenIcon", "wc", null, null, null, null, "pfence", null, null, null],
['Observatorielundens Parklek', 59.3413877, 18.056007, 'http://leksplay.com/observatorielundensparklek', "greenIcon", "wc", null, null, null, null, "pfence", null, null, "toddler"],
];
parks.forEach(([name, lat, lng, url, icon, ...props]) => {
props.filter(Boolean).forEach(prop => {
if (!(prop in markers)) markers[prop] = []; // Prepare if not exists
markers[prop].push(newMarker({name, lat, lng, url, icon}));
});
})
console.log(markers);
Пример (только с объектами, для демонстрации):
const markers = {};
const newMarker = poi => poi;
const parks = [
['Spårvagnsparken', 59.3298868, 18.0031605, 'http://leksplay.com/sparvagnsparken', "greenIcon", "wc", "grill", null, null, "pfence", null, null, null, null],
['Fredhällsparkens plaskdamm', 59.3320485, 18.0029481, 'http://leksplay.com/fredhallsparkensplaskdamm', "greenIcon", "wc", null, null, null, null, null, null, "water", null],
['Uggleparken', 59.3343715, 18.0040208, 'http://leksply.com/uggleparken', "greenIcon", "wc", null, null, null, null, "pfence", null, null, null],
['Observatorielundens Parklek', 59.3413877, 18.056007, 'http://leksplay.com/observatorielundensparklek', "greenIcon", "wc", null, null, null, null, "pfence", null, null, "toddler"],
];
parks.forEach(([name, lat, lng, url, icon, ...props]) => {
props.filter(Boolean).forEach(prop => {
if (!(prop in markers)) markers[prop] = []; // Prepare if not exists
markers[prop].push(newMarker({name, lat, lng, url, icon}));
});
})
console.log(markers);