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.1036516, -1.6250304, "otis-07e45ace-88d2-4131-b69e-965151dbdc2a"], [47.2629956, -1.5037905, "otis-69b034d2-6ec2-45da-b704-1735b81c966b"], [49.1957652, -0.4037868, "otis-23f37946-c15d-45bf-94b5-0f2409eb1708"], [49.1957652, -0.4037868, "otis-2004597b-0d30-481b-b867-0e11ebd073a7"], [18.0785256, -63.0628159, "otis-2875f76e-9040-4767-a04a-34d9bdc46e8b"], [46.67565949999999, 5.579091099999999, "otis-db999ed4-7987-4dbc-80e0-c60bc47c3e67"], [47.2289952, 5.9862489, "otis-a360e69b-7b04-4b87-bffe-94bc8607b301"], [48.429954, 2.7465639, "otis-5c13b97b-7b1c-4020-8dcf-a0495f67cf49"], [43.8734158, -0.4796326, "eco-efficacite-isolation-73d644f6-179c-44ea-aabe-5e50b5fc6769"], [47.5945703, -1.6835756, "le-lorec-couverture-27778"]];
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();
});