/* Config : À éditer selon vos besoins */
var tiles_provider = 'http://{s}.tile.osm.org/{z}/{x}/{y}.png';
var reverse_geolocation_provider = "http://open.mapquestapi.com/nominatim/v1/reverse.php";
var directions_provider = "http://router.project-osrm.org/viaroute";
var email = "webmaster@phyks.me"; //Mettre votre adresse e-mail ici si vous utilisez Nominatim (cf Usage Policy de Nominatim)
/* Script : */
window.onload = function() {
function params() //Get all the parameters in the URL
{
var t = location.search.substring(1).split('&');
var params = [];
for (var i=0; i
À "+json[i].dist+" mètres | "+json[i].nom+" | "; if(json[i].nombre == 1) { if(available == true) display += ""+json[i].nombre+" vélo | "+json[i].nombre+" emplacement | "; } else { if(available == true) display += ""+json[i].nombre+" vélos | "; else display += ""+json[i].nombre+" emplacements | "; } } display += "
Adresse : "+json[1].address+"
"; if(json[1].nombre == 1) { if(available == true) { display += "Il y a actuellement "+json[1].nombre+" vélo disponible.
"; nombre = "1 vélo"; } else { display += "Il y a actuellement "+json[1].nombre+" emplacement disponible.
"; nombre = "1 emplacement"; } } else { if(available == true) { display += "Il y a actuellement "+json[1].nombre+" vélos disponibles.
"; nombre = json[1].nombre+" vélos"; } else { display += "Il y a actuellement "+json[1].nombre+" emplacements disponibles.
"; nombre = json[1].nombre+" emplacements"; } } document.getElementById('stations').innerHTML = display; if(available) //Add the markers and the popups L.marker([json[1].lat, json[1].lng], {icon: cycleMarker}).addTo(map).bindPopup(json[1].nom+"La liste des stations n'a pu être récupérée.
"; } document.getElementById("adresse").innerHTML = json[0].reverse_geolocation+"→ ↻ Actualiser ?"; //Display the interesting part of the address } }; xhr.open("POST", "ajax.php", true); //xhr handle the data about stations xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.send("latitude=" + latitude + "&longitude=" + longitude + "&" + params_url + "&email=" + email + "&directions_provider="+ encodeURI(directions_provider) +"&reverse_geolocation_provider="+ encodeURI(reverse_geolocation_provider)); } if(map_get == true || station) //If we need a map { document.getElementById("position").innerHTML = "Latitude : "+latitude+", Longitude : "+longitude+" → ↻ Actualiser ?
"; // create a map in the "map" div, set the view to a given place and zoom var map = L.map('map').setView([latitude, longitude], 16); // add an OpenStreetMap tile layer L.tileLayer(tiles_provider, {attribution: '© OpenStreetMap contributors'}).addTo(map); var redMarker = L.icon({ iconUrl: 'images/marker-icon-red.png', shadowUrl: 'images/marker-shadow.png', iconSize: [25, 41], // size of the icon shadowSize: [41, 41], // size of the shadow iconAnchor: [12, 41], // point of the icon which will correspond to marker's location shadowAnchor: [12, 41], // the same for the shadow popupAnchor: [1, -34] // point from which the popup should open relative to the iconAnchor }); var cycleMarker = L.icon({ iconUrl: 'images/marker_cycle.png', shadowUrl: 'images/shadow_icons.png', iconSize: [32, 37], // size of the icon shadowSize: [38, 25], // size of the shadow iconAnchor: [16, 35], // point of the icon which will correspond to marker's location shadowAnchor: [11, 18], // the same for the shadow popupAnchor: [0, -31] // point from which the popup should open relative to the iconAnchor }); var parkingMarker = L.icon({ iconUrl: 'images/marker_parking.png', shadowUrl: 'images/shadow_icons.png', iconSize: [32, 37], // size of the icon shadowSize: [37, 21], // size of the shadow iconAnchor: [16, 35], // point of the icon which will correspond to marker's location shadowAnchor: [11, 18], // the same for the shadow popupAnchor: [0, -31] // point from which the popup should open relative to the iconAnchor }); var parkingMarkerBonus = L.icon({ iconUrl: 'images/marker_parking_bonus.png', shadowUrl: 'images/shadow_icons.png', iconSize: [32, 37], // size of the icon shadowSize: [37, 21], // size of the shadow iconAnchor: [16, 35], // point of the icon which will correspond to marker's location shadowAnchor: [11, 18], // the same for the shadow popupAnchor: [0, -31] // point from which the popup should open relative to the iconAnchor }); // add a marker in the given location, attach some popup content to it and open the popup var position_marker = L.marker([latitude, longitude], {icon: redMarker}).addTo(map); position_marker.bindPopup('Ma position.'); } else { document.getElementById("position").innerHTML = "Latitude : "+latitude+", Longitude : "+longitude+" → ↻ Actualiser ?
"; document.getElementById("see_map").innerHTML = ""; } } function errorFunction(error) //Handle errors { switch(error.code) { case error.TIMEOUT: //Restart with a greater timeout if(refresh) navigator.geolocation.getCurrentPosition(successFunction, errorFunction, {enableHighAccuracy:true, maximumAge:0, timeout:20000}); else navigator.geolocation.getCurrentPosition(successFunction, errorFunction, {enableHighAccuracy:true, maximumAge:60000, timeout:20000}); break; case error.PERMISSION_DENIED: document.getElementById("position").innerHTML = "Erreur : L'application n'a pas l'autorisation d'utiliser les ressources de geolocalisation.
"; break; case error.POSITION_UNAVAILABLE: document.getElementById("position").innerHTML = "Erreur : La position n'a pu être déterminée.
"; break; default: document.getElementById("position").innerHTML = "Erreur "+error.code+" : "+error.message+"
"; break; } } if(refresh) //If refresh, we want to force a new position (non cached) navigator.geolocation.getCurrentPosition(successFunction, errorFunction, {enableHighAccuracy:true, maximumAge:0, timeout:2000}); else navigator.geolocation.getCurrentPosition(successFunction, errorFunction, {enableHighAccuracy:true, maximumAge:60000, timeout:2000}); //Else, we are ok with 60 seconds old position } else { document.getElementById("position").innerHTML = "Votre navigateur doit prendre en charge la géolocalisation pour que ce site puisse fonctionner correctement.
"; } } else //If we didn't choose what to do, display the choices { document.getElementById("position").innerHTML = "