{% extends 'base.html.twig' %}
{% block title %}Maps{% endblock %}
{% block body %}
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<div id="map" style="min-height: 600px; width: 100%" ></div>
<br/>
<a class="btn btn-outline-secondary waves-effect" href="{{ path('app_addresses_list_index') }}">Revenir à la liste</a>
</div>
</div>
</div>
</div>
<script type="text/javascript">
function initMap() {
var locations = [
{% for addresse in addresses_list.getAddresses() %}
['{{ addresse.address }} {{ addresse.zipcode }} {{ addresse.city }}', {{ addresse.lat }},{{ addresse.lon }}, 4],
{% endfor %}
];
var bounds = new google.maps.LatLngBounds();
var markers = [];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(-33.92, 151.25),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
markers.push(marker);
bounds.extend(marker.position);
}
map.fitBounds(bounds);
}
$( document ).ready(function() {
window.initMap = initMap;
});
</script>
{% endblock %}