var map,markers = [],iterator = 0,srcmarker,ib;
function initializeMap() {var isDraggable = $(document).width() > 767 ? true : false;
var mapOptions = {zoom: 6,disableDoubleClickZoom: false,draggable: isDraggable,center: new google.maps.LatLng(52, 6),mapTypeId: google.maps.MapTypeId.ROADMAP,disableDefaultUI: false,scrollwheel: false};
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
google.maps.event.addListenerOnce(map, 'idle', function () {dropMarkers();});
google.maps.event.trigger(map, 'resize');}
function dropMarkers() {deleteMarkers();var bounds = new google.maps.LatLngBounds();
$.getJSON("https://www.achterhoekinbeweging.nl/CMS/Custom/YounitedMarkers").done(function (data) {console.log(data);$.each(data, function (index, el) {var ll = new google.maps.LatLng(el.lat, el.lng);console.log(el.lat, el.lng);var imgIcon = "https://www.achterhoekinbeweging.nl/Content/images/icons/marker-green.png";
setTimeout(function () {markers.push(new google.maps.Marker({position: ll,map: map,draggable: false,animation: google.maps.Animation.DROP,icon: new google.maps.MarkerImage(imgIcon)}));var marker = markers[index];
}, index * 10);bounds.extend(ll);});
if (bounds.getNorthEast().equals(bounds.getSouthWest())) {var extendPoint1 = new google.maps.LatLng(bounds.getNorthEast().lat() + 0.03, bounds.getNorthEast().lng() + 0.03);var extendPoint2 = new google.maps.LatLng(bounds.getNorthEast().lat() - 0.03, bounds.getNorthEast().lng() - 0.03);bounds.extend(extendPoint1);bounds.extend(extendPoint2);}
map.fitBounds(bounds);});}
// Sets the map on all markers in the array.function setMapOnAll(map) {for (var i = 0; i < markers.length; i++) {markers[i].setMap(map);}}// Removes the markers from the map, but keeps them in the array.function clearMarkers() {setMapOnAll(null);}// Deletes all markers in the array by removing references to them.function deleteMarkers() {clearMarkers();markers = [];}initializeMap();