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.3641035, 1.4519385, "eurogem-9018c210-174d-4b7d-9c7e-fe7265d74d09"], [44.7776946, -0.6469984, "eurogem-3a4944a5-0733-4f68-b7b8-4ce5ab8ac9ef"], [48.80348799999999, 2.4090325, "eurogem-7f564fb1-2196-4caf-890e-02a2b747c054"], [49.4897631, 5.5128667, "bp-chauffage-sanitaire"], [50.3344687, 3.5316058, "dabrax-42200"], [43.605171, -0.99759, "elec-2000-63471"], [43.3335064, 3.2808605, "marc-habitat-solutions-b654292f-f98f-4ebe-a83e-78d107a048e7"], [43.571808, 1.487538, "spie-industrie-ce8749ef-fa1c-496e-8463-38943c0feaca"], [46.35802, 2.602607, "spie-industrie-5e58baa8-0ebc-4e99-8fd8-5a0137b69240"], [48.4343578, 1.5265979, "spie-industrie-c8b2ceeb-801a-400d-974a-0c74e670dd1a"]];
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();
});