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.987278, 6.606980999999999, "vue-du-ciel-sarl"], [48.3163837, 6.299854499999999, "adonis"], [48.9475224, 2.2585566, "otis-5be4a064-6ee0-4219-8fa3-d1291625b1c2"], [47.704203, 2.623451, "otis-faa3043d-8517-49ea-ba35-9acb7bbec0df"], [50.6751347, 3.1166688, "otis-5ed82951-e33b-4ebf-8d6e-5fc11a883c3f"], [48.7668168, 2.054973, "otis-104e980f-1257-4ece-a603-887b1537b10e"], [45.90415609999999, 6.091861, "otis-16a1b28f-3964-4ecc-8879-851ec68e5f36"], [48.8609151, 2.3861562, "otis-c990b182-5b25-4175-9c55-35cbaf6ba3d5"], [46.622981, -1.443282, "otis-d579c036-a385-4851-96ba-445c3fea5654"], [47.7829707, -3.3500624, "otis-92422358-8044-4e71-b45e-5fe3273c3f15"]];
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();
});