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 = [[48.778416, 2.3146197, "entreprise-rousseau-ae4984c5-cdfb-4e81-a644-cbd57417c3a3"], [48.10043899999999, -0.7547929999999999, "spie-industrie-tertiaire-28e73569-6051-40ae-bfbb-af65728d2e2b"], [48.12750620000001, 7.3508941, "ensio-est-08bbad03-aed9-43d1-9b03-231442c221d6"], [45.369679, 6.051264, "energies-renouvelables-services"], [45.809069, 1.2848876, "spie-industrie-tertiaire-1cfbc175-ca1b-45d2-b6a2-6ea1119232cf"], [43.6766994, 3.9802494, "patrick-suay-69132"], [44.40098, 0.9979094, "haka-energy-66958"], [48.817275, 2.2977599, "spie-industrie-tertiaire-0b3c379d-7187-44e5-8756-4e326e07db91"], [48.3997563, -2.5883225, "etablissements-franck-herve-29839"], [46.053662, 4.6699149, "kmc-toitures"]];
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();
});