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.7719432, 2.4937498, "proxiserve-2fee2006-bf98-4c20-8f21-4a9d1f96c09e"], [45.9223396, 6.0915626, "33487372601872"], [45.7048475, 4.989859, "proxiserve-a140b2ee-0371-4b32-b579-57b620a29293"], [48.9581629, 2.3923245, "proxiserve-f717be6e-03c7-4a3a-88d3-dcf9ae128395"], [48.7621484, 2.122883, "proxiserve-01d80761-8592-4a40-b90a-268e44dbba80"], [48.8495611, 2.4164747, "proxiserve-cc3a6742-0c54-4da8-8a40-68a9f3f9bd1f"], [43.9436133, 1.3241595, "proxiserve-3879b75d-e41f-46d0-b061-1f7d16b32541"], [46.2999552, -0.4986427, "proxiserve-041eec63-4339-48f8-bf17-09fe6bf04360"], [43.5099916, -1.435475, "proxiserve-f91a2568-39f3-47a9-8ca3-80f0839452ab"], [46.653046, -1.4438149, "proxiserve-316b5776-6ef9-4771-9fa1-55e0f7595225"]];
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();
});