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.5764638, 3.9114032, "84165153200027"], [48.6792905, 6.1566555, "timo-53608"], [48.8572008, 2.4927717, "yarok-2cac9ac1-12c9-4210-95b3-a4f25a9230a2"], [48.7332177, 2.5507232, "rubik-s-clim"], [14.6826541, -61.0337749, "eiffage-energie-systemes-clemessy-85d3685b-87ee-4680-8474-3c6142e5fbe1"], [47.816391, 0.731629, "eiffage-energie-systemes-clemessy-25b5d3f5-d5c9-4099-84f2-ebd1d71067cc"], [48.184176, 3.323282, "eiffage-energie-systemes-clemessy-76c1e0e1-c65d-4ae7-8373-89ad8df62c7a"], [48.4572142, -4.44925, "eiffage-energie-systemes-clemessy-0ae20f46-a0c6-4ad8-b2b6-afae69a702d2"], [45.7679252, 5.0365909, "eiffage-energie-systemes-clemessy-9f70dc4f-38fc-4dce-bde5-30ccc87edb75"], [47.024636, 2.493629, "gressier-jean-luc-20a6fbd1-2016-44d0-a079-c9338828ac9c"]];
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();
});