Accueil Assets
function initMap() { var bounds = new google.maps.LatLngBounds(); var map = new google.maps.Map(document.getElementById('artisans-map'), { styles: styleMap }); var icon = { url: "https://artisans.quelleenergie.fr/assets/icones/geolocalize-02-57f71366ba86f935cf6949b551c67cc17042750d0fc34a5d7af80ac028bfae86.svg", scaledSize: new google.maps.Size(40, 40) } var iconSelectionne = { url: "https://artisans.quelleenergie.fr/assets/icones/geolocalize-01-5fe26a2a4ce9fd6566cc27b4fabb592a37fa7722f3e3d73019830ede8c4dbd05.svg", scaledSize: new google.maps.Size(40, 40) } var markers = [[4.937977399999999, -52.3354386, "cabestan-1c09f039-2f79-48ef-849b-208134d22ce3"], [43.28177609999999, 5.388999, "sarl-societe-construction-renovation"], [50.1131366, 3.042876, "gls-habitat-056b099a-3b51-4c60-b41a-3b31dba049b1"], [45.697663, 5.9234349, "martin-aymeric"], [47.96908, 7.397180999999999, "bex-jean-marc-4558374d-2cf6-4cfe-8edc-5e2f13be4429"], [46.057375, 6.2871104, "vidonne-sandy-maconnerie"], [44.964989, -0.2249183, "france-habitat-enr-5af4fdb3-5779-4365-a473-57f1416d6069"], [45.2187404, 2.3446735, "bellanger-sarl-6074"], [48.79701530000001, 2.3270924, "serrurerie-nouvelle-mdt-62295"], [43.4907838, 1.3189453, "tradi-renovation-0df0339a-4381-4920-860a-b8898c4191c2"]]; var dernierMarkerSelectionne; var listeObjetMarkers = [] for( i = 0; i < markers.length; i++ ) { var position = new google.maps.LatLng(markers[i][0], markers[i][1]); bounds.extend(position); marker = new google.maps.Marker({ position: position, map: map, url: markers[i][2], icon: icon }); listeObjetMarkers.push(marker) google.maps.event.addListener(marker, 'click', function() { montreCardArtisan(this); }); } map.fitBounds(bounds) map.panToBounds(bounds) $('.artisans-container .artisan-item').hover(function(){ montrePositionArtisan($(this)); }); function deselectionneMarker() { if (dernierMarkerSelectionne != undefined) { dernierMarkerSelectionne.setIcon(icon); } } function selectionneMarker(element) { $('.artisan-item.selectionne').removeClass('selectionne') element.toggleClass('selectionne') } function montreCardArtisan(marker) { deselectionneMarker(); marker.setIcon(iconSelectionne); var element = $('#'+marker.url); $('html, body').animate({ scrollTop: element.offset().top }, 600 ); selectionneMarker(element); dernierMarkerSelectionne = marker } function montrePositionArtisan(element) { selectionneMarker(element) var index = element.attr('id') for( i = 0; i < markers.length; i++ ) { if (listeObjetMarkers[i].url == index) { deselectionneMarker(); listeObjetMarkers[i].setIcon(iconSelectionne); dernierMarkerSelectionne = listeObjetMarkers[i] } }; } } $(document).on('turbolinks:load', function () { initMap(); });