templates/addresses_list/show_addresses_maps.html.twig line 1

Open in your IDE?
  1. {% extends 'base.html.twig' %}
  2. {% block title %}Maps{% endblock %}
  3. {% block body %}
  4. <div class="row">
  5.     <div class="col-12">
  6.         <div class="card">
  7.             <div class="card-body">
  8.                 <div id="map" style="min-height: 600px; width: 100%" ></div>
  9.                 <br/>
  10.                 <a class="btn btn-outline-secondary waves-effect"  href="{{ path('app_addresses_list_index') }}">Revenir à la liste</a>
  11.             </div>
  12.         </div>
  13.     </div>
  14. </div>
  15.     <script type="text/javascript">
  16.         function initMap() {
  17.             var locations = [
  18.                 {% for addresse in addresses_list.getAddresses() %}
  19.                 ['{{ addresse.address }} {{ addresse.zipcode }} {{ addresse.city }}', {{ addresse.lat }},{{ addresse.lon }}, 4],
  20.                 {% endfor %}
  21.             ];
  22.             var bounds = new google.maps.LatLngBounds();
  23.             var markers = [];
  24.             var map = new google.maps.Map(document.getElementById('map'), {
  25.                 zoom: 10,
  26.                 center: new google.maps.LatLng(-33.92, 151.25),
  27.                 mapTypeId: google.maps.MapTypeId.ROADMAP
  28.             });
  29.             var infowindow = new google.maps.InfoWindow();
  30.             var marker, i;
  31.             for (i = 0; i < locations.length; i++) {
  32.                 marker = new google.maps.Marker({
  33.                     position: new google.maps.LatLng(locations[i][1], locations[i][2]),
  34.                     map: map
  35.                 });
  36.                 google.maps.event.addListener(marker, 'click', (function (marker, i) {
  37.                     return function () {
  38.                         infowindow.setContent(locations[i][0]);
  39.                         infowindow.open(map, marker);
  40.                     }
  41.                 })(marker, i));
  42.                 markers.push(marker);
  43.                 bounds.extend(marker.position);
  44.             }
  45.             map.fitBounds(bounds);
  46.         }
  47.         $( document ).ready(function() {
  48.             window.initMap = initMap;
  49.         });
  50.     </script>
  51. {% endblock %}