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.103791, 5.4720159, "sade-compagnie-generale-de-travaux-hydrauliques-7591560e-9fc5-4e1c-b593-d502f6108c3f"], [47.3565095, -1.9503284, "sade-compagnie-generale-de-travaux-hydrauliques-7b5b2d1c-6782-46db-a188-b3922167e904"], [47.8218351, -0.3063016, "eiffage-energie-systemes-clemessy-936608e6-7674-4197-a1de-b57a2d01bf9c"], [49.0269284, 1.1868329, "sade-compagnie-generale-de-travaux-hydrauliques-d8f3df1b-2a74-41b8-a28a-d39eb4fb80bc"], [49.42003940000001, 1.1065743, "sade-compagnie-generale-de-travaux-hydrauliques-68332e55-d5fc-4de3-828f-33239b279b9f"], [49.5067833, 0.6274583, "85280219800014"], [48.27082000000001, 1.6194991, "service-assistance-bardage-etancheite"], [49.4066067, 0.6041811, "89501967700023"], [48.9502646, 1.1177134, "82234769600020"], [44.6429784, -1.0575987, "40129861700069"]];
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();
});