/* 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].nom+""; if(json[i].nombre == 1) { if(available == true) display += ""+json[i].nombre+" vélo"; else display += ""+json[i].nombre+" emplacement"; } else { if(available == true) display += ""+json[i].nombre+" vélos"; else display += ""+json[i].nombre+" emplacements"; } } display += ""; document.getElementById('stations').innerHTML = display; } else if(station == true) //Else, if we want to display information about a specific station { var display = "

Station "+json[1].nom+" (À "+json[1].dist+" mètres)

"; 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+"
"+nombre+"
(À "+json[1].dist+" mètres)").openPopup(); else { if(json[i].bonus == 1) L.marker([json[1].lat, json[1].lng], {icon: parkingMarkerBonus}).addTo(map).bindPopup(""+json[i].nom+"
"+nombre+"
(À "+json[i].dist+" mètres)"); else L.marker([json[1].lat, json[1].lng], {icon: parkingMarker}).addTo(map).bindPopup(""+json[i].nom+"
"+nombre+"
(À "+json[i].dist+" mètres)"); } if(free) var routeType = "bicycle"; else var routeType = "pedestrian"; var route_line = L.Polyline.fromEncoded(json[1].directions, {color: 'blue'}).addTo(map); map.fitBounds(route_line.getBounds()); //Make the map size optimized for the content } else //Else, we want to display a map { var latitude_max = 0; var latitude_min = 90; var longitude_max = -180; var longitude_min = 180; for(var i = 1; i < json.length; i++) { var nombre; if(json[i].nombre == 1) { if(available == true) nombre = json[i].nombre+" vélo"; else nombre = json[i].nombre+" emplacement"; } else { if(available == true) nombre = json[i].nombre+" vélos"; else nombre = json[i].nombre+" emplacements"; } if(json[i].lat < latitude_min) latitude_min = json[i].lat; if(json[i].lat > latitude_max) latitude_max = json[i].lat; if(json[i].lng < longitude_min) longitude_min = json[i].lng; if(json[i].lng > longitude_max) longitude_max = json[i].lng; if(available) //Set the markers and popups L.marker([json[i].lat, json[i].lng], {icon: cycleMarker}).addTo(map).bindPopup(""+json[i].nom+"
"+nombre+"
(À "+json[i].dist+" mètres)"); else { if(json[i].bonus == 1) L.marker([json[i].lat, json[i].lng], {icon: parkingMarkerBonus}).addTo(map).bindPopup(""+json[i].nom+"
"+nombre+"
(À "+json[i].dist+" mètres)"); else L.marker([json[i].lat, json[i].lng], {icon: parkingMarker}).addTo(map).bindPopup(""+json[i].nom+"
"+nombre+"
(À "+json[i].dist+" mètres)"); } } map.fitBounds([[parseFloat(latitude_min), parseFloat(longitude_min)], [parseFloat(latitude_max) + 0.00015, parseFloat(longitude_max) + 0.00015]]); //0.00015 = margin because of markers size //Make the map fit the data } } } else { document.getElementById("stations").innerHTML = "

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 = "

Position :

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 = "

Position :

Latitude : "+latitude+", Longitude : "+longitude+" → ↻ Actualiser ?

"; document.getElementById("see_map").innerHTML = "

Voir la carte

"; } } 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 = "

Retirer un vélo ou Rendre un vélo"; } }