Within my leaflet project, I created a function that accepts an array containing objects, each of which holds an array of markers and an ID to distinguish the group.
Here is the sample array:
var markerGroupArray = [
{ features: [L.marker([39.61, -105.02]).bindPopup('This is Littleton, CO.'),
L.marker([39.74, -104.99]).bindPopup('This is Denver, CO.'),
L.marker([39.73, -104.8]).bindPopup('This is Aurora, CO.'),
L.marker([39.77, -105.23]).bindPopup('This is Golden, CO.')], id: 'Group 1'},
{ features: [L.marker([39.51, -105.02]).bindPopup('Somewhere else'),
L.marker([39.64, -104.99]).bindPopup('Somewhere else'),
L.marker([39.63, -104.8]).bindPopup('Somewhere else'),
L.marker([39.67, -105.23]).bindPopup('Somewhere else')], id: 'Group 2'}
];
This array is used as input for the following function:
addOverlayMap: function (overlayMapArray) {
for (var i = 0; i < overlayMapArray.length; i++)
{
var layerGroup = L.layerGroup();
for (var j = 0; j < overlayMapArray[i][features].length; j++)
{
layerGroup.addLayer(overlayMapArray[i][features][j]);
}
this.overlayMapObject[overlayMapArray[i][id]] = layerGroup;
}
this.refreshLayerControl();
}
I encounter an error stating that the "features" key is not defined. What could be causing this issue?