Source: How to use map function and arrow function inside another function?
1 2 3 4 |
function arrayCalc(arr, fn){ const arrRes = arr.map(a => fn(a)); // and not .map(arr => arr) return arrRes; // missing return statement } |
Ou:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
function setMarkers(sourceArray, handleBounds = true) { // Autozoom and autocenter for Google maps Clustermap // https://stackoverflow.com/a/40109734 let labels = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; if (handleBounds) { mapApi.boundsObj = mapApi.setBoundsRestriction(); } const arrRes = sourceArray.map(function(location, i) { // console.log('location: ', location); if (handleBounds) { mapApi.boundsObj.extend(location); /* Sets the viewport to contain the given bounds. */ mapApi.mapObj.fitBounds(mapApi.boundsObj); } let marker = new google.maps.Marker({ position: location, label: labels[i % labels.length] }); return marker; }); return arrRes; } |
1 |
stateSynchronizer.allMarkersObj = mapApi.setMarkers(stateSynchronizer.allLocationsArr, false); |