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.4982097, -2.7866034, "proxiserve-eb7ff627-1597-4147-826f-b81aa5f5fac4"], [48.46764169999999, -2.0524762, "proxiserve-2b32f53e-f3bf-46c6-ba57-40598d158cfd"], [43.228298, 0.042608, "proxiserve-7ea8f701-51c5-470d-93c8-9fb34a3ba853"], [47.2289952, 5.9862489, "proxiserve-fffef52a-b7f9-46fe-8c26-72578971b68e"], [43.438578, 3.709031, "proxiserve-2bc822c7-aec0-46c9-a01e-7a3e6f4501e3"], [45.1393279, 5.690822199999999, "proxiserve-b7eef0d1-18ce-4656-991e-c8d1ada87b71"], [43.5773738, 3.8189307, "proxiserve-d4519fba-d307-4f49-9d57-0a2d01802260"], [48.8682805, 2.2847374, "alarmes-coffres-securite-alcof-securite-12241"], [47.86593, 7.351814, "proxiserve-6f399f1a-d455-48b8-bfc6-b4073dd780a9"], [46.9911365, -0.434266, "94910509200017"]];
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();
});