templates/_partials/map_home.html.twig line 1

Open in your IDE?
  1. <script src="https://maps.google.com/maps/api/js?key={{ api_key_google }}&libraries=places"></script>
  2. <script src="https://unpkg.com/@googlemaps/markerclusterer/dist/index.min.js"></script>
  3. <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  4. <script>
  5.     var locations1 = [
  6.         {% for a in adherents %}
  7.             { 'position':  {  lat: {{ a.lat }}, lng: {{ a.lon }}  }, 'nom' :'{{ a.societe }}', 'adresse': '{{ a.adresse|replace({"\n": "", "\r": "", "\t": ""}) }}<br/>{{ a.cp }} {{ a.ville }}', 'tel' : '{{ a.tel }}', 'url' : '{{ a.urlVente }}', 'btn': '{{ a.societe }} {{ a.ville }}', 'concept':'{{ a.concept  }}'},
  8.             {% endfor %}
  9.     ]
  10.     var placeSearch;
  11.     var map, input, autocomplete;
  12.     $(".searchFormSubmit").click(function(){
  13.         $("#exampleModalCenter").modal("hide");
  14.         const myTimeout = setTimeout(searchFormModal, 1000);
  15.     });
  16.     function searchFormModal(){
  17.         map.setCenter(placeSearch.geometry.location);
  18.         map.setZoom(9);
  19.         var element = document.getElementById("scrollSmothHere");
  20.         element.scrollIntoView({behavior: "smooth"});
  21.     }
  22.     function initAutocomplete1() {
  23.         input2 = document.getElementById("pac-input-2");
  24.         const options1 = {
  25.             fields: ["formatted_address", "geometry", "name"],
  26.             strictBounds: false,
  27.             componentRestrictions: { country: "fr" },
  28.         };
  29.         autocomplete2 = new google.maps.places.Autocomplete(input2, options1);
  30.         map = new google.maps.Map(document.getElementById("mapAdherent1"), {
  31.             zoom: 7,
  32.             center: { lat: 46.8066357, lng: 2.2216369},
  33.         });
  34.         var infoWindow = new google.maps.InfoWindow({
  35.             content: "",
  36.             disableAutoPan: true,
  37.         });
  38.         var markers1 = locations1.map((element, i) => {
  39.             var position = element['position'];
  40.             var label = element['nom'];
  41.             const svgMarker = {
  42.             path: "M10.453 14.016l6.563-6.609-1.406-1.406-5.156 5.203-2.063-2.109-1.406 1.406zM12 2.016q2.906 0 4.945 2.039t2.039 4.945q0 1.453-0.727 3.328t-1.758 3.516-2.039 3.070-1.711 2.273l-0.75 0.797q-0.281-0.328-0.75-0.867t-1.688-2.156-2.133-3.141-1.664-3.445-0.75-3.375q0-2.906 2.039-4.945t4.945-2.039z",
  43.             fillColor: "blue",
  44.             fillOpacity: 0.6,
  45.             strokeWeight: 0,
  46.             rotation: 0,
  47.             scale: 2,
  48.             anchor: new google.maps.Point(15, 30),
  49.       };
  50.       let urlSvg1 = "{{ asset("img/map-marker.svg") | escape('js') }}"
  51.             var marker1 = new google.maps.Marker({position, icon: urlSvg1});
  52.             marker1.addListener("click", () => {
  53.                  if(element['concept'] == 'Open Point'){
  54.                       infoWindow.setContent("<div style='font-fmily: LATO;' class='mapInfoWindow text-center'><p class='mb-0'><img src='{{ asset('img/logo_points_3.png')| escape('js') }}' style='width: 130px;'></p><p class='mb-1'>"+element['adresse']+"</p><p class='mb-1'>Tel: "+element['tel']+"</p><a href='"+element['url']+"' class='btn btn-sm blue_points_background btn-gmap mt-2 mb-2' target='_blank'>Accéder à mon centre</a></div>");
  55.                     }else{
  56.                       infoWindow.setContent("<div style='font-fmily: LATO;' class='mapInfoWindow text-center'><p class='mb-1'>"+element['nom']+"</p><p class='mb-1'>"+element['adresse']+"</p><p class='mb-1'>Tel: "+element['tel']+"</p><a href='"+element['url']+"' class='btn btn-sm blue_points_background btn-gmap mt-2 mb-2' target='_blank'>Accéder à mon centre</a></div>");
  57.                     }
  58.                 infoWindow.open(map, marker1);
  59.             });
  60.             return marker1;
  61.         });
  62.         
  63.         autocomplete2.bindTo("bounds", map);
  64.         autocomplete2.addListener("place_changed", () => {
  65.             //const place = autocomplete2.getPlace();
  66.             placeSearch = autocomplete2.getPlace();
  67.             {#map.setCenter(place.geometry.location);
  68.                 map.setZoom(9);#}
  69.         });
  70.     }
  71.     initAutocomplete1();
  72.     $('#formSearchMap').on('submit', function(e) {
  73.         e.preventDefault()
  74.     });
  75.     </script>
  76.         <script>
  77.         var locations = [
  78.             {% for a in adherents %}
  79.             { 'position':  {  lat: {{ a.lat }}, lng: {{ a.lon }}  }, 'nom' :'{{ a.societe }}', 'adresse': '{{ a.adresse|replace({"\n": "", "\r": "", "\t": ""}) }}<br/>{{ a.cp }} {{ a.ville }}', 'tel' : '{{ a.tel }}', 'url' : '{{ a.urlVente }}', 'btn': '{{ a.societe }} {{ a.ville }}', 'concept':'{{ a.concept  }}'},
  80.             {% endfor %}
  81.         ]
  82.         var placeSearch;
  83.         var map, input, autocomplete;
  84.         $(".searchFormSubmit").click(function(){
  85.             $("#exampleModalCenter").modal("hide");
  86.             const myTimeout = setTimeout(searchFormModal, 1000);
  87.         });
  88.         function searchFormModal(){
  89.             map.setCenter(placeSearch.geometry.location);
  90.             map.setZoom(9);
  91.             var element = document.getElementById("scrollSmothHere");
  92.             element.scrollIntoView({behavior: "smooth"});
  93.         }
  94.         function initAutocomplete1() {
  95.             input2 = document.getElementById("pac-input-2");
  96.             const options1 = {
  97.                 fields: ["formatted_address", "geometry", "name"],
  98.                 strictBounds: false,
  99.                 componentRestrictions: { country: "fr" },
  100.             };
  101.             autocomplete2 = new google.maps.places.Autocomplete(input2, options1);
  102.             map = new google.maps.Map(document.getElementById("mapAdherent1"), {
  103.                 zoom: 7,
  104.                 center: { lat: 46.8066357, lng: 2.2216369},
  105.             });
  106.             var infoWindow = new google.maps.InfoWindow({
  107.                 content: "",
  108.                 disableAutoPan: true,
  109.             });
  110.             var markers1 = locations1.map((element, i) => {
  111.                 var position = element['position'];
  112.                 var label = element['nom'];
  113.                 const svgMarker = {
  114.                 path: "M10.453 14.016l6.563-6.609-1.406-1.406-5.156 5.203-2.063-2.109-1.406 1.406zM12 2.016q2.906 0 4.945 2.039t2.039 4.945q0 1.453-0.727 3.328t-1.758 3.516-2.039 3.070-1.711 2.273l-0.75 0.797q-0.281-0.328-0.75-0.867t-1.688-2.156-2.133-3.141-1.664-3.445-0.75-3.375q0-2.906 2.039-4.945t4.945-2.039z",
  115.                 fillColor: "blue",
  116.                 fillOpacity: 0.6,
  117.                 strokeWeight: 0,
  118.                 rotation: 0,
  119.                 scale: 2,
  120.                 anchor: new google.maps.Point(15, 30),
  121.           };
  122.           let urlSvg1 = "{{ asset("img/map-marker.svg") | escape('js') }}"
  123.                 var marker1 = new google.maps.Marker({position, icon: urlSvg1});
  124.                 marker1.addListener("click", () => {
  125.                    if(element['concept'] == 'Open Point'){
  126.                       infoWindow.setContent("<div style='font-fmily: LATO;' class='mapInfoWindow text-center'><p class='mb-0'><img src='{{ asset('img/logo_points_3.png')| escape('js') }}' style='width: 130px;'></p><p class='mb-1'>"+element['adresse']+"</p><p class='mb-1'>Tel: "+element['tel']+"</p><a href='"+element['url']+"' class='btn btn-sm blue_points_background btn-gmap mt-2 mb-2' target='_blank'>Accéder à mon centre</a></div>");
  127.                     }else{
  128.                       infoWindow.setContent("<div style='font-fmily: LATO;' class='mapInfoWindow text-center'><p class='mb-1'>"+element['nom']+"</p><p class='mb-1'>"+element['adresse']+"</p><p class='mb-1'>Tel: "+element['tel']+"</p><a href='"+element['url']+"' class='btn btn-sm blue_points_background btn-gmap mt-2 mb-2' target='_blank'>Accéder à mon centre</a></div>");
  129.                     }
  130.                     infoWindow.open(map, marker1);
  131.                 });
  132.                 return marker1;
  133.             });
  134.             
  135.             autocomplete2.bindTo("bounds", map);
  136.             autocomplete2.addListener("place_changed", () => {
  137.                 placeSearch = autocomplete2.getPlace();
  138.             });
  139.         }
  140.         initAutocomplete1();
  141.         $('#formSearchMap').on('submit', function(e) {
  142.             e.preventDefault()
  143.         });
  144.         </script>
  145.         <script>
  146.         var locations = [
  147.             {% for a in adherents %}
  148.             { 'position':  {  lat: {{ a.lat }}, lng: {{ a.lon }}  }, 'nom' :'{{ a.societe }}', 'adresse': '{{ a.adresse|replace({"\n": "", "\r": "", "\t": ""}) }}<br/>{{ a.cp }} {{ a.ville }}', 'tel' : '{{ a.tel }}', 'url' : '{{ a.urlVente }}', 'btn': '{{ a.societe }} {{ a.ville }}', 'concept':'{{ a.concept  }}'},
  149.             {% endfor %}
  150.         ]
  151.         var placeSearch;
  152.         var map, input, autocomplete;
  153.         $('#formSearchMap').on('submit', function(e) {
  154.             e.preventDefault();
  155.             const myTimeout = setTimeout(searchForm, 1000);
  156.         });
  157.         function searchForm(){
  158.             map.setCenter(placeSearch.geometry.location);
  159.             map.setZoom(9);
  160.             var element = document.getElementById("scrollSmothHere");
  161.             element.scrollIntoView({behavior: "smooth"});
  162.         }
  163.         function initAutocomplete() {
  164.             input = document.getElementById("pac-input");
  165.             const options = {
  166.                 fields: ["formatted_address", "geometry", "name"],
  167.                 strictBounds: false,
  168.                 componentRestrictions: { country: "fr" },
  169.             };
  170.             autocomplete = new google.maps.places.Autocomplete(input, options);
  171.             map = new google.maps.Map(document.getElementById("mapAdherent"), {
  172.                 zoom: 7,
  173.                 center: { lat: 46.8066357, lng: 2.2216369},
  174.             });
  175.             var infoWindow = new google.maps.InfoWindow({
  176.                 content: "",
  177.                 disableAutoPan: true,
  178.             });
  179.             var markers = locations.map((element, i) => {
  180.                 var position = element['position'];
  181.                 var label = element['nom'];
  182.                 const svgMarker = {
  183.                 path: "M10.453 14.016l6.563-6.609-1.406-1.406-5.156 5.203-2.063-2.109-1.406 1.406zM12 2.016q2.906 0 4.945 2.039t2.039 4.945q0 1.453-0.727 3.328t-1.758 3.516-2.039 3.070-1.711 2.273l-0.75 0.797q-0.281-0.328-0.75-0.867t-1.688-2.156-2.133-3.141-1.664-3.445-0.75-3.375q0-2.906 2.039-4.945t4.945-2.039z",
  184.                 fillColor: "blue",
  185.                 fillOpacity: 0.6,
  186.                 strokeWeight: 0,
  187.                 rotation: 0,
  188.                 scale: 2,
  189.                 anchor: new google.maps.Point(15, 30),
  190.           };
  191.             let urlSvg = "{{ asset("img/map-marker.svg") | escape('js') }}"
  192.             var marker = new google.maps.Marker({position, icon: urlSvg});
  193.                 marker.addListener("click", () => {
  194.                      if(element['concept'] == 'Open Point'){
  195.                       infoWindow.setContent("<div style='font-fmily: LATO;' class='mapInfoWindow text-center'><p class='mb-0'><img src='{{ asset('img/logo_points_3.png')| escape('js') }}' style='width: 130px;'></p><p class='mb-1'>"+element['adresse']+"</p><p class='mb-1'>Tel: "+element['tel']+"</p><a href='"+element['url']+"' class='btn btn-sm blue_points_background btn-gmap mt-2 mb-2' target='_blank'>Accéder à mon centre</a></div>");
  196.                     }else{
  197.                       infoWindow.setContent("<div style='font-fmily: LATO;' class='mapInfoWindow text-center'><p class='mb-1'>"+element['nom']+"</p><p class='mb-1'>"+element['adresse']+"</p><p class='mb-1'>Tel: "+element['tel']+"</p><a href='"+element['url']+"' class='btn btn-sm blue_points_background btn-gmap mt-2 mb-2' target='_blank'>Accéder à mon centre</a></div>");
  198.                     }
  199.                     infoWindow.open(map, marker);
  200.                 });
  201.                 return marker;
  202.             });
  203.             // Marker clusterer
  204.             const markerCluster = new markerClusterer.MarkerClusterer({
  205.                 map: map,
  206.                 markers: markers, 
  207.                 renderer: {
  208.                     render: ({ markers, _position: position }) => {
  209.                         return new google.maps.Marker({
  210.                             position: {
  211.                                 lat: position.lat(),
  212.                                 lng: position.lng(),
  213.                             },
  214.                             label: {
  215.                                 text: String(markers.length),
  216.                                 color: "white",
  217.                                 fontSize: '12px',
  218.                                 fontWeight: '600'
  219.                             },
  220.                             icon: "{{ asset('img/m1.png')}}",
  221.                         });
  222.                     },
  223.                 }
  224.                 });
  225.             autocomplete.bindTo("bounds", map);
  226.             autocomplete.addListener("place_changed", () => {
  227.                 placeSearch = autocomplete.getPlace();
  228.             });
  229.         }
  230.         initAutocomplete();
  231.         </script>