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.6172082, 1.3565093, "evo-fermetures"], [47.34985, 5.022149, "sarl-styl-renov-b7d0b2ba-2436-4ffd-a7b3-67e7f43ee09e"], [49.2347343, 1.0873995, "mennerun-bruno-1a93fbeb-c8bd-46b2-b38a-866a9de993f3"], [46.1753228, 5.5662641, "clim-monnier-3205"], [49.00752730000001, 2.1152539, "totalenergies-proxi-nord-est-fd7c7b19-6666-4d48-b38b-d7a33a988565"], [46.4042299, 6.688692499999999, "scdf-pertuiset-bruno-et-marc-23013"], [45.989771, 6.181936899999999, "audouin-charpente"], [48.8493678, 2.349987, "80748599000061"], [48.3742823, -2.6325777, "la-henonnaise-sarl-29767"], [49.2981482, 6.1078158, "climali"]];
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();
});