Hey there, I'm currently facing an issue with generating markers using leaflet js. I have an object that includes multiple entries for each year, and my goal is to create a layer group for each year that can be toggled on and off. However, I've encountered a roadblock - I'm struggling to figure out how to map only the entries that match the parent array, like matching 2016 == 2016.year...
The main challenge lies in mapping the second level items within the object structure:
{
"2016": [
{
"year": 2016,
"latitude": 50.9500019,
"longitude": 6.4836722
},
{
"year": 2016,
"latitude": 50.9500019,
"longitude": 6.4836722
}
],
"2017": [
{
"year": 2017,
"latitude": 50.9500019,
"longitude": 6.4836722
}
]
}
Here's the code snippet I'm currently working with:
const getGroupMarkers = (array, groupName) => Object.keys(array).map(function(keys, value){
array[keys].map(createMarkers.bind(groupName));
});
While this approach somewhat works, it returns markers for all years instead of just 2016.
If you're interested, here's a link to a pen showcasing what I'm trying to achieve. Look at line 270 for the specific function in question. https://codepen.io/sharperwebdev/pen/gvEQXe?editors=0010
Any assistance or insights on how to tackle this tricky situation would be greatly appreciated!
Thank you