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 = [[43.118668, 5.831990999999999, "les-fenetres-seynoises-fd1625a0-e891-4cf9-a826-192f1c57d63f"], [43.109766, 5.8502741, "brizzi-facades-671d4809-0f25-4932-a4fc-b33ce2b7b550"], [48.9031159, 2.2751018, "coprom-12520"], [46.276821, 6.344812000000001, "saniconfort-8ee1d2b9-210f-414a-8553-eb8386ad0ee3"], [48.8567913, 2.317399, "coprom-e1be3bce-5e7b-42d9-b0eb-04ddea0489fb"], [49.0019106, 3.3615503, "eiffage-energie-systemes-lorraine-marne-ardennes-1c00ee93-4903-4309-8185-66c3cd1f7440"], [49.1099105, 7.0967949, "eiffage-energie-systemes-lorraine-marne-ardennes-120a7d8d-f62e-479c-a2ce-6fd1778948fe"], [48.2010953, 5.9408334, "eiffage-energie-systemes-lorraine-marne-ardennes-ff385504-06a4-4011-bc2c-e99981e0204a"], [46.2442252, 4.787332999999999, "flash-bat-sarl-51107"], [42.7736291, 3.015066, "espace-bois-43457"]];
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();
});