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 = [[47.4302664, 0.6769695, "cegelec-val-de-loire-d5e31ee5-401f-4683-9795-bc500d79f4a0"], [45.855033, 0.2869019, "amarenco-construction-ebcc6fc6-c4a6-408b-9da7-ea444324932c"], [44.5652416, 4.7350701, "amarenco-construction-df099695-3490-465f-bcde-20d42fadc916"], [45.7752912, 4.8243219, "ceci"], [43.1281785, 5.9127112, "electric-company"], [47.982961, -4.026273, "bouygues-energies-services-da9c6963-6284-4c94-bf66-b0800d064309"], [44.8841175, 4.8879742, "bouygues-energies-services-607bef06-bbb4-4e2e-b5f3-ea349c0eaa61"], [43.439236, -1.590062, "biscaichipy-bertrand-sarl-65822"], [50.6805631, 3.0549248, "menuiserie-vanson-sarl"], [45.636626, 6.441132, "bouygues-energies-services-d5dc1ca9-27d0-4e59-b070-3daf27451284"]]; 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(); });