templates/Lenord/Main/cartographie.html.twig line 1

Open in your IDE?
  1. {% extends 'Lenord/base.html.twig' %}
  2. {% block header_epingles %}
  3.   {{ include('Lenord/Main/parts/epingles.html.twig') }}
  4. {% endblock %}
  5. {% block header_breadcrumb %}
  6.   {% include 'Nordinfo/Main/parts/breadcrumb.html.twig' with {'variation':'le-nord'} %}
  7. {% endblock %}
  8. {% block header_breadcrumb_pdf %}
  9.   {% include 'Nordinfo/Main/parts/breadcrumb.html.twig' with {'variation':'le-nord'} %}
  10. {% endblock %}
  11. {% block body %}
  12.   <main tabindex="-1" role="main" id="mainContent">
  13.     {% include 'Nordinfo/Main/parts/back_btn.html.twig' with {'back_btn_class':'--leNord --barHeading --barHeadingIcon --blueMedium'} %}
  14.     <div class="barHeading --leNord --icon">
  15.       <h1>
  16.         <span class="__icon">{{ source('svg/icons/icon-map.svg') }}</span>
  17.         <span class="__text">Cartographie</span>
  18.       </h1>
  19.     </div>
  20.     <form class="containerFiltersMap">
  21.       <div class="barFilter --top">
  22.         <div class="container">
  23.           <div class="__inner">
  24.             <div id="blockFilter1" class="">
  25.               <div>
  26.                 <div><select id="dropdown_thematique" class="form-control" aria-label="Thématiques, mise à jour de la carte des services du Département du Nord">
  27.                     <option value="thematique" selected class="__first">THÉMATIQUE</option>
  28.                     {% for categorie in array_thematiques %}
  29.                       <option
  30.                         value="{{ categorie.slug| replace({ 'á':'a', 'é':'e', 'í':'i', 'ó':'o', 'ú':'u' }) }}">{{ categorie.name|capitalize|replace({ '-':' ' }) }}</option>
  31.                     {% endfor %}
  32.                   </select></div>
  33.                 <div><select id="dropdown_besoin" disabled class="form-control" aria-label="Besoin, mise à jour de la carte des services du Département du Nord">
  34.                     <option selected value="besoin" class="__first">BESOIN</option>
  35.                     {% for categorie in array_besoins %}
  36.                       <option style="display:none;" class="option_besoin {{ categorie.parent }}"
  37.                               data-parent="{{ categorie.parent }}"
  38.                               value="{{ categorie.slug }}">{{ categorie.name }}</option>
  39.                     {% endfor %}
  40.                   </select></div>
  41.               </div>
  42.             </div>
  43.             <div id="blockFilter2" class="">
  44.               <div>
  45.                 <select id="dropdown_final" class="form-control" aria-label="Type d'établissement, mise à jour de la carte des services du Département du Nord">
  46.                   <option value="type" selected class="__first">TYPE D'ÉTABLISSEMENT</option>
  47.                   {% for categorie in array_etablissements %}
  48.                     <option value="{{ categorie.slug }}">{{ categorie.name }}</option>
  49.                   {% endfor %}
  50.                 </select>
  51.               </div>
  52.             </div>
  53.             <div id="blockFilter3" class="">
  54.               <div class="formSearchMain _header form --leNord">
  55.                 <label for="inputSearchPoints" hidden>Rechercher</label>
  56.                 <div class="__input-wrapper">
  57.                   <input required name="search" title="Je recherche" type="text" id="inputSearchPoints"
  58.                          placeholder="Je recherche" class="form-control __input-search">
  59.                   <button class="__btn-search" id="btnSubmitFormFilterSearch">
  60.                     <img src="{{ asset('img/brandmaster/icon-search-le-nord.svg') }}" alt="" aria-hidden="true">
  61.                     <span class="sr-only">Recherche</span>
  62.                   </button>
  63.                 </div>
  64.               </div>
  65.             </div>
  66.           </div>
  67.         </div>
  68.       </div>
  69.       <div class="barFilter --bottom">
  70.         <div class="container">
  71.           <div class="__inner">
  72.             <div>
  73.               <button type="button" class="btn btnMain --icon" id="btnGetLocation">
  74.                 <span class="__icon">{{ source('svg/icons/icon-target.svg') }}</span>
  75.                 <span class="__text">Près de moi</span>
  76.               </button>
  77.             </div>
  78.             <div id="blockFilterRegion">
  79.               <select class="form-control" id="dropdown_region" aria-label="Territoire, mise à jour de la carte des services du Département du Nord">
  80.                 <option selected value="region">Tout le département</option>
  81.                 {% for categorie in array_territoires %}
  82.                   <option value="{{ categorie.slug }}">{{ categorie.name|capitalize|replace({ '-':' ' }) }}</option>
  83.                 {% endfor %}
  84.               </select>
  85.             </div>
  86.             <div>
  87.               <button type="button" class="btn btnMain --transparent" data-toggle="collapse"
  88.                       data-target="#collapseSearch" aria-expanded="false" aria-controls="collapseSearch">
  89.                 <span class="__text">Je ne connais pas mon lieu de vie</span>
  90.                 <span class="__icon">{{ source('svg/icons/icon-chevron.svg') }}</span>
  91.               </button>
  92.             </div>
  93.           </div>
  94.         </div>
  95.       </div>
  96.     </form>
  97.     <div class="collapse collapseSearch" id="collapseSearch">
  98.       <div class="card card-body">
  99.         <div class="container">
  100.           <div class="__title">Je ne connais pas mon lieu de vie</div>
  101.           <div class="__search">
  102.             <form action="" id="search_territory" method="POST" class="formSearchMain _header form --leNord">
  103.               <label for="inputCollapseSearch" hidden>Rechercher</label>
  104.               <div class="__input-wrapper">
  105.                 <div class="containerAutocomplete">
  106.                   {% if false %}
  107.                     <input required name="search"
  108.                            title="Je recherche"
  109.                            type="text"
  110.                            id="inputCollapseSearch"
  111.                            aria-expanded="false"
  112.                            placeholder="Je recherche"
  113.                            class="form-control __input-search"
  114.                            role="combobox"
  115.                            aria-controls="autoComplete_list"
  116.                            autocomplete="off">
  117.                   {% endif %}
  118.                   <label for="inputAddress" hidden>
  119.                     <span class="label-text">Votre commune</span>
  120.                   </label>
  121.                   <div id="autocomplete" class="autocomplete --map">
  122.                     <input class="autocomplete-input --no-icon"
  123.                            placeholder="Je saisis ma commune"
  124.                            aria-label="Je saisis ma commune"
  125.                            id="inputCollapseSearch"
  126.                     >
  127.                     <ul class="autocomplete-result-list"></ul>
  128.                   </div>
  129.                   <script>
  130.                     (() => {
  131.                       new Autocomplete('#autocomplete', {
  132.                         search: input => {
  133.                           return new Promise(resolve => {
  134.                             if (input.length < 3) {
  135.                               return resolve([]);
  136.                             }
  137.                             fetch("{{ asset('json/autocomplete_vos_lieux.json') }}")
  138.                               .then(response => response.json())
  139.                               .then(data => {
  140.                                 let results = data
  141.                                   .map((result, index) => {
  142.                                     return { ...result, index };
  143.                                   })
  144.                                   .filter(result => result.name.toLowerCase().includes(input.toLowerCase()))
  145.                                   .sort((a, b) => {
  146.                                     if (a.match < b.match) return -1;
  147.                                     if (a.match > b.match) return 1;
  148.                                     return 0;
  149.                                   });
  150.                                 results = results.slice(0, 5);
  151.                                 resolve(results);
  152.                               })
  153.                           })
  154.                         },
  155.                         debounceTime: 0,
  156.                         submitOnEnter: true,
  157.                         renderResult: (result, props) => {
  158.                           return `
  159.                               <li ${props}>
  160.                                 ${result.name}
  161.                               </li>
  162.                             `
  163.                         },
  164.                         getResultValue: result => {
  165.                           return result.name;
  166.                         },
  167.                         onSubmit: result => {
  168.                           console.log(result);
  169.                         }
  170.                       })
  171.                     })();
  172.                   </script>
  173.                 </div>
  174.                 <div>
  175.                   <button type="submit"
  176.                           class="btn btnMain --icon"
  177.                           aria-controls="autoComplete_list"
  178.                           id="btnSubmitAutocomplete">
  179.                     <span class="__icon" aria-hidden="true">
  180.                       <img src="{{ asset('img/brandmaster/icon-search-1.svg') }}" alt="" aria-hidden="true">
  181.                     </span>
  182.                     <span class="sr-only">Recherche</span>
  183.                   </button>
  184.                 </div>
  185.               </div>
  186.             </form>
  187.           </div>
  188.           <div style="min-height:24px;display:none;" class="__containerResult" id="containerResultTerritory"
  189.                aria-live="polite">
  190.             <p id='myTerritory' class="__result" aria-hidden="true" style="display:none;height:0;"></p>
  191.             <p id="loadingSearchTerritory" class="loaderContainer __loader" aria-hidden="true"
  192.                style="display:none;height:0;">
  193.               <span class="loader">Chargement en cours</span>
  194.             </p>
  195.           </div>
  196.         </div>
  197.       </div>
  198.       <button type="button" class="__btnClose" data-toggle="collapse" data-target="#collapseSearch"
  199.               aria-expanded="false" aria-controls="collapseSearch">
  200.         <span class="__icon">{{ source('svg/icons/icon-chevron.svg') }}</span>
  201.       </button>
  202.     </div>
  203.     <div class="container pBMd pTMd" aria-live="polite">
  204.       <h2 class="headingSection" id="containerCountResults" style="display:none;"><span id="countResults">Aucun filtre ou lieu actif</span>
  205.       </h2>
  206.       <div class="containerLoadingSpinner" style="display:block;min-height:54px;" id="containerLoader"
  207.            aria-hidden="true">
  208.         <div class="loader"></div>
  209.       </div>
  210.       <div class="containerAnchorReset pT mB" id="containerAnchorReset">
  211.         <button class="btn btnMain --transparent --underlineDefault" id="anchorResetFilters"><span class="__text">Rénitialiser ma recherche</span>
  212.         </button>
  213.       </div>
  214.       <p class="py-2 m-0"><a href="#skipmap" id="backmap" class="sr-only sr-only-focusable bg-white">Passer la carte</a></p>
  215.       <div>
  216.         <button type="button" class="btn btnMain btnShowCollapseMap" data-toggle="collapse" data-target="#collapseMap"
  217.                 aria-expanded="true" aria-controls="collapseMap" id="btnShowCollapseMap">
  218.           <span class="__text">Masquer la carte</span>
  219.           <span class="__text --hide">Déplier la carte</span>
  220.           <span class="__icon">{{ source('svg/icons/icon-chevron.svg') }}</span>
  221.         </button>
  222.       </div>
  223.       <div class="collapse collapseMap show" id="collapseMap">
  224.         <div class="card card-body">
  225.           <div id='map-container' style="height:31.25em;"></div>
  226.         </div>
  227.       </div>
  228.       <p class="py-2 m-0"><a href="#backmap" id="skipmap" class="sr-only sr-only-focusable bg-white no-after">Revenir avant la carte</a></p>
  229.     </div>
  230.     {# knp_pagination_render(pagination) #}
  231.     <ul class="listResultsMap" id="containerResults">
  232.       <div class="container pBMd pTMd"><p class="__messageNoResults">Pour afficher un résultat de recherche, activez
  233.           l'un filtres ou l'une des options mis à votre disposition ci-avant</p></div>
  234.       {% if false %}
  235.         {% for poi in pois %}
  236.           <li class="__item {% if loop.index is odd %}--dark{% endif %}">
  237.             <div class="container">
  238.               <div class="__inner">
  239.                 <div>
  240.                   <div class="__img">
  241.                     <img src="{{ poi.image_url }}" alt="">
  242.                   </div>
  243.                 </div>
  244.                 <div>
  245.                   <div class="__details">
  246.                     <h3>{{ poi.name }}</h3>
  247.                     <p>{{ poi.address }}</p>
  248.                     <div>
  249.                       {% if poi.phone is not null %}<a href="tel:+33{{ poi.pĥone }}">+33
  250.                         (0){{poi.phone}}</a>{% endif %}
  251.                     </div>
  252.                   </div>
  253.                 </div>
  254.                 <div>
  255.                   <a href="https://www.google.com/maps/dir/?api=1&destination={{ poi.latitude }},{{ poi.longitude }}"
  256.                      target="_blank" data-open-point="{{ poi.id }}">
  257.                     <span class="__icon">{{ source('svg/icons/icon-send.svg') }}</span>
  258.                     <span class="__text">Y aller</span>
  259.                   </a>
  260.                 </div>
  261.                 {% if poi.description|length > 0 %}
  262.                   <div>
  263.                     <button type="button" class="btn btnMain btnShowCollapseInfoResult" data-toggle="collapse"
  264.                             data-target="#collapseInfoResultMap{{ poi.id }}" aria-expanded="false"
  265.                             aria-controls="collapseInfoResultMap{{ poi.id }}">
  266.                       <span class="__text">Plus d'information</span>
  267.                       <span class="__text --hide">Moins d'informations</span>
  268.                       <span class="__icon">{{ source('svg/icons/icon-chevron.svg') }}</span>
  269.                     </button>
  270.                     <div class="collapse collapseInfoResultMap" id="collapseInfoResultMap{{ poi.id }}">
  271.                       <div class="card card-body">
  272.                         <div class="__inner">
  273.                           {{ poi.description|raw }}
  274.                         </div>
  275.                       </div>
  276.                     </div>
  277.                   </div>
  278.                 {% endif %}
  279.               </div>
  280.             </div>
  281.           </li>
  282.         {% endfor %}
  283.       {% endif %}
  284.     </ul>
  285.     {# knp_pagination_render(pagination) #}
  286.   </main>
  287. {% endblock %}
  288. {% block footer_top %}
  289.   {% if is_preview != 1 %}
  290.     <div class="container pB pT">
  291.       {% include 'Nordinfo/Main/parts/article-actions.html.twig' with {'post_title':'test', 'post_id':'test', 'is_nord_services':true} %}
  292.     </div>
  293.   {% endif %}
  294.   {% include 'Nordinfo/Main/parts/our-websites.html.twig' %}
  295. {% endblock %}
  296. {% block include_js %}
  297.   <script type='application/javascript' src='https://livemap.getwemap.com/js/sdk.min.js'></script>
  298.   <script>
  299.     $(function () {
  300.       var container = document.getElementById('map-container');
  301.       var btnGetLocation = document.getElementById('btnGetLocation');
  302.       var inputSearch = document.getElementById('inputSearchPoints');
  303.       var btnInputSearch = document.getElementById('btnSubmitFormFilterSearch');
  304.       var anchorResetFilters = document.getElementById('anchorResetFilters');
  305.       var containerResults = document.getElementById('containerResults');
  306.       var countResults = document.getElementById('countResults');
  307.       var containerCountResults = document.getElementById('containerCountResults');
  308.       var containerLoader = document.getElementById('containerLoader');
  309.       var blockFilter1 = document.getElementById('blockFilter1');
  310.       var blockFilter2 = document.getElementById('blockFilter2');
  311.       var blockFilter3 = document.getElementById('blockFilter3');
  312.       var blockFilterRegion = document.getElementById('blockFilterRegion');
  313.       var containerAnchorReset = document.getElementById('containerAnchorReset');
  314.       var dropdownThematique = document.getElementById('dropdown_thematique');
  315.       var dropdownBesoin = document.getElementById('dropdown_besoin');
  316.       var optionsBesoin = document.querySelectorAll('#dropdown_besoin option');
  317.       var dropdownFinal = document.getElementById('dropdown_final');
  318.       var dropdownRegion = document.getElementById('dropdown_region');
  319.       var btnShareUrl = document.getElementById('btnShareUrl');
  320.       if (document.body.contains(btnShareUrl)) {
  321.         btnShareUrl.setAttribute('data-clipboard-text', window.location.href);
  322.       }
  323.       var options = {
  324.         emmid: 22215,
  325.         token: '3GU8S4LI8EBXP87HGQBYBC21Z'
  326.       };
  327.       var livemap = wemap.v1.createLivemap(container, options);
  328.       var tag1 = '';
  329.       var tag2 = '';
  330.       var tags = [];
  331.       var query = '';
  332.       var filters = {};
  333.       var htmlResults = '';
  334.       var isActiveDropdownBesoin = false;
  335.       var isActiveDropdownFinal = false;
  336.       var isActiveDropdownRegion = false;
  337.       var isActiveInputSearch = false;
  338.       var isActiveInputSearchTemp = false;
  339.       var centerDefault = {latitude: 50.5450398, longitude: 2.9768406};
  340.       var zoomDefault = 8.39;
  341.       var htmlNoResults = `<div class="container pBMd pTMd"><p class="__messageNoResults">Pour afficher un résultat de recherche, activez l'un filtres ou l'une des options mis à votre disposition ci-avant</p></div>`;
  342.       $('#dropdown_thematique').on('change', function () {
  343.         resetSearch(true, false, false, false, true, true, true);
  344.         var parent = $(this).val();
  345.         blockFilter1.classList.remove('--active');
  346.         if ($(this).val() === 'thematique') {
  347.           $('#dropdown_besoin').prop("disabled", true);
  348.         } else {
  349.           containerAnchorReset.classList.add('--active');
  350.           $('#dropdown_besoin').prop("disabled", false);
  351.         }
  352.         if (!hasFilters()) {
  353.           resetSearch(true, false, false, false, false, false, false);
  354.         }
  355.         $('#dropdown_besoin option').each(function () {
  356.           if ($(this).val() !== "besoin") {
  357.             $(this).hide();
  358.           }
  359.         });
  360.         $('#dropdown_besoin').find('.' + parent).each(function () {
  361.           $(this).show();
  362.         });
  363.         $('#dropdown_besoin')[0].selectedIndex = 0;
  364.         $('#dropdown_final')[0].selectedIndex = 0;
  365.         tags = [];
  366.         tag1 = '';
  367.         tag2 = '';
  368.         filters = {
  369.           tags: tags,
  370.           query: query
  371.         };
  372.         livemap.setFilters(filters);
  373.         livemap.centerTo(centerDefault, zoomDefault);
  374.       });
  375.       $('#dropdown_besoin').on('change', function () {
  376.         containerCountResults.style.display = 'none';
  377.         containerLoader.style.display = 'block';
  378.         resetSearch(false, true, false, false, true, true, true);
  379.         if ($(this).val() === 'besoin') {
  380.           tag1 = ''
  381.           blockFilter1.classList.remove('--active');
  382.           isActiveDropdownBesoin = false;
  383.           if (!hasFilters()) {
  384.             resetSearch();
  385.           }
  386.         } else {
  387.           tag1 = $(this).val()
  388.           blockFilter1.classList.add('--active');
  389.           containerAnchorReset.classList.add('--active');
  390.           isActiveDropdownBesoin = true;
  391.         }
  392.         tags = [];
  393.         if (tag1 !== '') {
  394.           tags.push(tag1);
  395.         }
  396.         if (tag2 !== '') {
  397.           tags.push(tag2);
  398.         }
  399.         filters = {
  400.           tags: tags,
  401.           query: query
  402.         };
  403.         livemap.setFilters(filters);
  404.       });
  405.       $('#dropdown_final').on('change', function () {
  406.         containerCountResults.style.display = 'none';
  407.         containerLoader.style.display = 'block';
  408.         resetSearch(false, false, true, false, true, true, true);
  409.         if ($(this).val() === 'type') {
  410.           tag2 = '';
  411.           blockFilter2.classList.remove('--active');
  412.           isActiveDropdownFinal = false;
  413.           if (!hasFilters()) {
  414.             resetSearch();
  415.           }
  416.         } else {
  417.           tag2 = $(this).val();
  418.           blockFilter2.classList.add('--active');
  419.           containerAnchorReset.classList.add('--active');
  420.           isActiveDropdownFinal = true;
  421.         }
  422.         tags = [];
  423.         if (tag2 !== '') {
  424.           tags.push(tag2);
  425.         }
  426.         filters = {
  427.           tags: tags,
  428.           query: query
  429.         };
  430.         livemap.setFilters(filters);
  431.       });
  432.       $('#dropdown_region').on('change', function () {
  433.         containerCountResults.style.display = 'none';
  434.         containerLoader.style.display = 'block';
  435.         containerAnchorReset.classList.add('--active');
  436.         if ($(this).val() === 'region') {
  437.           isActiveDropdownRegion = false;
  438.           blockFilterRegion.classList.remove('--active');
  439.           if (!hasFilters()) {
  440.             resetSearch();
  441.           } else {
  442.             livemap.centerTo(centerDefault, zoomDefault);
  443.           }
  444.         } else {
  445.           isActiveDropdownRegion = true;
  446.           blockFilterRegion.classList.add('--active');
  447.         }
  448.         var center = {};
  449.         var zoom = 0;
  450.         switch ($(this).val()) {
  451.           case "douaisis":
  452.             center = {latitude: 50.3859531, longitude: 3.1599802};
  453.             zoom = 10.64;
  454.             livemap.centerTo(center, zoom);
  455.             break;
  456.           case "valenciennois":
  457.             center = {latitude: 50.3836017, longitude: 3.4548478};
  458.             zoom = 10.62;
  459.             livemap.centerTo(center, zoom);
  460.             break;
  461.           case "avesnois":
  462.             center = {latitude: 50.1677594, longitude: 3.9007506};
  463.             zoom = 10.31;
  464.             livemap.centerTo(center, zoom);
  465.             break;
  466.           case "cambrésis":
  467.             center = {latitude: 50.1442189, longitude: 3.3595081};
  468.             zoom = 10.66;
  469.             livemap.centerTo(center, zoom);
  470.             break;
  471.           case "flandre-intérieure":
  472.             center = {latitude: 50.8189520, longitude: 2.5221642};
  473.             zoom = 10.22;
  474.             livemap.centerTo(center, zoom);
  475.             break;
  476.           case "métropole":
  477.             center = {latitude: 50.6142362, longitude: 3.0592083};
  478.             zoom = 10.40;
  479.             livemap.centerTo(center, zoom);
  480.             break;
  481.           case "flandre-maritime":
  482.             center = {latitude: 50.9769493, longitude: 2.3545548};
  483.             zoom = 10.89;
  484.             livemap.centerTo(center, zoom);
  485.             break;
  486.         }
  487.         filters = {
  488.           tags: tags,
  489.           query: " "
  490.         };
  491.         if (query !== '') {
  492.           filters = {
  493.             tags: tags,
  494.             query: query
  495.           };
  496.         }
  497.         livemap.setFilters(filters);
  498.       });
  499.       function isOdd(num) {
  500.         return num % 2;
  501.       }
  502.       btnGetLocation.addEventListener('click', function () {
  503.         containerAnchorReset.classList.add('--active');
  504.         livemap.aroundMe().then(function () {
  505.           livemap.getUserLocation().then(function (location) {
  506.             //rechercher territoire
  507.             if (location != null) {
  508.               $.ajax({
  509.                 url: "https://api-adresse.data.gouv.fr/reverse/?lon=" + location.lng + "&lat=" + location.lat,
  510.                 success: function (response) {
  511.                   if (response.features.length > 0) {
  512.                     $.ajax({
  513.                       url: "{{ path('ajax_territory_lenord') }}",
  514.                       data: {
  515.                         'search': response.features[0].properties.city
  516.                       },
  517.                       type: "POST",
  518.                       success: function (response) {
  519.                         if (response.error === false) {
  520.                           var name = response.t.name;
  521.                           name = name.toLowerCase();
  522.                           name = name.replace(" ", "-");
  523.                           $('#dropdown_region').val(name);
  524.                         }
  525.                       }
  526.                     });
  527.                   } else {
  528.                     $('#dropdown_region').val('region');
  529.                   }
  530.                 }
  531.               });
  532.             }
  533.           });
  534.         });
  535.       });
  536.       btnInputSearch.addEventListener('click', function (e) {
  537.         e.preventDefault();
  538.         containerCountResults.style.display = 'none';
  539.         containerLoader.style.display = 'block';
  540.         handleInputSearch();
  541.       });
  542.       inputSearch.addEventListener("keyup", function (event) {
  543.         if (event.key === "Enter") {
  544.           handleInputSearch();
  545.         }
  546.       });
  547.       function handleInputSearch() {
  548.         let valueInputSearch = '';
  549.         if (inputSearch.value.length > 2) {
  550.           valueInputSearch = inputSearch.value;
  551.           resetSearch(false, false, false, true, true, true, true);
  552.           blockFilter3.classList.add('--active');
  553.           containerAnchorReset.classList.add('--active');
  554.           isActiveInputSearch = true;
  555.         } else {
  556.           valueInputSearch = '';
  557.           blockFilter3.classList.remove('--active');
  558.           isActiveInputSearch = false;
  559.           resetSearch(false, false, false, true, false, false, false);
  560.         }
  561.         filters = {
  562.           tags: tags,
  563.           query: valueInputSearch,
  564.         };
  565.         livemap.setFilters(filters);
  566.       }
  567.       livemap.addEventListener('contentUpdated', function (data) {
  568.         if (data.query.query) {
  569.           inputSearch.value = data.query.query;
  570.           // resetSearch(false, false, false, true, true, true, true);
  571.           if (data.query.query.length > 2) {
  572.             blockFilter3.classList.add('--active');
  573.             containerAnchorReset.classList.add('--active');
  574.             isActiveInputSearch = true;
  575.           } else {
  576.             blockFilter3.classList.remove('--active');
  577.             isActiveInputSearch = false;
  578.             countResults.innerText = 'Aucun filtre ou lieu actif';
  579.           }
  580.           isActiveInputSearchTemp = true;
  581.         } else {
  582.           inputSearch.value = '';
  583.           blockFilter3.classList.remove('--active');
  584.           if (isActiveInputSearchTemp) {
  585.             // resetSearch(false, false, false, true, false, false, false);
  586.             isActiveInputSearchTemp = false;
  587.           }
  588.           isActiveInputSearch = false;
  589.         }
  590.         if (hasFilters()) {
  591.           htmlResults = ``;
  592.           var classDark = '';
  593.           var htmlAnchorTel = ``;
  594.           var htmlAnchorEmail = ``;
  595.           containerResults.innerHTML = ``;
  596.           if (data.items.length > 0) {
  597.             data.items.forEach(function (el, index) {
  598.               if (el.phone) {
  599.                 const one = el.phone.slice(0, 3);
  600.                 const two = ' <span class="font-weight-bold">0' + el.phone.slice(3, 4) + ' ';
  601.                 const three = ' ' + el.phone.slice(4, 6) + ' ';
  602.                 const four = ' ' + el.phone.slice(6, 8) + ' ';
  603.                 const five = ' ' + el.phone.slice(8, 10) + ' ';
  604.                 const six = ' ' + el.phone.slice(10, 12) + '</span>';
  605.                 const phone = one + two + three + four + five + six;
  606.                 htmlAnchorTel = `<a href="tel:` + el.phone + `"><span class="__icon">{{ source('svg/icons/icon-telephone.svg') }}</span><span class="__text">` + phone + `</span></a>`;
  607.               }
  608.               if (el.external_data != null) {
  609.                 htmlAnchorEmail = `<a href="mailto::` + el.external_data + `"><span class="__icon">{{ source('svg/icons/icon-envelope.svg') }}</span><span class="__text"><b>` + el.external_data + `</b></span></a>`;
  610.               }
  611.               if (isOdd(index)) {
  612.                 classDark = '--dark';
  613.               } else {
  614.                 classDark = '';
  615.               }
  616.               var htmlMoreInfo = `
  617.               <div class="__colMoreDetails">
  618.                 <button type="button" class="btn btnMain btnShowCollapseInfoResult" data-toggle="collapse" data-target="#collapseInfoResultMap${el.id}" aria-expanded="false" aria-controls="collapseInfoResultMap${el.id}">
  619.                   <span class="__text">Plus d'information</span>
  620.                   <span class="__text --hide">Moins d'informations</span>
  621.                   <span class="__icon">{{ source('svg/icons/icon-chevron.svg') }}</span>
  622.                 </button>
  623.                 <div class="collapse collapseInfoResultMap" id="collapseInfoResultMap${el.id}">
  624.                   <div class="card card-body">
  625.                     <div class="__inner">
  626.                       ${el.description}
  627.                     </div>
  628.                   </div>
  629.                 </div>
  630.               </div>
  631.             `;
  632.               if (el.description.length === 0) {
  633.                 htmlMoreInfo = '';
  634.               }
  635.               htmlResults += `
  636.             <li class="__item ${classDark}">
  637.               <div class="container">
  638.                 <div class="__inner">
  639.                   <div class="__colImg">
  640.                     <div class="__img">
  641.                       <img src="${el.image_url}" alt="">
  642.                     </div>
  643.                   </div>
  644.                   <div class="__colDetails">
  645.                     <div class="__details">
  646.                       <h3>${el.name}</h3>
  647.                       <p>${el.address}</p>
  648.                       <div class="__buttons">
  649.                         ${htmlAnchorTel}
  650.                         ${htmlAnchorEmail}
  651.                       </div>
  652.                     </div>
  653.                   </div>
  654.                   ${htmlMoreInfo}
  655.                   <div class="__colAnchor">
  656.                     <a href="https://www.google.com/maps/dir/?api=1&destination=${el.latitude},${el.longitude}" target="_blank" data-open-point="${el.id}" title="Aller à ${el.name} (ouvre un autre onglet)">
  657.                         <span class="__icon">{{ source('svg/icons/icon-send.svg') }}</span>
  658.                         <span class="__text">
  659.                           <span>Y aller</span>
  660.                           <span>{{ source('svg/icons/icon-external.svg') }}</span>
  661.                         </span>
  662.                     </a>
  663.                   </div>
  664.                 </div>
  665.               </div>
  666.             </li>
  667.           `;
  668.             });
  669.           } else {
  670.             htmlResults += htmlNoResults
  671.           }
  672.           containerResults.innerHTML = htmlResults;
  673.           var str_lieu = ' lieux';
  674.           if (data.items.length === 1) {
  675.             str_lieu = ' lieu';
  676.           }
  677.           if ($('#dropdown_thematique').val() !== "thematique" && $('#dropdown_besoin').val() !== 'besoin') {
  678.             str_lieu += ' pour "' + $('#dropdown_thematique option:selected').text() + '", "' + $('#dropdown_besoin option:selected').text() + '"';
  679.           } else if ($('#dropdown_final').val() !== "type") {
  680.             str_lieu += ' pour "' + $('#dropdown_final option:selected').text() + '"';
  681.           }
  682.           if ($('#dropdown_region').val() !== "region") {
  683.             str_lieu += ' en ' + $('#dropdown_region option:selected').text();
  684.           }
  685.           if (inputSearch.value.length > 0 && inputSearch.value !== ' ') {
  686.             str_lieu += ' pour "' + inputSearch.value + '"';
  687.           }
  688.           countResults.innerText = data.items.length.toString() + str_lieu;
  689.         }
  690.         btnShareUrl.setAttribute('data-clipboard-text', window.location.href);
  691.         containerCountResults.style.display = 'block';
  692.         containerLoader.style.display = 'none';
  693.       });
  694.       anchorResetFilters.addEventListener('click', function (e) {
  695.         e.preventDefault();
  696.         resetSearch();
  697.       });
  698.       livemap.waitForReady().then(function() {
  699.         const iframes = document.querySelectorAll('iframe');
  700.         iframes.forEach((el) => {
  701.           if (el.getAttribute('title') === 'Interactive map') {
  702.             el.setAttribute('title', 'Carte interactive');
  703.           }
  704.         })
  705.       });
  706.       function resetSearch(
  707.         keepDropdownThematique = false,
  708.         keepDropdownBesoin = false,
  709.         keepDropdownFinal = false,
  710.         keepInputSearch = false,
  711.         keepDropdownRegion = false,
  712.         keepMapPosition = false,
  713.         keepResultsText = false
  714.       ) {
  715.         isActiveDropdownBesoin = false;
  716.         isActiveDropdownFinal = false;
  717.         isActiveDropdownRegion = false;
  718.         isActiveInputSearch = false;
  719.         tags = [];
  720.         query = '';
  721.         if (keepDropdownBesoin === false && keepDropdownThematique === false) {
  722.           $('#dropdown_besoin')[0].selectedIndex = 0;
  723.           $('#dropdown_thematique')[0].selectedIndex = 0;
  724.           $('#dropdown_besoin').prop("disabled", true);
  725.           blockFilter1.classList.remove('--active');
  726.         }
  727.         if (keepDropdownBesoin === true) {
  728.           tags.push($('#dropdown_besoin').val());
  729.         }
  730.         if (keepDropdownFinal === false) {
  731.           $('#dropdown_final')[0].selectedIndex = 0;
  732.           blockFilter2.classList.remove('--active');
  733.         } else {
  734.           tags.push($('#dropdown_final').val());
  735.         }
  736.         if (keepInputSearch === false) {
  737.           blockFilter3.classList.remove('--active');
  738.           inputSearch.value = '';
  739.         } else {
  740.           query = inputSearch.value;
  741.         }
  742.         if (keepDropdownRegion === false) {
  743.           $('#dropdown_region')[0].selectedIndex = 0;
  744.         }
  745.         filters = {
  746.           tags: tags,
  747.           query: query,
  748.         };
  749.         livemap.setFilters(filters);
  750.         if (keepMapPosition === false) {
  751.           livemap.centerTo(centerDefault, zoomDefault);
  752.         }
  753.         containerAnchorReset.classList.remove('--active');
  754.         if (keepResultsText === false) {
  755.           containerResults.innerHTML = '';
  756.           countResults.innerText = 'Aucun filtre ou lieu actif';
  757.         }
  758.         containerResults.innerHTML = htmlNoResults;
  759.       }
  760.       function hasFilters() {
  761.         return isActiveDropdownRegion || isActiveInputSearch || isActiveDropdownFinal || isActiveDropdownBesoin;
  762.       }
  763.       function updateFromUrl() {
  764.         let hash = '#/search@50.5432363,3.0645499,2.00'
  765.         if (window.location.hash !== '') {
  766.           hash = window.location.hash
  767.         }
  768.         const queryString = hash.replace('#/search?', '').split("@")[0]
  769.         const queryStringLatLongZoom = hash.replace('#/search?', '').split("@")[1].split(",")
  770.         const queryLat = parseFloat(queryStringLatLongZoom[0])
  771.         const queryLong = parseFloat(queryStringLatLongZoom[1])
  772.         const queryZoom = parseFloat(queryStringLatLongZoom[2])
  773.         const urlParams = new URLSearchParams(queryString)
  774.         let urlParamQuery = urlParams.get('query')
  775.         const urlParamTags = urlParams.get('tags')
  776.         if (urlParamTags) {
  777.           let isTagTypeBesoin = false;
  778.           for (let i = 0; i < optionsBesoin.length; i++) {
  779.             optionsBesoin[i].style.display = 'block';
  780.             if (urlParamTags === optionsBesoin[i].value) {
  781.               isTagTypeBesoin = true;
  782.             }
  783.           }
  784.           if (isTagTypeBesoin) {
  785.             dropdownBesoin.value = urlParamTags;
  786.             dropdownBesoin.disabled = false;
  787.             const optionSelected = dropdownBesoin.options[dropdownBesoin.selectedIndex];
  788.             const categoryParent = optionSelected.getAttribute('data-parent');
  789.             dropdownThematique.value = categoryParent;
  790.             for (let i = 0; i < optionsBesoin.length; i++) {
  791.               if (optionsBesoin[i].getAttribute('data-parent') !== categoryParent && optionsBesoin[i].value !== 'besoin') {
  792.                 optionsBesoin[i].style.display = 'none';
  793.               }
  794.             }
  795.             blockFilter1.classList.add('--active');
  796.             containerAnchorReset.classList.add('--active');
  797.             isActiveDropdownBesoin = true;
  798.           } else {
  799.             dropdownFinal.value = urlParamTags;
  800.             blockFilter2.classList.add('--active');
  801.             containerAnchorReset.classList.add('--active');
  802.             isActiveDropdownFinal = true;
  803.           }
  804.           filters = {
  805.             tags: [urlParamTags],
  806.             query: ''
  807.           };
  808.         } else if (urlParamQuery) {
  809.           if (urlParamQuery === ' ') {
  810.             filters = {
  811.               tags: [],
  812.               query: ' '
  813.             };
  814.           } else {
  815.             if (urlParamQuery.length < 3) {
  816.               urlParamQuery = ''
  817.             } else {
  818.               inputSearch.value = urlParamQuery;
  819.               blockFilter3.classList.add('--active');
  820.               containerAnchorReset.classList.add('--active');
  821.               isActiveInputSearch = true;
  822.             }
  823.             filters = {
  824.               tags: [],
  825.               query: urlParamQuery
  826.             };
  827.           }
  828.         }
  829.         setTimeout(function () {
  830.           const center = {latitude: queryLat + 0.00000001, longitude: queryLong};
  831.           const zoom = queryZoom;
  832.           if (urlParamQuery !== null) {
  833.             isActiveDropdownRegion = true;
  834.           }
  835.           if (queryLat === 50.3902713 && queryLong === 3.1783104 && queryZoom === 10.42) {
  836.             dropdownRegion.value = 'douaisis';
  837.             dropdownRegion.selectedIndex = 1;
  838.             containerAnchorReset.classList.add('--active');
  839.             blockFilterRegion.classList.add('--active');
  840.           } else if (queryLat === 50.3791889 && queryLong === 3.4514666 && queryZoom === 10.18) {
  841.             dropdownRegion.value = 'valenciennois';
  842.             containerAnchorReset.classList.add('--active');
  843.             blockFilterRegion.classList.add('--active');
  844.           } else if (queryLat === 50.1635116 && queryLong === 3.8820791 && queryZoom === 9.87) {
  845.             dropdownRegion.value = 'avesnois';
  846.             containerAnchorReset.classList.add('--active');
  847.             blockFilterRegion.classList.add('--active');
  848.           } else if (queryLat === 50.1488014 && queryLong === 3.5250235 && queryZoom === 10.44) {
  849.             dropdownRegion.value = 'cambrésis';
  850.             containerAnchorReset.classList.add('--active');
  851.             blockFilterRegion.classList.add('--active');
  852.           } else if (queryLat === 50.9742106 && queryLong === 2.3248100 && queryZoom === 10.58) {
  853.             dropdownRegion.value = 'flandres';
  854.             containerAnchorReset.classList.add('--active');
  855.             blockFilterRegion.classList.add('--active');
  856.           } else if (queryLat === 50.6164147 && queryLong === 3.0590916 && queryZoom === 10.00) {
  857.             dropdownRegion.value = 'métropole-lille';
  858.             containerAnchorReset.classList.add('--active');
  859.             blockFilterRegion.classList.add('--active');
  860.           } else if (queryLat === 50.8139616 && queryLong === 2.5300312 && queryZoom === 9.80) {
  861.             dropdownRegion.value = 'métropole-roubaix-tourcoing';
  862.             containerAnchorReset.classList.add('--active');
  863.             blockFilterRegion.classList.add('--active');
  864.           }
  865.           livemap.setCenter(center, zoom);
  866.           livemap.setFilters(filters);
  867.           containerCountResults.style.display = 'block';
  868.           containerLoader.style.display = 'none';
  869.         }, 1500)
  870.       }
  871.       updateFromUrl();
  872.     });
  873.   </script>
  874.   {% if false %}
  875.     <script>
  876.       (function() {
  877.         {% set autocomplete_selector = 'inputCollapseSearch' %}
  878.         const inputCollapseSearch = document.getElementById('inputCollapseSearch');
  879.         const btnSubmitAutocomplete = document.getElementById('btnSubmitAutocomplete');
  880.         const autoCompletejs = new autoComplete({
  881.           data: {
  882.             src: async function () {
  883.               document.querySelector("#{{ autocomplete_selector }}");
  884.               const source = await fetch("{{ asset('json/autocomplete_vos_lieux.json') }}");
  885.               return await source.json();
  886.             },
  887.             key: ["name"],
  888.           },
  889.           sort: function (a, b) {
  890.             if (a.match < b.match) {
  891.               return -1;
  892.             }
  893.             if (a.match > b.match) {
  894.               return 1;
  895.             }
  896.             return 0;
  897.           },
  898.           query: {
  899.             manipulate: function (query) {
  900.               return query.replace("@pizza", "burger");
  901.             },
  902.           },
  903.           trigger: {
  904.             event: ["input", "focusin", "focusout"],
  905.             condition: function (query) {
  906.               return !!query.replace(/ /g, "").length && query !== "hamburger";
  907.             },
  908.           },
  909.           placeHolder: "Je saisis ma commune",
  910.           selector: "#{{ autocomplete_selector }}",
  911.           debounce: 0,
  912.           searchEngine: "loose",
  913.           highlight: true,
  914.           maxResults: 5,
  915.           resultsList: {
  916.             render: true,
  917.             container: function (source) {
  918.               source.setAttribute("id", "autoComplete_list");
  919.               source.setAttribute('role', 'listbox');
  920.               source.setAttribute('aria-label', 'territoires');
  921.             },
  922.             element: "ul",
  923.             destination: document.querySelector("#{{ autocomplete_selector }}"),
  924.             position: "afterend",
  925.           },
  926.           resultItem: {
  927.             content: function (data, source) {
  928.               source.innerHTML = data.match;
  929.               source.setAttribute('role', 'option');
  930.             },
  931.             element: "li",
  932.           },
  933.           noResults: function () {
  934.             const result = document.createElement("li");
  935.             result.setAttribute("class", "no_result");
  936.             result.setAttribute("tabindex", "1");
  937.             result.innerHTML = "Aucun territoire trouvé";
  938.             document.querySelector("#autoComplete_list").appendChild(result);
  939.           },
  940.           onSelection: function (feedback) {
  941.             document.querySelector("#{{ autocomplete_selector }}").blur();
  942.             document.querySelector("#{{ autocomplete_selector }}").value = feedback.selection.value.name;
  943.             document.querySelector("#{{ autocomplete_selector }}").setAttribute("placeholder", "Je saisis ma commune");
  944.           }
  945.         });
  946.         ["focus", "blur"].forEach(function (eventType) {
  947.           const resultsList = document.querySelector("#autoComplete_list");
  948.           document.querySelector("#{{ autocomplete_selector }}").addEventListener(eventType, function () {
  949.             if (eventType === "blur") {
  950.               resultsList.style.display = "none";
  951.             } else if (eventType === "focus") {
  952.               resultsList.style.display = "block";
  953.             }
  954.           });
  955.         });
  956.         inputCollapseSearch.addEventListener('blur', () => {
  957.           inputCollapseSearch.setAttribute('aria-expanded', 'false');
  958.           btnSubmitAutocomplete.setAttribute('aria-expanded', 'false');
  959.         });
  960.         inputCollapseSearch.addEventListener('focus', () => {
  961.           inputCollapseSearch.setAttribute('aria-expanded', 'true');
  962.           btnSubmitAutocomplete.setAttribute('aria-expanded', 'true');
  963.         });
  964.         inputCollapseSearch.addEventListener('keyup', (e) => {
  965.           if (e.key === 'Escape' || e.keyCode === 27) {
  966.             inputCollapseSearch.blur();
  967.           }
  968.         });
  969.       })();
  970.     </script>
  971.   {% endif %}
  972.   <script>
  973.     (function () {
  974.       $('#search_territory').on('submit', function (event) {
  975.         event.preventDefault();
  976.         $('#containerResultTerritory').fadeIn();
  977.         $('#loadingSearchTerritory').fadeIn();
  978.         $('#myTerritory').fadeOut();
  979.         $('#loadingSearchTerritory')[0].setAttribute('aria-hidden', 'true');
  980.         $('#myTerritory')[0].setAttribute('aria-hidden', 'true');
  981.         $.ajax({
  982.           url: "{{ path('ajax_territory_lenord') }}",
  983.           data: {
  984.             'search': $('#inputCollapseSearch').val()
  985.           },
  986.           type: "POST",
  987.           success: function (response) {
  988.             $('#loadingSearchTerritory').fadeOut();
  989.             $('#loadingSearchTerritory')[0].setAttribute('aria-hidden', 'true');
  990.             if (response.error === false) {
  991.               $('#myTerritory').empty().append("Mon territoire : " + response.t.name);
  992.             } else {
  993.               $('#myTerritory').empty().append(response.error);
  994.             }
  995.             $('#myTerritory').fadeIn();
  996.             $('#myTerritory')[0].setAttribute('aria-hidden', 'false');
  997.           }
  998.         });
  999.         return false;
  1000.       });
  1001.     })();
  1002.   </script>
  1003. {% endblock %}