templates/includes/mapa_javascript.html.twig line 1

  1. {% if oficinasMapa is defined %}
  2. {% set slug = app.request.attributes.get('slugO') %}
  3. <script>
  4. function initMap() {  
  5.     const map = new google.maps.Map(document.getElementById("map"), {
  6.         zoom: {%if oficinasMapa|length > 1%}6{%else%}10{%endif%},
  7.         center: {%if oficinasMapa|length > 1%}{ lat: 40.4165, lng: -3.70256 }{%elseif oficinasMapa[0].latitud%}{ lat: {{oficinasMapa[0].latitud}}, lng: {{oficinasMapa[0].longitud}} }{%endif%},
  8.     });
  9.     
  10.     var styledMapType = new google.maps.StyledMapType(styleMapDefault);
  11.     
  12.     map.mapTypes.set('styled_map', styledMapType);
  13.     map.setMapTypeId('styled_map');
  14.     var markers = [];
  15.     
  16.     {% for oficina in oficinasMapa %}
  17.     {% if oficina.latitud and oficina.slug %}
  18.     
  19.     {% apply spaceless %}
  20.         const contentString{{ oficina.id }} = 
  21.         '<div class="card card-mapa" tabindex="0" style="border:none;display: flex;flex-direction: row;"><div class="izq" style="padding: 10px;"><a href="{{ path('ficha_oficina', {slugP: oficina.localidad.provincia.slug, slugL: oficina.localidad.slug, slugO: oficina.slug} ) }}">{% if oficina.imagenMapa %}<img src="{{ sonata_path(oficina.imagenMapa, 'smallN') }}" style="width: fit-content;height: 100%;"/>{% else %}<b>{{ oficina.nombre }}</b>{% endif %}</a></div><div class="der" style="display: flex;flex-direction: column;max-width: 230px;"><img src="/img/logo_azul.svg" style="width: 160px;"/><p style="margin: 0;font-size: 20px;font-weight: bold;color: #1C3264;margin-top: 8px;">{{ oficina.provincia.nombre }}</p><p style="margin-bottom: 10px;font-size: 20px;font-weight: 400;color: #1C3264;">{{ oficina.nombre }}</p>{% if oficina.slug != slug %}<a href="{{ path('ficha_oficina', {slugP: oficina.localidad.provincia.slug, slugL: oficina.localidad.slug, slugO: oficina.slug} ) }}" style="text-decoration: none;font-size: 17px;font-weight: bold;color: #1C3264;"><b>Seleccionar Oficina</b></a>{% else %}<a target="_blank" href="https://www.google.com/maps/dir/Current+Location/{{ oficina.latitud }},{{ oficina.longitud }}" style="text-decoration: none;font-size: 17px;font-weight: bold;color: #1C3264;">{{ '¿Cómo llegar? >' | trans}}</a>{% endif %}</div></div>';
  22.     {% endapply %}
  23.         const infowindow{{ oficina.id }} = new google.maps.InfoWindow({
  24.             content: contentString{{ oficina.id }},
  25.         });
  26.         
  27.         const marker{{ oficina.id }} = new google.maps.Marker({
  28.             position: { lat: {{ oficina.latitud }}, lng: {{ oficina.longitud }} },
  29.             map: map,
  30.             title: '{{ oficina.nombre }}',
  31. {#             icon: '{{ absolute_url(asset('/img/locMap.svg')) }}' #}
  32.             icon: {
  33.                 url: '{{ absolute_url(asset('/img/locMap.svg')) }}',
  34.                 scaledSize: new google.maps.Size(50, 60),
  35.             }
  36.         });
  37.         
  38.         infowindow{{ oficina.id }}.addListener('closeclick', ()=>{
  39.         });
  40.         
  41.         marker{{ oficina.id }}.addListener("click", () => {
  42.             infowindow{{ oficina.id }}.open({
  43.             anchor: marker{{ oficina.id }},
  44.             map,
  45.             shouldFocus: false,
  46.             });
  47.         });
  48.         
  49.         markers.push(marker{{ oficina.id }});
  50.     
  51.     {% endif %}
  52.   {% endfor %}
  53.   var markerCluster = new MarkerClusterer(map, markers,
  54.         {imagePath: '/img/m'});
  55. }
  56. </script>
  57. {% endif %}