templates/common/components/gmap.html.twig line 1

Open in your IDE?
  1. <div class="map-container">
  2.     <div class="map"></div>
  3. </div>
  4. <script>
  5.     const locations = {{ markers|default("[]")|raw }};
  6.     const pin = '/img/pin.png';
  7.     window.map_init = () => {
  8.         const mapElement = document.querySelector(".map-container > .map");
  9.         if (!mapElement) {
  10.             return;
  11.         }
  12.         const map = new google.maps.Map(mapElement, {
  13.             center: {lat: 49.5, lng: -30},
  14.             zoom: 3,
  15.             minZoom: 3,
  16.             zoomControl: true,
  17.             mapTypeControl: false,
  18.             scaleControl: false,
  19.             streetViewControl: false,
  20.             rotateControl: false,
  21.             fullscreenControl: false,
  22.             scrollwheel: false,
  23.             styles: [
  24.                 {
  25.                     featureType: "administrative",
  26.                     stylers: [
  27.                         {hue: "#000000"},
  28.                         {lightness: -100},
  29.                         {visibility: "off"},
  30.                     ],
  31.                 },
  32.                 {
  33.                     featureType: "landscape",
  34.                     elementType: "geometry",
  35.                     stylers: [
  36.                         {hue: "#dddddd"},
  37.                         {saturation: -100},
  38.                         {lightness: -3},
  39.                         {visibility: "on"},
  40.                     ],
  41.                 },
  42.                 {
  43.                     featureType: "landscape",
  44.                     elementType: "labels",
  45.                     stylers: [
  46.                         {hue: "#000000"},
  47.                         {saturation: -100},
  48.                         {lightness: -100},
  49.                         {visibility: "off"},
  50.                     ],
  51.                 },
  52.                 {
  53.                     featureType: "poi",
  54.                     stylers: [
  55.                         {hue: "#000000"},
  56.                         {saturation: -100},
  57.                         {lightness: -100},
  58.                         {visibility: "off"},
  59.                     ],
  60.                 },
  61.                 {
  62.                     featureType: "road",
  63.                     elementType: "geometry",
  64.                     stylers: [
  65.                         {hue: "#bbbbbb"},
  66.                         {saturation: -100},
  67.                         {lightness: 26},
  68.                         {visibility: "on"},
  69.                     ],
  70.                 },
  71.                 {
  72.                     featureType: "road",
  73.                     elementType: "labels",
  74.                     stylers: [
  75.                         {hue: "#ffffff"},
  76.                         {saturation: -100},
  77.                         {lightness: 100},
  78.                         {visibility: "off"},
  79.                     ],
  80.                 },
  81.                 {
  82.                     featureType: "road.local",
  83.                     stylers: [
  84.                         {hue: "#ffffff"},
  85.                         {saturation: -100},
  86.                         {lightness: 100},
  87.                         {visibility: "on"},
  88.                     ],
  89.                 },
  90.                 {
  91.                     featureType: "transit",
  92.                     elementType: "labels",
  93.                     stylers: [
  94.                         {hue: "#000000"},
  95.                         {lightness: -100},
  96.                         {visibility: "off"},
  97.                     ],
  98.                 },
  99.                 {
  100.                     featureType: "water",
  101.                     stylers: [
  102.                         {saturation: -100}
  103.                     ]
  104.                 },
  105.                 {
  106.                     featureType: "water",
  107.                     elementType: "geometry",
  108.                     stylers: [
  109.                         {saturation: -100},
  110.                         {lightness: 100},
  111.                         {visibility: "on"},
  112.                     ],
  113.                 },
  114.                 {
  115.                     featureType: "water",
  116.                     elementType: "geometry.fill",
  117.                     stylers: [
  118.                         {color: "#fbfafa"}
  119.                     ],
  120.                 },
  121.                 {
  122.                     featureType: "water",
  123.                     elementType: "labels",
  124.                     stylers: [
  125.                         {hue: "#000000"},
  126.                         {saturation: -100},
  127.                         {lightness: -100},
  128.                         {visibility: "off"},
  129.                     ],
  130.                 },
  131.             ],
  132.         });
  133.         const latLngList = [];
  134.         for (const location of locations) {
  135.             const position = new google.maps.LatLng(location["coords"]);
  136.             latLngList.push(position);
  137.             const marker = new google.maps.Marker({
  138.                 position: position,
  139.                 map: map,
  140.                 icon: {
  141.                     url: pin,
  142.                     labelOrigin: new google.maps.Point(-30, 20),
  143.                 },
  144.                 title: location.title,
  145.                 animation: google.maps.Animation.DROP,
  146.                 label: {
  147.                     color: "#000",
  148.                     fontWeight: "bold",
  149.                     fontSize: "12px",
  150.                     text: location.city,
  151.                 },
  152.                 optimized: false,
  153.                 visible: true,
  154.             });
  155.             if (location.uri) {
  156.                 google.maps.event.addListener(marker, "click", function () {
  157.                     window.location.href = location.uri;
  158.                 });
  159.             }
  160.         }
  161.         if (latLngList.length > 1) {
  162.             if (latLngList.length > 2 && window.innerWidth < 600) {
  163.                 map.fitBounds({
  164.                     south: 21.639712295652373,
  165.                     west: -21.062955980857527,
  166.                     north: 66.29012644366672,
  167.                     east: 44.85501276914247,
  168.                 });
  169.             } else {
  170.                 const bounds = new google.maps.LatLngBounds();
  171.                 for (const latLng of latLngList) {
  172.                     bounds.extend(latLng);
  173.                 }
  174.                 map.fitBounds(bounds);
  175.             }
  176.         }
  177.     };
  178. </script>