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 = [[45.47695909999999, 4.5181887, "peyrard-julien-pierre-39826"], [49.3340529, 6.0770431, "entreprise-czerevaty"], [48.88996909999999, 2.348202, "abaco-collaborative-design-studio-f57d90de-d45c-4d1c-bfcd-b4e4ac9c950d"], [43.4167219, 1.6284043, "90379756100011"], [48.903651, 2.2568247, "lusogaz-6ee089c5-6fa5-4aad-b439-fcbd097d22b7"], [48.8174891, 2.2975797, "raval-3000"], [50.0059268, 1.4125156, "92852741500014"], [49.4374089, 2.8486254, "totalenergies-proxi-nord-est-53a42988-054d-4831-bc0a-b2e1650b48fe"], [50.64098, 2.4115669, "totalenergies-proxi-nord-est-bc1875f8-0b7b-43c9-8edc-2695c63ac295"], [48.0714685, 6.814923400000001, "totalenergies-proxi-nord-est-b8091d7b-a80f-4767-80d9-4d0096d56d80"]];
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();
});