Advertisement
Guest User

v_recherche_carte.php

a guest
Dec 6th, 2019
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <div class='recherche' id='faireRecherche'>
  3.    
  4.     <form action="./?action=recherche&vue=carte" method="POST">
  5.          <h2>Recherche</h2>
  6.         <div class="choixPersAffichage" >
  7.             <label><strong>Afficher :</strong></label><br/>
  8.             <input type="radio" name="choixPersAffichage" id="choixPersAffichage" value="visiteur" <?php if($choixPersAffichage == 'visiteur') {?>checked <?php }?>>Visiteur
  9.             <input type="radio" name="choixPersAffichage" id="choixPersAffichage" value="praticien" <?php if($choixPersAffichage == 'praticien') {?>checked <?php }?>>Praticien
  10.         </div>
  11.         <div class="choixTri">
  12.             <label><strong>Trier par :</strong></label><br/>
  13.             <input type="checkbox" name="dateVisite" onchange="if(this.checked) this.value='true'; else this.value='false';" <?php if($dateVisite ="true"){ ?> onchange="this.value='true'" <?php } ?> /> Date de visite
  14.             <input type="checkbox" name="secteur"  onchange="if(this.checked) this.value='true'; else this.value='false';"> Secteur
  15.             <br/>
  16.             <input type="checkbox" name="region" onchange="if(this.checked) this.value='true'; else this.value='false';"/> Region
  17.             <input type="checkbox" name="nom" onchange="if(this.checked) this.value='true'; else this.value='false';"/> Nom
  18.             <br/>
  19.             <input type="checkbox" name="notoriete"  onchange="if(this.checked) this.value='true'; else this.value='false';"/> Notoriété (que pour praticiens)
  20.             <input type="checkbox" name="specialite"  onchange="if(this.checked) this.value='true'; else this.value='false';"/> Spécialité (que pour praticiens)
  21.         </div>
  22.         <br/>
  23.         <div class="choixTexte">
  24.             <label><strong>Localisation :</strong></label>
  25.             <input type="text" name="localisation" <?php if(!empty($_POST['localisation'])){ ?> value = <?php echo($_POST['localisation']);} ?>><br/>
  26.             <label><strong>Nom :</strong></label>
  27.             <input type="text" name="nom" <?php if(!empty($_POST['nom'])){ ?> value = <?php echo($_POST['nom']);} ?>><br/>
  28.             <label><strong>Spécialité : </strong>(que pour praticiens)</label>
  29.             <input type="text" name="specialite" <?php if(!empty($_POST['specialite'])){ ?> value = <?php echo($_POST['specialite']);} ?>><br/>
  30.             <label><strong>Notoriété : </strong>(que pour praticiens)</label>
  31.             <input type="text" name="notoriete" <?php if(!empty($_POST['notoriete'])){ ?> value = <?php echo($_POST['notoriete']);} ?>><br/>
  32.         </div>
  33.         <div class="choixAfficher">
  34.             <h3>Afficher les résultats :</h3>
  35.             <a class='btnListe' id="btnListe"><button>image Liste</button></a>
  36.             <a class='btnMaps' id="btnMaps"><button>image Maps</button></a>
  37.         </div>
  38.         <input type="submit" value="Rechercher">
  39.     </form>
  40. </div>
  41.  
  42. <div class='rechercheAffichage' id="rechercheAffichage">
  43.  
  44.  
  45.     <br/>
  46.     <br/>
  47.     <div id="map"></div>
  48.     <script type="text/javascript">
  49.  
  50.         // New York
  51.         var startlat = 48.864716;
  52.         var startlon = 2.349014;
  53.  
  54.         var options = {
  55.          center: [startlat, startlon],
  56.          zoom: 9
  57.         }
  58.  
  59.         var map = L.map('map', options);
  60.         var nzoom = 12;
  61.  
  62.         //L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {attribution: 'OSM'}).addTo(map);
  63.         var Hydda_Full = L.tileLayer('https://{s}.tile.openstreetmap.se/hydda/full/{z}/{x}/{y}.png', {
  64.             maxZoom: 18,
  65.             attribution: 'OSM'
  66.         }).addTo(map);
  67.  
  68.         // Liste dans laquelle on va rentre toutes les adresses des praticiens
  69.         var listePraticiens = <?php echo json_encode($listePraticiens);?>;
  70.         console.log(listePraticiens);
  71.         var listeAdresses = [];
  72.         var nouvelleAdresse = 0;
  73.         var rowsLA = <?php if(isset($listePraticiens)) {echo count($listePraticiens);} else {echo 0;}?>;
  74.         console.log("Nombre de lignes : " + rowsLA);
  75.         var colsLA = 2;
  76.  
  77.         // Création des lignes de la liste d'adresses
  78.         for( var i=0; i<rowsLA; i++ ) {
  79.           listeAdresses.push( [] );
  80.         }
  81.  
  82.         // Création des colonnes de la liste d'adresses
  83.         for (var i = 0; i < rowsLA; i++)
  84.         {
  85.             for (var j =  listeAdresses[i].length; j < colsLA; j++)
  86.             {
  87.                 listeAdresses[i].push(0);
  88.                
  89.                 if (listePraticiens[i].longitude == null || listePraticiens[i].latitude == null) {
  90.                     // On génère l'adresse complète pour rechercher sa longitude/latitude
  91.                     if (listePraticiens[i].numRue == 0) {
  92.                         var inp = listePraticiens[i].rue + ', ' + listePraticiens[i].cp + ' ' + listePraticiens[i].ville;
  93.                     } else {
  94.                         var inp = listePraticiens[i].numRue + ' ' + listePraticiens[i].rue + ', ' + listePraticiens[i].cp + ' ' + listePraticiens[i].ville;
  95.                     }
  96.                     setTimeout(function(){addr_search(inp)}, 2000);
  97.                     console.log(i + "g : " + inp);
  98.  
  99.                 } else { // Longitude & latitude déjà renseignées dans la BDD
  100.                     listeAdresses[i][0] = listePraticiens[i].latitude;
  101.                     listeAdresses[i][1] = listePraticiens[i].longitude;
  102.                 }
  103.                 //addr_search(inp);
  104.             }
  105.         }
  106.  
  107.  
  108.         var myMarker = L.marker([startlat, startlon], {title: "Coordinates", alt: "Coordinates", draggable: false}).addTo(map).on('dragend', function() {
  109.          var lat = myMarker.getLatLng().lat.toFixed(8);
  110.          var lon = myMarker.getLatLng().lng.toFixed(8);
  111.          var czoom = map.getZoom();
  112.          if(czoom < 18) { nzoom = czoom + 2; }
  113.          if(nzoom > 18) { nzoom = 18; }
  114.          if(czoom != 18) { map.setView([lat,lon], nzoom); } else { map.setView([lat,lon]); }
  115.          document.getElementById('lat').value = lat;
  116.          document.getElementById('lon').value = lon;
  117.          myMarker.bindPopup("Lat " + lat + "<br />Lon " + lon).openPopup();
  118.         });
  119.  
  120.         function chooseAddr(lat1, lng1)
  121.         {
  122.          myMarker.closePopup();
  123.          map.setView([lat1, lng1],18);
  124.          myMarker.setLatLng([lat1, lng1]);
  125.          lat = lat1.toFixed(8);
  126.          lon = lng1.toFixed(8);
  127.          document.getElementById('lat').value = lat;
  128.          document.getElementById('lon').value = lon;
  129.          myMarker.bindPopup("Lat " + lat + "<br />Lon " + lon).openPopup();
  130.         }
  131.  
  132.         function myFunction(arr)
  133.         {
  134.          var i;
  135.  
  136.          if(arr.length > 0)
  137.          {
  138.  
  139.           //chooseAddr(arr[0].lat, arr[0].lon);
  140.           console.log(arr);
  141.           listeAdresses[nouvelleAdresse][0] = arr[0].lat;
  142.           listeAdresses[nouvelleAdresse][1] = arr[0].lon;
  143.           nouvelleAdresse = nouvelleAdresse+1;
  144.           console.log(arr[0].lat + ", " + arr[0].lon);
  145.           // Ajout sur la carte des markers
  146.           for (var i = 0; i < listeAdresses.length; i++) {
  147.               marker = new L.marker([listeAdresses[i][0],listeAdresses[i][1]])
  148.                 .bindPopup(listeAdresses[i][0])
  149.                 .addTo(map);
  150.           }
  151.  
  152.           /*
  153.           for(i = 0; i < arr.length; i++) {
  154.            out += "<div class='address' title='Show Location and Coordinates' onclick='chooseAddr(" + arr[i].lat + ", " + arr[i].lon + ");return false;'>" + arr[i].display_name + "</div>";
  155.           }
  156.           document.getElementById('results').innerHTML = out;
  157.           */
  158.          }
  159.          else
  160.          {
  161.           document.getElementById('results').innerHTML = "Sorry, no results...";
  162.          }
  163.         }
  164.  
  165.         function addr_search(inp)
  166.         {
  167.          //var inp = document.getElementById("addr");
  168.          var xmlhttp = new XMLHttpRequest();
  169.          var url = "http://nominatim.openstreetmap.org/search?format=json&limit=3&q=" + inp;
  170.          xmlhttp.onreadystatechange = function()
  171.          {
  172.            if (this.readyState == 4 && this.status == 200)
  173.            {
  174.             var myArr = JSON.parse(this.responseText);
  175.             //console.log(myArr);
  176.             myFunction(myArr);
  177.            }
  178.          };
  179.          xmlhttp.open("GET", url, true);
  180.          setTimeout(function(){xmlhttp.send()}, 20000);
  181.          console.log(inp);
  182.          
  183.         }
  184.     </script>
  185. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement