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 = [[49.2292203, 4.0872414, "otis-63a6084a-5170-4de4-a6b2-d49eb0e516c7"], [-20.9381149, 55.32709089999999, "otis-705e7dc4-22dd-41d4-96aa-d576bcb72b64"], [47.9740197, 0.1460997, "portis-8d733244-aa1c-4239-ab38-a42163faa621"], [48.3247197, 4.1035206, "portis-fe8a8260-f277-4fe1-96eb-c3b1dcfe1d7d"], [49.06001639999999, 3.941871, "otis-8f722ed0-a28b-4434-b0ad-5f987eaaf099"], [49.1753563, 6.161514899999999, "otis-74c2b088-05c1-491e-9cf1-30ba261a16ee"], [43.4928058, -1.4517673, "otis-d35af2d6-bb71-4d5b-8069-87a96768cd49"], [44.8363354, -0.6898120999999999, "otis-44333f63-93fb-4959-afa1-4fb07234a6a3"], [45.4166564, 4.3845147, "otis-2bbf710c-3824-4008-a653-e279b07b7207"], [14.6070561, -61.00555959999999, "otis-6f8d854f-6acc-44f4-a01e-21f04d023ad7"]];
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();
});