$('#collapseMap').on('shown.bs.collapse', function(e){ (function(A) { if (!Array.prototype.forEach) A.forEach = A.forEach || function(action, that) { for (var i = 0, l = this.length; i < l; i++) if (i in this) action.call(that, this[i], i, this); }; })(Array.prototype); var mapObject, markers = [], markersData = { 'experience': [ { name: 'Etna 4x4 excursion. Deep into the wild Nature', location_latitude: 37.700134, location_longitude: 14.998231, map_image_url: 'js/temp/thumb_mappa_suntripsicily_experience_1.jpg', name_point: 'Etna 4x4 excursion. Deep into the wild Nature', description_point: '', get_directions_start_address: '', phone: '+393927661318', url_point: '1-experience-etna-x-excursion-deep-into-the-wild-nature.php' }, { name: 'Private Sailing Experience', location_latitude: 37.728652, location_longitude: 15.208455, map_image_url: 'js/temp/thumb_mappa_suntripsicily_experience_2.jpg', name_point: 'Private Sailing Experience', description_point: '', get_directions_start_address: '', phone: '+393927661318', url_point: '2-experience-private-sailing-experience.php' }, { name: 'Cooking class with Piero D\'Agostino, Michelin starred chef of exquisite Restaurant ', location_latitude: 37.864203, location_longitude: 15.296088, map_image_url: 'js/temp/thumb_mappa_suntripsicily_experience_11.jpg', name_point: 'Cooking class with Piero D\'Agostino, Michelin starred chef of exquisite Restaurant ', description_point: '', get_directions_start_address: '', phone: '+393927661318', url_point: '11-experience-cooking-class-with-piero-dagostino-michelin-starred-chef-of-exquisite-restaurant.php' }, { name: 'Discovering the South-East: Noto, Modica, Ragusa Ibla', location_latitude: 36.890900, location_longitude: 15.070673, map_image_url: 'js/temp/thumb_mappa_suntripsicily_experience_13.jpg', name_point: 'Discovering the South-East: Noto, Modica, Ragusa Ibla', description_point: '', get_directions_start_address: '', phone: '+393927661318', url_point: '13-experience-discovering-the-southeast-noto-modica-ragusa-ibla.php' }, { name: 'Motor Boat Day Rental', location_latitude: 37.728649, location_longitude: 15.208452, map_image_url: 'js/temp/thumb_mappa_suntripsicily_experience_16.jpg', name_point: 'Motor Boat Day Rental', description_point: '', get_directions_start_address: '', phone: '+393927661318', url_point: '16-experience-motor-boat-day-rental.php' }, { name: 'Home Restaurant', location_latitude: 37.621019, location_longitude: 15.129797, map_image_url: 'js/temp/thumb_mappa_suntripsicily_experience_18.jpg', name_point: 'Home Restaurant', description_point: '', get_directions_start_address: '', phone: '+393927661318', url_point: '18-experience-home-restaurant.php' }, { name: 'Wine Tasting Experience', location_latitude: 37.814467, location_longitude: 15.118592, map_image_url: 'js/temp/thumb_mappa_suntripsicily_experience_20.jpg', name_point: 'Wine Tasting Experience', description_point: '', get_directions_start_address: '', phone: '+393927661318', url_point: '20-experience-wine-tasting-experience.php' }, { name: 'Adventure Park on Mount Etna', location_latitude: 37.730998, location_longitude: 15.111749, map_image_url: 'js/temp/thumb_mappa_suntripsicily_experience_21.jpg', name_point: 'Adventure Park on Mount Etna', description_point: '', get_directions_start_address: '', phone: '+393927661318', url_point: '21-experience-adventure-park-on-mount-etna.php' }, { name: 'Sicilian Farm & Nature - Milo', location_latitude: 37.717668, location_longitude: 15.127542, map_image_url: 'js/temp/thumb_mappa_suntripsicily_experience_22.jpg', name_point: 'Sicilian Farm & Nature - Milo', description_point: '', get_directions_start_address: '', phone: '+393927661318', url_point: '22-experience-sicilian-farm-nature-milo.php' }, { name: 'Vip Sailing & Sunset Dolphin', location_latitude: 37.824811, location_longitude: 15.274689, map_image_url: 'js/temp/thumb_mappa_suntripsicily_experience_25.jpg', name_point: 'Vip Sailing & Sunset Dolphin', description_point: '', get_directions_start_address: '', phone: '+393927661318', url_point: '25-experience-vip-sailing-sunset-dolphin.php' }, { name: 'Excursion to Etna Summit', location_latitude: 37.700661, location_longitude: 14.999111, map_image_url: 'js/temp/thumb_mappa_suntripsicily_experience_24.jpg', name_point: 'Excursion to Etna Summit', description_point: '', get_directions_start_address: '', phone: '+393927661318', url_point: '24-experience-excursion-to-etna-summit.php' }, { name: 'Etna Quad Adventure', location_latitude: 37.80819, location_longitude: 15.07476, map_image_url: 'js/temp/thumb_mappa_suntripsicily_experience_26.jpg', name_point: 'Etna Quad Adventure', description_point: '', get_directions_start_address: '', phone: '+393927661318', url_point: '26-experience-etna-quad-adventure.php' }, ] }; var coords = "37.700134,14.998231|37.728652,15.208455|37.864203,15.296088|36.890900,15.070673|37.728649,15.208452|37.621019,15.129797|37.814467,15.118592|37.730998,15.111749|37.717668,15.127542|37.824811,15.274689|37.700661,14.999111|37.80819,15.07476|"; var filteredtextCoordinatesArray = coords.split('|'); centerLatArray = []; centerLngArray = []; for (i=0 ; i < filteredtextCoordinatesArray.length ; i++) { var centerCoords = filteredtextCoordinatesArray[i]; var centerCoordsArray = centerCoords.split(','); if (isNaN(Number(centerCoordsArray[0]))) { } else { centerLatArray.push(Number(centerCoordsArray[0])); } if (isNaN(Number(centerCoordsArray[1]))) { } else { centerLngArray.push(Number(centerCoordsArray[1])); } } var centerLatSum = centerLatArray.reduce(function(a, b) { return a + b; }); var centerLngSum = centerLngArray.reduce(function(a, b) { return a + b; }); var centerLat = centerLatSum / filteredtextCoordinatesArray.length ; var centerLng = centerLngSum / filteredtextCoordinatesArray.length ; console.log(centerLat); console.log(centerLng); var mapOptions = { zoom: 8, /*center: new google.maps.LatLng(37.80819, 15.07476),*/ center: new google.maps.LatLng(37.574841, 14.255670), mapTypeId: google.maps.MapTypeId.ROADMAP, mapTypeControl: false, mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU, position: google.maps.ControlPosition.LEFT_CENTER }, panControl: false, panControlOptions: { position: google.maps.ControlPosition.TOP_RIGHT }, zoomControl: true, zoomControlOptions: { style: google.maps.ZoomControlStyle.LARGE, position: google.maps.ControlPosition.TOP_LEFT }, scrollwheel: false, scaleControl: false, scaleControlOptions: { position: google.maps.ControlPosition.TOP_LEFT }, streetViewControl: true, streetViewControlOptions: { position: google.maps.ControlPosition.LEFT_TOP }, styles: [ { "featureType": "landscape", "stylers": [ { "hue": "#FFBB00" }, { "saturation": 43.400000000000006 }, { "lightness": 37.599999999999994 }, { "gamma": 1 } ] }, { "featureType": "road.highway", "stylers": [ { "hue": "#FFC200" }, { "saturation": -61.8 }, { "lightness": 45.599999999999994 }, { "gamma": 1 } ] }, { "featureType": "road.arterial", "stylers": [ { "hue": "#FF0300" }, { "saturation": -100 }, { "lightness": 51.19999999999999 }, { "gamma": 1 } ] }, { "featureType": "road.local", "stylers": [ { "hue": "#FF0300" }, { "saturation": -100 }, { "lightness": 52 }, { "gamma": 1 } ] }, { "featureType": "water", "stylers": [ { "hue": "#0078FF" }, { "saturation": -13.200000000000003 }, { "lightness": 2.4000000000000057 }, { "gamma": 1 } ] }, { "featureType": "poi", "stylers": [ { "hue": "#00FF6A" }, { "saturation": -1.0989010989011234 }, { "lightness": 11.200000000000017 }, { "gamma": 1 } ] } ] }; var marker; mapObject = new google.maps.Map(document.getElementById('map'), mapOptions); for (var key in markersData) markersData[key].forEach(function (item) { marker = new google.maps.Marker({ position: new google.maps.LatLng(item.location_latitude, item.location_longitude), map: mapObject, icon: 'img/pins/' + key + '.png', }); if ('undefined' === typeof markers[key]) markers[key] = []; markers[key].push(marker); google.maps.event.addListener(marker, 'click', (function () { closeInfoBox(); getInfoBox(item).open(mapObject, this); mapObject.setCenter(new google.maps.LatLng(item.location_latitude, item.location_longitude)); })); }); function hideAllMarkers () { for (var key in markers) markers[key].forEach(function (marker) { marker.setMap(null); }); }; function closeInfoBox() { $('div.infoBox').remove(); }; function getInfoBox(item) { return new InfoBox({ content: '
' + 'Image' + '

'+ item.name_point +'

' + ''+ item.description_point +'' + '
' + '
' + ''+ item.phone +'' + '
' + 'Details' + '
', disableAutoPan: false, maxWidth: 0, pixelOffset: new google.maps.Size(10, 125), closeBoxMargin: '5px -20px 2px 2px', closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif", isHidden: false, alignBottom: true, pane: 'floatPane', enableEventPropagation: true }); }; });