templates/themes/theme/common/map.html.twig line 1

Open in your IDE?
  1. <div id="map"></div>
  2. {# Do not use this API key for production sites - Generate a new key and allow the LIVE and DEV domains #}
  3. {# Get a new API key here: https://developers.google.com/maps/documentation/javascript/get-api-key #}
  4. <script async
  5.     src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAFQr5-BviDSycw3hxKecYJoCsTet11WlQ&loading=async&callback=initMap">
  6. </script>
  7. <script type="text/javascript">
  8.     var map;
  9.     function initMap() {
  10.         var mapOptions = {
  11.             center: new google.maps.LatLng({{ renderSetting(4, 'content') }},{{ renderSetting(5, 'content') }}),
  12.             zoom: 14,
  13.             zoomControl: false,
  14.             mapTypeId: 'hybrid',
  15.             zoomControlOptions: {
  16.                 style: google.maps.ZoomControlStyle.DEFAULT,
  17.             },
  18.             disableDoubleClickZoom: true,
  19.             mapTypeControl: false,
  20.             scaleControl: false,
  21.             scrollwheel: false,
  22.             cameraControl: false,
  23.             streetViewControl: false,
  24.             fullscreenControl: false,
  25.             draggable: true,
  26.             overviewMapControl: false,
  27.             overviewMapControlOptions: {
  28.                 opened: false,
  29.             },
  30.             styles: [],
  31.         }
  32.         var mapElement = document.getElementById('map');
  33.         var map = new google.maps.Map(mapElement, mapOptions);
  34.         var locations = [
  35.             [
  36.                 '{{ sitename }}',
  37.                 `{{ renderSetting(1, 'content') }}`,
  38.                 '{{ renderSetting(2, 'content') }}',
  39.                 '{{ renderSetting(3, 'content') }}',
  40.                 '{{ renderSetting(4, 'content') }}','{{ renderSetting(5, 'content') }}'
  41.             ]
  42.         ];
  43.         for (i = 0; i < locations.length; i++) {
  44.             if (locations[i][0] == 'undefined') { description = ''; } else {name = locations[i][0]; }
  45.             if (locations[i][1] == 'undefined') { description = ''; } else {description = locations[i][1]; }
  46.             if (locations[i][2] == 'undefined') { telephone = ''; } else { telephone = locations[i][2]; }
  47.             if (locations[i][3] == 'undefined') { email = ''; } else { email = locations[i][3]; }
  48.             var infoWindowContent = '<div id="maps-infowindow" class="leading-normal text-sm">'+
  49.             '<div class="mb-3"><strong>'+name+'</strong>'+'<br/>'+description+'</div>'+
  50.             '<div>'+telephone+'<br/>'+email+'</div>'+
  51.             '</div>';
  52.             var infowindow = new google.maps.InfoWindow({content: infoWindowContent});
  53.             var markericon = {
  54.                 url: "/images/map-pin.png",
  55.                 scaledSize: new google.maps.Size(60, 60)
  56.             };
  57.             marker = new google.maps.Marker({
  58.                 icon: markericon,
  59.                 position: new google.maps.LatLng(locations[i][4], locations[i][5]),
  60.                 map: map,
  61.                 title: locations[i][0],
  62.                 desc: description,
  63.                 tel: telephone,
  64.                 email: email
  65.             });
  66.             marker.addListener('click', function() { infowindow.open(map, marker); });
  67.         }
  68.     }
  69. </script>