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.9181526, 2.5357905, "giroux-olivier"], [46.7435894, -1.3877821, "88426664400019"], [46.39485579999999, 5.8673691, "engie-home-services-f325ad1a-ca2c-487f-985d-380ed5d0e64e"], [47.6328216, 5.8576666, "poissenot-patrick"], [43.553857, 2.178013, "ponce-menuiserie-entreprise-artibois-39731"], [46.979945, -0.2168536, "savelys-ag-thouars"], [49.1589458, 6.8516085, "engie-home-services-88d6b504-1e5c-4370-8963-5ea736c21224"], [46.9745609, 3.1585797, "engie-home-services-2027"], [48.8570247, 2.755689, "engie-home-services-69bda6c0-137a-47a4-93a5-ad68b9773d5b"], [44.8312059, -0.6737837999999999, "engie-home-services-3d6c8208-50c4-4941-8845-19842d3e16c3"]];
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();
});