{% extends 'base.html.twig' %}
{% block title %}{{'map.0'|trans}}{% endblock %}
{% block body %}
<style>
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
.styledMap {
padding: 5px 10px;
}
.styledMap h1{
color: #dd7d17;
font-size: 1.3em;
text-transform: uppercase;
}
.styledMap p{
font-size: 1.1em;
margin:0;
}
</style>
<div class="maptacos">
<div class="wrapper">
<ul class="breadcrumb">
<li><a href="{{path('home')}}">{{'accueil'|trans}}</a></li>
<li>{{'map.1'|trans}}</li>
</ul>
<h1 class="titreDualFont"><div>{{'map.2'|trans|raw}}</div></h1>
<div class="maptacosform">
<form id="rechercheMap" action="#">
<input type="text" name="recherche" id="recherche" placeholder="{{'map.5'|trans}}" />
<input type="submit" value="GO !" />
</form>
</div>
</div>
</div>
<div class="wrapper maptacos-content">
<div class="maptacos-content-listing">
<div class="maptacos-content-listing-header">
{# <span id="filtrer">{{'map.4'|trans}}</span> #}
<p id="restoCount">{{restos|length}} {{'map.3'|trans}}{{restos|length >1 ? 's'}}</p>
{# <div id="filtres">
<p>Voir uniquement les restaurants proposant :
<ul>
<li><label><input type="checkbox" name="boxDrive" class="boxfiltre" value="drive" /> Drive <img src="/img/map-drive.png" /></label></li>
<li><label><input type="checkbox" name="boxDelivery" class="boxfiltre" value="delivery" /> {{'map.6'|trans}} <img src="/img/map-delivery.png" /></label></li>
<li><label><input type="checkbox" name="boxCollect" class="boxfiltre" value="collect" /> Click & Collect <img src="/img/map-collect.png" /></label></li>
<li><label><input type="checkbox" name="boxKiosk" class="boxfiltre" value="kiosk" /> Bornes de commande <img src="/img/map-borne.png" /></label></li>
</ul>
</div> #}
</div>
<div class="maptacos-content-listing-restos">
{% for resto in restos %}
<div class="restoFiche"
style="display:block;"
data-geovalid="1"
data-lng="{{resto.lng}}"
data-lat="{{resto.lat}}"
data-collect="{{resto.collect}}"
data-kiosk="{{resto.kiosk}}"
data-drive="{{resto.drive}}"
data-delivery="{{resto.delivery}}" >
<p class="titre">{{resto.name}}</p>
<p>{{resto.address}}</p>
{% if resto.address2 is not empty %}
<p>{{resto.address2}}</p>
{% endif %}
<p>{{resto.zipcode}} {{resto.city}}</p>
{% if resto.phone is not empty %}
<p>T. {{resto.phone}}</p>
{% endif %}
<br/>
{#
{% if resto.mondayOpen is not null and resto.mondayClose is not null %}
<p>{{'lundi'|trans}} : {{resto.mondayOpen|date('H')}}h{{resto.mondayOpen|date('i')}} - {{resto.mondayClose|date('H')}}h{{resto.mondayClose|date('i')}}</p>
{% else %}
<p>{{'lundi'|trans}} : {{'ferme'|trans}} </p>
{% endif %}
{% if resto.tuesdayOpen is not null and resto.tuesdayClose is not null %}
<p>{{'mardi'|trans}} : {{resto.tuesdayOpen|date('H')}}h{{resto.tuesdayOpen|date('i')}} - {{resto.tuesdayClose|date('H')}}h{{resto.tuesdayClose|date('i')}}</p>
{% else %}
<p>{{'mardi'|trans}} : {{'ferme'|trans}}</p>
{% endif %}
{% if resto.wednesdayOpen is not null and resto.wednesdayClose is not null %}
<p>{{'mercredi'|trans}} : {{resto.wednesdayOpen|date('H')}}h{{resto.wednesdayOpen|date('i')}} - {{resto.wednesdayClose|date('H')}}h{{resto.wednesdayClose|date('i')}}</p>
{% else %}
<p>{{'mercredi'|trans}} : {{'ferme'|trans}}</p>
{% endif %}
{% if resto.thursdayOpen is not null and resto.thursdayClose is not null %}
<p>{{'jeudi'|trans}} : {{resto.thursdayOpen|date('H')}}h{{resto.thursdayOpen|date('i')}} - {{resto.thursdayClose|date('H')}}h{{resto.thursdayClose|date('i')}}</p>
{% else %}
<p>{{'jeudi'|trans}} : {{'ferme'|trans}}</p>
{% endif %}
{% if resto.fridayOpen is not null and resto.fridayClose is not null %}
<p>{{'vendredi'|trans}} : {{resto.fridayOpen|date('H')}}h{{resto.fridayOpen|date('i')}} - {{resto.fridayClose|date('H')}}h{{resto.fridayClose|date('i')}}</p>
{% else %}
<p>{{'vendredi'|trans}} : {{'ferme'|trans}}</p>
{% endif %}
{% if resto.saturdayOpen is not null and resto.saturdayClose is not null %}
<p>{{'samedi'|trans}} : {{resto.saturdayOpen|date('H')}}h{{resto.saturdayOpen|date('i')}} - {{resto.saturdayClose|date('H')}}h{{resto.saturdayClose|date('i')}}</p>
{% else %}
<p>{{'samedi'|trans}} : {{'ferme'|trans}}</p>
{% endif %}
{% if resto.sundayOpen is not null and resto.sundayClose is not null %}
<p>{{'dimanche'|trans}} : {{resto.sundayOpen|date('H')}}h{{resto.sundayOpen|date('i')}} - {{resto.sundayClose|date('H')}}h{{resto.sundayClose|date('i')}}</p>
{% else %}
<p>{{'dimanche'|trans}} : {{'ferme'|trans}}</p>
{% endif %}
<div>
{% if resto.drive %}<img src="/img/map-drive.png" />{% endif %}
{% if resto.delivery %}<img src="/img/map-delivery.png" />{% endif %}
{% if resto.collect %}<img src="/img/map-collect.png" />{% endif %}
{% if resto.kiosk %}<img src="/img/map-borne.png" />{% endif %}
</div> #}
</div>
{% endfor %}
</div>
</div>
<div class="maptacos-content-map">
<div id="map" style="width:100%;height:100%;"></div>
</div>
</div>
{% endblock %}
{% block javascripts_bottom %}
<script>
let map;
let geocoder;
const image = "{{ app.request.schemeAndHttpHost ~ app.request.baseUrl }}/img/markermap.svg";
let rechercheLocation;
let filters = [];
function initMap() {
geocoder = new google.maps.Geocoder();
map = new google.maps.Map(document.getElementById("map"), {
mapId: "2262022a4ce1b38",
{% if app.request.getLocale() == "be" or app.request.getLocale() == "nl" %}
center: { lat: 50.8509848, lng: 4.352069 },
{% elseif app.request.getLocale() == "it" %}
{% if restos|length == 1 %}
center: { lat: {{restos[0].lat}}, lng: {{restos[0].lng}} },
{% else %}
center: { lat: 41.903027, lng: 12.498918 },
{% endif %}
{% else %}
{% if restos|length == 1 %}
center: { lat: {{restos[0].lat}}, lng: {{restos[0].lng}} },
{% else %}
center: { lat: 48.85596, lng: 2.35452 },
{% endif %}
{% endif %}
zoom: 14,
});
let infowindow;
{% for resto in restos %}
let marker{{loop.index0}} = new google.maps.Marker({
position: { lat: {{resto.lat}}, lng: {{resto.lng}}},
map,
title: '{{resto.name|escape('js')}}',
icon: image,
});
marker{{loop.index0}}.addListener("click", () => {
if(infowindow) infowindow.close();
let contentInfo = "<div class=\"styledMap\">";
contentInfo+= "<h1>{{resto.name|escape('js')}}</h1>";
contentInfo+= "<p><b>{{resto.address|escape('js')}}</b></p>";
{% if resto.address2 is not empty %}
contentInfo+= "<p><b>{{resto.address2|escape('js')}}</b></p>";
{% endif %}
contentInfo+= "<p><b>{{resto.zipcode|escape('js')}} {{resto.city|escape('js')}}</b></p>";
{#
{% if resto.phone is not null %}
contentInfo+= "<p>Tél. <a href=\"tel:{{resto.phone}}\">{{resto.phone}}</a></p>";
{% endif %}
contentInfo+= "<br/><p>{{'lundi'|trans}} : ";
{% if resto.mondayOpen is not null and resto.mondayClose is not null %}
contentInfo+= "{{resto.mondayOpen|date('H')}}h{{resto.mondayOpen|date('i')}} - {{resto.mondayClose|date('H')}}h{{resto.mondayClose|date('i')}}</p>";
{% else %}
contentInfo+= " {{'ferme'|trans}}";
{% endif %}
contentInfo+= "<p>{{'mardi'|trans}} : ";
{% if resto.tuesdayOpen is not null and resto.tuesdayClose is not null %}
contentInfo+= "{{resto.tuesdayOpen|date('H')}}h{{resto.tuesdayOpen|date('i')}} - {{resto.tuesdayClose|date('H')}}h{{resto.tuesdayClose|date('i')}}</p>";
{% else %}
contentInfo+= " {{'ferme'|trans}}";
{% endif %}
contentInfo+= "<p>{{'mercredi'|trans}} : ";
{% if resto.wednesdayOpen is not null and resto.wednesdayClose is not null %}
contentInfo+= "{{resto.wednesdayOpen|date('H')}}h{{resto.wednesdayOpen|date('i')}} - {{resto.wednesdayClose|date('H')}}h{{resto.wednesdayClose|date('i')}}</p>";
{% else %}
contentInfo+= " {{'ferme'|trans}}";
{% endif %}
contentInfo+= "<p>{{'jeudi'|trans}} : ";
{% if resto.thursdayOpen is not null and resto.thursdayClose is not null %}
contentInfo+= "{{resto.thursdayOpen|date('H')}}h{{resto.thursdayOpen|date('i')}} - {{resto.thursdayClose|date('H')}}h{{resto.thursdayClose|date('i')}}</p>";
{% else %}
contentInfo+= " {{'ferme'|trans}}";
{% endif %}
contentInfo+= "<p>{{'vendredi'|trans}} : ";
{% if resto.fridayOpen is not null and resto.fridayClose is not null %}
contentInfo+= "{{resto.fridayOpen|date('H')}}h{{resto.fridayOpen|date('i')}} - {{resto.fridayClose|date('H')}}h{{resto.fridayClose|date('i')}}</p>";
{% else %}
contentInfo+= " {{'ferme'|trans}}";
{% endif %}
contentInfo+= "<p>{{'samedi'|trans}} : ";
{% if resto.saturdayOpen is not null and resto.saturdayClose is not null %}
contentInfo+= "{{resto.saturdayOpen|date('H')}}h{{resto.saturdayOpen|date('i')}} - {{resto.saturdayClose|date('H')}}h{{resto.saturdayClose|date('i')}}</p>";
{% else %}
contentInfo+= " {{'ferme'|trans}}";
{% endif %}
contentInfo+= "<p>{{'dimanche'|trans}} : ";
{% if resto.sundayOpen is not null and resto.sundayClose is not null %}
contentInfo+= "{{resto.sundayOpen|date('H')}}h{{resto.sundayOpen|date('i')}} - {{resto.sundayClose|date('H')}}h{{resto.sundayClose|date('i')}}</p>";
{% else %}
contentInfo+= " {{'ferme'|trans}}";
{% endif %}
#}
contentInfo+= "</div>";
infowindow = new google.maps.InfoWindow({
content: contentInfo,
});
infowindow.open({
anchor: marker{{loop.index0}},
map,
shouldFocus: false,
});
});
{% endfor %}
}
function getCoord(recherche) {
geocoder.geocode( { 'address': recherche}, function(results, status) {
if (status == 'OK') {
map.setCenter(results[0].geometry.location);
map.setZoom(11);
if(results[0].geometry.location_type =="APPROXIMATE" || results[0].geometry.location_type =="ROOFTOP") {
let rechLat;
let rechLong;
if(results[0].geometry.location_type =="APPROXIMATE") {
let bounds = results[0].geometry.bounds;
let boundsLat = bounds[Object.keys(bounds)[0]];
rechLat = (boundsLat[Object.keys(boundsLat)[0]] + boundsLat[Object.keys(boundsLat)[1]]) / 2;
let boundsLong = bounds[Object.keys(bounds)[1]];
rechLong = (boundsLong[Object.keys(boundsLong)[0]] + boundsLong[Object.keys(boundsLong)[1]]) / 2;
} else {
if(results[0].geometry.viewport !== undefined) {
let viewport = results[0].geometry.viewport;
let viewportLat = viewport[Object.keys(viewport)[0]];
rechLat = (viewportLat[Object.keys(viewportLat)[0]] + viewportLat[Object.keys(viewportLat)[1]]) / 2;
let viewportLong = viewport[Object.keys(viewport)[1]];
rechLong = (viewportLong[Object.keys(viewportLong)[0]] + viewportLong[Object.keys(viewportLong)[1]]) / 2;
} else {
let bounds = results[0].geometry.bounds;
let boundsLat = bounds[Object.keys(bounds)[0]];
rechLat = (boundsLat[Object.keys(boundsLat)[0]] + boundsLat[Object.keys(boundsLat)[1]]) / 2;
let boundsLong = bounds[Object.keys(bounds)[1]];
rechLong = (boundsLong[Object.keys(boundsLong)[0]] + boundsLong[Object.keys(boundsLong)[1]]) / 2;
}
}
// Affiche cache les resto
const restos = document.getElementsByClassName('restoFiche');
const distance = 0.2;
for (let fiche of restos) {
if(
fiche.getAttribute('data-lat') > (rechLat-distance)
&& fiche.getAttribute('data-lat') < (rechLat+distance)
&& fiche.getAttribute('data-lng') > (rechLong-distance)
&& fiche.getAttribute('data-lng') < (rechLong+distance)
) {
//fiche.style.display = "block";
fiche.setAttribute('data-geovalid', '1');
//fiche.style.order = Math.round( (Math.abs(rechLat-fiche.getAttribute('data-lat')) + Math.abs(rechLong-fiche.getAttribute('data-lng')) * 100));
var order = Math.round(Math.abs(rechLat*1000-fiche.getAttribute('data-lat')*1000) + Math.abs(rechLong*1000-fiche.getAttribute('data-lng')*1000));
fiche.style.order = order;
} else {
//fiche.style.display = "none";
fiche.setAttribute('data-geovalid', '0');
}
}
activFilters();
}
} else {
//alert('Geocode was not successful for the following reason: ' + status);
}
});
}
function activFilters() {
filters = [];
for (let checkbox of document.getElementsByClassName('boxfiltre')) {
if(checkbox.checked) {
filters.push(checkbox.value);
}
}
let countResto = 0;
const restos = document.getElementsByClassName('restoFiche');
for (let fiche of restos) {
if(
//fiche.style.display == "block" &&
fiche.getAttribute('data-geovalid') == "1" &&
(
(filters.length &&
(
(fiche.getAttribute('data-collect') == 1 && filters.includes('collect'))
|| (fiche.getAttribute('data-delivery') == 1 && filters.includes('delivery'))
|| (fiche.getAttribute('data-kiosk') == 1 && filters.includes('kiosk'))
|| (fiche.getAttribute('data-drive') == 1 && filters.includes('drive'))
))
|| !filters.length
)
) {
// La fiche est déjà valide, et les filtres souhaités correspondent
countResto++;
fiche.style.display = "block";
} else {
// Les filtres ne correspondent pas à la fiche
fiche.style.display = "none";
}
}
// Mise à jour du compteur de resto
if(countResto) {
document.getElementById('restoCount').innerHTML = countResto+" {{'map.3'|trans}}"+(countResto > 1 ? 's':'')+" à proximité";
} else {
document.getElementById('restoCount').innerHTML = "Aucun restaurant à proximité";
}
}
for (let checkbox of document.getElementsByClassName('boxfiltre')) {
checkbox.addEventListener('change', activFilters);
}
// var geocoder = new google.maps.Geocoder();
document.getElementById("rechercheMap").addEventListener("submit", function(e) {
rechercheLocation = document.getElementById("recherche").value;
if(rechercheLocation != "" && rechercheLocation != undefined) {
getCoord(rechercheLocation);
}
e.preventDefault();
return false;
});
// document.getElementById('filtrer').addEventListener("click", function(e) {
// if(document.getElementById('filtrer').classList.contains("filtrerOn")) {
// document.getElementById('filtrer').classList.remove("filtrerOn");
// document.getElementById('filtres').style.display = "none";
// } else {
// document.getElementById('filtrer').classList.add("filtrerOn");
// document.getElementById('filtres').style.display = "block";
// }
// });
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDdDbL-0mCap-U8hE8UrIktLcvdxYOXWVg&callback=initMap&v=weekly"
async defer
></script>
{% endblock %}